@@ -1010,6 +1010,62 @@ func TestSupplyCommitBroadcastStateTransitions(t *testing.T) {
1010
1010
)
1011
1011
})
1012
1012
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
+
1013
1069
// This test verifies that a SupplyUpdateEvent received by the
1014
1070
// CommitBroadcastState results in a self-transition after inserting
1015
1071
// the update.
0 commit comments