Skip to content

Commit 2687f13

Browse files
feat: update EthGetTransactionCount test for earliest, latest, and pending block parameters (#12548)
* chore: fix EthGetTransactionCount for earliest block parameter * feat: update `EthGetTransactionCount` test for `earliest`, `latest`, and `pending` block parameters and refactor `EthGetTransactionCount` to return empty block for `earliest` * chore: refactor EthGetTransactionCount test * update changelog * refactor EthGetTransactionCount test and fix for earliest block parameter * Update CHANGELOG.md
1 parent 720ae49 commit 2687f13

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
## Improvements
1414

15+
- Update `TestEthGetTransactionCount` to test for `earliest`, `pending` and `finalized`. ([filecoin-project/lotus#12448](https://github.com/filecoin-project/lotus/pull/12448))
1516
- Reduce size of embedded genesis CAR files by removing WASM actor blocks and compressing with zstd. This reduces the `lotus` binary size by approximately 10 MiB. ([filecoin-project/lotus#12439](https://github.com/filecoin-project/lotus/pull/12439))
1617
- Add ChainSafe operated Calibration archival node to the bootstrap list ([filecoin-project/lotus#12517](https://github.com/filecoin-project/lotus/pull/12517))
1718

itests/fevm_test.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,7 +1259,14 @@ func TestEthGetTransactionCount(t *testing.T) {
12591259
client.EVM().SignTransaction(tx, key.PrivateKey)
12601260
lastHash = client.EVM().SubmitTransaction(ctx, tx)
12611261

1262-
// Check pending transaction count immediately after submission
1262+
// Check counts for "earliest", "latest", and "pending"
1263+
_, err = client.EVM().EthGetTransactionCount(ctx, ethAddr, ethtypes.NewEthBlockNumberOrHashFromPredefined("earliest"))
1264+
require.Error(t, err) // earliest is not supported
1265+
1266+
latestCount, err := client.EVM().EthGetTransactionCount(ctx, ethAddr, ethtypes.NewEthBlockNumberOrHashFromPredefined("latest"))
1267+
require.NoError(t, err)
1268+
require.Equal(t, ethtypes.EthUint64(i), latestCount, "Latest transaction count should be equal to the number of mined transactions")
1269+
12631270
pendingCount, err := client.EVM().EthGetTransactionCount(ctx, ethAddr, ethtypes.NewEthBlockNumberOrHashFromPredefined("pending"))
12641271
require.NoError(t, err)
12651272
require.True(t, int(pendingCount) == i || int(pendingCount) == i+1,
@@ -1268,17 +1275,19 @@ func TestEthGetTransactionCount(t *testing.T) {
12681275
// Wait for the transaction to be mined
12691276
_, err = client.EVM().WaitTransaction(ctx, lastHash)
12701277
require.NoError(t, err)
1271-
1272-
// Check latest transaction count after the transaction is mined
1273-
latestCount, err := client.EVM().EthGetTransactionCount(ctx, ethAddr, ethtypes.NewEthBlockNumberOrHashFromPredefined("latest"))
1274-
require.NoError(t, err)
1275-
require.Equal(t, ethtypes.EthUint64(i+1), latestCount, "Latest transaction count should increment after mining")
12761278
}
12771279

1278-
// Get the final latest transaction count
1280+
// Get the final counts for "earliest", "latest", and "pending"
1281+
_, err = client.EVM().EthGetTransactionCount(ctx, ethAddr, ethtypes.NewEthBlockNumberOrHashFromPredefined("earliest"))
1282+
require.Error(t, err) // earliest is not supported
1283+
12791284
finalLatestCount, err := client.EVM().EthGetTransactionCount(ctx, ethAddr, ethtypes.NewEthBlockNumberOrHashFromPredefined("latest"))
12801285
require.NoError(t, err)
1281-
require.Equal(t, ethtypes.EthUint64(numTx), finalLatestCount)
1286+
require.Equal(t, ethtypes.EthUint64(numTx), finalLatestCount, "Final latest transaction count should equal the number of transactions sent")
1287+
1288+
finalPendingCount, err := client.EVM().EthGetTransactionCount(ctx, ethAddr, ethtypes.NewEthBlockNumberOrHashFromPredefined("pending"))
1289+
require.NoError(t, err)
1290+
require.Equal(t, ethtypes.EthUint64(numTx), finalPendingCount, "Final pending transaction count should equal the number of transactions sent")
12821291

12831292
// Test with a contract
12841293
createReturn := client.EVM().DeployContract(ctx, client.DefaultKey.Address, contract)

0 commit comments

Comments
 (0)