tendermint/tests/test_app/app.go

98 lines
2.5 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-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"
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-11-14 10:53:40 -08:00
[]string{"-c", fmt.Sprintf("abci-cli %s", 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 {
panic(err.Error())
}
2017-05-15 09:59:44 -07:00
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
client.SetLogger(logger.With("module", "abcicli"))
if _, err := client.Start(); 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
}
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()
2017-09-22 06:45:50 -07:00
_, data, _ := res.Code, res.Data, res.Log
2016-03-23 02:50:29 -07:00
if res.IsErr() {
2017-09-22 06:14:20 -07:00
panic(fmt.Sprintf("committing err %v\n", res))
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))
}
}
2017-09-21 12:26:43 -07:00
/*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))
}
2017-09-21 12:26:43 -07:00
}*/