Skip to content

[Rebased] Migrate governance tests from Truffle to Foundry #11415

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

Open
wants to merge 15 commits into
base: release/core-contracts/13
Choose a base branch
from

Conversation

Mc01
Copy link

@Mc01 Mc01 commented May 20, 2025

Rebased clone of #11402

Description

PR porting old governance integration tests from Truffle as new governance e2e tests in Foundry

Other changes

I needed to fix Migrations.s.sol scripts and additionally added ton of small improvements over the way - including disabling anvil rpc call logging with env var

Tested

With e2e testing.

Related issues

Backwards compatibility

Previous integration tests in Truffle were not running currently, so it brings some of them back.

Documentation

Internal tooling - no changes here

@Mc01 Mc01 requested review from a team as code owners May 20, 2025 12:18
@Mc01 Mc01 requested a review from alvarof2 May 20, 2025 12:18
@Mc01 Mc01 changed the base branch from master to release/core-contracts/13 May 20, 2025 12:18
Copy link

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​celo/​env-tests@​1.0.3100100100100100

View full report

Copy link
Author

@Mc01 Mc01 left a comment

Choose a reason for hiding this comment

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

Ported old review comments from @pahor167
For accessing resolved comments -> take a look on older PR: #11402

keccak256(abi.encodePacked("EpochManagerEnabler"));
bytes32 internal constant EPOCH_MANAGER_REGISTRY_ID = keccak256(abi.encodePacked("EpochManager"));
bytes32 internal constant ESCROW_REGISTRY_ID = keccak256(abi.encodePacked("Escrow"));
// bytes32 internal constant EXCHANGE_REGISTRY_ID = keccak256(abi.encodePacked("Exchange"));
Copy link
Author

Choose a reason for hiding this comment

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

Screenshot 2025-05-20 at 14 22 18

Copy link
Contributor

@soloseng soloseng May 20, 2025

Choose a reason for hiding this comment

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

If they have been commented since CR12, they can be removed as they are not being used. Since this file is only used for testing, It should be safe to remove.

// import { BlockchainParameters } from "@celo-contracts/governance/BlockchainParameters.sol";
import { ICeloUnreleasedTreasury } from "@celo-contracts/common/interfaces/ICeloUnreleasedTreasury.sol";
import { ICeloToken } from "@celo-contracts/common/interfaces/ICeloToken.sol";
// import { DoubleSigningSlasher } from "@celo-contracts/governance/DoubleSigningSlasher.sol";
Copy link
Author

Choose a reason for hiding this comment

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

Screenshot 2025-05-20 at 14 23 04

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure why these were added since they are not being used in this file.

Also note:
DownTimeSlasher,DoubleSigningSlasher,BlockchainParameters have been deprecated post L2.

uint256 threshold = abi.decode(
constitutionJson.parseRaw(string.concat(".", contractName, ".", functionName)),
(uint256)
string.concat(" Setting constitution thresholds for function: ", loop_.functionName)
Copy link
Author

Choose a reason for hiding this comment

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

Screenshot 2025-05-20 at 14 24 04

@@ -7,7 +7,8 @@ contract MigrationsConstants is TestConstants {
address constant DEPLOYER_ACCOUNT = 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266;

// List of contracts that are expected to be in Registry.sol
string[27] contractsInRegistry = [
// TODO: Probably should be synced with Migration.s.sol
Copy link
Author

Choose a reason for hiding this comment

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

Screenshot 2025-05-20 at 14 25 50

Comment on lines +70 to +72
// doubleSigningSlasher = DoubleSigningSlasher(
// registryContract.getAddressForOrDie(DOUBLE_SIGNING_SLASHER_REGISTRY_ID)
// ); // FIXME: DoubleSigningSlasher is not in UsingRegistry.sol
Copy link
Author

Choose a reason for hiding this comment

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

Screenshot 2025-05-20 at 14 26 49

Copy link
Contributor

Choose a reason for hiding this comment

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

see comment above as to why they are no longer in registry.

@@ -95,14 +110,47 @@ contract UsingRegistryV2NoMento {
return IAccounts(registryContract.getAddressForOrDie(ACCOUNTS_REGISTRY_ID));
}

// FIXME: Deprecated?
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it's safe to remove, it's a helper anyways

Copy link
Collaborator

Choose a reason for hiding this comment

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

would maybe add somewhere else, maybe inside migrations_sol, because this will likely be out of scope in the next audit, but if we ever use it in production following that, then it wont show up in the diff and thus will not be audited

Copy link
Collaborator

Choose a reason for hiding this comment

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

I wouldn't change it, but I try not to do linting in PRs doing something else as they get hard to review, just a nit

uint256 proposalId
) external view returns (address, uint256, uint256, uint256, string memory, uint256, bool);

// referendum
Copy link
Collaborator

Choose a reason for hiding this comment

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

remove?

@@ -7,7 +7,8 @@ contract MigrationsConstants is TestConstants {
address constant DEPLOYER_ACCOUNT = 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266;

// List of contracts that are expected to be in Registry.sol
string[27] contractsInRegistry = [
// TODO: Probably should be synced with Migration.s.sol
string[26] contractsInRegistry = [
Copy link
Collaborator

Choose a reason for hiding this comment

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

I couldn't figure out how to make the compiler come up with the number of items automatically, maybe we should move to json at some point

@@ -45,7 +45,7 @@ while ! nc -z localhost $ANVIL_PORT; do
done

# enabled logging
cast rpc anvil_setLoggingEnabled true --rpc-url $ANVIL_RPC_URL
cast rpc anvil_setLoggingEnabled $ANVIL_LOGGING_ENABLED --rpc-url $ANVIL_RPC_URL
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we keep the default as true?

Copy link
Author

Choose a reason for hiding this comment

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

We can, but I freshly changed it to true based on @pahor167 request 😁

Comment on lines +95 to +123
JsonFiles memory files_ = JsonFiles(
vm.readFile("./governanceConstitution.json"), // constitution json
vm.readFile("./.tmp/selectors/Proxy.json") // proxy selectors
);
FileProps memory props_ = FileProps(
vm.parseJsonKeys(files_.constitutionJson, ""), // contract names
vm.parseJsonKeys(files_.constitutionJson, ".Proxy"), // proxy names
vm.parseJsonKeys(files_.proxySelectors, "") // proxy sigs
);

// vars for looping
LoopVars memory loop_;
string memory contractSelectors_;
string[] memory functionsWithTypes_;
string[] memory functionNames_;

// loop over contract names
for (uint256 i = 0; i < props_.contractNames.length; i++) {
loop_.contractName = props_.contractNames[i];
if (loop_.contractName.equals("Proxy")) {
// skip proxy address
continue;
} else {
// set address from registry
loop_.contractAddress = registryContract.getAddressForStringOrDie(loop_.contractName);
}

// load selectors for given contract from file
contractSelectors_ = vm.readFile(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this block (and beyond) duplicated from Migrations.s.sol?

Copy link
Author

Choose a reason for hiding this comment

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

It overlaps with Migrations.s.sol to some extent -> will check how much I can de-duplicate it tomorrow 👍

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.

Recreate governance integration tests in Foundry
3 participants