diff --git a/vms/platformvm/block/executor/acceptor_test.go b/vms/platformvm/block/executor/acceptor_test.go index 32543e249627..bed32a6c6354 100644 --- a/vms/platformvm/block/executor/acceptor_test.go +++ b/vms/platformvm/block/executor/acceptor_test.go @@ -272,70 +272,34 @@ func TestAcceptorVisitCommitBlock(t *testing.T) { blk, err := block.NewApricotCommitBlock(parentID, 1 /*height*/) require.NoError(err) - - err = acceptor.ApricotCommitBlock(blk) - require.ErrorIs(err, state.ErrMissingParentState) - - // Set [blk]'s parent in the state map. - parentOnAcceptState := state.NewMockDiff(ctrl) - parentOnAbortState := state.NewMockDiff(ctrl) - parentOnCommitState := state.NewMockDiff(ctrl) - parentStatelessBlk := block.NewMockBlock(ctrl) - parentState := &blockState{ - statelessBlock: parentStatelessBlk, - onAcceptState: parentOnAcceptState, - optionsState: optionsState{ - onAbortState: parentOnAbortState, - onCommitState: parentOnCommitState, - }, - } - acceptor.backend.blkIDToState[parentID] = parentState - blkID := blk.ID() - // Set expected calls on dependencies. - // Make sure the parent is accepted first. - gomock.InOrder( - parentStatelessBlk.EXPECT().ID().Return(parentID).Times(2), - s.EXPECT().SetLastAccepted(parentID).Times(1), - parentStatelessBlk.EXPECT().Height().Return(blk.Height()-1).Times(1), - s.EXPECT().SetHeight(blk.Height()-1).Times(1), - s.EXPECT().AddStatelessBlock(parentState.statelessBlock).Times(1), - - s.EXPECT().SetLastAccepted(blkID).Times(1), - s.EXPECT().SetHeight(blk.Height()).Times(1), - s.EXPECT().AddStatelessBlock(blk).Times(1), - ) - - err = acceptor.ApricotCommitBlock(blk) - require.ErrorIs(err, errMissingBlockState) - // Set [blk]'s state in the map as though it had been verified. - acceptor.backend.blkIDToState[parentID] = parentState - onAcceptState := state.NewMockDiff(ctrl) - acceptor.backend.blkIDToState[blkID] = &blockState{ - onAcceptState: onAcceptState, + { + err = acceptor.ApricotCommitBlock(blk) + require.ErrorIs(err, errMissingBlockState) } - // Set expected calls on dependencies. - // Make sure the parent is accepted first. - gomock.InOrder( - parentStatelessBlk.EXPECT().ID().Return(parentID).Times(2), - s.EXPECT().SetLastAccepted(parentID).Times(1), - parentStatelessBlk.EXPECT().Height().Return(blk.Height()-1).Times(1), - s.EXPECT().SetHeight(blk.Height()-1).Times(1), - s.EXPECT().AddStatelessBlock(parentState.statelessBlock).Times(1), - - s.EXPECT().SetLastAccepted(blkID).Times(1), - s.EXPECT().SetHeight(blk.Height()).Times(1), - s.EXPECT().AddStatelessBlock(blk).Times(1), - - onAcceptState.EXPECT().Apply(s).Times(1), - s.EXPECT().Commit().Return(nil).Times(1), - s.EXPECT().Checksum().Return(ids.Empty).Times(1), - ) - - require.NoError(acceptor.ApricotCommitBlock(blk)) - require.Equal(blk.ID(), acceptor.backend.lastAccepted) + { + onAcceptState := state.NewMockDiff(ctrl) + acceptor.backend.blkIDToState[blkID] = &blockState{ + onAcceptState: onAcceptState, + } + + // Set expected calls on dependencies. + // Make sure the parent is accepted first. + gomock.InOrder( + s.EXPECT().SetLastAccepted(blkID).Times(1), + s.EXPECT().SetHeight(blk.Height()).Times(1), + s.EXPECT().AddStatelessBlock(blk).Times(1), + + onAcceptState.EXPECT().Apply(s).Times(1), + s.EXPECT().Commit().Return(nil).Times(1), + s.EXPECT().Checksum().Return(ids.Empty).Times(1), + ) + + require.NoError(acceptor.ApricotCommitBlock(blk)) + require.Equal(blk.ID(), acceptor.backend.lastAccepted) + } } func TestAcceptorVisitAbortBlock(t *testing.T) { @@ -363,69 +327,31 @@ func TestAcceptorVisitAbortBlock(t *testing.T) { blk, err := block.NewApricotAbortBlock(parentID, 1 /*height*/) require.NoError(err) - - err = acceptor.ApricotAbortBlock(blk) - require.ErrorIs(err, state.ErrMissingParentState) - - // Set [blk]'s parent in the state map. - parentOnAcceptState := state.NewMockDiff(ctrl) - parentOnAbortState := state.NewMockDiff(ctrl) - parentOnCommitState := state.NewMockDiff(ctrl) - parentStatelessBlk := block.NewMockBlock(ctrl) - parentState := &blockState{ - statelessBlock: parentStatelessBlk, - onAcceptState: parentOnAcceptState, - optionsState: optionsState{ - onAbortState: parentOnAbortState, - onCommitState: parentOnCommitState, - }, - } - acceptor.backend.blkIDToState[parentID] = parentState - blkID := blk.ID() - // Set expected calls on dependencies. - // Make sure the parent is accepted first. - gomock.InOrder( - parentStatelessBlk.EXPECT().ID().Return(parentID).Times(2), - s.EXPECT().SetLastAccepted(parentID).Times(1), - parentStatelessBlk.EXPECT().Height().Return(blk.Height()-1).Times(1), - s.EXPECT().SetHeight(blk.Height()-1).Times(1), - s.EXPECT().AddStatelessBlock(parentState.statelessBlock).Times(1), - - s.EXPECT().SetLastAccepted(blkID).Times(1), - s.EXPECT().SetHeight(blk.Height()).Times(1), - s.EXPECT().AddStatelessBlock(blk).Times(1), - ) - - err = acceptor.ApricotAbortBlock(blk) - require.ErrorIs(err, errMissingBlockState) - // Set [blk]'s state in the map as though it had been verified. - acceptor.backend.blkIDToState[parentID] = parentState - - onAcceptState := state.NewMockDiff(ctrl) - acceptor.backend.blkIDToState[blkID] = &blockState{ - onAcceptState: onAcceptState, + { + err = acceptor.ApricotAbortBlock(blk) + require.ErrorIs(err, errMissingBlockState) } - // Set expected calls on dependencies. - // Make sure the parent is accepted first. - gomock.InOrder( - parentStatelessBlk.EXPECT().ID().Return(parentID).Times(2), - s.EXPECT().SetLastAccepted(parentID).Times(1), - parentStatelessBlk.EXPECT().Height().Return(blk.Height()-1).Times(1), - s.EXPECT().SetHeight(blk.Height()-1).Times(1), - s.EXPECT().AddStatelessBlock(parentState.statelessBlock).Times(1), - - s.EXPECT().SetLastAccepted(blkID).Times(1), - s.EXPECT().SetHeight(blk.Height()).Times(1), - s.EXPECT().AddStatelessBlock(blk).Times(1), - - onAcceptState.EXPECT().Apply(s).Times(1), - s.EXPECT().Commit().Return(nil).Times(1), - s.EXPECT().Checksum().Return(ids.Empty).Times(1), - ) - - require.NoError(acceptor.ApricotAbortBlock(blk)) - require.Equal(blk.ID(), acceptor.backend.lastAccepted) + { + onAcceptState := state.NewMockDiff(ctrl) + acceptor.backend.blkIDToState[blkID] = &blockState{ + onAcceptState: onAcceptState, + } + + // Set expected calls on dependencies. + gomock.InOrder( + s.EXPECT().SetLastAccepted(blkID).Times(1), + s.EXPECT().SetHeight(blk.Height()).Times(1), + s.EXPECT().AddStatelessBlock(blk).Times(1), + + onAcceptState.EXPECT().Apply(s).Times(1), + s.EXPECT().Commit().Return(nil).Times(1), + s.EXPECT().Checksum().Return(ids.Empty).Times(1), + ) + + require.NoError(acceptor.ApricotAbortBlock(blk)) + require.Equal(blk.ID(), acceptor.backend.lastAccepted) + } } diff --git a/vms/platformvm/txs/executor/advance_time_test.go b/vms/platformvm/txs/executor/advance_time_test.go index 694d6b7ff7fa..87e386838b06 100644 --- a/vms/platformvm/txs/executor/advance_time_test.go +++ b/vms/platformvm/txs/executor/advance_time_test.go @@ -42,17 +42,15 @@ func TestAdvanceTimeTxUpdatePrimaryNetworkStakers(t *testing.T) { tx, err := env.txBuilder.NewAdvanceTimeTx(pendingValidatorStartTime) require.NoError(err) - onCommitState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) - - onAbortState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) + proposalBlkID := ids.GenerateTestID() + onProposalBlockState, onCommitState, onAbortState := makeProposalAndOptionsStates(require, env, lastAcceptedID, proposalBlkID) executor := ProposalTxExecutor{ - OnCommitState: onCommitState, - OnAbortState: onAbortState, - Backend: &env.backend, - Tx: tx, + OnProposalBlockState: onProposalBlockState, + OnCommitState: onCommitState, + OnAbortState: onAbortState, + Backend: &env.backend, + Tx: tx, } require.NoError(tx.Unsigned.Visit(&executor)) @@ -91,17 +89,15 @@ func TestAdvanceTimeTxTimestampTooEarly(t *testing.T) { tx, err := env.txBuilder.NewAdvanceTimeTx(defaultGenesisTime) require.NoError(err) - onCommitState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) - - onAbortState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) + proposalBlkID := ids.GenerateTestID() + onProposalBlockState, onCommitState, onAbortState := makeProposalAndOptionsStates(require, env, lastAcceptedID, proposalBlkID) executor := ProposalTxExecutor{ - OnCommitState: onCommitState, - OnAbortState: onAbortState, - Backend: &env.backend, - Tx: tx, + OnProposalBlockState: onProposalBlockState, + OnCommitState: onCommitState, + OnAbortState: onAbortState, + Backend: &env.backend, + Tx: tx, } err = tx.Unsigned.Visit(&executor) require.ErrorIs(err, ErrChildBlockNotAfterParent) @@ -125,17 +121,15 @@ func TestAdvanceTimeTxTimestampTooLate(t *testing.T) { tx, err := env.txBuilder.NewAdvanceTimeTx(pendingValidatorStartTime.Add(1 * time.Second)) require.NoError(err) - onCommitState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) - - onAbortState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) + proposalBlkID := ids.GenerateTestID() + onProposalBlockState, onCommitState, onAbortState := makeProposalAndOptionsStates(require, env, lastAcceptedID, proposalBlkID) executor := ProposalTxExecutor{ - OnCommitState: onCommitState, - OnAbortState: onAbortState, - Backend: &env.backend, - Tx: tx, + OnProposalBlockState: onProposalBlockState, + OnCommitState: onCommitState, + OnAbortState: onAbortState, + Backend: &env.backend, + Tx: tx, } err = tx.Unsigned.Visit(&executor) require.ErrorIs(err, ErrChildBlockAfterStakerChangeTime) @@ -158,17 +152,15 @@ func TestAdvanceTimeTxTimestampTooLate(t *testing.T) { tx, err := env.txBuilder.NewAdvanceTimeTx(defaultValidateEndTime.Add(1 * time.Second)) require.NoError(err) - onCommitState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) - - onAbortState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) + proposalBlkID := ids.GenerateTestID() + onProposalBlockState, onCommitState, onAbortState := makeProposalAndOptionsStates(require, env, lastAcceptedID, proposalBlkID) executor := ProposalTxExecutor{ - OnCommitState: onCommitState, - OnAbortState: onAbortState, - Backend: &env.backend, - Tx: tx, + OnProposalBlockState: onProposalBlockState, + OnCommitState: onCommitState, + OnAbortState: onAbortState, + Backend: &env.backend, + Tx: tx, } err = tx.Unsigned.Visit(&executor) require.ErrorIs(err, ErrChildBlockAfterStakerChangeTime) @@ -397,17 +389,15 @@ func TestAdvanceTimeTxUpdateStakers(t *testing.T) { tx, err := env.txBuilder.NewAdvanceTimeTx(newTime) require.NoError(err) - onCommitState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) - - onAbortState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) + proposalBlkID := ids.GenerateTestID() + onProposalBlockState, onCommitState, onAbortState := makeProposalAndOptionsStates(require, env, lastAcceptedID, proposalBlkID) executor := ProposalTxExecutor{ - OnCommitState: onCommitState, - OnAbortState: onAbortState, - Backend: &env.backend, - Tx: tx, + OnProposalBlockState: onProposalBlockState, + OnCommitState: onCommitState, + OnAbortState: onAbortState, + Backend: &env.backend, + Tx: tx, } require.NoError(tx.Unsigned.Visit(&executor)) @@ -521,17 +511,15 @@ func TestAdvanceTimeTxRemoveSubnetValidator(t *testing.T) { tx, err = env.txBuilder.NewAdvanceTimeTx(subnetVdr1EndTime) require.NoError(err) - onCommitState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) - - onAbortState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) + proposalBlkID := ids.GenerateTestID() + onProposalBlockState, onCommitState, onAbortState := makeProposalAndOptionsStates(require, env, lastAcceptedID, proposalBlkID) executor := ProposalTxExecutor{ - OnCommitState: onCommitState, - OnAbortState: onAbortState, - Backend: &env.backend, - Tx: tx, + OnProposalBlockState: onProposalBlockState, + OnCommitState: onCommitState, + OnAbortState: onAbortState, + Backend: &env.backend, + Tx: tx, } require.NoError(tx.Unsigned.Visit(&executor)) @@ -597,17 +585,15 @@ func TestTrackedSubnet(t *testing.T) { tx, err = env.txBuilder.NewAdvanceTimeTx(subnetVdr1StartTime) require.NoError(err) - onCommitState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) - - onAbortState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) + proposalBlkID := ids.GenerateTestID() + onProposalBlockState, onCommitState, onAbortState := makeProposalAndOptionsStates(require, env, lastAcceptedID, proposalBlkID) executor := ProposalTxExecutor{ - OnCommitState: onCommitState, - OnAbortState: onAbortState, - Backend: &env.backend, - Tx: tx, + OnProposalBlockState: onProposalBlockState, + OnCommitState: onCommitState, + OnAbortState: onAbortState, + Backend: &env.backend, + Tx: tx, } require.NoError(tx.Unsigned.Visit(&executor)) @@ -647,17 +633,15 @@ func TestAdvanceTimeTxDelegatorStakerWeight(t *testing.T) { tx, err := env.txBuilder.NewAdvanceTimeTx(pendingValidatorStartTime) require.NoError(err) - onCommitState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) - - onAbortState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) + proposalBlkID := ids.GenerateTestID() + onProposalBlockState, onCommitState, onAbortState := makeProposalAndOptionsStates(require, env, lastAcceptedID, proposalBlkID) executor := ProposalTxExecutor{ - OnCommitState: onCommitState, - OnAbortState: onAbortState, - Backend: &env.backend, - Tx: tx, + OnProposalBlockState: onProposalBlockState, + OnCommitState: onCommitState, + OnAbortState: onAbortState, + Backend: &env.backend, + Tx: tx, } require.NoError(tx.Unsigned.Visit(&executor)) @@ -704,17 +688,14 @@ func TestAdvanceTimeTxDelegatorStakerWeight(t *testing.T) { tx, err = env.txBuilder.NewAdvanceTimeTx(pendingDelegatorStartTime) require.NoError(err) - onCommitState, err = state.NewDiff(lastAcceptedID, env) - require.NoError(err) - - onAbortState, err = state.NewDiff(lastAcceptedID, env) - require.NoError(err) + onProposalBlockState, onCommitState, onAbortState = makeProposalAndOptionsStates(require, env, lastAcceptedID, proposalBlkID) executor = ProposalTxExecutor{ - OnCommitState: onCommitState, - OnAbortState: onAbortState, - Backend: &env.backend, - Tx: tx, + OnProposalBlockState: onProposalBlockState, + OnCommitState: onCommitState, + OnAbortState: onAbortState, + Backend: &env.backend, + Tx: tx, } require.NoError(tx.Unsigned.Visit(&executor)) @@ -748,17 +729,15 @@ func TestAdvanceTimeTxDelegatorStakers(t *testing.T) { tx, err := env.txBuilder.NewAdvanceTimeTx(pendingValidatorStartTime) require.NoError(err) - onCommitState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) - - onAbortState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) + proposalBlkID := ids.GenerateTestID() + onProposalBlockState, onCommitState, onAbortState := makeProposalAndOptionsStates(require, env, lastAcceptedID, proposalBlkID) executor := ProposalTxExecutor{ - OnCommitState: onCommitState, - OnAbortState: onAbortState, - Backend: &env.backend, - Tx: tx, + OnProposalBlockState: onProposalBlockState, + OnCommitState: onCommitState, + OnAbortState: onAbortState, + Backend: &env.backend, + Tx: tx, } require.NoError(tx.Unsigned.Visit(&executor)) @@ -800,17 +779,14 @@ func TestAdvanceTimeTxDelegatorStakers(t *testing.T) { tx, err = env.txBuilder.NewAdvanceTimeTx(pendingDelegatorStartTime) require.NoError(err) - onCommitState, err = state.NewDiff(lastAcceptedID, env) - require.NoError(err) - - onAbortState, err = state.NewDiff(lastAcceptedID, env) - require.NoError(err) + onProposalBlockState, onCommitState, onAbortState = makeProposalAndOptionsStates(require, env, lastAcceptedID, proposalBlkID) executor = ProposalTxExecutor{ - OnCommitState: onCommitState, - OnAbortState: onAbortState, - Backend: &env.backend, - Tx: tx, + OnProposalBlockState: onProposalBlockState, + OnCommitState: onCommitState, + OnAbortState: onAbortState, + Backend: &env.backend, + Tx: tx, } require.NoError(tx.Unsigned.Visit(&executor)) @@ -838,17 +814,15 @@ func TestAdvanceTimeTxInitiallyPrefersCommit(t *testing.T) { tx, err := env.txBuilder.NewAdvanceTimeTx(defaultGenesisTime.Add(SyncBound)) require.NoError(err) - onCommitState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) - - onAbortState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) + proposalBlkID := ids.GenerateTestID() + onProposalBlockState, onCommitState, onAbortState := makeProposalAndOptionsStates(require, env, lastAcceptedID, proposalBlkID) executor := ProposalTxExecutor{ - OnCommitState: onCommitState, - OnAbortState: onAbortState, - Backend: &env.backend, - Tx: tx, + OnProposalBlockState: onProposalBlockState, + OnCommitState: onCommitState, + OnAbortState: onAbortState, + Backend: &env.backend, + Tx: tx, } require.NoError(tx.Unsigned.Visit(&executor)) @@ -869,17 +843,15 @@ func TestAdvanceTimeTxAfterBanff(t *testing.T) { tx, err := env.txBuilder.NewAdvanceTimeTx(defaultGenesisTime.Add(SyncBound)) require.NoError(err) - onCommitState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) - - onAbortState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) + proposalBlkID := ids.GenerateTestID() + onProposalBlockState, onCommitState, onAbortState := makeProposalAndOptionsStates(require, env, lastAcceptedID, proposalBlkID) executor := ProposalTxExecutor{ - OnCommitState: onCommitState, - OnAbortState: onAbortState, - Backend: &env.backend, - Tx: tx, + OnProposalBlockState: onProposalBlockState, + OnCommitState: onCommitState, + OnAbortState: onAbortState, + Backend: &env.backend, + Tx: tx, } err = tx.Unsigned.Visit(&executor) require.ErrorIs(err, ErrAdvanceTimeTxIssuedAfterBanff) @@ -948,3 +920,26 @@ func addPendingValidator( } return addPendingValidatorTx, nil } + +func makeProposalAndOptionsStates( + r *require.Assertions, + env *environment, + proposalParentBlkID, + proposalBlkID ids.ID) ( + onProposalBlockState state.Diff, + onCommitState state.Diff, + onAbortState state.Diff, +) { + var err error + onProposalBlockState, err = state.NewDiff(proposalParentBlkID, env) + r.NoError(err) + + env.SetState(proposalBlkID, onProposalBlockState) + + onCommitState, err = state.NewDiff(proposalBlkID, env) + r.NoError(err) + + onAbortState, err = state.NewDiff(proposalBlkID, env) + r.NoError(err) + return +} diff --git a/vms/platformvm/txs/executor/proposal_tx_executor_test.go b/vms/platformvm/txs/executor/proposal_tx_executor_test.go index bc95f3ed39b2..f374fefd127d 100644 --- a/vms/platformvm/txs/executor/proposal_tx_executor_test.go +++ b/vms/platformvm/txs/executor/proposal_tx_executor_test.go @@ -262,17 +262,15 @@ func TestProposalTxExecuteAddDelegator(t *testing.T) { tt.setup(freshTH) } - onCommitState, err := state.NewDiff(lastAcceptedID, freshTH) - require.NoError(err) - - onAbortState, err := state.NewDiff(lastAcceptedID, freshTH) - require.NoError(err) + proposalBlkID := ids.GenerateTestID() + onProposalBlockState, onCommitState, onAbortState := makeProposalAndOptionsStates(require, freshTH, lastAcceptedID, proposalBlkID) executor := ProposalTxExecutor{ - OnCommitState: onCommitState, - OnAbortState: onAbortState, - Backend: &freshTH.backend, - Tx: tx, + OnProposalBlockState: onProposalBlockState, + OnCommitState: onCommitState, + OnAbortState: onAbortState, + Backend: &freshTH.backend, + Tx: tx, } err = tx.Unsigned.Visit(&executor) require.ErrorIs(err, tt.expectedErr) @@ -304,17 +302,15 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { ) require.NoError(err) - onCommitState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) - - onAbortState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) + proposalBlkID := ids.GenerateTestID() + onProposalBlockState, onCommitState, onAbortState := makeProposalAndOptionsStates(require, env, lastAcceptedID, proposalBlkID) executor := ProposalTxExecutor{ - OnCommitState: onCommitState, - OnAbortState: onAbortState, - Backend: &env.backend, - Tx: tx, + OnProposalBlockState: onProposalBlockState, + OnCommitState: onCommitState, + OnAbortState: onAbortState, + Backend: &env.backend, + Tx: tx, } err = tx.Unsigned.Visit(&executor) require.ErrorIs(err, ErrPeriodMismatch) @@ -336,17 +332,15 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { ) require.NoError(err) - onCommitState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) - - onAbortState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) + proposalBlkID := ids.GenerateTestID() + onProposalBlockState, onCommitState, onAbortState := makeProposalAndOptionsStates(require, env, lastAcceptedID, proposalBlkID) executor := ProposalTxExecutor{ - OnCommitState: onCommitState, - OnAbortState: onAbortState, - Backend: &env.backend, - Tx: tx, + OnProposalBlockState: onProposalBlockState, + OnCommitState: onCommitState, + OnAbortState: onAbortState, + Backend: &env.backend, + Tx: tx, } require.NoError(tx.Unsigned.Visit(&executor)) } @@ -382,17 +376,15 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { ) require.NoError(err) - onCommitState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) - - onAbortState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) + proposalBlkID := ids.GenerateTestID() + onProposalBlockState, onCommitState, onAbortState := makeProposalAndOptionsStates(require, env, lastAcceptedID, proposalBlkID) executor := ProposalTxExecutor{ - OnCommitState: onCommitState, - OnAbortState: onAbortState, - Backend: &env.backend, - Tx: tx, + OnProposalBlockState: onProposalBlockState, + OnCommitState: onCommitState, + OnAbortState: onAbortState, + Backend: &env.backend, + Tx: tx, } err = tx.Unsigned.Visit(&executor) require.ErrorIs(err, ErrNotValidator) @@ -427,17 +419,15 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { ) require.NoError(err) - onCommitState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) - - onAbortState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) + proposalBlkID := ids.GenerateTestID() + onProposalBlockState, onCommitState, onAbortState := makeProposalAndOptionsStates(require, env, lastAcceptedID, proposalBlkID) executor := ProposalTxExecutor{ - OnCommitState: onCommitState, - OnAbortState: onAbortState, - Backend: &env.backend, - Tx: tx, + OnProposalBlockState: onProposalBlockState, + OnCommitState: onCommitState, + OnAbortState: onAbortState, + Backend: &env.backend, + Tx: tx, } err = tx.Unsigned.Visit(&executor) require.ErrorIs(err, ErrPeriodMismatch) @@ -457,17 +447,15 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { ) require.NoError(err) - onCommitState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) - - onAbortState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) + proposalBlkID := ids.GenerateTestID() + onProposalBlockState, onCommitState, onAbortState := makeProposalAndOptionsStates(require, env, lastAcceptedID, proposalBlkID) executor := ProposalTxExecutor{ - OnCommitState: onCommitState, - OnAbortState: onAbortState, - Backend: &env.backend, - Tx: tx, + OnProposalBlockState: onProposalBlockState, + OnCommitState: onCommitState, + OnAbortState: onAbortState, + Backend: &env.backend, + Tx: tx, } err = tx.Unsigned.Visit(&executor) require.ErrorIs(err, ErrPeriodMismatch) @@ -487,17 +475,15 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { ) require.NoError(err) - onCommitState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) - - onAbortState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) + proposalBlkID := ids.GenerateTestID() + onProposalBlockState, onCommitState, onAbortState := makeProposalAndOptionsStates(require, env, lastAcceptedID, proposalBlkID) executor := ProposalTxExecutor{ - OnCommitState: onCommitState, - OnAbortState: onAbortState, - Backend: &env.backend, - Tx: tx, + OnProposalBlockState: onProposalBlockState, + OnCommitState: onCommitState, + OnAbortState: onAbortState, + Backend: &env.backend, + Tx: tx, } require.NoError(tx.Unsigned.Visit(&executor)) } @@ -519,17 +505,15 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { ) require.NoError(err) - onCommitState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) - - onAbortState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) + proposalBlkID := ids.GenerateTestID() + onProposalBlockState, onCommitState, onAbortState := makeProposalAndOptionsStates(require, env, lastAcceptedID, proposalBlkID) executor := ProposalTxExecutor{ - OnCommitState: onCommitState, - OnAbortState: onAbortState, - Backend: &env.backend, - Tx: tx, + OnProposalBlockState: onProposalBlockState, + OnCommitState: onCommitState, + OnAbortState: onAbortState, + Backend: &env.backend, + Tx: tx, } err = tx.Unsigned.Visit(&executor) require.ErrorIs(err, ErrTimestampNotBeforeStartTime) @@ -576,17 +560,15 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { ) require.NoError(err) - onCommitState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) - - onAbortState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) + proposalBlkID := ids.GenerateTestID() + onProposalBlockState, onCommitState, onAbortState := makeProposalAndOptionsStates(require, env, lastAcceptedID, proposalBlkID) executor := ProposalTxExecutor{ - OnCommitState: onCommitState, - OnAbortState: onAbortState, - Backend: &env.backend, - Tx: duplicateSubnetTx, + OnProposalBlockState: onProposalBlockState, + OnCommitState: onCommitState, + OnAbortState: onAbortState, + Backend: &env.backend, + Tx: duplicateSubnetTx, } err = duplicateSubnetTx.Unsigned.Visit(&executor) require.ErrorIs(err, ErrDuplicateValidator) @@ -616,17 +598,15 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { // This tx was syntactically verified when it was created...pretend it wasn't so we don't use cache addSubnetValidatorTx.SyntacticallyVerified = false - onCommitState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) - - onAbortState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) + proposalBlkID := ids.GenerateTestID() + onProposalBlockState, onCommitState, onAbortState := makeProposalAndOptionsStates(require, env, lastAcceptedID, proposalBlkID) executor := ProposalTxExecutor{ - OnCommitState: onCommitState, - OnAbortState: onAbortState, - Backend: &env.backend, - Tx: tx, + OnProposalBlockState: onProposalBlockState, + OnCommitState: onCommitState, + OnAbortState: onAbortState, + Backend: &env.backend, + Tx: tx, } err = tx.Unsigned.Visit(&executor) require.ErrorIs(err, errUnauthorizedSubnetModification) @@ -650,17 +630,15 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { require.NoError(err) copy(tx.Creds[1].(*secp256k1fx.Credential).Sigs[0][:], sig) - onCommitState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) - - onAbortState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) + proposalBlkID := ids.GenerateTestID() + onProposalBlockState, onCommitState, onAbortState := makeProposalAndOptionsStates(require, env, lastAcceptedID, proposalBlkID) executor := ProposalTxExecutor{ - OnCommitState: onCommitState, - OnAbortState: onAbortState, - Backend: &env.backend, - Tx: tx, + OnProposalBlockState: onProposalBlockState, + OnCommitState: onCommitState, + OnAbortState: onAbortState, + Backend: &env.backend, + Tx: tx, } err = tx.Unsigned.Visit(&executor) require.ErrorIs(err, errUnauthorizedSubnetModification) @@ -692,17 +670,15 @@ func TestProposalTxExecuteAddSubnetValidator(t *testing.T) { env.state.SetHeight(dummyHeight) require.NoError(env.state.Commit()) - onCommitState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) - - onAbortState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) + proposalBlkID := ids.GenerateTestID() + onProposalBlockState, onCommitState, onAbortState := makeProposalAndOptionsStates(require, env, lastAcceptedID, proposalBlkID) executor := ProposalTxExecutor{ - OnCommitState: onCommitState, - OnAbortState: onAbortState, - Backend: &env.backend, - Tx: tx, + OnProposalBlockState: onProposalBlockState, + OnCommitState: onCommitState, + OnAbortState: onAbortState, + Backend: &env.backend, + Tx: tx, } err = tx.Unsigned.Visit(&executor) require.ErrorIs(err, ErrDuplicateValidator) @@ -733,17 +709,15 @@ func TestProposalTxExecuteAddValidator(t *testing.T) { ) require.NoError(err) - onCommitState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) - - onAbortState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) + proposalBlkID := ids.GenerateTestID() + onProposalBlockState, onCommitState, onAbortState := makeProposalAndOptionsStates(require, env, lastAcceptedID, proposalBlkID) executor := ProposalTxExecutor{ - OnCommitState: onCommitState, - OnAbortState: onAbortState, - Backend: &env.backend, - Tx: tx, + OnProposalBlockState: onProposalBlockState, + OnCommitState: onCommitState, + OnAbortState: onAbortState, + Backend: &env.backend, + Tx: tx, } err = tx.Unsigned.Visit(&executor) require.ErrorIs(err, ErrTimestampNotBeforeStartTime) @@ -763,17 +737,15 @@ func TestProposalTxExecuteAddValidator(t *testing.T) { ) require.NoError(err) - onCommitState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) - - onAbortState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) + proposalBlkID := ids.GenerateTestID() + onProposalBlockState, onCommitState, onAbortState := makeProposalAndOptionsStates(require, env, lastAcceptedID, proposalBlkID) executor := ProposalTxExecutor{ - OnCommitState: onCommitState, - OnAbortState: onAbortState, - Backend: &env.backend, - Tx: tx, + OnProposalBlockState: onProposalBlockState, + OnCommitState: onCommitState, + OnAbortState: onAbortState, + Backend: &env.backend, + Tx: tx, } err = tx.Unsigned.Visit(&executor) require.ErrorIs(err, ErrFutureStakeTime) @@ -795,17 +767,15 @@ func TestProposalTxExecuteAddValidator(t *testing.T) { ) require.NoError(err) - onCommitState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) - - onAbortState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) + proposalBlkID := ids.GenerateTestID() + onProposalBlockState, onCommitState, onAbortState := makeProposalAndOptionsStates(require, env, lastAcceptedID, proposalBlkID) executor := ProposalTxExecutor{ - OnCommitState: onCommitState, - OnAbortState: onAbortState, - Backend: &env.backend, - Tx: tx, + OnProposalBlockState: onProposalBlockState, + OnCommitState: onCommitState, + OnAbortState: onAbortState, + Backend: &env.backend, + Tx: tx, } err = tx.Unsigned.Visit(&executor) require.ErrorIs(err, ErrAlreadyValidator) @@ -838,17 +808,15 @@ func TestProposalTxExecuteAddValidator(t *testing.T) { env.state.SetHeight(dummyHeight) require.NoError(env.state.Commit()) - onCommitState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) - - onAbortState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) + proposalBlkID := ids.GenerateTestID() + onProposalBlockState, onCommitState, onAbortState := makeProposalAndOptionsStates(require, env, lastAcceptedID, proposalBlkID) executor := ProposalTxExecutor{ - OnCommitState: onCommitState, - OnAbortState: onAbortState, - Backend: &env.backend, - Tx: tx, + OnProposalBlockState: onProposalBlockState, + OnCommitState: onCommitState, + OnAbortState: onAbortState, + Backend: &env.backend, + Tx: tx, } err = tx.Unsigned.Visit(&executor) require.ErrorIs(err, ErrAlreadyValidator) @@ -876,17 +844,15 @@ func TestProposalTxExecuteAddValidator(t *testing.T) { env.state.DeleteUTXO(utxoID) } - onCommitState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) - - onAbortState, err := state.NewDiff(lastAcceptedID, env) - require.NoError(err) + proposalBlkID := ids.GenerateTestID() + onProposalBlockState, onCommitState, onAbortState := makeProposalAndOptionsStates(require, env, lastAcceptedID, proposalBlkID) executor := ProposalTxExecutor{ - OnCommitState: onCommitState, - OnAbortState: onAbortState, - Backend: &env.backend, - Tx: tx, + OnProposalBlockState: onProposalBlockState, + OnCommitState: onCommitState, + OnAbortState: onAbortState, + Backend: &env.backend, + Tx: tx, } err = tx.Unsigned.Visit(&executor) require.ErrorIs(err, ErrFlowCheckFailed)