Skip to content

Commit 5d593a6

Browse files
committed
universe/supplycommit: add new sub-test for self-transition with dangling updates
1 parent 55fe2cb commit 5d593a6

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

universe/supplycommit/supply_commit_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,62 @@ func TestSupplyCommitBroadcastStateTransitions(t *testing.T) {
10101010
)
10111011
})
10121012

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

0 commit comments

Comments
 (0)