From ff7955470afeb03edac9328a7735b0687b4f57c1 Mon Sep 17 00:00:00 2001 From: William Banfield Date: Tue, 17 May 2022 10:28:35 -0400 Subject: [PATCH] update proposal tests to ensure off-by-one is correctly handled --- internal/state/execution_test.go | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/internal/state/execution_test.go b/internal/state/execution_test.go index 0df621887..6b50712c5 100644 --- a/internal/state/execution_test.go +++ b/internal/state/execution_test.go @@ -1009,17 +1009,27 @@ func TestPrepareProposalErrorOnPrepareProposalError(t *testing.T) { // data that the method receives. func TestCreateProposalAbsentVoteExtensions(t *testing.T) { for _, testCase := range []struct { - name string - height int64 + name string + + // The height that is about to be proposed + height int64 + + // The first height during which vote extensions will be required for consensus to proceed. extensionEnableHeight int64 expectPanic bool }{ { - name: "missing extension data after required", + name: "missing extension data on first required height", height: 2, extensionEnableHeight: 1, expectPanic: true, }, + { + name: "missing extension during before required height", + height: 2, + extensionEnableHeight: 2, + expectPanic: false, + }, { name: "missing extension data and not required", height: 2, @@ -1027,7 +1037,7 @@ func TestCreateProposalAbsentVoteExtensions(t *testing.T) { expectPanic: false, }, { - name: "missing extension data and required in future", + name: "missing extension data and required in two heights", height: 2, extensionEnableHeight: 3, expectPanic: false, @@ -1051,7 +1061,7 @@ func TestCreateProposalAbsentVoteExtensions(t *testing.T) { err := proxyApp.Start(ctx) require.NoError(t, err) - state, stateDB, privVals := makeState(t, 1, int(testCase.height)) + state, stateDB, privVals := makeState(t, 1, int(testCase.height-1)) stateStore := sm.NewStore(stateDB) state.ConsensusParams.ABCI.VoteExtensionsEnableHeight = testCase.extensionEnableHeight mp := &mpmocks.Mempool{} @@ -1077,19 +1087,19 @@ func TestCreateProposalAbsentVoteExtensions(t *testing.T) { eventBus, sm.NopMetrics(), ) - block := sf.MakeBlock(state, 1, new(types.Commit)) + block := sf.MakeBlock(state, testCase.height, new(types.Commit)) bps, err := block.MakePartSet(testPartSize) require.NoError(t, err) blockID := types.BlockID{Hash: block.Hash(), PartSetHeader: bps.Header()} pa, _ := state.Validators.GetByIndex(0) - commit, _ := makeValidCommit(ctx, t, testCase.height, blockID, state.Validators, privVals) - stripSignatures(commit) + lastCommit, _ := makeValidCommit(ctx, t, testCase.height-1, blockID, state.Validators, privVals) + stripSignatures(lastCommit) if testCase.expectPanic { require.Panics(t, func() { - blockExec.CreateProposalBlock(ctx, testCase.height, state, commit, pa) + blockExec.CreateProposalBlock(ctx, testCase.height, state, lastCommit, pa) }) } else { - _, err = blockExec.CreateProposalBlock(ctx, testCase.height, state, commit, pa) + _, err = blockExec.CreateProposalBlock(ctx, testCase.height, state, lastCommit, pa) require.NoError(t, err) } })