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.

90 lines
2.3 KiB

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