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.

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