-
Notifications
You must be signed in to change notification settings - Fork 548
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add basic end-to-end test cases (#5450)
Partial fix for #5291. This adds a basic set of test cases for core network invariants. Although small, it is sufficient to replace and extend the current set of P2P tests. Further test cases can be added later.
- Loading branch information
1 parent
a58454e
commit 64b0f5b
Showing
4 changed files
with
386 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package e2e_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
e2e "github.com/tendermint/tendermint/test/e2e/pkg" | ||
) | ||
|
||
// Tests that block headers are identical across nodes where present. | ||
func TestBlock_Header(t *testing.T) { | ||
blocks := fetchBlockChain(t) | ||
testNode(t, func(t *testing.T, node e2e.Node) { | ||
client, err := node.Client() | ||
require.NoError(t, err) | ||
status, err := client.Status(ctx) | ||
require.NoError(t, err) | ||
|
||
first := status.SyncInfo.EarliestBlockHeight | ||
last := status.SyncInfo.LatestBlockHeight | ||
if node.RetainBlocks > 0 { | ||
first++ // avoid race conditions with block pruning | ||
} | ||
|
||
for _, block := range blocks { | ||
if block.Header.Height < first { | ||
continue | ||
} | ||
if block.Header.Height > last { | ||
break | ||
} | ||
resp, err := client.Block(ctx, &block.Header.Height) | ||
require.NoError(t, err) | ||
require.Equal(t, block, resp.Block, | ||
"block mismatch for height %v", block.Header.Height) | ||
} | ||
}) | ||
} | ||
|
||
// Tests that the node contains the expected block range. | ||
func TestBlock_Range(t *testing.T) { | ||
testNode(t, func(t *testing.T, node e2e.Node) { | ||
client, err := node.Client() | ||
require.NoError(t, err) | ||
status, err := client.Status(ctx) | ||
require.NoError(t, err) | ||
|
||
first := status.SyncInfo.EarliestBlockHeight | ||
last := status.SyncInfo.LatestBlockHeight | ||
|
||
switch { | ||
case node.StateSync: | ||
assert.Greater(t, first, node.Testnet.InitialHeight, | ||
"state synced nodes should not contain network's initial height") | ||
|
||
case node.RetainBlocks > 0 && int64(node.RetainBlocks) < (last-node.Testnet.InitialHeight+1): | ||
// Delta handles race conditions in reading first/last heights. | ||
assert.InDelta(t, node.RetainBlocks, last-first+1, 1, | ||
"node not pruning expected blocks") | ||
|
||
default: | ||
assert.Equal(t, node.Testnet.InitialHeight, first, | ||
"node's first block should be network's initial height") | ||
} | ||
|
||
for h := first; h <= last; h++ { | ||
resp, err := client.Block(ctx, &(h)) | ||
if err != nil && node.RetainBlocks > 0 && h == first { | ||
// Ignore errors in first block if node is pruning blocks due to race conditions. | ||
continue | ||
} | ||
require.NoError(t, err) | ||
assert.Equal(t, h, resp.Block.Height) | ||
} | ||
|
||
for h := node.Testnet.InitialHeight; h < first; h++ { | ||
_, err := client.Block(ctx, &(h)) | ||
require.Error(t, err) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.