github.com/line/ostracon@v1.0.10-0.20230328032236-7f20145f065d/abci/tests/test_app/app.go (about) 1 package main 2 3 import ( 4 "bytes" 5 "fmt" 6 "os" 7 8 "github.com/tendermint/tendermint/abci/types" 9 10 abcicli "github.com/line/ostracon/abci/client" 11 "github.com/line/ostracon/libs/log" 12 ) 13 14 func startClient(abciType string) abcicli.Client { 15 // Start client 16 client, err := abcicli.NewClient("tcp://127.0.0.1:26658", abciType, true) 17 if err != nil { 18 panic(err.Error()) 19 } 20 logger := log.NewOCLogger(log.NewSyncWriter(os.Stdout)) 21 client.SetLogger(logger.With("module", "abcicli")) 22 if err := client.Start(); err != nil { 23 panicf("connecting to abci_app: %v", err.Error()) 24 } 25 26 return client 27 } 28 29 func setOption(client abcicli.Client, key, value string) { 30 _, err := client.SetOptionSync(types.RequestSetOption{Key: key, Value: value}) 31 if err != nil { 32 panicf("setting %v=%v: \nerr: %v", key, value, err) 33 } 34 } 35 36 func commit(client abcicli.Client, hashExp []byte) { 37 res, err := client.CommitSync() 38 if err != nil { 39 panicf("client error: %v", err) 40 } 41 if !bytes.Equal(res.Data, hashExp) { 42 panicf("Commit hash was unexpected. Got %X expected %X", res.Data, hashExp) 43 } 44 } 45 46 func deliverTx(client abcicli.Client, txBytes []byte, codeExp uint32, dataExp []byte) { 47 res, err := client.DeliverTxSync(types.RequestDeliverTx{Tx: txBytes}) 48 if err != nil { 49 panicf("client error: %v", err) 50 } 51 if res.Code != codeExp { 52 panicf("DeliverTx response code was unexpected. Got %v expected %v. Log: %v", res.Code, codeExp, res.Log) 53 } 54 if !bytes.Equal(res.Data, dataExp) { 55 panicf("DeliverTx response data was unexpected. Got %X expected %X", res.Data, dataExp) 56 } 57 } 58 59 /*func checkTx(client abcicli.Client, txBytes []byte, codeExp uint32, dataExp []byte) { 60 res, err := client.CheckTxSync(txBytes) 61 if err != nil { 62 panicf("client error: %v", err) 63 } 64 if res.IsErr() { 65 panicf("checking tx %X: %v\nlog: %v", txBytes, res.Log) 66 } 67 if res.Code != codeExp { 68 panicf("CheckTx response code was unexpected. Got %v expected %v. Log: %v", 69 res.Code, codeExp, res.Log) 70 } 71 if !bytes.Equal(res.Data, dataExp) { 72 panicf("CheckTx response data was unexpected. Got %X expected %X", 73 res.Data, dataExp) 74 } 75 }*/ 76 77 func panicf(format string, a ...interface{}) { 78 panic(fmt.Sprintf(format, a...)) 79 }