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.

78 lines
2.1 KiB

  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 setOption(client abcicli.Client, key, value string) {
  24. _, err := client.SetOptionSync(types.RequestSetOption{key, value})
  25. if err != nil {
  26. panicf("setting %v=%v: \nerr: %v", key, value, err)
  27. }
  28. }
  29. func commit(client abcicli.Client, hashExp []byte) {
  30. res, err := client.CommitSync()
  31. if err != nil {
  32. panicf("client error: %v", err)
  33. }
  34. if !bytes.Equal(res.Data, hashExp) {
  35. panicf("Commit hash was unexpected. Got %X expected %X", res.Data, hashExp)
  36. }
  37. }
  38. func deliverTx(client abcicli.Client, txBytes []byte, codeExp uint32, dataExp []byte) {
  39. res, err := client.DeliverTxSync(txBytes)
  40. if err != nil {
  41. panicf("client error: %v", err)
  42. }
  43. if res.Code != codeExp {
  44. panicf("DeliverTx response code was unexpected. Got %v expected %v. Log: %v", res.Code, codeExp, res.Log)
  45. }
  46. if !bytes.Equal(res.Data, dataExp) {
  47. panicf("DeliverTx response data was unexpected. Got %X expected %X", res.Data, dataExp)
  48. }
  49. }
  50. /*func checkTx(client abcicli.Client, txBytes []byte, codeExp uint32, dataExp []byte) {
  51. res, err := client.CheckTxSync(txBytes)
  52. if err != nil {
  53. panicf("client error: %v", err)
  54. }
  55. if res.IsErr() {
  56. panicf("checking tx %X: %v\nlog: %v", txBytes, res.Log)
  57. }
  58. if res.Code != codeExp {
  59. panicf("CheckTx response code was unexpected. Got %v expected %v. Log: %v",
  60. res.Code, codeExp, res.Log)
  61. }
  62. if !bytes.Equal(res.Data, dataExp) {
  63. panicf("CheckTx response data was unexpected. Got %X expected %X",
  64. res.Data, dataExp)
  65. }
  66. }*/
  67. func panicf(format string, a ...interface{}) {
  68. panic(fmt.Sprintf(format, a...))
  69. }