mirror of
https://github.com/fluencelabs/tendermint
synced 2025-05-29 06:01:21 +00:00
Spell out the package explicitly. This commit is totally textual, and does not change any logic. The swiss-army knife package may serve a kick-start in early stage development. But as the codebase growing, we might want to retire it gradually: For simple wrapping functions, just inline it on the call site. For larger pice of code, make it an independent package.
93 lines
2.3 KiB
Go
93 lines
2.3 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"os"
|
|
"time"
|
|
|
|
"github.com/tendermint/abci/client"
|
|
"github.com/tendermint/abci/types"
|
|
common "github.com/tendermint/go-common"
|
|
"github.com/tendermint/go-process"
|
|
)
|
|
|
|
//----------------------------------------
|
|
|
|
func StartApp(abciApp string) *process.Process {
|
|
// Start the app
|
|
//outBuf := NewBufferCloser(nil)
|
|
proc, err := process.StartProcess("abci_app",
|
|
"",
|
|
"bash",
|
|
[]string{"-c", abciApp},
|
|
nil,
|
|
os.Stdout,
|
|
)
|
|
if err != nil {
|
|
panic("running abci_app: " + err.Error())
|
|
}
|
|
|
|
// TODO a better way to handle this?
|
|
time.Sleep(time.Second)
|
|
|
|
return proc
|
|
}
|
|
|
|
func StartClient(abciType string) abcicli.Client {
|
|
// Start client
|
|
client, err := abcicli.NewClient("tcp://127.0.0.1:46658", abciType, true)
|
|
if err != nil {
|
|
panic("connecting to abci_app: " + err.Error())
|
|
}
|
|
return client
|
|
}
|
|
|
|
func SetOption(client abcicli.Client, key, value string) {
|
|
res := client.SetOptionSync(key, value)
|
|
_, _, log := res.Code, res.Data, res.Log
|
|
if res.IsErr() {
|
|
panic(common.Fmt("setting %v=%v: \nlog: %v", key, value, log))
|
|
}
|
|
}
|
|
|
|
func Commit(client abcicli.Client, hashExp []byte) {
|
|
res := client.CommitSync()
|
|
_, data, log := res.Code, res.Data, res.Log
|
|
if res.IsErr() {
|
|
panic(common.Fmt("committing %v\nlog: %v", log))
|
|
}
|
|
if !bytes.Equal(res.Data, hashExp) {
|
|
panic(common.Fmt("Commit hash was unexpected. Got %X expected %X",
|
|
data, hashExp))
|
|
}
|
|
}
|
|
|
|
func DeliverTx(client abcicli.Client, txBytes []byte, codeExp types.CodeType, dataExp []byte) {
|
|
res := client.DeliverTxSync(txBytes)
|
|
code, data, log := res.Code, res.Data, res.Log
|
|
if code != codeExp {
|
|
panic(common.Fmt("DeliverTx response code was unexpected. Got %v expected %v. Log: %v",
|
|
code, codeExp, log))
|
|
}
|
|
if !bytes.Equal(data, dataExp) {
|
|
panic(common.Fmt("DeliverTx response data was unexpected. Got %X expected %X",
|
|
data, dataExp))
|
|
}
|
|
}
|
|
|
|
func CheckTx(client abcicli.Client, txBytes []byte, codeExp types.CodeType, dataExp []byte) {
|
|
res := client.CheckTxSync(txBytes)
|
|
code, data, log := res.Code, res.Data, res.Log
|
|
if res.IsErr() {
|
|
panic(common.Fmt("checking tx %X: %v\nlog: %v", txBytes, log))
|
|
}
|
|
if code != codeExp {
|
|
panic(common.Fmt("CheckTx response code was unexpected. Got %v expected %v. Log: %v",
|
|
code, codeExp, log))
|
|
}
|
|
if !bytes.Equal(data, dataExp) {
|
|
panic(common.Fmt("CheckTx response data was unexpected. Got %X expected %X",
|
|
data, dataExp))
|
|
}
|
|
}
|