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.

107 lines
2.8 KiB

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