Skip to content

Commit cbc73f0

Browse files
committed
Update nonce behavior to be managed by tx creator
1 parent d5c83bb commit cbc73f0

File tree

9 files changed

+18
-24
lines changed

9 files changed

+18
-24
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Edit `my-config.json`:
2121
```json
2222
{
2323
"endpoints": ["http://localhost:8545"],
24-
"chainId": 1329,
24+
"chainId": 713714,
2525
"scenarios": [
2626
{"name": "EVMTransfer", "weight": 100}
2727
],
@@ -94,7 +94,7 @@ Edit `my-config.json`:
9494
```json
9595
{
9696
"endpoints": ["http://localhost:8545"],
97-
"chainId": 1329,
97+
"chainId": 713714,
9898
"scenarios": [...],
9999
"accounts": {...},
100100
"settings": {...}

generator/prewarm.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ func (pg *PrewarmGenerator) Generate() (*types.LoadTx, bool) {
7979
Name: "EVMTransfer",
8080
Sender: account,
8181
Receiver: account.Address, // Send to self
82-
Nonce: account.GetAndIncrementNonce(),
8382
}
8483

8584
// Generate the transaction using EVMTransfer scenario

generator/scenario.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ func (g *scenarioGenerator) Generate() (*types.LoadTx, bool) {
4040
Name: g.scenario.Name(),
4141
Sender: sender,
4242
Receiver: receiver.Address,
43-
Nonce: sender.GetAndIncrementNonce(),
4443
}), true
4544
}
4645

