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.

81 lines
2.1 KiB

8 years ago
8 years ago
8 years ago
8 years ago
7 years ago
7 years ago
7 years ago
  1. package main
  2. import (
  3. "bytes"
  4. "fmt"
  5. "os"
  6. abcicli "github.com/tendermint/abci/client"
  7. "github.com/tendermint/abci/types"
  8. "github.com/tendermint/tmlibs/log"
  9. )
  10. func startClient(abciType string) abcicli.Client {
  11. // Start client
  12. client, err := abcicli.NewClient("tcp://127.0.0.1:46658", 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 res.IsErr() {
  35. panicf("committing err %v\n", res)
  36. }
  37. if !bytes.Equal(res.Data, hashExp) {
  38. panicf("Commit hash was unexpected. Got %X expected %X", res.Data, hashExp)
  39. }
  40. }
  41. func deliverTx(client abcicli.Client, txBytes []byte, codeExp uint32, dataExp []byte) {
  42. res, err := client.DeliverTxSync(txBytes)
  43. if err != nil {
  44. panicf("client error: %v", err)
  45. }
  46. if res.Code != codeExp {
  47. panicf("DeliverTx response code was unexpected. Got %v expected %v. Log: %v", res.Code, codeExp, res.Log)
  48. }
  49. if !bytes.Equal(res.Data, dataExp) {
  50. panicf("DeliverTx response data was unexpected. Got %X expected %X", res.Data, dataExp)
  51. }
  52. }
  53. /*func checkTx(client abcicli.Client, txBytes []byte, codeExp uint32, dataExp []byte) {
  54. res, err := client.CheckTxSync(txBytes)
  55. if err != nil {
  56. panicf("client error: %v", err)
  57. }
  58. if res.IsErr() {
  59. panicf("checking tx %X: %v\nlog: %v", txBytes, res.Log)
  60. }
  61. if res.Code != codeExp {
  62. panicf("CheckTx response code was unexpected. Got %v expected %v. Log: %v",
  63. res.Code, codeExp, res.Log)
  64. }
  65. if !bytes.Equal(res.Data, dataExp) {
  66. panicf("CheckTx response data was unexpected. Got %X expected %X",
  67. res.Data, dataExp)
  68. }
  69. }*/
  70. func panicf(format string, a ...interface{}) {
  71. panic(fmt.Sprintf(format, a...))
  72. }