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.

112 lines
3.1 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 node.Stateless() {
  17. return
  18. }
  19. if len(node.Testnet.InitialState) == 0 {
  20. return
  21. }
  22. client, err := node.Client()
  23. require.NoError(t, err)
  24. for k, v := range node.Testnet.InitialState {
  25. resp, err := client.ABCIQuery(ctx, "", []byte(k))
  26. require.NoError(t, err)
  27. assert.Equal(t, k, string(resp.Response.Key))
  28. assert.Equal(t, v, string(resp.Response.Value))
  29. }
  30. })
  31. }
  32. // Tests that the app hash (as reported by the app) matches the last
  33. // block and the node sync status.
  34. func TestApp_Hash(t *testing.T) {
  35. testNode(t, func(t *testing.T, node e2e.Node) {
  36. // disables tests for light clients
  37. // see https://github.com/tendermint/tendermint/issues/6671
  38. if node.Mode == e2e.ModeSeed || node.Mode == e2e.ModeLight {
  39. return
  40. }
  41. client, err := node.Client()
  42. require.NoError(t, err)
  43. info, err := client.ABCIInfo(ctx)
  44. require.NoError(t, err)
  45. require.NotEmpty(t, info.Response.LastBlockAppHash, "expected app to return app hash")
  46. block, err := client.Block(ctx, nil)
  47. require.NoError(t, err)
  48. require.EqualValues(t, info.Response.LastBlockAppHash, block.Block.AppHash,
  49. "app hash does not match last block's app hash")
  50. status, err := client.Status(ctx)
  51. require.NoError(t, err)
  52. require.EqualValues(t, info.Response.LastBlockAppHash, status.SyncInfo.LatestAppHash,
  53. "app hash does not match node status")
  54. })
  55. }
  56. // Tests that we can set a value and retrieve it.
  57. func TestApp_Tx(t *testing.T) {
  58. testNode(t, func(t *testing.T, node e2e.Node) {
  59. // disables tests for light clients
  60. // see https://github.com/tendermint/tendermint/issues/6671
  61. if node.Mode == e2e.ModeSeed || node.Mode == e2e.ModeLight {
  62. return
  63. }
  64. client, err := node.Client()
  65. require.NoError(t, err)
  66. // Generate a random value, to prevent duplicate tx errors when
  67. // manually running the test multiple times for a testnet.
  68. r := rand.New(rand.NewSource(time.Now().UnixNano()))
  69. bz := make([]byte, 32)
  70. _, err = r.Read(bz)
  71. require.NoError(t, err)
  72. key := fmt.Sprintf("testapp-tx-%v", node.Name)
  73. value := fmt.Sprintf("%x", bz)
  74. tx := types.Tx(fmt.Sprintf("%v=%v", key, value))
  75. _, err = client.BroadcastTxSync(ctx, tx)
  76. require.NoError(t, err)
  77. hash := tx.Hash()
  78. waitTime := 30 * time.Second
  79. require.Eventuallyf(t, func() bool {
  80. txResp, err := client.Tx(ctx, hash, false)
  81. return err == nil && bytes.Equal(txResp.Tx, tx)
  82. }, waitTime, time.Second,
  83. "submitted tx wasn't committed after %v", waitTime,
  84. )
  85. // NOTE: we don't test abci query of the light client
  86. if node.Mode == e2e.ModeLight {
  87. return
  88. }
  89. abciResp, err := client.ABCIQuery(ctx, "", []byte(key))
  90. require.NoError(t, err)
  91. assert.Equal(t, key, string(abciResp.Response.Key))
  92. assert.Equal(t, value, string(abciResp.Response.Value))
  93. })
  94. }