@@ -229,6 +229,54 @@ func TestReconcileConfirmationsForTransaction_NewConfirmation(t *testing.T) {
229229 mRPC .AssertExpectations (t )
230230}
231231
232+ func TestReconcileConfirmationsForTransaction_DifferentTxBlock (t * testing.T ) {
233+
234+ _ , c , mRPC , _ := newTestConnectorWithNoBlockerFilterDefaultMocks (t )
235+ bl := c .blockListener
236+ bl .canonicalChain = createTestChain (1976 , 1978 ) // Single block at 50, tx is at 100
237+
238+ // Mock for TransactionReceipt call
239+ mRPC .On ("CallRPC" , mock .Anything , mock .Anything , "eth_getTransactionReceipt" ,
240+ mock .MatchedBy (func (txHash string ) bool {
241+ assert .Equal (t , "0x6197ef1a58a2a592bb447efb651f0db7945de21aa8048801b250bd7b7431f9b6" , txHash )
242+ return true
243+ })).
244+ Return (nil ).
245+ Run (func (args mock.Arguments ) {
246+ err := json .Unmarshal ([]byte (sampleJSONRPCReceipt ), args [1 ])
247+ assert .NoError (t , err )
248+ })
249+
250+ mRPC .On ("CallRPC" , mock .Anything , mock .Anything , "eth_getBlockByNumber" , mock .MatchedBy (func (bn * ethtypes.HexInteger ) bool {
251+ return bn .BigInt ().String () == "1977"
252+ }), false ).Return (nil ).Run (func (args mock.Arguments ) {
253+ * args [1 ].(* * blockInfoJSONRPC ) = & blockInfoJSONRPC {
254+ Number : ethtypes .NewHexInteger64 (1977 ),
255+ Hash : ethtypes .MustNewHexBytes0xPrefix (generateTestHash (1977 )),
256+ ParentHash : ethtypes .MustNewHexBytes0xPrefix (generateTestHash (1976 )),
257+ }
258+ })
259+
260+ // Execute the reconcileConfirmationsForTransaction function
261+ result , err := c .ReconcileConfirmationsForTransaction (context .Background (), "0x6197ef1a58a2a592bb447efb651f0db7945de21aa8048801b250bd7b7431f9b6" , []* ffcapi.MinimalBlockInfo {
262+ {BlockNumber : fftypes .FFuint64 (1979 ), BlockHash : generateTestHash (1979 ), ParentHash : generateTestHash (1978 )},
263+ {BlockNumber : fftypes .FFuint64 (1980 ), BlockHash : generateTestHash (1980 ), ParentHash : generateTestHash (1979 )},
264+ }, 5 )
265+
266+ // Assertions - expect the existing confirmation queue to be returned because the tx block doesn't match the same block number in the canonical chain
267+ assert .NoError (t , err )
268+ assert .NotNil (t , result )
269+ assert .True (t , result .NewFork )
270+ assert .False (t , result .Confirmed )
271+ assert .Equal (t , []* ffcapi.MinimalBlockInfo {
272+ {BlockNumber : fftypes .FFuint64 (1977 ), BlockHash : generateTestHash (1977 ), ParentHash : generateTestHash (1976 )},
273+ {BlockNumber : fftypes .FFuint64 (1978 ), BlockHash : generateTestHash (1978 ), ParentHash : generateTestHash (1977 )},
274+ }, result .Confirmations )
275+ assert .Equal (t , uint64 (5 ), result .TargetConfirmationCount )
276+
277+ mRPC .AssertExpectations (t )
278+ }
279+
232280func TestBuildConfirmationList_GapInExistingConfirmationsError (t * testing.T ) {
233281 // Setup
234282 _ , c , mRPC , _ := newTestConnectorWithNoBlockerFilterDefaultMocks (t )
@@ -281,7 +329,6 @@ func TestBuildConfirmationList_MismatchConfirmationBlockError(t *testing.T) {
281329 assert .Nil (t , confirmationUpdateResult )
282330 assert .Regexp (t , "FF23063" , err .Error ())
283331}
284-
285332func TestBuildConfirmationList_ExistingConfirmationLaterThanCurrentBlockError (t * testing.T ) {
286333 // Setup
287334 _ , c , mRPC , _ := newTestConnectorWithNoBlockerFilterDefaultMocks (t )
@@ -650,41 +697,6 @@ func TestBuildConfirmationList_ConnectionNodeMismatch(t *testing.T) {
650697 assert .Equal (t , txBlockNumber + 5 , uint64 (confirmationUpdateResult .Confirmations [5 ].BlockNumber ))
651698}
652699
653- func TestBuildConfirmationList_CorruptedExistingConfirmationAfterFirstConfirmation (t * testing.T ) {
654- // Setup
655- bl , done := newBlockListenerWithTestChain (t , 100 , 5 , 100 , 150 , []uint64 {})
656- defer done ()
657-
658- ctx := context .Background ()
659- existingQueue := []* ffcapi.MinimalBlockInfo {
660- {BlockHash : generateTestHash (100 ), BlockNumber : fftypes .FFuint64 (100 ), ParentHash : generateTestHash (99 )},
661- {BlockHash : generateTestHash (101 ), BlockNumber : fftypes .FFuint64 (101 ), ParentHash : generateTestHash (100 )},
662- {BlockHash : generateTestHash (102 ), BlockNumber : fftypes .FFuint64 (102 ), ParentHash : "0xblockwrong" },
663- }
664- txBlockNumber := uint64 (100 )
665- txBlockHash := generateTestHash (100 )
666- txBlockInfo := & ffcapi.MinimalBlockInfo {
667- BlockNumber : fftypes .FFuint64 (txBlockNumber ),
668- BlockHash : txBlockHash ,
669- ParentHash : generateTestHash (99 ),
670- }
671- targetConfirmationCount := uint64 (5 )
672-
673- // Execute
674- confirmationUpdateResult , err := bl .buildConfirmationList (ctx , existingQueue , txBlockInfo , targetConfirmationCount )
675- assert .NoError (t , err )
676- // Assert
677- assert .True (t , confirmationUpdateResult .NewFork )
678- assert .True (t , confirmationUpdateResult .Confirmed )
679- assert .Len (t , confirmationUpdateResult .Confirmations , 6 )
680- assert .Equal (t , txBlockNumber , uint64 (confirmationUpdateResult .Confirmations [0 ].BlockNumber ))
681- assert .Equal (t , txBlockNumber + 1 , uint64 (confirmationUpdateResult .Confirmations [1 ].BlockNumber ))
682- assert .Equal (t , txBlockNumber + 2 , uint64 (confirmationUpdateResult .Confirmations [2 ].BlockNumber ))
683- assert .Equal (t , txBlockNumber + 3 , uint64 (confirmationUpdateResult .Confirmations [3 ].BlockNumber ))
684- assert .Equal (t , txBlockNumber + 4 , uint64 (confirmationUpdateResult .Confirmations [4 ].BlockNumber ))
685- assert .Equal (t , txBlockNumber + 5 , uint64 (confirmationUpdateResult .Confirmations [5 ].BlockNumber ))
686- }
687-
688700func TestBuildConfirmationList_FailedToFetchBlockInfo (t * testing.T ) {
689701 // Setup
690702 mRPC := & rpcbackendmocks.Backend {}
0 commit comments