Skip to content

Commit 6ccf8db

Browse files
committed
Improve tests for tx submission with nonce validation
1 parent 41c7839 commit 6ccf8db

1 file changed

Lines changed: 47 additions & 7 deletions

File tree

tests/tx_batching_test.go

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ func Test_MultipleTransactionSubmissionsWithinNonRecentInterval(t *testing.T) {
515515
}
516516

517517
func Test_TransactionSubmissionWithPreviouslySubmittedTransactions(t *testing.T) {
518-
_, cfg, stop := setupGatewayNode(t)
518+
emu, cfg, stop := setupGatewayNode(t)
519519
defer stop()
520520

521521
rpcTester := &rpcTest{
@@ -528,16 +528,28 @@ func Test_TransactionSubmissionWithPreviouslySubmittedTransactions(t *testing.T)
528528
testAddr := common.HexToAddress("0x061B63D29332e4de81bD9F51A48609824CD113a8")
529529
nonces := []uint64{0, 1, 2, 3, 2, 3, 4, 5}
530530

531+
g := errgroup.Group{}
532+
533+
startBlock, err := emu.GetLatestBlock()
534+
require.NoError(t, err)
535+
531536
hashes := []common.Hash{}
532537
// transfer some funds to the test address
533538
transferAmount := int64(1_000_000_000)
534-
for _, nonce := range nonces {
535-
signed, _, err := evmSign(big.NewInt(transferAmount), 23_500, eoaKey, nonce, &testAddr, nil)
536-
require.NoError(t, err)
537539

538-
txHash, err := rpcTester.sendRawTx(signed)
539-
require.NoError(t, err)
540-
hashes = append(hashes, txHash)
540+
for range 3 {
541+
g.Go(func() error {
542+
for _, nonce := range nonces {
543+
signed, _, err := evmSign(big.NewInt(transferAmount), 23_500, eoaKey, nonce, &testAddr, nil)
544+
require.NoError(t, err)
545+
546+
txHash, err := rpcTester.sendRawTx(signed)
547+
require.NoError(t, err)
548+
hashes = append(hashes, txHash)
549+
}
550+
551+
return nil
552+
})
541553
}
542554

543555
expectedBalance := big.NewInt(6 * transferAmount)
@@ -550,6 +562,34 @@ func Test_TransactionSubmissionWithPreviouslySubmittedTransactions(t *testing.T)
550562

551563
return balance.Cmp(expectedBalance) == 0
552564
}, time.Second*15, time.Second*1, "all transactions were not executed")
565+
566+
endBlock, err := emu.GetLatestBlock()
567+
require.NoError(t, err)
568+
569+
blockEvents, err := emu.GetEventsForHeightRange(
570+
"A.f8d6e0586b0a20c7.EVM.TransactionExecuted",
571+
startBlock.Height+1,
572+
endBlock.Height,
573+
)
574+
575+
totalEVMEvents := 0
576+
for _, blockEvent := range blockEvents {
577+
totalEVMEvents += len(blockEvent.Events)
578+
}
579+
assert.Equal(t, 6, totalEVMEvents)
580+
581+
for i := startBlock.Height; i <= endBlock.Height; i++ {
582+
block, err := emu.GetBlockByHeight(i)
583+
require.NoError(t, err)
584+
585+
txResults, err := emu.GetTransactionResultsByBlockID(block.ID())
586+
require.NoError(t, err)
587+
588+
for _, txResult := range txResults {
589+
// Assert that we have no errors on the submitted transactions
590+
require.Empty(t, txResult.ErrorMessage)
591+
}
592+
}
553593
}
554594

555595
func setupGatewayNode(t *testing.T) (emulator.Emulator, config.Config, func()) {

0 commit comments

Comments
 (0)