hedera-mirror-node
hedera-mirror-node copied to clipboard
Refactor and reorganize integration tests in `hedera-mirror-web3` module
Problem
Currently all integrations tests in hedera-mirorr-web3
rely on a DB test setup, which is processed in ContractCallTestSetup
, which creates a strong dependency between all test data. As a result if we change the ID of a single entity, for example, we might break an existing set of tests or see unexpected results. In addition maintenance and adding new tests with new test data would become harder and harder in the future.
Solution
Remove ContractCallTestSetup
as a central database setup and refactor all integration tests to include their own test data and be self-sufficient without relying on an external setup. Each test should create their own entities and needed data, that would be discarded after the test execution.
Some extraction of ContractCallTestSetup logic into the separate integration tests, might be an option, but probably the best approach would be adding new DB test data for each separate test from scratch. Avoid extracting common entities and methods in a parent class, as eventually we would construct the same problem of a common big and complex class with DB setup.
We should rely on the existing DomainBuilder as much as possible and avoid hardcoding fields of the built entity if possible. We should use dynamic data and validate the test against it.
Also, research about web3j-solidity-gradle-plugin and web3j-gradle-plugin plugins and investigate if we can make a use of them in the refactor of web3 module integration tests
Alternatives
No response
### Tasks
- [ ] https://github.com/hashgraph/hedera-mirror-node/issues/8466
- [ ] https://github.com/hashgraph/hedera-mirror-node/issues/8467
- [ ] https://github.com/hashgraph/hedera-mirror-node/issues/8449
- [ ] https://github.com/hashgraph/hedera-mirror-node/issues/8450
- [ ] https://github.com/hashgraph/hedera-mirror-node/issues/8380
- [ ] https://github.com/hashgraph/hedera-mirror-node/issues/8455
- [ ] https://github.com/hashgraph/hedera-mirror-node/issues/8456
- [ ] https://github.com/hashgraph/hedera-mirror-node/issues/8451
- [ ] https://github.com/hashgraph/hedera-mirror-node/issues/8452
- [ ] https://github.com/hashgraph/hedera-mirror-node/issues/8453
- [ ] https://github.com/hashgraph/hedera-mirror-node/issues/8379
- [ ] https://github.com/hashgraph/hedera-mirror-node/issues/8383
- [ ] https://github.com/hashgraph/hedera-mirror-node/issues/8942
- [ ] https://github.com/hashgraph/hedera-mirror-node/issues/8944
- [ ] https://github.com/hashgraph/hedera-mirror-node/issues/8945
- [ ] https://github.com/hashgraph/hedera-mirror-node/issues/8956
In addition to separation of test data across tests, I would like to also see separation of test data between tests within a class. This should be done by generating test input instead of relying upon hard-coded, static data. With this approach, there should be zero static constants at the top shared between different tests even within a test class.
The general principle in mirror node is to use the DomainBuilder
to generate as much as possible of the data, only overriding specific fields that are necessary for the test. That is, IDs should not be overridden and left random except if you need to link object B to object A by setting b.setA(a.getId())
, which still uses dynamic data. Then the test output should be compared against the dynamically generated input for correctness.
All tasks complete