Skip to content

Commit a0a98b9

Browse files
cloudgrayaljo242
andauthored
refactor: systemtests (#720)
* refactor(systemtests): change CheckTxsQueuedSync to CheckTxsQueuedAsync * refactor(systemtests): remove calling AfterEachAction from TestTxsOrdering * refactor(systemtests): refactor account type * refactor(systemtests): apply mutex for accounts * refactor(systemtests): apply account pool to test cases * refactor(systemtests): apply account pool to eip7702 test * refactor(systemtests): fix CheckTxsQueuedAsync * refactor(systemtests): apply global chain * refactor(systemtests): fix eip7702 test * refactor(systemtests): fix test suite * chore(systemtests): refactor test suite * refactor(systemtests): fix eip712 test * refactor(systemtests): fix validation method * refactor(systemtests): refactor suite * WIP: refactor test suite * chore: modify makefile * refactor: change upgrade test file name and apply --mempool.max-txs=0 flag * refactor test suite * refactor(systemtest): add test cases * refactor(systemtest): enable chainupgrade test * refactor(systemtest): refactor suite * fix system tests * fix system tests * fix system tests * refactor test cases * chore: change test name * fix upgrade test * fix upgrade test * resolve merge conflic * test(systemtests): remove additional test accounts setting * test(systemtests): fix helper function for pending txs * test(systemtests): fix test case * tet(systemtests): refactor test execution * test(systemtests): remove account pool * test(systemtests): fix pending cosmos tx verification * chore: update CHANGELOG.md * chore: update comments * test(systemtests): increase block time of replacement test cases * fix: rollback block time increase for test * test(systemtests): apply 6s blocktime only for specific test case * test(systemtests): apply 9s blocktime only for specific test case * chore: modify Makefile * test(systemtest): disable non-deterministic test case * resolve merge conflict --------- Co-authored-by: Alex | Cosmos Labs <[email protected]>
1 parent de4f0d2 commit a0a98b9

29 files changed

+1113
-1112
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
- [\#709](https://github.com/cosmos/evm/pull/709) Fix mempool e2e test
8282
- [\#710](https://github.com/cosmos/evm/pull/710) Fix EoA-CA Identification logic
8383
- [\#711](https://github.com/cosmos/evm/pull/711) Add debug_traceCall api
84+
- [\#720](https://github.com/cosmos/evm/pull/720) Refactor systemtests
8485
- [\#734](https://github.com/cosmos/evm/pull/734) Disable evm mempool if max-txs set to -1.
8586
- [\#743](https://github.com/cosmos/evm/pull/743) Apply state overrides to eth_estimateGas api
8687

evmd/upgrades.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ package evmd
33
import (
44
"context"
55

6-
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
76
"github.com/cosmos/evm/x/vm/types"
87

9-
sdk "github.com/cosmos/cosmos-sdk/types"
10-
"github.com/cosmos/cosmos-sdk/types/module"
11-
128
storetypes "cosmossdk.io/store/types"
139
upgradetypes "cosmossdk.io/x/upgrade/types"
10+
11+
sdk "github.com/cosmos/cosmos-sdk/types"
12+
"github.com/cosmos/cosmos-sdk/types/module"
13+
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
1414
)
1515

1616
// UpgradeName defines the on-chain upgrade name for the sample EVMD upgrade
@@ -60,7 +60,9 @@ func (app EVMD) RegisterUpgradeHandlers() {
6060
if err != nil {
6161
return nil, err
6262
}
63-
// Initialize EvmCoinInfo in the module store
63+
// Initialize EvmCoinInfo in the module store. Chains bootstrapped before v0.5.0
64+
// binaries never stored this information (it lived only in process globals),
65+
// so migrating nodes would otherwise see an empty EvmCoinInfo on upgrade.
6466
if err := app.EVMKeeper.InitEvmCoinInfo(sdkCtx); err != nil {
6567
return nil, err
6668
}

tests/systemtests/Makefile

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,4 @@
33
WAIT_TIME ?= 20s
44

55
test:
6-
go test -failfast -timeout=30m -p=1 -mod=readonly -tags='system_test' -v ./... -run TestCosmosTxCompat --wait-time=$(WAIT_TIME) --block-time=9.5s --binary evmd --chain-id local-4221
7-
go test -failfast -timeout=30m -p=1 -mod=readonly -tags='system_test' -v ./... -run TestTxsReplacement --wait-time=$(WAIT_TIME) --block-time=9.5s --binary evmd --chain-id local-4221
8-
go test -failfast -timeout=30m -p=1 -mod=readonly -tags='system_test' -v ./... -run TestTxsOrdering --wait-time=$(WAIT_TIME) --block-time=3s --binary evmd --chain-id local-4221
9-
go test -failfast -timeout=30m -p=1 -mod=readonly -tags='system_test' -v ./... -run TestExceptions --wait-time=$(WAIT_TIME) --block-time=8s --binary evmd --chain-id local-4221
10-
go test -failfast -timeout=30m -p=1 -mod=readonly -tags='system_test' -v ./... -run TestEIP7702 --wait-time=$(WAIT_TIME) --block-time=5s --binary evmd --chain-id local-4221
11-
go test -failfast -timeout=30m -p=1 -mod=readonly -tags='system_test' -v ./... -run TestEIP712 --wait-time=$(WAIT_TIME) --block-time=5s --binary evmd --chain-id local-4221
12-
go test -failfast -timeout=30m -p=1 -mod=readonly -tags='system_test' -v ./... -run 'TestUpgrade|TestEth' --wait-time=$(WAIT_TIME) --block-time=5s --binary evmd --chain-id local-4221
6+
go test -failfast -timeout=30m -mod=readonly -tags='system_test' -v ./... --wait-time=$(WAIT_TIME) --binary evmd --chain-id local-4221

tests/systemtests/README.md

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,46 @@ cp ./build/evmd ./tests/systemtests/binaries/v0.4
2323

2424
## Run Individual test
2525

26-
### Run test cases for txs ordering
26+
Each scenario now has its own `Test…` wrapper in `main_test.go`, so you can target a specific flow directly. For example, to exercise the mempool ordering suite:
2727

2828
```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
29+
cd tests/systemtests
30+
go test -failfast -mod=readonly -tags=system_test ./... -run TestMempoolTxsOrdering \
31+
--verbose --binary evmd --block-time 3s --chain-id local-4221
3132
```
3233

33-
### Run test cases for txs replacement
34+
Mempool scenarios:
3435

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-
```
36+
| Test name | Description |
37+
|-----------|-------------|
38+
| `TestMempoolTxsOrdering` | Ordering of pending transactions across nodes |
39+
| `TestMempoolTxsReplacement` | Replacement behaviour for EVM transactions |
40+
| `TestMempoolTxsReplacementWithCosmosTx` | Replacement when Cosmos transactions are present |
41+
| `TestMempoolMixedTxsReplacementEVMAndCosmos` | Mixed Cosmos/EVM replacement coverage |
42+
| `TestMempoolTxRebroadcasting` | Rebroadcasting and nonce-gap handling |
43+
| `TestMempoolCosmosTxsCompatibility` | Cosmos-only transactions interacting with the mempool |
3944

40-
### Run test exceptions
45+
EIP-712 scenarios:
4146

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-
```
47+
| Test name | Description |
48+
|-----------|-------------|
49+
| `TestEIP712BankSend` | Single transfer signed via EIP-712 |
50+
| `TestEIP712BankSendWithBalanceCheck` | Transfer plus balance assertions |
51+
| `TestEIP712MultipleBankSends` | Sequential transfers with nonce management |
4652

47-
### Run EIP-7702 test
53+
Account abstraction:
4854

49-
```shell
50-
go test -p 1 -mod=readonly -tags='system_test' -v ./... \
51-
--run TestEIP7702 --verbose --binary evmd --block-time 3s --chain-id local-4221
52-
```
55+
| Test name | Description |
56+
|-----------|-------------|
57+
| `TestAccountAbstractionEIP7702` | Account abstraction (EIP-7702) flow |
58+
59+
Chain lifecycle:
60+
61+
| Test name | Description |
62+
|-----------|-------------|
63+
| `TestChainUpgrade` | End-to-end upgrade handling |
64+
65+
> ℹ️ The shared system test suite keeps a single chain alive across multiple tests when the node arguments are identical. Running several tests back-to-back therefore re-uses the same process unless a scenario explicitly changes the node configuration.
5366
5467
## Run all tests
5568

tests/systemtests/accountabstraction/interface.go

Lines changed: 0 additions & 31 deletions
This file was deleted.

tests/systemtests/accountabstraction/test_eip7702.go

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build system_test
2+
13
package accountabstraction
24

35
import (
@@ -10,23 +12,29 @@ import (
1012
. "github.com/onsi/ginkgo/v2"
1113
//nolint:revive // dot imports are fine for Ginkgo
1214
. "github.com/onsi/gomega"
13-
)
1415

15-
func TestEIP7702(t *testing.T) {
16-
const (
17-
user0 = "acc0"
18-
user1 = "acc1"
19-
)
16+
suite "github.com/cosmos/evm/tests/systemtests/suite"
17+
)
2018

19+
func RunEIP7702(t *testing.T, base *suite.BaseTestSuite) {
2120
Describe("test EIP-7702 scenorios", Ordered, func() {
2221
var (
23-
s AccountAbstractionTestSuite
22+
s *TestSuite
23+
user0Acc *suite.TestAccount
24+
user1Acc *suite.TestAccount
25+
user0 string
26+
user1 string
2427
)
2528

2629
// We intentionally use BeforeAll instead of BeforeAll because,
2730
// The test takes too much time if we restart network for each test case.
2831
BeforeAll(func() {
29-
s = NewTestSuite(t)
32+
s = NewTestSuite(base)
33+
user0Acc = s.BaseTestSuite.Acc(0)
34+
user1Acc = s.BaseTestSuite.Acc(1)
35+
user0 = user0Acc.ID
36+
user1 = user1Acc.ID
37+
s.SetPrimaryAccount(user0Acc)
3038
s.SetupTest(t)
3139
})
3240

@@ -59,20 +67,20 @@ func TestEIP7702(t *testing.T) {
5967
authChainID func() uint64
6068
authNonce func() uint64
6169
authAddress func() common.Address
62-
authSigner string
63-
txSender string
70+
authSigner func() string
71+
txSender func() string
6472
expDelegation bool
6573
}
6674

6775
DescribeTable("SetCode authorization scenarios", func(tc testCase) {
6876
authorization := createSetCodeAuthorization(tc.authChainID(), tc.authNonce(), tc.authAddress())
69-
signedAuthorization, err := signSetCodeAuthorization(s.GetPrivKey(tc.authSigner), authorization)
77+
signedAuthorization, err := signSetCodeAuthorization(s.GetPrivKey(tc.authSigner()), authorization)
7078
Expect(err).To(BeNil())
7179

72-
txHash, err := s.SendSetCodeTx(tc.txSender, signedAuthorization)
80+
txHash, err := s.SendSetCodeTx(tc.txSender(), signedAuthorization)
7381
Expect(err).To(BeNil(), "error while sending SetCode tx")
7482
s.WaitForCommit(txHash)
75-
s.CheckSetCode(tc.authSigner, tc.authAddress(), tc.expDelegation)
83+
s.CheckSetCode(tc.authSigner(), tc.authAddress(), tc.expDelegation)
7684
},
7785
Entry("setCode with invalid chainID should fail", testCase{
7886
authChainID: func() uint64 { return s.GetChainID() + 1 },
@@ -82,8 +90,8 @@ func TestEIP7702(t *testing.T) {
8290
authAddress: func() common.Address {
8391
return s.GetCounterAddr()
8492
},
85-
authSigner: user0,
86-
txSender: user0,
93+
authSigner: func() string { return user0 },
94+
txSender: func() string { return user0 },
8795
expDelegation: false,
8896
}),
8997
Entry("setCode with empty address should reset delegation", testCase{
@@ -94,8 +102,8 @@ func TestEIP7702(t *testing.T) {
94102
authAddress: func() common.Address {
95103
return common.HexToAddress("0x0")
96104
},
97-
authSigner: user0,
98-
txSender: user0,
105+
authSigner: func() string { return user0 },
106+
txSender: func() string { return user0 },
99107
expDelegation: false,
100108
}),
101109
Entry("setCode with invalid address should fail", testCase{
@@ -106,8 +114,8 @@ func TestEIP7702(t *testing.T) {
106114
authAddress: func() common.Address {
107115
return common.BytesToAddress([]byte("invalid"))
108116
},
109-
authSigner: user0,
110-
txSender: user0,
117+
authSigner: func() string { return user0 },
118+
txSender: func() string { return user0 },
111119
expDelegation: true,
112120
}),
113121
Entry("setCode with EoA address should fail", testCase{
@@ -118,8 +126,8 @@ func TestEIP7702(t *testing.T) {
118126
authAddress: func() common.Address {
119127
return s.GetAddr(user1)
120128
},
121-
authSigner: user0,
122-
txSender: user0,
129+
authSigner: func() string { return user0 },
130+
txSender: func() string { return user0 },
123131
expDelegation: true,
124132
}),
125133
Entry("same signer/sender with matching nonce should fail", testCase{
@@ -130,8 +138,8 @@ func TestEIP7702(t *testing.T) {
130138
authAddress: func() common.Address {
131139
return s.GetCounterAddr()
132140
},
133-
authSigner: user0,
134-
txSender: user0,
141+
authSigner: func() string { return user0 },
142+
txSender: func() string { return user0 },
135143
expDelegation: false,
136144
}),
137145
Entry("same signer/sender with future nonce sholud succeed", testCase{
@@ -142,8 +150,8 @@ func TestEIP7702(t *testing.T) {
142150
authAddress: func() common.Address {
143151
return s.GetCounterAddr()
144152
},
145-
authSigner: user0,
146-
txSender: user0,
153+
authSigner: func() string { return user0 },
154+
txSender: func() string { return user0 },
147155
expDelegation: true,
148156
}),
149157
Entry("different signer/sender with current nonce should succeed", testCase{
@@ -154,8 +162,8 @@ func TestEIP7702(t *testing.T) {
154162
authAddress: func() common.Address {
155163
return s.GetCounterAddr()
156164
},
157-
authSigner: user1,
158-
txSender: user0,
165+
authSigner: func() string { return user1 },
166+
txSender: func() string { return user0 },
159167
expDelegation: true,
160168
}),
161169
Entry("different signer/sender with future nonce should fail", testCase{
@@ -166,8 +174,8 @@ func TestEIP7702(t *testing.T) {
166174
authAddress: func() common.Address {
167175
return s.GetCounterAddr()
168176
},
169-
authSigner: user1,
170-
txSender: user0,
177+
authSigner: func() string { return user1 },
178+
txSender: func() string { return user0 },
171179
expDelegation: false,
172180
}),
173181
)

0 commit comments

Comments
 (0)