generator/scenarios/EVMTransfer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (s *EVMTransferScenario) AttachScenario(config *config.LoadConfig, address
4848
func (s *EVMTransferScenario) CreateTransaction(config *config.LoadConfig, scenario *types2.TxScenario) (*ethtypes.Transaction, error) {
4949
// Create transaction with value transfer
5050
tx := &ethtypes.DynamicFeeTx{
51-
Nonce: scenario.Nonce,
51+
Nonce: scenario.Sender.GetAndIncrementNonce(),
5252
To: &scenario.Receiver,
5353
Value: big.NewInt(time.Now().Unix()),
5454
Gas: 21000, // Standard gas limit for ETH transfer

generator/scenarios/EVMTransferNoop.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (s *EVMTransferNoopScenario) AttachScenario(config *config.LoadConfig, addr
4747
func (s *EVMTransferNoopScenario) CreateTransaction(config *config.LoadConfig, scenario *types2.TxScenario) (*ethtypes.Transaction, error) {
4848
// Create transaction with value transfer
4949
tx := &ethtypes.DynamicFeeTx{
50-
Nonce: scenario.Nonce,
50+
Nonce: scenario.Sender.GetAndIncrementNonce(),
5151
To: &scenario.Sender.Address,
5252
Value: big.NewInt(0),
5353
Gas: 21000, // Standard gas limit for ETH transfer

generator/scenarios/base.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@ func (c *ContractScenarioBase[T]) DeployScenario(config *config.LoadConfig, depl
200200
}
201201

202202
log.Printf("✅ Deployment successful at block %d (gas used: %d)", receipt.BlockNumber.Uint64(), receipt.GasUsed)
203-
deployer.GetAndIncrementNonce()
204203

205204
// Bind contract instance using the provided bind function
206205
bindFunc := c.deployer.GetBindFunc()

generator/utils/utils.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func createTransactOpts(chainID *big.Int, account *loadtypes.Account, gasLimit u
4545
}
4646

4747
// Set transaction parameters
48-
auth.Nonce = big.NewInt(int64(account.Nonce))
48+
auth.Nonce.SetUint64(account.GetAndIncrementNonce())
4949
auth.NoSend = noSend
5050

5151
auth.GasLimit = gasLimit
@@ -68,6 +68,5 @@ func CreateTransactionOpts(chainID *big.Int, scenario *loadtypes.TxScenario) *bi
6868
if err != nil {
6969
panic("Failed to create transaction options: " + err.Error())
7070
}
71-
opts.Nonce.SetUint64(scenario.Nonce)
7271
return opts
7372
}

types/scenario.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ func (tx *LoadTx) ShardID(n int) int {
4949
// TxScenario captures the scenario of this test transaction.
5050
type TxScenario struct {
5151
Name string
52-
Nonce uint64
5352
Sender *Account
5453
Receiver common.Address
5554
}

types/types_test.go

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -250,18 +250,18 @@ func TestCreateTxFromEthTx(t *testing.T) {
250250
account, err := NewAccount()
251251
require.NoError(t, err)
252252

253+
account.Nonce = 42
253254
receiver := common.HexToAddress("0x1234567890123456789012345678901234567890")
254255
scenario := &TxScenario{
255256
Name: "TestScenario",
256-
Nonce: 42,
257257
Sender: account,
258258
Receiver: receiver,
259259
}
260260

261261
// Create a test transaction using DynamicFeeTx (EIP-1559)
262262
tx := types.NewTx(&types.DynamicFeeTx{
263-
ChainID: big.NewInt(1329), // Sei testnet chain ID
264-
Nonce: scenario.Nonce,
263+
ChainID: big.NewInt(713714), // Sei testnet chain ID
264+
Nonce: scenario.Sender.Nonce,
265265
GasTipCap: big.NewInt(2000000000), // 2 Gwei tip
266266
GasFeeCap: big.NewInt(20000000000), // 20 Gwei max fee
267267
Gas: 21000, // Gas limit
@@ -314,15 +314,15 @@ func TestLoadTxShardID(t *testing.T) {
314314
account := accounts[i%len(accounts)]
315315
scenario := &TxScenario{
316316
Name: "TestScenario",
317-
Nonce: uint64(i),
318317
Sender: account,
319318
Receiver: common.Address{},
320319
}
321320

321+
scenario.Sender.Nonce = uint64(i)
322322
// Create a simple transaction
323323
tx := types.NewTx(&types.DynamicFeeTx{
324-
ChainID: big.NewInt(1329), // Sei testnet chain ID
325-
Nonce: scenario.Nonce,
324+
ChainID: big.NewInt(713714), // Sei testnet chain ID
325+
Nonce: scenario.Sender.Nonce,
326326
GasTipCap: big.NewInt(2000000000), // 2 Gwei tip
327327
GasFeeCap: big.NewInt(20000000000), // 20 Gwei max fee
328328
Gas: 21000, // Gas limit
@@ -374,14 +374,13 @@ func TestLoadTxShardIDConsistency(t *testing.T) {
374374

375375
scenario := &TxScenario{
376376
Name: "TestScenario",
377-
Nonce: 0,
378377
Sender: account,
379378
Receiver: common.Address{},
380379
}
381380

382381
tx := types.NewTx(&types.DynamicFeeTx{
383-
ChainID: big.NewInt(1329), // Sei testnet chain ID
384-
Nonce: scenario.Nonce,
382+
ChainID: big.NewInt(713714), // Sei testnet chain ID
383+
Nonce: scenario.Sender.Nonce,
385384
GasTipCap: big.NewInt(2000000000), // 2 Gwei tip
386385
GasFeeCap: big.NewInt(20000000000), // 20 Gwei max fee
387386
Gas: 21000, // Gas limit
@@ -408,16 +407,17 @@ func TestTxScenario(t *testing.T) {
408407

409408
receiver := common.HexToAddress("0xabcdefabcdefabcdefabcdefabcdefabcdefabcd")
410409

410+
account.Nonce = 123
411+
411412
scenario := &TxScenario{
412413
Name: "TestScenario",
413-
Nonce: 123,
414414
Sender: account,
415415
Receiver: receiver,
416416
}
417417

418418
// Verify all fields are set correctly
419419
assert.Equal(t, "TestScenario", scenario.Name)
420-
assert.Equal(t, uint64(123), scenario.Nonce)
420+
assert.Equal(t, uint64(123), scenario.Sender.Nonce)
421421
assert.Equal(t, account, scenario.Sender)
422422
assert.Equal(t, receiver, scenario.Receiver)
423423
}
@@ -477,14 +477,13 @@ func BenchmarkCreateTxFromEthTx(b *testing.B) {
477477

478478
scenario := &TxScenario{
479479
Name: "BenchmarkScenario",
480-
Nonce: 0,
481480
Sender: account,
482481
Receiver: common.Address{},
483482
}
484483

485484
tx := types.NewTx(&types.DynamicFeeTx{
486-
ChainID: big.NewInt(1329), // Sei testnet chain ID
487-
Nonce: scenario.Nonce,
485+
ChainID: big.NewInt(713714), // Sei testnet chain ID
486+
Nonce: scenario.Sender.Nonce,
488487
GasTipCap: big.NewInt(2000000000), // 2 Gwei tip
489488
GasFeeCap: big.NewInt(20000000000), // 20 Gwei max fee
490489
Gas: 21000, // Gas limit

0 commit comments

Comments
 (0)