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.

94 lines
2.7 KiB

  1. package testsuite
  2. import (
  3. "bytes"
  4. "errors"
  5. "fmt"
  6. abcicli "github.com/tendermint/abci/client"
  7. "github.com/tendermint/abci/types"
  8. cmn "github.com/tendermint/tmlibs/common"
  9. )
  10. func InitChain(client abcicli.Client) error {
  11. total := 10
  12. vals := make([]types.Validator, total)
  13. for i := 0; i < total; i++ {
  14. pubkey := cmn.RandBytes(33)
  15. power := cmn.RandInt()
  16. vals[i] = types.Validator{pubkey, int64(power)}
  17. }
  18. _, err := client.InitChainSync(types.RequestInitChain{Validators: vals})
  19. if err != nil {
  20. fmt.Printf("Failed test: InitChain - %v\n", err)
  21. return err
  22. }
  23. fmt.Println("Passed test: InitChain")
  24. return nil
  25. }
  26. func SetOption(client abcicli.Client, key, value string) error {
  27. _, err := client.SetOptionSync(types.RequestSetOption{Key: key, Value: value})
  28. if err != nil {
  29. fmt.Println("Failed test: SetOption")
  30. fmt.Printf("error while setting %v=%v: \nerror: %v\n", key, value)
  31. return err
  32. }
  33. fmt.Println("Passed test: SetOption")
  34. return nil
  35. }
  36. func Commit(client abcicli.Client, hashExp []byte) error {
  37. res, err := client.CommitSync()
  38. data := res.Data
  39. if err != nil {
  40. fmt.Println("Failed test: Commit")
  41. fmt.Printf("error while committing: %v\n", err)
  42. return err
  43. }
  44. if !bytes.Equal(data, hashExp) {
  45. fmt.Println("Failed test: Commit")
  46. fmt.Printf("Commit hash was unexpected. Got %X expected %X\n", data, hashExp)
  47. return errors.New("CommitTx failed")
  48. }
  49. fmt.Println("Passed test: Commit")
  50. return nil
  51. }
  52. func DeliverTx(client abcicli.Client, txBytes []byte, codeExp uint32, dataExp []byte) error {
  53. res, _ := client.DeliverTxSync(txBytes)
  54. code, data, log := res.Code, res.Data, res.Log
  55. if code != codeExp {
  56. fmt.Println("Failed test: DeliverTx")
  57. fmt.Printf("DeliverTx response code was unexpected. Got %v expected %v. Log: %v\n",
  58. code, codeExp, log)
  59. return errors.New("DeliverTx error")
  60. }
  61. if !bytes.Equal(data, dataExp) {
  62. fmt.Println("Failed test: DeliverTx")
  63. fmt.Printf("DeliverTx response data was unexpected. Got %X expected %X\n",
  64. data, dataExp)
  65. return errors.New("DeliverTx error")
  66. }
  67. fmt.Println("Passed test: DeliverTx")
  68. return nil
  69. }
  70. func CheckTx(client abcicli.Client, txBytes []byte, codeExp uint32, dataExp []byte) error {
  71. res, _ := client.CheckTxSync(txBytes)
  72. code, data, log := res.Code, res.Data, res.Log
  73. if code != codeExp {
  74. fmt.Println("Failed test: CheckTx")
  75. fmt.Printf("CheckTx response code was unexpected. Got %v expected %v. Log: %v\n",
  76. code, codeExp, log)
  77. return errors.New("CheckTx")
  78. }
  79. if !bytes.Equal(data, dataExp) {
  80. fmt.Println("Failed test: CheckTx")
  81. fmt.Printf("CheckTx response data was unexpected. Got %X expected %X\n",
  82. data, dataExp)
  83. return errors.New("CheckTx")
  84. }
  85. fmt.Println("Passed test: CheckTx")
  86. return nil
  87. }