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.

103 lines
2.6 KiB

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. panicf("running abci_app: %v", err)
  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. panicf("connecting to abci_app: %v", err.Error())
  39. }
  40. return client
  41. }
  42. func setOption(client abcicli.Client, key, value string) {
  43. _, err := client.SetOptionSync(types.RequestSetOption{key, value})
  44. if err != nil {
  45. panicf("setting %v=%v: \nerr: %v", key, value, err)
  46. }
  47. }
  48. func commit(client abcicli.Client, hashExp []byte) {
  49. res, err := client.CommitSync()
  50. if err != nil {
  51. panicf("client error: %v", err)
  52. }
  53. if res.IsErr() {
  54. panicf("committing err %v\n", res)
  55. }
  56. if !bytes.Equal(res.Data, hashExp) {
  57. panicf("Commit hash was unexpected. Got %X expected %X", res.Data, hashExp)
  58. }
  59. }
  60. func deliverTx(client abcicli.Client, txBytes []byte, codeExp types.CodeType, dataExp []byte) {
  61. res, err := client.DeliverTxSync(txBytes)
  62. if err != nil {
  63. panicf("client error: %v", err)
  64. }
  65. if res.Code != codeExp {
  66. panicf("DeliverTx response code was unexpected. Got %v expected %v. Log: %v", res.Code, codeExp, res.Log)
  67. }
  68. if !bytes.Equal(res.Data, dataExp) {
  69. panicf("DeliverTx response data was unexpected. Got %X expected %X", res.Data, dataExp)
  70. }
  71. }
  72. /*func checkTx(client abcicli.Client, txBytes []byte, codeExp types.CodeType, dataExp []byte) {
  73. res, err := client.CheckTxSync(txBytes)
  74. if err != nil {
  75. panicf("client error: %v", err)
  76. }
  77. if res.IsErr() {
  78. panicf("checking tx %X: %v\nlog: %v", txBytes, res.Log)
  79. }
  80. if res.Code != codeExp {
  81. panicf("CheckTx response code was unexpected. Got %v expected %v. Log: %v",
  82. res.Code, codeExp, res.Log)
  83. }
  84. if !bytes.Equal(res.Data, dataExp) {
  85. panicf("CheckTx response data was unexpected. Got %X expected %X",
  86. res.Data, dataExp)
  87. }
  88. }*/
  89. func panicf(format string, a ...interface{}) {
  90. panic(fmt.Sprintf(format, a...))
  91. }