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.

92 lines
2.3 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
8 years ago
8 years ago
8 years ago
  1. package main
  2. import (
  3. "bytes"
  4. "os"
  5. "time"
  6. . "github.com/tendermint/go-common"
  7. "github.com/tendermint/go-process"
  8. "github.com/tendermint/abci/client"
  9. "github.com/tendermint/abci/types"
  10. )
  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. return client
  36. }
  37. func SetOption(client abcicli.Client, key, value string) {
  38. res := client.SetOptionSync(key, value)
  39. _, _, log := res.Code, res.Data, res.Log
  40. if res.IsErr() {
  41. panic(Fmt("setting %v=%v: \nlog: %v", key, value, log))
  42. }
  43. }
  44. func Commit(client abcicli.Client, hashExp []byte) {
  45. res := client.CommitSync()
  46. _, data, log := res.Code, res.Data, res.Log
  47. if res.IsErr() {
  48. panic(Fmt("committing %v\nlog: %v", log))
  49. }
  50. if !bytes.Equal(res.Data, hashExp) {
  51. panic(Fmt("Commit hash was unexpected. Got %X expected %X",
  52. data, hashExp))
  53. }
  54. }
  55. func DeliverTx(client abcicli.Client, txBytes []byte, codeExp types.CodeType, dataExp []byte) {
  56. res := client.DeliverTxSync(txBytes)
  57. code, data, log := res.Code, res.Data, res.Log
  58. if code != codeExp {
  59. panic(Fmt("DeliverTx response code was unexpected. Got %v expected %v. Log: %v",
  60. code, codeExp, log))
  61. }
  62. if !bytes.Equal(data, dataExp) {
  63. panic(Fmt("DeliverTx response data was unexpected. Got %X expected %X",
  64. data, dataExp))
  65. }
  66. }
  67. func CheckTx(client abcicli.Client, txBytes []byte, codeExp types.CodeType, dataExp []byte) {
  68. res := client.CheckTxSync(txBytes)
  69. code, data, log := res.Code, res.Data, res.Log
  70. if res.IsErr() {
  71. panic(Fmt("checking tx %X: %v\nlog: %v", txBytes, log))
  72. }
  73. if code != codeExp {
  74. panic(Fmt("CheckTx response code was unexpected. Got %v expected %v. Log: %v",
  75. code, codeExp, log))
  76. }
  77. if !bytes.Equal(data, dataExp) {
  78. panic(Fmt("CheckTx response data was unexpected. Got %X expected %X",
  79. data, dataExp))
  80. }
  81. }