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.

55 lines
1.5 KiB

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