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.

95 lines
2.5 KiB

  1. package e2e_test
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. "github.com/stretchr/testify/require"
  6. e2e "github.com/tendermint/tendermint/test/e2e/pkg"
  7. )
  8. // Tests that block headers are identical across nodes where present.
  9. func TestBlock_Header(t *testing.T) {
  10. blocks := fetchBlockChain(t)
  11. testNode(t, func(t *testing.T, node e2e.Node) {
  12. if node.Mode == e2e.ModeSeed {
  13. return
  14. }
  15. client, err := node.Client()
  16. require.NoError(t, err)
  17. status, err := client.Status(ctx)
  18. require.NoError(t, err)
  19. first := status.SyncInfo.EarliestBlockHeight
  20. last := status.SyncInfo.LatestBlockHeight
  21. if node.RetainBlocks > 0 {
  22. first++ // avoid race conditions with block pruning
  23. }
  24. for _, block := range blocks {
  25. if block.Header.Height < first {
  26. continue
  27. }
  28. if block.Header.Height > last {
  29. break
  30. }
  31. resp, err := client.Block(ctx, &block.Header.Height)
  32. require.NoError(t, err)
  33. require.Equal(t, block, resp.Block,
  34. "block mismatch for height %d", block.Header.Height)
  35. require.NoError(t, resp.Block.ValidateBasic(),
  36. "block at height %d is invalid", block.Header.Height)
  37. }
  38. })
  39. }
  40. // Tests that the node contains the expected block range.
  41. func TestBlock_Range(t *testing.T) {
  42. testNode(t, func(t *testing.T, node e2e.Node) {
  43. if node.Mode == e2e.ModeSeed {
  44. return
  45. }
  46. client, err := node.Client()
  47. require.NoError(t, err)
  48. status, err := client.Status(ctx)
  49. require.NoError(t, err)
  50. first := status.SyncInfo.EarliestBlockHeight
  51. last := status.SyncInfo.LatestBlockHeight
  52. switch {
  53. case node.StateSync:
  54. assert.Greater(t, first, node.Testnet.InitialHeight,
  55. "state synced nodes should not contain network's initial height")
  56. case node.RetainBlocks > 0 && int64(node.RetainBlocks) < (last-node.Testnet.InitialHeight+1):
  57. // Delta handles race conditions in reading first/last heights.
  58. assert.InDelta(t, node.RetainBlocks, last-first+1, 1,
  59. "node not pruning expected blocks")
  60. default:
  61. assert.Equal(t, node.Testnet.InitialHeight, first,
  62. "node's first block should be network's initial height")
  63. }
  64. for h := first; h <= last; h++ {
  65. resp, err := client.Block(ctx, &(h))
  66. if err != nil && node.RetainBlocks > 0 && h == first {
  67. // Ignore errors in first block if node is pruning blocks due to race conditions.
  68. continue
  69. }
  70. require.NoError(t, err)
  71. assert.Equal(t, h, resp.Block.Height)
  72. }
  73. for h := node.Testnet.InitialHeight; h < first; h++ {
  74. _, err := client.Block(ctx, &(h))
  75. require.Error(t, err)
  76. }
  77. })
  78. }