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.

80 lines
2.3 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 len(node.Testnet.InitialState) == 0 {
  16. return
  17. }
  18. client, err := node.Client()
  19. require.NoError(t, err)
  20. for k, v := range node.Testnet.InitialState {
  21. resp, err := client.ABCIQuery(ctx, "", []byte(k))
  22. require.NoError(t, err)
  23. assert.Equal(t, k, string(resp.Response.Key))
  24. assert.Equal(t, v, string(resp.Response.Value))
  25. }
  26. })
  27. }
  28. // Tests that the app hash (as reported by the app) matches the last
  29. // block and the node sync status.
  30. func TestApp_Hash(t *testing.T) {
  31. testNode(t, func(t *testing.T, node e2e.Node) {
  32. client, err := node.Client()
  33. require.NoError(t, err)
  34. info, err := client.ABCIInfo(ctx)
  35. require.NoError(t, err)
  36. require.NotEmpty(t, info.Response.LastBlockAppHash, "expected app to return app hash")
  37. block, err := client.Block(ctx, nil)
  38. require.NoError(t, err)
  39. require.EqualValues(t, info.Response.LastBlockAppHash, block.Block.AppHash,
  40. "app hash does not match last block's app hash")
  41. status, err := client.Status(ctx)
  42. require.NoError(t, err)
  43. require.EqualValues(t, info.Response.LastBlockAppHash, status.SyncInfo.LatestAppHash,
  44. "app hash does not match node status")
  45. })
  46. }
  47. // Tests that we can set a value and retrieve it.
  48. func TestApp_Tx(t *testing.T) {
  49. testNode(t, func(t *testing.T, node e2e.Node) {
  50. client, err := node.Client()
  51. require.NoError(t, err)
  52. // Generate a random value, to prevent duplicate tx errors when
  53. // manually running the test multiple times for a testnet.
  54. r := rand.New(rand.NewSource(time.Now().UnixNano()))
  55. bz := make([]byte, 32)
  56. _, err = r.Read(bz)
  57. require.NoError(t, err)
  58. key := fmt.Sprintf("testapp-tx-%v", node.Name)
  59. value := fmt.Sprintf("%x", bz)
  60. tx := types.Tx(fmt.Sprintf("%v=%v", key, value))
  61. _, err = client.BroadcastTxCommit(ctx, tx)
  62. require.NoError(t, err)
  63. resp, err := client.ABCIQuery(ctx, "", []byte(key))
  64. require.NoError(t, err)
  65. assert.Equal(t, key, string(resp.Response.Key))
  66. assert.Equal(t, value, string(resp.Response.Value))
  67. })
  68. }