github.com/aergoio/aergo@v1.3.1/contract/measure/main.go (about) 1 // +build measure 2 3 package main 4 5 import ( 6 "io/ioutil" 7 "log" 8 9 "github.com/aergoio/aergo/contract" 10 ) 11 12 func main() { 13 bc, err := contract.LoadDummyChain() 14 if err != nil { 15 log.Printf("failed to create test database: %v\n", err) 16 } 17 18 err = bc.ConnectBlock( 19 contract.NewLuaTxAccount("ktlee", 100), 20 ) 21 if err != nil { 22 log.Println(err) 23 } 24 25 runner := func(luaFileName, mainFuncName string) { 26 src, err := ioutil.ReadFile(luaFileName) 27 if err != nil { 28 log.Printf("can not read `%s`: %s", luaFileName, err.Error()) 29 } 30 31 err = bc.ConnectBlock( 32 contract.NewLuaTxDef("ktlee", luaFileName, 0, string(src)), 33 ) 34 if err != nil { 35 log.Println(err) 36 } 37 38 err = bc.ConnectBlock( 39 contract.NewLuaTxCall("ktlee", luaFileName, 0, `{"Name": "`+mainFuncName+`"}`), 40 ) 41 if err != nil { 42 log.Println(err) 43 } 44 } 45 46 runner("./bf.lua", "basic_fns") 47 runner("./bf.lua", "string_fns") 48 runner("./bf.lua", "table_fns1") 49 runner("./bf.lua", "table_fns2") 50 runner("./bf.lua", "table_fns3") 51 runner("./bf.lua", "table_fns4") 52 runner("./bf.lua", "math_fns") 53 runner("./bf.lua", "bit_fns") 54 runner("./aef.lua", "run_test") 55 }