-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: move governance out of core (#8823)
Slight extension on #8818 to separate gov and instance more clearly. Gov does not have dependencies on core, but core can depend on the gov. Removes the registry value from the `Rollup` does not address that an upgrade would make the fee contract unbacked, that is to be handled separately in #8756. Updates testing for the `Registry` contract to use the [Branching Tree Technique](https://www.youtube.com/watch?v=0-EmbNVgFA4) from Paul. Found it quite neat. If using `bulloak` as well quite convenient to build the setups. The TL;DR is, build a `.tree` file outlining the test for a function, and then use `bulloak scaffold` to prepare a testing file and then fill in the logic. Makes it quite nice to follow the logic. # Example time ```.tree UpgradeTest ├── when caller is not owner │ └── it should revert └── when caller is owner ├── when rollup already in set │ └── it should revert └── when rollup not already in set ├── it should add the rollup to state └── it should emit a {InstanceAdded} event ``` ```solidity // SPDX-License-Identifier: UNLICENSED pragma solidity >=0.8.27; import {Test} from "forge-std/Test.sol"; import {Registry} from "@aztec/governance/Registry.sol"; contract RegistryBase is Test { Registry internal registry; function setUp() public { registry = new Registry(address(this)); } } ``` ```solidity // SPDX-License-Identifier: UNLICENSED pragma solidity >=0.8.27; import {RegistryBase} from "./Base.t.sol"; import {Ownable} from "@oz/access/Ownable.sol"; import {IRegistry} from "@aztec/governance/interfaces/IRegistry.sol"; import {Errors} from "@aztec/governance/libraries/Errors.sol"; import {DataStructures} from "@aztec/governance/libraries/DataStructures.sol"; contract UpgradeTest is RegistryBase { function test_RevertWhen_CallerIsNotOwner(address _caller) external { // it should revert vm.assume(_caller != address(this)); vm.prank(_caller); vm.expectRevert(abi.encodeWithSelector(Ownable.OwnableUnauthorizedAccount.selector, _caller)); registry.upgrade(address(uint160(uint256(bytes32("new instance"))))); } modifier whenCallerIsOwner() { _; } function test_RevertWhen_RollupAlreadyInSet() external whenCallerIsOwner { // it should revert address rollup = registry.getRollup(); vm.expectRevert( abi.encodeWithSelector(Errors.Registry__RollupAlreadyRegistered.selector, rollup) ); registry.upgrade(rollup); } function test_WhenRollupNotAlreadyInSet(address _rollup) external whenCallerIsOwner { // it should add the rollup to state // it should emit a {InstanceAdded} event vm.assume(_rollup != address(0xdead)); { DataStructures.RegistrySnapshot memory snapshotBefore = registry.getCurrentSnapshot(); assertEq(snapshotBefore.blockNumber, block.number); assertEq(snapshotBefore.rollup, address(0xdead)); assertEq(registry.numberOfVersions(), 1); } vm.expectEmit(true, true, false, false, address(registry)); emit IRegistry.InstanceAdded(_rollup, 1); registry.upgrade(_rollup); assertEq(registry.numberOfVersions(), 2); DataStructures.RegistrySnapshot memory snapshot = registry.getCurrentSnapshot(); assertEq(snapshot.blockNumber, block.number); assertGt(snapshot.blockNumber, 0); assertEq(snapshot.rollup, _rollup); } } ```
- Loading branch information
Showing
32 changed files
with
391 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 4 additions & 3 deletions
7
...re/interfaces/messagebridge/IRegistry.sol → ...s/src/governance/interfaces/IRegistry.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright 2023 Aztec Labs. | ||
pragma solidity >=0.8.18; | ||
|
||
/** | ||
* @title Data Structures Library | ||
* @author Aztec Labs | ||
* @notice Library that contains data structures used throughout Aztec governance | ||
*/ | ||
library DataStructures { | ||
// docs:start:registry_snapshot | ||
/** | ||
* @notice Struct for storing address of cross communication components and the block number when it was updated | ||
* @param rollup - The address of the rollup contract | ||
* @param blockNumber - The block number of the snapshot | ||
*/ | ||
struct RegistrySnapshot { | ||
address rollup; | ||
uint256 blockNumber; | ||
} | ||
// docs:end:registry_snapshot | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright 2023 Aztec Labs. | ||
pragma solidity >=0.8.18; | ||
|
||
/** | ||
* @title Errors Library | ||
* @author Aztec Labs | ||
* @notice Library that contains errors used throughout the Aztec governance | ||
* Errors are prefixed with the contract name to make it easy to identify where the error originated | ||
* when there are multiple contracts that could have thrown the error. | ||
*/ | ||
library Errors { | ||
// Registry | ||
error Registry__RollupNotRegistered(address rollup); // 0xa1fee4cf | ||
error Registry__RollupAlreadyRegistered(address rollup); // 0x3c34eabf | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.