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