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.

85 lines
2.4 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. tmrand "github.com/tendermint/tendermint/libs/rand"
  9. )
  10. func InitChain(client abcicli.Client) error {
  11. total := 10
  12. vals := make([]types.ValidatorUpdate, total)
  13. for i := 0; i < total; i++ {
  14. pubkey := tmrand.Bytes(33)
  15. power := tmrand.Int()
  16. vals[i] = types.Ed25519ValidatorUpdate(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 Commit(client abcicli.Client, hashExp []byte) error {
  29. res, err := client.CommitSync()
  30. data := res.Data
  31. if err != nil {
  32. fmt.Println("Failed test: Commit")
  33. fmt.Printf("error while committing: %v\n", err)
  34. return err
  35. }
  36. if !bytes.Equal(data, hashExp) {
  37. fmt.Println("Failed test: Commit")
  38. fmt.Printf("Commit hash was unexpected. Got %X expected %X\n", data, hashExp)
  39. return errors.New("commitTx failed")
  40. }
  41. fmt.Println("Passed test: Commit")
  42. return nil
  43. }
  44. func DeliverTx(client abcicli.Client, txBytes []byte, codeExp uint32, dataExp []byte) error {
  45. res, _ := client.DeliverTxSync(types.RequestDeliverTx{Tx: txBytes})
  46. code, data, log := res.Code, res.Data, res.Log
  47. if code != codeExp {
  48. fmt.Println("Failed test: DeliverTx")
  49. fmt.Printf("DeliverTx response code was unexpected. Got %v expected %v. Log: %v\n",
  50. code, codeExp, log)
  51. return errors.New("deliverTx error")
  52. }
  53. if !bytes.Equal(data, dataExp) {
  54. fmt.Println("Failed test: DeliverTx")
  55. fmt.Printf("DeliverTx response data was unexpected. Got %X expected %X\n",
  56. data, dataExp)
  57. return errors.New("deliverTx error")
  58. }
  59. fmt.Println("Passed test: DeliverTx")
  60. return nil
  61. }
  62. func CheckTx(client abcicli.Client, txBytes []byte, codeExp uint32, dataExp []byte) error {
  63. res, _ := client.CheckTxSync(types.RequestCheckTx{Tx: txBytes})
  64. code, data, log := res.Code, res.Data, res.Log
  65. if code != codeExp {
  66. fmt.Println("Failed test: CheckTx")
  67. fmt.Printf("CheckTx response code was unexpected. Got %v expected %v. Log: %v\n",
  68. code, codeExp, log)
  69. return errors.New("checkTx")
  70. }
  71. if !bytes.Equal(data, dataExp) {
  72. fmt.Println("Failed test: CheckTx")
  73. fmt.Printf("CheckTx response data was unexpected. Got %X expected %X\n",
  74. data, dataExp)
  75. return errors.New("checkTx")
  76. }
  77. fmt.Println("Passed test: CheckTx")
  78. return nil
  79. }