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.

91 lines
2.4 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 %v", block.Header.Height)
  35. }
  36. })
  37. }
  38. // Tests that the node contains the expected block range.
  39. func TestBlock_Range(t *testing.T) {
  40. testNode(t, func(t *testing.T, node e2e.Node) {
  41. if node.Mode == e2e.ModeSeed {
  42. return
  43. }
  44. client, err := node.Client()
  45. require.NoError(t, err)
  46. status, err := client.Status(ctx)
  47. require.NoError(t, err)
  48. first := status.SyncInfo.EarliestBlockHeight
  49. last := status.SyncInfo.LatestBlockHeight
  50. switch {
  51. case node.StateSync:
  52. assert.Greater(t, first, node.Testnet.InitialHeight,
  53. "state synced nodes should not contain network's initial height")
  54. case node.RetainBlocks > 0 && int64(node.RetainBlocks) < (last-node.Testnet.InitialHeight+1):
  55. // Delta handles race conditions in reading first/last heights.
  56. assert.InDelta(t, node.RetainBlocks, last-first+1, 1,
  57. "node not pruning expected blocks")
  58. default:
  59. assert.Equal(t, node.Testnet.InitialHeight, first,
  60. "node's first block should be network's initial height")
  61. }
  62. for h := first; h <= last; h++ {
  63. resp, err := client.Block(ctx, &(h))
  64. if err != nil && node.RetainBlocks > 0 && h == first {
  65. // Ignore errors in first block if node is pruning blocks due to race conditions.
  66. continue
  67. }
  68. require.NoError(t, err)
  69. assert.Equal(t, h, resp.Block.Height)
  70. }
  71. for h := node.Testnet.InitialHeight; h < first; h++ {
  72. _, err := client.Block(ctx, &(h))
  73. require.Error(t, err)
  74. }
  75. })
  76. }