You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.4 KiB

7 years ago
  1. package main
  2. import (
  3. "bytes"
  4. "fmt"
  5. "os"
  6. abcicli "github.com/tendermint/tendermint/abci/client"
  7. "github.com/tendermint/tendermint/abci/types"
  8. "github.com/tendermint/tendermint/libs/log"
  9. )
  10. func startClient(abciType string) abcicli.Client {
  11. // Start client
  12. client, err := abcicli.NewClient("tcp://127.0.0.1:26658", abciType, true)
  13. if err != nil {
  14. panic(err.Error())
  15. }
  16. logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
  17. client.SetLogger(logger.With("module", "abcicli"))
  18. if err := client.Start(); err != nil {
  19. panicf("connecting to abci_app: %v", err.Error())
  20. }
  21. return client
  22. }
  23. func commit(client abcicli.Client, hashExp []byte) {
  24. res, err := client.CommitSync()
  25. if err != nil {
  26. panicf("client error: %v", err)
  27. }
  28. if !bytes.Equal(res.Data, hashExp) {
  29. panicf("Commit hash was unexpected. Got %X expected %X", res.Data, hashExp)
  30. }
  31. }
  32. func deliverTx(client abcicli.Client, txBytes []byte, codeExp uint32, dataExp []byte) {
  33. res, err := client.DeliverTxSync(types.RequestDeliverTx{Tx: txBytes})
  34. if err != nil {
  35. panicf("client error: %v", err)
  36. }
  37. if res.Code != codeExp {
  38. panicf("DeliverTx response code was unexpected. Got %v expected %v. Log: %v", res.Code, codeExp, res.Log)
  39. }
  40. if !bytes.Equal(res.Data, dataExp) {
  41. panicf("DeliverTx response data was unexpected. Got %X expected %X", res.Data, dataExp)
  42. }
  43. }
  44. func panicf(format string, a ...interface{}) {
  45. panic(fmt.Sprintf(format, a...))
  46. }