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.

96 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. client, err := node.Client()
  13. require.NoError(t, err)
  14. status, err := client.Status(ctx)
  15. require.NoError(t, err)
  16. first := status.SyncInfo.EarliestBlockHeight
  17. last := status.SyncInfo.LatestBlockHeight
  18. if node.RetainBlocks > 0 {
  19. first++ // avoid race conditions with block pruning
  20. }
  21. for _, block := range blocks {
  22. if block.Header.Height < first {
  23. continue
  24. }
  25. // the first blocks after state sync come from the backfill process
  26. // and are therefore not complete
  27. if node.StateSync != e2e.StateSyncDisabled && block.Header.Height <= first+e2e.EvidenceAgeHeight+1 {
  28. continue
  29. }
  30. if block.Header.Height > last {
  31. break
  32. }
  33. resp, err := client.Block(ctx, &block.Header.Height)
  34. require.NoError(t, err)
  35. require.Equal(t, block, resp.Block,
  36. "block mismatch for height %d", block.Header.Height)
  37. require.NoError(t, resp.Block.ValidateBasic(),
  38. "block at height %d is invalid", block.Header.Height)
  39. }
  40. })
  41. }
  42. // Tests that the node contains the expected block range.
  43. func TestBlock_Range(t *testing.T) {
  44. testNode(t, func(t *testing.T, node e2e.Node) {
  45. client, err := node.Client()
  46. require.NoError(t, err)
  47. status, err := client.Status(ctx)
  48. require.NoError(t, err)
  49. first := status.SyncInfo.EarliestBlockHeight
  50. last := status.SyncInfo.LatestBlockHeight
  51. switch {
  52. // if the node state synced we ignore any assertions because it's hard to know how far back
  53. // the node ran reverse sync for
  54. case node.StateSync != e2e.StateSyncDisabled:
  55. break
  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. if node.StateSync != e2e.StateSyncDisabled && h <= first+e2e.EvidenceAgeHeight+1 {
  66. continue
  67. }
  68. resp, err := client.Block(ctx, &(h))
  69. if err != nil && node.RetainBlocks > 0 && h == first {
  70. // Ignore errors in first block if node is pruning blocks due to race conditions.
  71. continue
  72. }
  73. require.NoError(t, err)
  74. require.NotNil(t, resp.Block)
  75. assert.Equal(t, h, resp.Block.Height)
  76. }
  77. for h := node.Testnet.InitialHeight; h < first; h++ {
  78. _, err := client.Block(ctx, &(h))
  79. require.Error(t, err)
  80. }
  81. })
  82. }