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.

97 lines
2.5 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
7 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", fmt.Sprintf("abci-cli %s", 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(err.Error())
  34. }
  35. logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
  36. client.SetLogger(logger.With("module", "abcicli"))
  37. if _, err := client.Start(); err != nil {
  38. panic("connecting to abci_app: " + err.Error())
  39. }
  40. return client
  41. }
  42. func setOption(client abcicli.Client, key, value string) {
  43. res := client.SetOptionSync(key, value)
  44. _, _, log := res.Code, res.Data, res.Log
  45. if res.IsErr() {
  46. panic(fmt.Sprintf("setting %v=%v: \nlog: %v", key, value, log))
  47. }
  48. }
  49. func commit(client abcicli.Client, hashExp []byte) {
  50. res := client.CommitSync()
  51. _, data, _ := res.Code, res.Data, res.Log
  52. if res.IsErr() {
  53. panic(fmt.Sprintf("committing err %v\n", res))
  54. }
  55. if !bytes.Equal(res.Data, hashExp) {
  56. panic(fmt.Sprintf("Commit hash was unexpected. Got %X expected %X",
  57. data, hashExp))
  58. }
  59. }
  60. func deliverTx(client abcicli.Client, txBytes []byte, codeExp types.CodeType, dataExp []byte) {
  61. res := client.DeliverTxSync(txBytes)
  62. code, data, log := res.Code, res.Data, res.Log
  63. if code != codeExp {
  64. panic(fmt.Sprintf("DeliverTx response code was unexpected. Got %v expected %v. Log: %v",
  65. code, codeExp, log))
  66. }
  67. if !bytes.Equal(data, dataExp) {
  68. panic(fmt.Sprintf("DeliverTx response data was unexpected. Got %X expected %X",
  69. data, dataExp))
  70. }
  71. }
  72. /*func checkTx(client abcicli.Client, txBytes []byte, codeExp types.CodeType, dataExp []byte) {
  73. res := client.CheckTxSync(txBytes)
  74. code, data, log := res.Code, res.Data, res.Log
  75. if res.IsErr() {
  76. panic(fmt.Sprintf("checking tx %X: %v\nlog: %v", txBytes, log))
  77. }
  78. if code != codeExp {
  79. panic(fmt.Sprintf("CheckTx response code was unexpected. Got %v expected %v. Log: %v",
  80. code, codeExp, log))
  81. }
  82. if !bytes.Equal(data, dataExp) {
  83. panic(fmt.Sprintf("CheckTx response data was unexpected. Got %X expected %X",
  84. data, dataExp))
  85. }
  86. }*/