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.

56 lines
1.4 KiB

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