-
Notifications
You must be signed in to change notification settings - Fork 51
refactor: common test utils #2650
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
Conversation
plus `precomputed_kes_key`
As it produce the error directly in the caller test, allowing to give the line of the failure.
…ger` creation Also move this new and the existing test logging utilities to a `test::logging` module.
And move its definition to a `test` module instead of a `test_utils` to be in line with the latest naming scheme (only for crates that already have a `test` module).
As mocks are test double, it should have been there in the first place
…ion traits This allow a clean split between the production and test code even when using thoses methods as to do so you will now need to import a trait located in the `mithril_common::test` module. one caveat: in order to transform `Blockrange::new` into a extension trait method, its `inner_range` property had to be made `pub(crate)`.
…:new` Has its value was low and it was even confusing since both parameters use the same type. This allow to remove the last usage of `cfg_test_tools` in mithril common, beside the one on the test module.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This pull request refactors the mithril-common crate's test utilities by renaming the test_utils module to test and reorganizing its structure to follow a more consistent pattern across the codebase.
Key changes:
- Renamed
test_utilsmodule totestthroughout the codebase - Reorganized test utilities into logical submodules (
assert,builder,double,crypto_helper,logging) - Moved test-only methods from production code to extension traits in the
testmodule - Introduced a
define_test_logger!macro to standardize test logging across crates
Reviewed Changes
Copilot reviewed 268 out of 272 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| mithril-common/src/test_utils/mod.rs | Removed old test utilities module (251 lines deleted) |
| mithril-common/src/test/mod.rs | New organized test module with submodule structure |
| mithril-common/src/test/logging/mod.rs | New logging utilities with define_test_logger! macro |
| mithril-common/src/test/entities_extensions.rs | Extension traits for test utilities on entity types |
| mithril-common/src/test/crypto_helper/ | Moved crypto helper test utilities to dedicated module |
| Multiple files across all crates | Updated imports from test_utils to test with new submodule paths |
Test Results 4 files ±0 154 suites ±0 22m 27s ⏱️ -1s Results for commit f0e30e0. ± Comparison against base commit 377d7f6. This pull request removes 81 and adds 81 tests. Note that renamed tests count towards both.♻️ This comment has been updated with latest results. |
dlachaume
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🚀
- fix incorrect paths in tests - fix making pub(crate) previously internal fields for test extension traits by implementing the trait alongside the type (at the cost of mixing tests tools code with production code, but we keep the benefit of the trait import tagged as a test tool) - update `mithril_common::test` module doc - fix `FakeCertificaterRetriever` async trait use in wasm - remove `cfg_test_tools` macro to limit additional uses until the `test_tools` feature is removed
* mithril-cardano-node-chain from `0.1.5` to `0.1.6` * mithril-cardano-node-internal-database from `0.1.2` to `0.1.3` * mithril-dmq from `0.1.5` to `0.1.6` * mithril-era from `0.1.3` to `0.1.4` * mithril-metric from `0.1.16` to `0.1.17` * mithril-persistence from `0.2.56` to `0.2.57` * mithril-signed-entity-preloader from `0.0.8` to `0.0.9` * mithril-api-spec from `0.1.3` to `0.1.4` * mithril-aggregator from `0.7.75` to `0.7.76` * mithril-client-cli from `0.12.23` to `0.12.24` * mithril-client from `0.12.23` to `0.12.24` * mithril-common from `0.6.10` to `0.6.11` * mithril-relay from `0.1.48` to `0.1.49` * mithril-signer from `0.2.261` to `0.2.262` * mithril-end-to-end from `0.4.97` to `0.4.98`
turmelclem
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM ☀️
Content
This PR:
mithril-commontest_utilsmodule to simplytest: this align common to our latest practicemithril_common::testmodule:test::assertincludes:assert_dir_eq,assert_equivalent,assert_same_jsontest::builderincludes builder of: cardano transactions, certificates chain, mithril fixturefake_data,fake_keys,precomputed_kes_keytotest::doubleloggingwhich includes the memory logger and a newdefine_test_logger!macros to avoid redefining theTestLoggerin every cratescfg_testto thetestmodule:FakeCertificaterRetrieverandDummyApiVersionDiscriminantSourcetotest::doublecrypto_helpertest utilities totest::crypto_helper,test_utilsmethods attached toMKProofandProtocolInitializerare transformed into extension traitstest_utilsmethods attached toentitiesto extension traits located intest::entities_extensionsCardanoTransactionsSigningConfig::newas it was behindtest_utilsand bring more confusion than valueWith those changes the
test_utilsfeature ofmithril-commoncan be removed easily.Resulting structure
src/test/: (renamed) was
src/test_utils/├── assert : (new) module for custom assertions
│ ├── dir_eq.rs: (moved) from
src/test_utils/│ ├── iters_equivalent.rs: (new) new module for
assert_equivalentthat was insrc/test_utils/mod.rs│ ├── json.rs: (new) new module for
assert_same_jsonthat was insrc/test_utils/mod.rs│ └── mod.rs
├── builder: (new) module for test specialized builders of common, mostly business, objects
│ ├── cardano_transactions_builder.rs: (moved) from
src/test_utils/│ ├── certificate_chain_builder.rs: (moved) from
src/test_utils/│ ├── fixture_builder.rs: (moved) from
src/test_utils/│ ├── mithril_fixture.rs: (moved) from
src/test_utils/│ └── mod.rs
├── crypto_helper: (new) test utilities moved from the
src/crypto_helpermodule│ ├── cardano
│ │ ├── extensions.rs: (new) define extension traits to replace
test_toolsonly methods for types incrypto_helper│ │ ├── kes: (moved) from
src/crypto_helper/cardano/kes│ │ │ ├── mod.rs
│ │ │ ├── setup.rs: (moved) from
src/crypto_helpercardano/kes/tests_setup.rs│ │ │ └── signer_fake.rs: (moved) from
src/crypto_helpercardano/kes/signer_fake.rs│ │ └── mod.rs
│ ├── mod.rs
│ └── setup.rs: (moved) from
src/crypto_helper/tests_setup.rs├── double
│ ├── api_version.rs: (new) file for
DummyApiVersionDiscriminantSourcethat was insrc/api_version│ ├── certificate_retriever.rs: (moved) from
src/certificate_chain/fake_certificate_retriever│ ├── dummies.rs
│ ├── fake_data.rs: (moved) from
src/test_utils/│ ├── fake_keys.rs: (moved) from
src/test_utils/│ ├── mod.rs
│ └── precomputed_kes_key.rs: (moved)
├── entities_extensions.rs: (new) define extension traits to replace
test_toolsonly methods for types insrc/entities├── logging: (new) utilities to use logging in tests
│ ├── memory_logger.rs
│ └── mod.rs: (new)
define_test_loggermacro to simplify creation ofTestLoggerin child crates├── mock_extensions.rs
├── mod.rs
└── temp_dir.rs
Pre-submit checklist
Branch
PR
Documentation
Comments
The strategy used to move
test_utilsspecific methods attached to public types was to transform them into extensions traits, this strategy allow to force import of a item located in thetestmodule, making explicit the usage of a test only tool, but have one caveat:if the trait impl is not located beside the type some private properties must be made
pub(crate)in order to access them (problem raised withBlockRange::inner_rangeandStmInitializerWrapper::stm_initializer).A way to solve this problem is to move the trait impl, and only the impl, to the type, this have the cost of keeping part of the test code alongside the production code.
edit: The extensions traits for test impl were moved alongside the type to avoid making their internal
pub(crate).Next step
testmodules should be madetest_utilsfeature frommithril-commonIssue(s)
Relates to #2580