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.

93 lines
2.4 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. package main
  2. import (
  3. "bytes"
  4. "fmt"
  5. "os"
  6. "time"
  7. abcicli "github.com/tendermint/abci/client"
  8. "github.com/tendermint/abci/types"
  9. "github.com/tendermint/tmlibs/log"
  10. "github.com/tendermint/tmlibs/process"
  11. )
  12. func startApp(abciApp string) *process.Process {
  13. // Start the app
  14. //outBuf := NewBufferCloser(nil)
  15. proc, err := process.StartProcess("abci_app",
  16. "",
  17. "bash",
  18. []string{"-c", abciApp},
  19. nil,
  20. os.Stdout,
  21. )
  22. if err != nil {
  23. panic("running abci_app: " + err.Error())
  24. }
  25. // TODO a better way to handle this?
  26. time.Sleep(time.Second)
  27. return proc
  28. }
  29. func startClient(abciType string) abcicli.Client {
  30. // Start client
  31. client, err := abcicli.NewClient("tcp://127.0.0.1:46658", abciType, true)
  32. if err != nil {
  33. panic("connecting to abci_app: " + err.Error())
  34. }
  35. logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
  36. client.SetLogger(logger.With("module", "abcicli"))
  37. return client
  38. }
  39. func setOption(client abcicli.Client, key, value string) {
  40. res := client.SetOptionSync(key, value)
  41. _, _, log := res.Code, res.Data, res.Log
  42. if res.IsErr() {
  43. panic(fmt.Sprintf("setting %v=%v: \nlog: %v", key, value, log))
  44. }
  45. }
  46. func commit(client abcicli.Client, hashExp []byte) {
  47. res := client.CommitSync()
  48. _, data, log := res.Code, res.Data, res.Log
  49. if res.IsErr() {
  50. panic(fmt.Sprintf("committing %v\nlog: %v", log))
  51. }
  52. if !bytes.Equal(res.Data, hashExp) {
  53. panic(fmt.Sprintf("Commit hash was unexpected. Got %X expected %X",
  54. data, hashExp))
  55. }
  56. }
  57. func deliverTx(client abcicli.Client, txBytes []byte, codeExp types.CodeType, dataExp []byte) {
  58. res := client.DeliverTxSync(txBytes)
  59. code, data, log := res.Code, res.Data, res.Log
  60. if code != codeExp {
  61. panic(fmt.Sprintf("DeliverTx response code was unexpected. Got %v expected %v. Log: %v",
  62. code, codeExp, log))
  63. }
  64. if !bytes.Equal(data, dataExp) {
  65. panic(fmt.Sprintf("DeliverTx response data was unexpected. Got %X expected %X",
  66. data, dataExp))
  67. }
  68. }
  69. func checkTx(client abcicli.Client, txBytes []byte, codeExp types.CodeType, dataExp []byte) {
  70. res := client.CheckTxSync(txBytes)
  71. code, data, log := res.Code, res.Data, res.Log
  72. if res.IsErr() {
  73. panic(fmt.Sprintf("checking tx %X: %v\nlog: %v", txBytes, log))
  74. }
  75. if code != codeExp {
  76. panic(fmt.Sprintf("CheckTx response code was unexpected. Got %v expected %v. Log: %v",
  77. code, codeExp, log))
  78. }
  79. if !bytes.Equal(data, dataExp) {
  80. panic(fmt.Sprintf("CheckTx response data was unexpected. Got %X expected %X",
  81. data, dataExp))
  82. }
  83. }