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.

97 lines
2.7 KiB

  1. package e2e_test
  2. import (
  3. "bytes"
  4. "fmt"
  5. "math/rand"
  6. "testing"
  7. "time"
  8. "github.com/stretchr/testify/assert"
  9. "github.com/stretchr/testify/require"
  10. e2e "github.com/tendermint/tendermint/test/e2e/pkg"
  11. "github.com/tendermint/tendermint/types"
  12. )
  13. // Tests that any initial state given in genesis has made it into the app.
  14. func TestApp_InitialState(t *testing.T) {
  15. testNode(t, func(t *testing.T, node e2e.Node) {
  16. if len(node.Testnet.InitialState) == 0 {
  17. return
  18. }
  19. client, err := node.Client()
  20. require.NoError(t, err)
  21. for k, v := range node.Testnet.InitialState {
  22. resp, err := client.ABCIQuery(ctx, "", []byte(k))
  23. require.NoError(t, err)
  24. assert.Equal(t, k, string(resp.Response.Key))
  25. assert.Equal(t, v, string(resp.Response.Value))
  26. }
  27. })
  28. }
  29. // Tests that the app hash (as reported by the app) matches the last
  30. // block and the node sync status.
  31. func TestApp_Hash(t *testing.T) {
  32. testNode(t, func(t *testing.T, node e2e.Node) {
  33. client, err := node.Client()
  34. require.NoError(t, err)
  35. info, err := client.ABCIInfo(ctx)
  36. require.NoError(t, err)
  37. require.NotEmpty(t, info.Response.LastBlockAppHash, "expected app to return app hash")
  38. block, err := client.Block(ctx, nil)
  39. require.NoError(t, err)
  40. require.EqualValues(t, info.Response.LastBlockAppHash, block.Block.AppHash,
  41. "app hash does not match last block's app hash")
  42. status, err := client.Status(ctx)
  43. require.NoError(t, err)
  44. require.EqualValues(t, info.Response.LastBlockAppHash, status.SyncInfo.LatestAppHash,
  45. "app hash does not match node status")
  46. })
  47. }
  48. // Tests that we can set a value and retrieve it.
  49. func TestApp_Tx(t *testing.T) {
  50. testNode(t, func(t *testing.T, node e2e.Node) {
  51. client, err := node.Client()
  52. require.NoError(t, err)
  53. // Generate a random value, to prevent duplicate tx errors when
  54. // manually running the test multiple times for a testnet.
  55. r := rand.New(rand.NewSource(time.Now().UnixNano()))
  56. bz := make([]byte, 32)
  57. _, err = r.Read(bz)
  58. require.NoError(t, err)
  59. key := fmt.Sprintf("testapp-tx-%v", node.Name)
  60. value := fmt.Sprintf("%x", bz)
  61. tx := types.Tx(fmt.Sprintf("%v=%v", key, value))
  62. _, err = client.BroadcastTxSync(ctx, tx)
  63. require.NoError(t, err)
  64. hash := tx.Hash()
  65. waitTime := 30 * time.Second
  66. require.Eventuallyf(t, func() bool {
  67. txResp, err := client.Tx(ctx, hash, false)
  68. return err == nil && bytes.Equal(txResp.Tx, tx)
  69. }, waitTime, time.Second,
  70. "submitted tx wasn't committed after %v", waitTime,
  71. )
  72. // NOTE: we don't test abci query of the light client
  73. if node.Mode == e2e.ModeLight {
  74. return
  75. }
  76. abciResp, err := client.ABCIQuery(ctx, "", []byte(key))
  77. require.NoError(t, err)
  78. assert.Equal(t, key, string(abciResp.Response.Key))
  79. assert.Equal(t, value, string(abciResp.Response.Value))
  80. })
  81. }