-
Notifications
You must be signed in to change notification settings - Fork 359
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
test: add integration tests for Anvil migrations #11002
test: add integration tests for Anvil migrations #11002
Conversation
MVP test: Assert that existing tests that are known to pass also pass when run against the devchain.
This is done in cd987f3 |
Ideas for invariants in the integration tests:
|
a12fb19
to
cd987f3
Compare
This is a test run, to see how `setUp()` and contract definitions work. 1. run devchain ```sh ./migrations_sol/create_and_migrate_anvil_devchain.sh ``` 2. run test against devchain ```sh forge test \ --match-path test-sol/integration/Integration.t.sol \ --match-contract GoldTokenTest_General \ -vvv \ --fork-url http://127.0.0.1:8546 ``` Tests pass Output: ```sh [⠰] Compiling... No files changed, compilation skipped Running 3 tests for test-sol/integration/Integration.t.sol:GoldTokenTest_General [PASS] test_decimals() (gas: 10837) Logs: GoldToken address is: 0xfE8CbC1cFA1b3b8256f310bdfd40E60597083448 [PASS] test_name() (gas: 12537) Logs: GoldToken address is: 0xfE8CbC1cFA1b3b8256f310bdfd40E60597083448 [PASS] test_symbol() (gas: 12579) Logs: GoldToken address is: 0xfE8CbC1cFA1b3b8256f310bdfd40E60597083448 Test result: ok. 3 passed; 0 failed; 0 skipped; finished in 135.40ms Ran 1 test suites: 3 tests passed, 0 failed, 0 skipped (3 total tests) ```
As of ee24877, I'm able to run end-to-end tests against a local devchain: MVP testThis is a test run, to see how
./migrations_sol/create_and_migrate_anvil_devchain.sh
forge test \
--match-path test-sol/integration/Integration.t.sol \
--match-contract GoldTokenTest_General \
-vvv \
--fork-url http://127.0.0.1:8546/ The tests pass Output: [⠰] Compiling...
No files changed, compilation skipped
Running 3 tests for test-sol/integration/Integration.t.sol:GoldTokenTest_General
[PASS] test_decimals() (gas: 10837)
Logs:
GoldToken address is: 0xfE8CbC1cFA1b3b8256f310bdfd40E60597083448
[PASS] test_name() (gas: 12537)
Logs:
GoldToken address is: 0xfE8CbC1cFA1b3b8256f310bdfd40E60597083448
[PASS] test_symbol() (gas: 12579)
Logs:
GoldToken address is: 0xfE8CbC1cFA1b3b8256f310bdfd40E60597083448
Test result: ok. 3 passed; 0 failed; 0 skipped; finished in 135.40ms
Ran 1 test suites: 3 tests passed, 0 failed, 0 skipped (3 total tests) |
This is to allow me to use the `.code` property on deployed smart contracts, which is only supported on Solidity 0.8 and above.
In Solidity versions 0.7.0 and later, constructors are implicitly internal, meaning they can only be called within the contract itself or derived contracts, making the visibility keyword redundant.
The state mutability of a function can be restricted to view if the function does not modify the state of the blockchain. A view function promises not to alter the state, which allows the Ethereum Virtual Machine (EVM) to optimize how it handles the function. The function does not modify any state; it only reads from the registry and logs some information.
As of 714bc75, I'm asserting that a list of contract names is registered in [PASS] test_shouldHaveAddressInRegistry() (gas: 200293)
Logs:
Accounts address in Registry is: 0x8f24d37a4697e49AECd08d2b197E6968D2f007d3
BlockchainParameters address in Registry is: 0xFEB14C5787fd63a417612bF8Bc2232e169A7034F
DoubleSigningSlasher address in Registry is: 0xA920a6fF4249f9A4CDdE3D67ff6275EdA6A1D89f
DowntimeSlasher address in Registry is: 0xAADB35CAD2f922180106F50BF7ead66C5AD0f101
Election address in Registry is: 0x5E386A280030a076528aD192BA94D7e31090F461
EpochRewards address in Registry is: 0xfff723D9B8f466Cd9e11BF4aaca171550aCF18Fc
Escrow address in Registry is: 0xd773882801F417427aE5C7A032296D93Fcf11DA9
FederatedAttestations address in Registry is: 0x93f2E9307e3003a0a10A5171478CE18796aA2333
FeeCurrencyWhitelist address in Registry is: 0x99f389e8a9903aF72ba481e8f000e8E229e529dA
FeeCurrencyDirectory address in Registry is: 0x42Fe5a2A61ed9705eb2F08a04A58CEB606D22f6a
Freezer address in Registry is: 0x91dfD4C1B1262fad0f75A38D955B42b4bC586Bc1
FeeHandler address in Registry is: 0x04dE09026097347E2D540b6fbD9dC4aae3Ab0A90
GoldToken address in Registry is: 0xfE8CbC1cFA1b3b8256f310bdfd40E60597083448
Governance address in Registry is: 0xcF636ab1f15d3FB684A82cB1c69977DAfDFc6a0d
GovernanceSlasher address in Registry is: 0xE41a630372DE5B890a81B148a982b464Aa3B3625
LockedGold address in Registry is: 0xc7F0E00681356896c06d5c810F0333ab30fBB8D1
OdisPayments address in Registry is: 0xf7EfD92E61aB144483738B5F0f9cd46E6E9190BC
Random address in Registry is: 0x8982140ccFb38d7Dc439f953b37829f019A3e6e5
Registry address in Registry is: 0x000000000000000000000000000000000000ce10
SortedOracles address in Registry is: 0xa2204011717369e044106e3bC93599E02538d65b
UniswapFeeHandlerSeller address in Registry is: 0x27D282cBE154FD738de3242F80005cc2ca183981
MentoFeeHandlerSeller address in Registry is: 0x677e4E735a36A7Ed935D424fCCe57a33831BF0Dc
Validators address in Registry is: 0xA6aaDC309AA8E134d4a150eb4b58254801353FDc |
The goal is to use that in both the migration script (`Migration.s.sol`) and the integration test (`Integration.t.sol`).
Mistakenly deleted earlier
As of 130523e:
The only thing stopping this PR from being ready for review is the failing bytecode test. |
Also adds docstring for better readability.
Because I'm downgrading to a previous foundry version, I have to undo the change to this line made in this PR: #10997
I always forget to run `yarn prettify` in the top-level directory
As of dcb09e1, the PR is all green and ready for review ✅ |
To explain what flags and arguments are used.
Using `yarn prettify` in the top-level directory
8248fdf
to
19faa9b
Compare
Adds function in `Integration.t.sol` directly to avoid 0.5.x version problems.
…r function Because the script is now on 0.8, we can use the `.code` property to fetch the runtime bytecode of a smart contract deployed on the devchain. Previously, we needed to load the bytecode from storage with inline assembly.
Functionally this should be the same, but the configs and flags are more readable.
Description
Registry
.Note
We cannot currently test contracts that depend on linked libraries because
vm.getDeployedCode()
cannot fetch bytecode of contracts that depend on linked libraries. I created a follow-up issue with context on why this can't be done in this PR:Other changes
constants.sol
that defines the list of contracts that are expected to be inRegistry.sol
. Refactors the migration and integration test scripts to import that list instead of defining the same list twice.integration_tests.sh
, and refactors the integration test script (run_integration_tests_in_anvil.sh
) to include commands fromintegration_tests.sh
instead.nightly-f625d0fa7c51e65b4bf1e8f7931cd1c6e2e285e9
(2024-04-02). This is the last foundry version that doesn't have a regression that affects the integration tests.ECDSAHelper.sol
is deployed to comply with the downgraded foundry versionnightly-f625d0fa7c51e65b4bf1e8f7931cd1c6e2e285e9
. This reverts a change made in Deprecate random.sol #10997.Note
For context
1. nightly-fbad377ab26a432e48444cf324feee1195a30960 (2024-06-04) has the regression ❌
2. nightly-0fc39763d46b8ffab5fa4eaeb2f65ae078fa07de (2024-06-03) has the regression ❌
3. nightly-5ac78a9cd4b94dc53d1fe5e0f42372b28b5a7559 (2024-06-02) has the regression ❌
4. nightly-f479e945c6be78bb902df12f9d683c3bb55e3fb0 (2024-06-01) has the regression ❌
5. nightly-cafc2606a2187a42b236df4aa65f4e8cdfcea970 (2024-05-02) has the regression ❌
6. nightly-f625d0fa7c51e65b4bf1e8f7931cd1c6e2e285e9 (2024-04-02) doesn't have the regression ✅
Tested
Yes, these are all tests. The tests run during CI when migrations are generated and separately.
Related issues
Backwards compatibility
Yes, only adds additional tests.
Documentation
Documentation in docstrings in code.