Skip to content

Commit 451e0ae

Browse files
committed
universe/supplycommit: add new sub-test for self-transition with dangling updates
1 parent 8612d2b commit 451e0ae

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

universe/supplycommit/state_machine_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,62 @@ func TestSupplyCommitBroadcastStateTransitions(t *testing.T) {
10131013
)
10141014
})
10151015

1016+
// This test verifies that a FinalizeEvent received by the
1017+
// CommitFinalizeState leads to a new commitment cycle if there are
1018+
// dangling updates.
1019+
t.Run("finalize_event_with_dangling_updates", func(t *testing.T) {
1020+
h := newSupplyCommitTestHarness(t, &harnessCfg{
1021+
initialState: &CommitFinalizeState{
1022+
SupplyTransition: initialTransition,
1023+
},
1024+
assetSpec: defaultAssetSpec,
1025+
})
1026+
h.start()
1027+
defer h.stopAndAssert()
1028+
1029+
h.expectApplyStateTransition()
1030+
1031+
// Mock the binding of dangling updates to return a new set of
1032+
// events.
1033+
danglingUpdate := newTestMintEvent(
1034+
t, test.RandPubKey(t), randOutPoint(t),
1035+
)
1036+
h.mockStateLog.On(
1037+
"BindDanglingUpdatesToTransition", mock.Anything,
1038+
mock.Anything,
1039+
).Return([]SupplyUpdateEvent{danglingUpdate}, nil).Once()
1040+
1041+
// Set up expectations for the new commitment cycle that should
1042+
// be triggered immediately.
1043+
h.expectFullCommitmentCycleMocks(true)
1044+
1045+
finalizeEvent := &FinalizeEvent{}
1046+
h.sendEvent(finalizeEvent)
1047+
1048+
// The state machine should transition to CommitTreeCreateState
1049+
// and then cascade through the commitment process.
1050+
h.assertStateTransitions(
1051+
&CommitTreeCreateState{},
1052+
&CommitTxCreateState{},
1053+
&CommitTxSignState{},
1054+
&CommitBroadcastState{},
1055+
&CommitBroadcastState{},
1056+
)
1057+
1058+
// We can also check that the new CreateTreeEvent was emitted
1059+
// with the correct dangling updates. This is a bit tricky as
1060+
// the event is internal. We can check the state of the next
1061+
// state.
1062+
finalState := assertAndGetCurrentState[*CommitBroadcastState](h)
1063+
require.Len(
1064+
t, finalState.SupplyTransition.PendingUpdates, 1,
1065+
)
1066+
require.Equal(
1067+
t, danglingUpdate,
1068+
finalState.SupplyTransition.PendingUpdates[0],
1069+
)
1070+
})
1071+
10161072
// This test verifies that a SupplyUpdateEvent received by the
10171073
// CommitBroadcastState results in a self-transition after inserting
10181074
// the update.

0 commit comments

Comments
 (0)