Skip to content

tests: refactoring #198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Jun 12, 2025
Merged

tests: refactoring #198

merged 23 commits into from
Jun 12, 2025

Conversation

zsystm
Copy link
Contributor

@zsystm zsystm commented Jun 4, 2025

Refactor Integration Tests and Modularize evmd Package

This PR introduces a major restructuring of the Cosmos EVM testing infrastructure to improve modularity, reusability, and maintainability.

Summary

  • Modularized evmd into a standalone package (github.com/cosmos/evm/evmd)
  • Refactored integration test suites to depend on an abstract EvmApp interface
  • Reorganized test structure for easier consumption by downstream client chains
  • Removed cyclic dependencies and cleaned up unused files

Key Changes

evmd Modularization

  • evmd is now a standalone package that imports from evm, but never the other way around.
  • This guarantees a clean and unidirectional dependency graph, ensuring that core logic remains encapsulated within evm.

Interface-Based Testing

  • Introduced an EvmApp interface to represent the application under test.
  • All integration test suites now depend on this interface rather than directly referencing evmd.
  • This allows any client chain to reuse the test suites by implementing EvmApp.

Test Structure Restructuring

  • Integration tests that use both network and evmd were moved to evm/tests/integration.
  • Test file names were changed from *_test.go to test_*.go to allow proper compilation and import from other packages.
    • Go ignores *_test.go files when importing, so this rename enables downstream reuse.

Internal Refactoring

  • Changed backend fields to public for easier access during tests.
    • If security is a concern, we may introduce getters.
  • Removed unused test files and redundant code.

Outcome

  • Enables downstream chains to reuse Cosmos EVM integration tests with minimal changes
  • Ensures modular and decoupled architecture between evm and evmd
  • Improves test suite maintainability and extensibility moving forward

Closes: #33


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • tackled an existing issue or discussed with a team member
  • left instructions on how to review the changes
  • targeted the main branch

Reviewers Checklist

All items are required.
Please add a note if the item is not applicable
and please add your handle next to the items reviewed
if you only reviewed selected items.

I have...

  • added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • confirmed all author checklist items have been addressed
  • confirmed that this PR does not change production code
  • reviewed content
  • tested instructions (if applicable)
  • confirmed all CI checks have passed

zsystm added 3 commits June 4, 2025 21:43
evmd as separate package
- we can make sure more clean dependency: only evmd -> evmd allows. not vice versa.

test re-structuring
- tests using network + evmd moved into evm/tests/integration
- test file names are changed from *_test.go to test_*.go, so any client chains can leverage cosmos/evm's test suites with their own application

refactoring
- all integration tests in evm uses EvmApp interface. so it allows other client application can leverage cosmos/evm's test suites.
- evmd implements methods of EvmApp
- separate Erc20Keeper interface to avoid cyclic import between erc20/keeper and precompiles/erc20
- change backend member variables to public. this is for making testing refactoring easier. if there are some security concern, we should consider introducing getters.

 removed un-used files
# Conflicts:
#	cmd/evmd/cmd/root.go
#	tests/integration/rpc/backend/test_backend_suite.go
#	tests/integration/rpc/backend/test_chain_info.go
removed already migrated test also
@zsystm zsystm force-pushed the tests/refactoring branch from f3642b4 to 1868405 Compare June 4, 2025 23:48
@zsystm zsystm force-pushed the tests/refactoring branch 3 times, most recently from dcf74a9 to 1d4201c Compare June 5, 2025 01:11
@zsystm zsystm force-pushed the tests/refactoring branch from 1d4201c to cce11c9 Compare June 5, 2025 02:01
@zsystm zsystm self-assigned this Jun 5, 2025
@zsystm zsystm marked this pull request as ready for review June 5, 2025 05:16
@zsystm zsystm requested a review from vladjdk June 5, 2025 05:16
@zsystm zsystm requested a review from Eric-Warehime June 5, 2025 19:44
evmd/go.mod Outdated
@@ -0,0 +1,280 @@
module cosmosevm.io/evmd
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to maintain the github based url.

Copy link
Contributor Author

@zsystm zsystm Jun 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Eric-Warehime
How about using github.com/cosmos/evm/evmd instead?
Happy to hear any other suggestions as well if you have something else in mind!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's fine. I think we just don't like the confusion that the github.com/cosmos/cosmos-sdk and cosmossdk.io naming has caused, so it's best to stick with the github prefixes here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Eric-Warehime
Applied in e7377b4

interfaces.go Outdated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we can just declare the interface wherever we need to use it. Are you doing it here because it's just used everywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Eric-Warehime
That’s a fair point.

Currently, EvmApp is used across quite a few directories. While it’s technically possible to define the interface locally wherever it's needed, I thought it made sense to keep it in evm/interfaces.go since it serves as a kind of reference interface for chains that want to integrate with cosmos/evm, especially when running the tests under tests/integration.

Putting it directly under cosmos/evm felt like a clear signal that it’s the standard interface contract for client chains implementing EvmApp.

That said, I’m not strongly opinionated here — if you still feel it’s better to colocate the interface with each usage site, I’m happy to revisit that direction.

go.mod Outdated
@@ -3,8 +3,8 @@ module github.com/cosmos/evm
go 1.23.8

require (
cosmosevm.io/evmd v0.0.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the idea was to remove this?

evmd is now a standalone package that imports from evm, but never the other way around.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Eric-Warehime
You're right — the ultimate goal is to remove evmd from evm entirely.
However, there are a few more changes needed before we can fully eliminate it.

For example, we'll need to:

  • Move evm/cmd to evm/evmd/cmd/
  • Relocate shared data structures currently under evmd into a more appropriate place within evm.

I considered including these changes in the testing refactoring PR, but it felt like too much to bundle into a single PR. That's why I thought it would be cleaner to address the removal of evmd in a follow-up PR.

Would you prefer we fully remove the evmd dependency as part of this PR?
Or does it make more sense to merge the testing refactoring first, and then handle the cleanup/removal in a separate one?

Happy to align either way.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, happy to do things in separate PRs since this is already large in terms of lines of code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created separate issue for following up this: #211

zsystm added 5 commits June 10, 2025 14:36
# Conflicts:
#	.golangci.yml
#	evmd/tests/ibc/helper.go
#	evmd/tests/ibc/ibc_middleware_test.go
#	evmd/testutil/abci.go
#	go.mod
#	precompiles/distribution/integration_test.go
#	precompiles/erc20/integration_test.go
#	precompiles/gov/integration_test.go
#	precompiles/p256/integration_test.go
#	precompiles/staking/integration_test.go
#	tests/integration/precompiles/erc20/test_events.go
#	tests/integration/rpc/backend/test_blocks.go
#	tests/integration/x/erc20/test_genesis.go
#	tests/integration/x/erc20/test_ibc_callback.go
#	tests/integration/x/vm/test_call_evm.go
#	testutil/integration/evm/network/abci.go
#	testutil/integration/evm/network/network.go
@zsystm zsystm requested a review from Eric-Warehime June 11, 2025 18:55
@zsystm zsystm merged commit 9fae984 into cosmos:main Jun 12, 2025
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Testing Refactor
2 participants