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