-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
test: scenario for upgrading gerousia (#9246)
- chore-docs-preview-tag
- barretenberg-v0.67.0
- barretenberg-v0.66.0
- barretenberg-v0.65.2
- barretenberg-v0.65.1
- barretenberg-v0.65.0
- barretenberg-v0.64.0
- barretenberg-v0.63.1
- barretenberg-v0.63.0
- barretenberg-v0.62.0
- barretenberg-v0.61.0
- barretenberg-v0.60.0
- barretenberg.js-v0.67.0
- barretenberg.js-v0.66.0
- barretenberg.js-v0.65.2
- barretenberg.js-v0.65.1
- barretenberg.js-v0.65.0
- barretenberg.js-v0.64.0
- barretenberg.js-v0.63.1
- barretenberg.js-v0.63.0
- barretenberg.js-v0.62.0
- barretenberg.js-v0.61.0
- barretenberg.js-v0.60.0
- aztec-packages-v0.67.0
- aztec-packages-v0.66.0
- aztec-packages-v0.65.2
- aztec-packages-v0.65.1
- aztec-packages-v0.65.0
- aztec-packages-v0.64.0
- aztec-packages-v0.63.1
- aztec-packages-v0.63.0
- aztec-packages-v0.62.0
- aztec-packages-v0.61.0
- aztec-packages-v0.60.0
- aztec-package-v0.67.0
- aztec-package-v0.66.0
- aztec-package-v0.65.2
- aztec-package-v0.65.1
- aztec-package-v0.65.0
- aztec-package-v0.64.0
- aztec-package-v0.63.1
- aztec-package-v0.63.0
- aztec-package-v0.62.0
- aztec-package-v0.61.0
- aztec-package-v0.60.0
Showing
3 changed files
with
149 additions
and
2 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
148 changes: 148 additions & 0 deletions
148
l1-contracts/test/governance/scenario/UpgradeGerousia.t.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity >=0.8.27; | ||
|
||
import {IPayload} from "@aztec/governance/interfaces/IPayload.sol"; | ||
import {TestBase} from "@test/base/Base.sol"; | ||
import {IMintableERC20} from "@aztec/governance/interfaces/IMintableERC20.sol"; | ||
import {IRegistry} from "@aztec/governance/interfaces/IRegistry.sol"; | ||
import {Rollup} from "@aztec/core/Rollup.sol"; | ||
import {Apella} from "@aztec/governance/Apella.sol"; | ||
import {Gerousia} from "@aztec/governance/Gerousia.sol"; | ||
import {Registry} from "@aztec/governance/Registry.sol"; | ||
import {DataStructures} from "@aztec/governance/libraries/DataStructures.sol"; | ||
import {IMintableERC20} from "@aztec/governance/interfaces/IMintableERC20.sol"; | ||
import {TestERC20} from "@aztec/mock/TestERC20.sol"; | ||
import {Timestamp} from "@aztec/core/libraries/TimeMath.sol"; | ||
import {MockFeeJuicePortal} from "@aztec/mock/MockFeeJuicePortal.sol"; | ||
import {Slot} from "@aztec/core/libraries/TimeMath.sol"; | ||
import {ProposalLib} from "@aztec/governance/libraries/ProposalLib.sol"; | ||
import {Errors} from "@aztec/governance/libraries/Errors.sol"; | ||
|
||
/** | ||
* @title NewGerousiaPayload | ||
* @author Aztec Labs | ||
* @notice A payload that upgrades the Gerousia contract to a new version. | ||
*/ | ||
contract NewGerousiaPayload is IPayload { | ||
IRegistry public immutable REGISTRY; | ||
address public immutable NEW_GEROUSIA; | ||
|
||
constructor(IRegistry _registry) { | ||
REGISTRY = _registry; | ||
NEW_GEROUSIA = address(new Gerousia(_registry, 667, 1000)); | ||
} | ||
|
||
function getActions() external view override(IPayload) returns (IPayload.Action[] memory) { | ||
IPayload.Action[] memory res = new IPayload.Action[](1); | ||
|
||
Apella apella = Apella(REGISTRY.getApella()); | ||
|
||
res[0] = Action({ | ||
target: address(apella), | ||
data: abi.encodeWithSelector(apella.updateGerousia.selector, NEW_GEROUSIA) | ||
}); | ||
|
||
return res; | ||
} | ||
} | ||
|
||
/** | ||
* @title UpgradeGerousiaTest | ||
* @author Aztec Labs | ||
* @notice A test that showcases an upgrade of the governance system, here the gerousia contract. | ||
*/ | ||
contract UpgradeGerousiaTest is TestBase { | ||
using ProposalLib for DataStructures.Proposal; | ||
|
||
IMintableERC20 internal token; | ||
Registry internal registry; | ||
Apella internal apella; | ||
Gerousia internal gerousia; | ||
Rollup internal rollup; | ||
|
||
DataStructures.Proposal internal proposal; | ||
|
||
mapping(uint256 => address) internal validators; | ||
mapping(address validator => uint256 privateKey) internal privateKeys; | ||
|
||
IPayload internal payload; | ||
|
||
uint256 internal constant VALIDATOR_COUNT = 4; | ||
address internal constant EMPEROR = address(uint160(bytes20("EMPEROR"))); | ||
|
||
function setUp() external { | ||
token = IMintableERC20(address(new TestERC20())); | ||
|
||
registry = new Registry(address(this)); | ||
gerousia = new Gerousia(registry, 7, 10); | ||
|
||
apella = new Apella(token, address(gerousia)); | ||
|
||
address[] memory initialValidators = new address[](VALIDATOR_COUNT); | ||
for (uint256 i = 1; i <= VALIDATOR_COUNT; i++) { | ||
uint256 privateKey = uint256(keccak256(abi.encode("validator", i))); | ||
address validator = vm.addr(privateKey); | ||
privateKeys[validator] = privateKey; | ||
validators[i - 1] = validator; | ||
initialValidators[i - 1] = validator; | ||
} | ||
|
||
rollup = | ||
new Rollup(new MockFeeJuicePortal(), bytes32(0), bytes32(0), address(this), initialValidators); | ||
|
||
registry.upgrade(address(rollup)); | ||
|
||
registry.transferOwnership(address(apella)); | ||
} | ||
|
||
function test_UpgradeIntoNewVersion() external { | ||
payload = IPayload(address(new NewGerousiaPayload(registry))); | ||
vm.warp(Timestamp.unwrap(rollup.getTimestampForSlot(Slot.wrap(1)))); | ||
|
||
for (uint256 i = 0; i < 10; i++) { | ||
address proposer = rollup.getCurrentProposer(); | ||
vm.prank(proposer); | ||
gerousia.vote(payload); | ||
vm.warp(Timestamp.unwrap(rollup.getTimestampForSlot(rollup.getCurrentSlot() + Slot.wrap(1)))); | ||
} | ||
|
||
gerousia.pushProposal(0); | ||
proposal = apella.getProposal(0); | ||
assertEq(address(proposal.payload), address(payload)); | ||
|
||
token.mint(EMPEROR, 10000 ether); | ||
|
||
vm.startPrank(EMPEROR); | ||
token.approve(address(apella), 10000 ether); | ||
apella.deposit(EMPEROR, 10000 ether); | ||
vm.stopPrank(); | ||
|
||
vm.warp(Timestamp.unwrap(proposal.pendingThrough()) + 1); | ||
assertTrue(apella.getProposalState(0) == DataStructures.ProposalState.Active); | ||
|
||
vm.prank(EMPEROR); | ||
apella.vote(0, 10000 ether, true); | ||
|
||
vm.warp(Timestamp.unwrap(proposal.activeThrough()) + 1); | ||
assertTrue(apella.getProposalState(0) == DataStructures.ProposalState.Queued); | ||
|
||
vm.warp(Timestamp.unwrap(proposal.queuedThrough()) + 1); | ||
assertTrue(apella.getProposalState(0) == DataStructures.ProposalState.Executable); | ||
assertEq(apella.gerousia(), address(gerousia)); | ||
|
||
apella.execute(0); | ||
|
||
assertNotEq(apella.gerousia(), address(gerousia)); | ||
address newGerousia = address(NewGerousiaPayload(address(payload)).NEW_GEROUSIA()); | ||
assertEq(apella.gerousia(), newGerousia); | ||
|
||
// Ensure that we cannot push a proposal after the upgrade. | ||
vm.expectRevert( | ||
abi.encodeWithSelector( | ||
Errors.Apella__CallerNotGerousia.selector, address(gerousia), newGerousia | ||
) | ||
); | ||
vm.prank(address(gerousia)); | ||
apella.propose(payload); | ||
} | ||
} |
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