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.

96 lines
2.7 KiB

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