Skip to content

Commit 3b5df7c

Browse files
Eric-Warehimealjo242vladjdk
committed
test(systemtests): add appside mempool e2e test (#580)
* test(mempool): setup e2e test suite for mempool testing * WIP * test(mempool): refactor test * test(mempool): refactor system test suite * test(systemtest): refactor mempool test * test(systemtests): add cosmosClient * test(systemtests): refactor mempool test * test(systemtests): refactor mempool test * test(systemtests): refactor mempool test * test(systemtests): add txpool content verification to mempool tests * test(systemtests): fix mempool test suite * test(systemtests): fix mempool test suite * test(systemtests): fix mempool tests * test(systemtests): fix mempool test suite * test(systemtests): fix mempool test suite * test(systemtests): fix mempool test suite * test(systemtests): add mempool test cases * test(systemtests): add comments * test(systemtests): chore: enable replacement tests * chore: modify names of test cases * test(systemtests): enhance helper functions * test(systemtests): fix mempool test * chore(systemtests): change test name and add readme.md * chore: update CHANGELOG.md * fix(proto): restore removed data field during merge * test(systemtests): refactor * test(systemtests): fix map iteration * chore(systemtests): fix build tag * test(systemtests): add test case for mempool * test(systemtests): fix map iteration * test(systemtests): refactor and add test case for --minimum-gas-prices=0stake * test(systemtests): enhance validation * fix: restore removed changes from merge * fix: restore removed changes from merge * fix: restore removed changes from merge * fix: restore removed changes from merge * chore(systemtests): rename test suite hooks * fix(systemtests): fix test cases * chore: modify mempool e2e test README.md * test(systemtests): enhance post check of mempool test * chore: apply codeQL feedback * chore: update tests/systemtests/go.sum * chore: go mod tidy * fix(rpc): SendRawTransaction doesn't return error when tx.nonce is lower than pending nonce * chore(systemtests): remove unused fields of RPCTransaction type --------- Co-authored-by: Alex | Interchain Labs <[email protected]> Co-authored-by: Vlad J <[email protected]>
1 parent 6afef97 commit 3b5df7c

File tree

20 files changed

+2393
-202
lines changed

20 files changed

+2393
-202
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
- [\#576](https://github.com/cosmos/evm/pull/576) Parse logs from the txResult.Data and avoid emitting EVM events to cosmos-sdk events.
2929
- [\#584](https://github.com/cosmos/evm/pull/584) Fill block hash and timestamp for json rpc.
3030
- [\#582](https://github.com/cosmos/evm/pull/582) Add block max-gas (from genesis.json) and new min-tip (from app.toml/flags) ingestion into mempool config
31+
- [\#580](https://github.com/cosmos/evm/pull/580) add appside mempool e2e test
3132
- [\#598](https://github.com/cosmos/evm/pull/598) Reduce number of times CreateQueryContext in mempool.
3233
- [\#606](https://github.com/cosmos/evm/pull/606) Regenerate mock file for bank keeper related test.
3334
- [\#609](https://github.com/cosmos/evm/pull/609) Make `erc20Keeper` optional in the EVM keeper

rpc/backend/call_tx.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,25 @@ func (b *Backend) SendRawTransaction(data hexutil.Bytes) (common.Hash, error) {
160160
b.Logger.Debug("transaction queued due to nonce gap", "hash", txHash.Hex())
161161
return txHash, nil
162162
}
163+
if b.Mempool != nil && strings.Contains(err.Error(), mempool.ErrNonceLow.Error()) {
164+
from, err := ethSigner.Sender(tx)
165+
if err != nil {
166+
return common.Hash{}, fmt.Errorf("failed to get sender address: %w", err)
167+
}
168+
nonce, err := b.getAccountNonce(from, false, b.ClientCtx.Height, b.Logger)
169+
if err != nil {
170+
return common.Hash{}, fmt.Errorf("failed to get sender's current nonce: %w", err)
171+
}
172+
173+
// SendRawTransaction returns error when tx.Nonce is lower than committed nonce
174+
if tx.Nonce() < nonce {
175+
return common.Hash{}, err
176+
}
177+
178+
// SendRawTransaction does not return error when committed nonce <= tx.Nonce < pending nonce
179+
return txHash, nil
180+
}
181+
163182
b.Logger.Error("failed to broadcast tx", "error", err.Error())
164183
return txHash, fmt.Errorf("failed to broadcast transaction: %w", err)
165184
}

tests/systemtests/README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Getting started with a new system test
2+
3+
## Overview
4+
5+
The systemtests suite is an end-to-end test suite that runs the evmd process and sends RPC requests from separate Ethereum/Cosmos clients. The systemtests for cosmos/evm use the `cosmossdk.io/systemtests` package by default. For more details, please refer to https://github.com/cosmos/cosmos-sdk/tree/main/tests/systemtests.
6+
7+
## Preparation
8+
9+
Build a new binary from current branch and copy it to the `tests/systemtests/binaries` folder by running system tests.
10+
11+
```shell
12+
make test-system
13+
```
14+
15+
Or via manual steps
16+
17+
```shell
18+
make build
19+
mkdir -= ./tests/systemtests/binaries
20+
cp ./build/evmd ./tests/systemtests/binaries
21+
cp ./build/evmd ./tests/systemtests/binaries/v0.4
22+
```
23+
24+
## Run Individual test
25+
26+
### Run test cases for txs ordering
27+
28+
```shell
29+
go test -p 1 -parallel 1 -mod=readonly -tags='system_test' -v ./... \
30+
--run TestTxsOrdering --verbose --binary evmd --block-time 5s --chain-id local-4221
31+
```
32+
33+
### Run test cases for txs replacement
34+
35+
```shell
36+
go test -p 1 -parallel 1 -mod=readonly -tags='system_test' -v ./... \
37+
--run TestTxsReplacement --verbose --binary evmd --block-time 5s --chain-id local-4221
38+
```
39+
40+
### Run test exceptions
41+
42+
```shell
43+
go test -p 1 -parallel 1 -mod=readonly -tags='system_test' -v ./... \
44+
--run TestExceptions --verbose --binary evmd --block-time 5s --chain-id local-4221
45+
```
46+
47+
## Run Entire test
48+
49+
```shell
50+
make test
51+
```
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package clients
2+
3+
import (
4+
"fmt"
5+
"math/big"
6+
)
7+
8+
/**
9+
# ---------------- dev mnemonics source ----------------
10+
# dev0 address 0xC6Fe5D33615a1C52c08018c47E8Bc53646A0E101 | cosmos1cml96vmptgw99syqrrz8az79xer2pcgp84pdun
11+
# dev0's private key: 0x88cbead91aee890d27bf06e003ade3d4e952427e88f88d31d61d3ef5e5d54305 # gitleaks:allow
12+
13+
# dev1 address 0x963EBDf2e1f8DB8707D05FC75bfeFFBa1B5BaC17 | cosmos1jcltmuhplrdcwp7stlr4hlhlhgd4htqh3a79sq
14+
# dev1's private key: 0x741de4f8988ea941d3ff0287911ca4074e62b7d45c991a51186455366f10b544 # gitleaks:allow
15+
16+
# dev2 address 0x40a0cb1C63e026A81B55EE1308586E21eec1eFa9 | cosmos1gzsvk8rruqn2sx64acfsskrwy8hvrmafqkaze8
17+
# dev2's private key: 0x3b7955d25189c99a7468192fcbc6429205c158834053ebe3f78f4512ab432db9 # gitleaks:allow
18+
19+
# dev3 address 0x498B5AeC5D439b733dC2F58AB489783A23FB26dA | cosmos1fx944mzagwdhx0wz7k9tfztc8g3lkfk6rrgv6l
20+
# dev3's private key: 0x8a36c69d940a92fcea94b36d0f2928c7a0ee19a90073eda769693298dfa9603b # gitleaks:allow
21+
*/
22+
23+
const (
24+
ChainID = "local-4221"
25+
EVMChainID = "262144"
26+
27+
Acc0PrivKey = "88cbead91aee890d27bf06e003ade3d4e952427e88f88d31d61d3ef5e5d54305"
28+
Acc1PrivKey = "741de4f8988ea941d3ff0287911ca4074e62b7d45c991a51186455366f10b544"
29+
Acc2PrivKey = "3b7955d25189c99a7468192fcbc6429205c158834053ebe3f78f4512ab432db9"
30+
Acc3PrivKey = "8a36c69d940a92fcea94b36d0f2928c7a0ee19a90073eda769693298dfa9603b"
31+
32+
JsonRPCUrl0 = "http://127.0.0.1:8545"
33+
JsonRPCUrl1 = "http://127.0.0.1:8555"
34+
JsonRPCUrl2 = "http://127.0.0.1:8565"
35+
JsonRPCUrl3 = "http://127.0.0.1:8575"
36+
37+
NodeRPCUrl0 = "http://127.0.0.1:26657"
38+
NodeRPCUrl1 = "http://127.0.0.1:26658"
39+
NodeRPCUrl2 = "http://127.0.0.1:26659"
40+
NodeRPCUrl3 = "http://127.0.0.1:26660"
41+
)
42+
43+
type Config struct {
44+
ChainID string
45+
EVMChainID *big.Int
46+
PrivKeys []string
47+
JsonRPCUrls []string
48+
NodeRPCUrls []string
49+
}
50+
51+
// NewConfig creates a new Config instance.
52+
func NewConfig() (*Config, error) {
53+
// evm chainID
54+
evmChainID, ok := new(big.Int).SetString(EVMChainID, 10)
55+
if !ok {
56+
return nil, fmt.Errorf("error whilte setting chain id")
57+
}
58+
59+
// private keys of test accounts
60+
privKeys := []string{Acc0PrivKey, Acc1PrivKey, Acc2PrivKey, Acc3PrivKey}
61+
62+
// jsonrpc urls of testnet nodes
63+
jsonRPCUrls := []string{JsonRPCUrl0, JsonRPCUrl1, JsonRPCUrl2, JsonRPCUrl3}
64+
65+
// rpc urls of test nodes
66+
nodeRPCUrls := []string{NodeRPCUrl0, NodeRPCUrl1, NodeRPCUrl2, NodeRPCUrl3}
67+
68+
return &Config{
69+
ChainID: ChainID,
70+
EVMChainID: evmChainID,
71+
PrivKeys: privKeys,
72+
JsonRPCUrls: jsonRPCUrls,
73+
NodeRPCUrls: nodeRPCUrls,
74+
}, nil
75+
}

0 commit comments

Comments
 (0)