tendermint/tests/test_app/app.go

91 lines
2.3 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"
"time"
2017-01-12 12:47:55 -08:00
"github.com/tendermint/abci/client"
"github.com/tendermint/abci/types"
2017-04-21 15:25:13 -07:00
"github.com/tendermint/tmlibs/process"
2016-02-14 14:59:53 -08:00
)
func startApp(abciApp string) *process.Process {
2016-02-14 14:59:53 -08:00
// Start the app
//outBuf := NewBufferCloser(nil)
2017-01-12 12:47:55 -08:00
proc, err := process.StartProcess("abci_app",
2016-12-06 02:15:32 -08:00
"",
2016-02-14 14:59:53 -08:00
"bash",
2017-01-12 12:47:55 -08:00
[]string{"-c", abciApp},
2016-02-14 14:59:53 -08:00
nil,
os.Stdout,
)
if err != nil {
2017-01-12 12:47:55 -08:00
panic("running abci_app: " + err.Error())
2016-02-14 14:59:53 -08:00
}
// TODO a better way to handle this?
time.Sleep(time.Second)
return proc
}
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 {
2017-01-12 12:47:55 -08:00
panic("connecting to abci_app: " + err.Error())
2016-02-14 14:59:53 -08:00
}
return client
}
func setOption(client abcicli.Client, key, value string) {
2016-03-24 10:19:48 -07:00
res := client.SetOptionSync(key, value)
_, _, log := res.Code, res.Data, res.Log
if res.IsErr() {
2017-01-16 22:59:46 -08:00
panic(fmt.Sprintf("setting %v=%v: \nlog: %v", key, value, log))
2016-02-14 14:59:53 -08:00
}
}
func commit(client abcicli.Client, hashExp []byte) {
2016-03-23 02:50:29 -07:00
res := client.CommitSync()
_, data, log := res.Code, res.Data, res.Log
if res.IsErr() {
2017-01-16 22:59:46 -08:00
panic(fmt.Sprintf("committing %v\nlog: %v", log))
2016-02-14 14:59:53 -08:00
}
2016-03-23 02:50:29 -07:00
if !bytes.Equal(res.Data, hashExp) {
2017-01-16 22:59:46 -08:00
panic(fmt.Sprintf("Commit hash was unexpected. Got %X expected %X",
2016-03-23 02:50:29 -07:00
data, hashExp))
2016-02-14 14:59:53 -08:00
}
}
func deliverTx(client abcicli.Client, txBytes []byte, codeExp types.CodeType, dataExp []byte) {
2017-01-12 12:27:08 -08:00
res := client.DeliverTxSync(txBytes)
2016-03-23 02:50:29 -07:00
code, data, log := res.Code, res.Data, res.Log
2016-02-14 14:59:53 -08:00
if code != codeExp {
2017-01-16 22:59:46 -08:00
panic(fmt.Sprintf("DeliverTx response code was unexpected. Got %v expected %v. Log: %v",
2016-02-14 14:59:53 -08:00
code, codeExp, log))
}
if !bytes.Equal(data, dataExp) {
2017-01-16 22:59:46 -08:00
panic(fmt.Sprintf("DeliverTx response data was unexpected. Got %X expected %X",
2016-02-14 14:59:53 -08:00
data, dataExp))
}
}
func checkTx(client abcicli.Client, txBytes []byte, codeExp types.CodeType, dataExp []byte) {
2016-03-23 02:50:29 -07:00
res := client.CheckTxSync(txBytes)
code, data, log := res.Code, res.Data, res.Log
if res.IsErr() {
2017-01-16 22:59:46 -08:00
panic(fmt.Sprintf("checking tx %X: %v\nlog: %v", txBytes, log))
2016-02-14 14:59:53 -08:00
}
if code != codeExp {
2017-01-16 22:59:46 -08:00
panic(fmt.Sprintf("CheckTx response code was unexpected. Got %v expected %v. Log: %v",
2016-02-14 14:59:53 -08:00
code, codeExp, log))
}
if !bytes.Equal(data, dataExp) {
2017-01-16 22:59:46 -08:00
panic(fmt.Sprintf("CheckTx response data was unexpected. Got %X expected %X",
2016-02-14 14:59:53 -08:00
data, dataExp))
}
}