tendermint/tests/test_app/app.go

79 lines
2.1 KiB
Go
Raw Normal View History

2016-02-14 14:59:53 -08:00
package main
import (
"bytes"
"fmt"
2016-02-14 14:59:53 -08:00
"os"
2017-04-27 13:37:18 -07:00
abcicli "github.com/tendermint/abci/client"
2017-01-12 12:47:55 -08:00
"github.com/tendermint/abci/types"
2017-04-27 13:37:18 -07:00
"github.com/tendermint/tmlibs/log"
2016-02-14 14:59:53 -08:00
)
func startClient(abciType string) abcicli.Client {
2016-02-14 14:59:53 -08:00
// Start client
2017-01-12 12:47:55 -08:00
client, err := abcicli.NewClient("tcp://127.0.0.1:46658", abciType, true)
2016-02-14 14:59:53 -08:00
if err != nil {
panic(err.Error())
}
2017-05-15 09:59:44 -07:00
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
client.SetLogger(logger.With("module", "abcicli"))
2017-12-26 00:45:31 -08:00
if _, err := client.Start(); err != nil {
panicf("connecting to abci_app: %v", err.Error())
2016-02-14 14:59:53 -08:00
}
2016-02-14 14:59:53 -08:00
return client
}
func setOption(client abcicli.Client, key, value string) {
2017-11-27 11:52:06 -08:00
_, err := client.SetOptionSync(types.RequestSetOption{key, value})
if err != nil {
panicf("setting %v=%v: \nerr: %v", key, value, err)
2016-02-14 14:59:53 -08:00
}
}
func commit(client abcicli.Client, hashExp []byte) {
res, err := client.CommitSync()
if err != nil {
panicf("client error: %v", err)
}
2016-03-23 02:50:29 -07:00
if !bytes.Equal(res.Data, hashExp) {
panicf("Commit hash was unexpected. Got %X expected %X", res.Data, hashExp)
2016-02-14 14:59:53 -08:00
}
}
2017-11-30 11:29:12 -08:00
func deliverTx(client abcicli.Client, txBytes []byte, codeExp uint32, dataExp []byte) {
res, err := client.DeliverTxSync(txBytes)
if err != nil {
panicf("client error: %v", err)
}
if res.Code != codeExp {
panicf("DeliverTx response code was unexpected. Got %v expected %v. Log: %v", res.Code, codeExp, res.Log)
2016-02-14 14:59:53 -08:00
}
if !bytes.Equal(res.Data, dataExp) {
panicf("DeliverTx response data was unexpected. Got %X expected %X", res.Data, dataExp)
2016-02-14 14:59:53 -08:00
}
}
2017-11-30 11:29:12 -08:00
/*func checkTx(client abcicli.Client, txBytes []byte, codeExp uint32, dataExp []byte) {
res, err := client.CheckTxSync(txBytes)
if err != nil {
panicf("client error: %v", err)
}
2016-03-23 02:50:29 -07:00
if res.IsErr() {
panicf("checking tx %X: %v\nlog: %v", txBytes, res.Log)
2016-02-14 14:59:53 -08:00
}
if res.Code != codeExp {
panicf("CheckTx response code was unexpected. Got %v expected %v. Log: %v",
res.Code, codeExp, res.Log)
2016-02-14 14:59:53 -08:00
}
if !bytes.Equal(res.Data, dataExp) {
panicf("CheckTx response data was unexpected. Got %X expected %X",
res.Data, dataExp)
2016-02-14 14:59:53 -08:00
}
2017-09-21 12:26:43 -07:00
}*/
func panicf(format string, a ...interface{}) {
2017-11-22 17:38:04 -08:00
panic(fmt.Sprintf(format, a...))
}