You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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);
}
}
```
Copy file name to clipboardexpand all lines: docs/docs/reference/developer_references/smart_contract_reference/portals/registry.md
+9-9
Original file line number
Diff line number
Diff line change
@@ -5,13 +5,13 @@ tags: [portals, contracts]
5
5
6
6
The registry is a contract deployed on L1, that contains addresses for the `Rollup`. It also keeps track of the different versions that have been deployed and let you query prior deployments easily.
Copy file name to clipboardexpand all lines: l1-contracts/README.md
+26-2
Original file line number
Diff line number
Diff line change
@@ -56,6 +56,29 @@ Currently not running any proofs _nor_ access control so blocks can be submitted
56
56
57
57
---
58
58
59
+
# Branching Tree Technique
60
+
61
+
For writing tests we will be using the [Branching Tree Technique](https://www.youtube.com/watch?v=0-EmbNVgFA4).
62
+
The approach is simple, for a function that is to be tested (all functions) you should write a `.tree` file first.
63
+
Then the tree file can be used to generate a solidity tests file using [Bulloak](https://github.com/alexfertel/bulloak) by running the `scaffold` command.
64
+
65
+
```bash
66
+
bulloak scaffold -w **/*.tree
67
+
```
68
+
69
+
To check that the tests are following the expected format, you can run the `check` command.
70
+
71
+
```bash
72
+
bulloak check **/*.tree
73
+
```
74
+
75
+
We assume that you already have `bulloak` installed, if not you can install it as `cargo install bulloak`.
76
+
Also, we suggest using [Ascii Tree Generator](https://marketplace.visualstudio.com/items?itemName=aprilandjan.ascii-tree-generator), since the pipes can be a bit of a pain otherwise.
77
+
78
+
For examples, see the tests for the registry.
79
+
80
+
---
81
+
59
82
# Linter
60
83
61
84
We use an extended version of solhint (https://github.com/LHerskind/solhint) to include custom rules. These custom rules relate to how errors should be named, using custom errors instead of reverts etc, see `.solhint.json` for more specifics about the rules.
@@ -73,12 +96,13 @@ yarn lint
73
96
# Slither & Slitherin
74
97
75
98
We use slither as an automatic way to find blunders and common vulnerabilities in our contracts. It is not part of the docker image due to its slowness, but it can be run using the following command to generate a markdown file with the results:
99
+
76
100
```bash
77
101
yarn slither
78
102
```
79
103
80
-
When this command is run in CI, it will fail if the markdown file generated in docker don't match the one in the repository.
104
+
When this command is run in CI, it will fail if the markdown file generated in docker don't match the one in the repository.
81
105
82
106
We assume that you already have slither installed. You can install it with `pip3 install slither-analyzer==0.10.0 slitherin==0.5.0`. It is kept out of the bootstrap script as it is not a requirement for people who just want to run tests or are uninterested in the contracts.
83
107
84
-
> We are not running the `naming-convention` detector because we have our own rules for naming which is enforced by the linter.
108
+
> We are not running the `naming-convention` detector because we have our own rules for naming which is enforced by the linter.
0 commit comments