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.

104 lines
2.8 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. // the first blocks after state sync come from the backfill process
  29. // and are therefore not complete
  30. if node.StateSync && block.Header.Height <= first+e2e.EvidenceAgeHeight+1 {
  31. continue
  32. }
  33. if block.Header.Height > last {
  34. break
  35. }
  36. resp, err := client.Block(ctx, &block.Header.Height)
  37. require.NoError(t, err)
  38. require.Equal(t, block, resp.Block,
  39. "block mismatch for height %d", block.Header.Height)
  40. require.NoError(t, resp.Block.ValidateBasic(),
  41. "block at height %d is invalid", block.Header.Height)
  42. }
  43. })
  44. }
  45. // Tests that the node contains the expected block range.
  46. func TestBlock_Range(t *testing.T) {
  47. testNode(t, func(t *testing.T, node e2e.Node) {
  48. if node.Mode == e2e.ModeSeed {
  49. return
  50. }
  51. client, err := node.Client()
  52. require.NoError(t, err)
  53. status, err := client.Status(ctx)
  54. require.NoError(t, err)
  55. first := status.SyncInfo.EarliestBlockHeight
  56. last := status.SyncInfo.LatestBlockHeight
  57. switch {
  58. // if the node state synced we ignore any assertions because it's hard to know how far back
  59. // the node ran reverse sync for
  60. case node.StateSync:
  61. break
  62. case node.RetainBlocks > 0 && int64(node.RetainBlocks) < (last-node.Testnet.InitialHeight+1):
  63. // Delta handles race conditions in reading first/last heights.
  64. assert.InDelta(t, node.RetainBlocks, last-first+1, 1,
  65. "node not pruning expected blocks")
  66. default:
  67. assert.Equal(t, node.Testnet.InitialHeight, first,
  68. "node's first block should be network's initial height")
  69. }
  70. for h := first; h <= last; h++ {
  71. if node.StateSync && h <= first+e2e.EvidenceAgeHeight+1 {
  72. continue
  73. }
  74. resp, err := client.Block(ctx, &(h))
  75. if err != nil && node.RetainBlocks > 0 && h == first {
  76. // Ignore errors in first block if node is pruning blocks due to race conditions.
  77. continue
  78. }
  79. require.NoError(t, err)
  80. require.NotNil(t, resp.Block)
  81. assert.Equal(t, h, resp.Block.Height)
  82. }
  83. for h := node.Testnet.InitialHeight; h < first; h++ {
  84. _, err := client.Block(ctx, &(h))
  85. require.Error(t, err)
  86. }
  87. })
  88. }