93 lines
2.3 KiB
Go
Raw Normal View History

2016-02-14 14:59:53 -08:00
package main
import (
"bytes"
"os"
"time"
. "github.com/tendermint/go-common"
"github.com/tendermint/go-process"
"github.com/tendermint/tmsp/client"
"github.com/tendermint/tmsp/types"
)
//----------------------------------------
2016-07-23 18:54:58 -04:00
func StartApp(tmspApp string) *process.Process {
2016-02-14 14:59:53 -08:00
// Start the app
//outBuf := NewBufferCloser(nil)
2016-07-23 18:54:58 -04:00
proc, err := process.StartProcess("tmsp_app",
2016-12-06 02:15:32 -08:00
"",
2016-02-14 14:59:53 -08:00
"bash",
2016-07-23 18:54:58 -04:00
[]string{"-c", tmspApp},
2016-02-14 14:59:53 -08:00
nil,
os.Stdout,
)
if err != nil {
2016-07-23 18:54:58 -04:00
panic("running tmsp_app: " + err.Error())
2016-02-14 14:59:53 -08:00
}
// TODO a better way to handle this?
time.Sleep(time.Second)
return proc
}
2016-07-23 18:54:58 -04:00
func StartClient(tmspType string) tmspcli.Client {
2016-02-14 14:59:53 -08:00
// Start client
2016-07-23 18:54:58 -04:00
client, err := tmspcli.NewClient("tcp://127.0.0.1:46658", tmspType, true)
2016-02-14 14:59:53 -08:00
if err != nil {
2016-07-23 18:54:58 -04:00
panic("connecting to tmsp_app: " + err.Error())
2016-02-14 14:59:53 -08:00
}
return client
}
2016-07-23 18:54:58 -04:00
func SetOption(client tmspcli.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() {
panic(Fmt("setting %v=%v: \nlog: %v", key, value, log))
2016-02-14 14:59:53 -08:00
}
}
2016-07-23 18:54:58 -04:00
func Commit(client tmspcli.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() {
panic(Fmt("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) {
2016-02-14 14:59:53 -08:00
panic(Fmt("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
}
}
2016-07-23 18:54:58 -04:00
func AppendTx(client tmspcli.Client, txBytes []byte, codeExp types.CodeType, dataExp []byte) {
2016-03-23 02:50:29 -07:00
res := client.AppendTxSync(txBytes)
code, data, log := res.Code, res.Data, res.Log
2016-02-14 14:59:53 -08:00
if code != codeExp {
panic(Fmt("AppendTx response code was unexpected. Got %v expected %v. Log: %v",
code, codeExp, log))
}
if !bytes.Equal(data, dataExp) {
panic(Fmt("AppendTx response data was unexpected. Got %X expected %X",
data, dataExp))
}
}
2016-07-23 18:54:58 -04:00
func CheckTx(client tmspcli.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() {
panic(Fmt("checking tx %X: %v\nlog: %v", txBytes, log))
2016-02-14 14:59:53 -08:00
}
if code != codeExp {
panic(Fmt("CheckTx response code was unexpected. Got %v expected %v. Log: %v",
code, codeExp, log))
}
if !bytes.Equal(data, dataExp) {
panic(Fmt("CheckTx response data was unexpected. Got %X expected %X",
data, dataExp))
}
}