@@ -514,6 +514,59 @@ func Test_MultipleTransactionSubmissionsWithinNonRecentInterval(t *testing.T) {
514514 )
515515}
516516
517+ func Test_MultipleTransactionSubmissionsWithDuplicates (t * testing.T ) {
518+ _ , cfg , stop := setupGatewayNode (t )
519+ defer stop ()
520+
521+ rpcTester := & rpcTest {
522+ url : fmt .Sprintf ("%s:%d" , cfg .RPCHost , cfg .RPCPort ),
523+ }
524+
525+ eoaKey , err := crypto .HexToECDSA (eoaTestPrivateKey )
526+ require .NoError (t , err )
527+
528+ testAddr := common .HexToAddress ("55253ed90B70b96C73092D8680915aaF50081194" )
529+ nonce := uint64 (0 )
530+ hashes := make ([]common.Hash , 0 )
531+
532+ signed , _ , err := evmSign (big .NewInt (10 ), 21000 , eoaKey , nonce , & testAddr , nil )
533+ require .NoError (t , err )
534+
535+ txHash , err := rpcTester .sendRawTx (signed )
536+ require .NoError (t , err )
537+ hashes = append (hashes , txHash )
538+
539+ // Increment nonce for the duplicate test transactions that follow
540+ nonce += 1
541+ dupSigned , _ , err := evmSign (big .NewInt (10 ), 15_000_000 , eoaKey , nonce , & testAddr , nil )
542+ require .NoError (t , err )
543+
544+ // Submit 5 identical transactions to test duplicate detection:
545+ // the first should succeed, the rest should be rejected as duplicates.
546+ for i := range 5 {
547+ if i == 0 {
548+ txHash , err := rpcTester .sendRawTx (dupSigned )
549+ require .NoError (t , err )
550+ hashes = append (hashes , txHash )
551+ } else {
552+ _ , err := rpcTester .sendRawTx (dupSigned )
553+ require .Error (t , err )
554+ require .ErrorContains (t , err , "invalid: transaction already in pool" )
555+ }
556+ }
557+
558+ assert .Eventually (t , func () bool {
559+ for _ , h := range hashes {
560+ rcp , err := rpcTester .getReceipt (h .String ())
561+ if err != nil || rcp == nil || rcp .Status != 1 {
562+ return false
563+ }
564+ }
565+
566+ return true
567+ }, time .Second * 15 , time .Second * 1 , "all transactions were not executed" )
568+ }
569+
517570func setupGatewayNode (t * testing.T ) (emulator.Emulator , config.Config , func ()) {
518571 srv , err := startEmulator (true )
519572 require .NoError (t , err )
0 commit comments