-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added L2VotingPowerPaused and L2GovernorPaused contract with test cas…
…es (#165) * Added L2VotingPowerPaused and L2GovernorPaused contract with test cases * Add deployment script * Update git submodules * Add foundry.toml * Change version function to be independent * Update comments * Update gitsubmodule, added Custom Errors * Rearrange functions according to requirements * pump forge-std to 1.8.2 * Add onReceive ERC721 and ERC1155 check * Test adjustVotingPower is unpaused * Add deployPausedDAO.sh * Add forge clean to deploy script * Clean before every forge script runs * Used `../../` to navigate paused script * rename assertInitParamsEq
- Loading branch information
Showing
14 changed files
with
778 additions
and
5 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
Submodule forge-std
updated
32 files
+6 −12 | .github/workflows/ci.yml | |
+3 −1 | .github/workflows/sync.yml | |
+0 −3 | .gitmodules | |
+1 −1 | README.md | |
+3 −3 | foundry.toml | |
+0 −1 | lib/ds-test | |
+1 −1 | package.json | |
+1 −1 | scripts/vm.py | |
+518 −225 | src/StdAssertions.sol | |
+10 −8 | src/StdChains.sol | |
+9 −3 | src/StdInvariant.sol | |
+7 −11 | src/StdJson.sol | |
+201 −106 | src/StdStorage.sol | |
+179 −0 | src/StdToml.sol | |
+1 −1 | src/StdUtils.sol | |
+4 −4 | src/Test.sol | |
+644 −7 | src/Vm.sol | |
+51 −33 | src/mocks/MockERC20.sol | |
+46 −32 | src/mocks/MockERC721.sol | |
+39 −909 | test/StdAssertions.t.sol | |
+31 −26 | test/StdChains.t.sol | |
+19 −11 | test/StdCheats.t.sol | |
+49 −0 | test/StdJson.t.sol | |
+8 −8 | test/StdMath.t.sol | |
+159 −11 | test/StdStorage.t.sol | |
+49 −0 | test/StdToml.t.sol | |
+18 −18 | test/StdUtils.t.sol | |
+3 −3 | test/Vm.t.sol | |
+8 −0 | test/fixtures/test.json | |
+6 −0 | test/fixtures/test.toml | |
+1 −1 | test/mocks/MockERC20.t.sol | |
+1 −1 | test/mocks/MockERC721.t.sol |
Submodule openzeppelin-foundry-upgrades
added at
4cd15f
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,53 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity 0.8.23; | ||
|
||
import { ERC1967Proxy } from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; | ||
import { Upgrades } from "openzeppelin-foundry-upgrades/Upgrades.sol"; | ||
import { Options } from "openzeppelin-foundry-upgrades/Options.sol"; | ||
import { Script, console2 } from "forge-std/Script.sol"; | ||
import { L2GovernorPaused } from "src/L2/paused/L2GovernorPaused.sol"; | ||
import "script/contracts/Utils.sol"; | ||
|
||
/// @title L2GovernorPausedScript - L2GovernorPaused contract deployment script | ||
/// @notice This contract is used to deploy L2GovernorPaused contract and write its address to JSON file. | ||
contract L2GovernorPausedScript is Script { | ||
/// @notice Utils contract which provides functions to read and write JSON files containing L1 and L2 addresses. | ||
Utils utils; | ||
|
||
function setUp() public { | ||
utils = new Utils(); | ||
} | ||
|
||
/// @notice This function deploys L2GovernorPaused contract and writes its address to JSON file. | ||
function run() public { | ||
// Deployer's private key. This key is used to deploy the contract. | ||
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); | ||
|
||
// Validate L2GovernorPaused contract if it is implemented correctly so that it may be used as new | ||
// implementation for the proxy contract. | ||
Options memory opts; | ||
opts.referenceContract = "L2Governor.sol"; | ||
opts.unsafeAllow = "constructor"; | ||
Upgrades.validateUpgrade("L2GovernorPaused.sol", opts); | ||
|
||
console2.log("Deploying L2GovernorPaused contract..."); | ||
|
||
// deploy L2GovernorPaused contract | ||
vm.startBroadcast(deployerPrivateKey); | ||
L2GovernorPaused l2GovernorPaused = new L2GovernorPaused(); | ||
vm.stopBroadcast(); | ||
|
||
assert(address(l2GovernorPaused) != address(0)); | ||
|
||
// ERC1967Utils: keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1. | ||
assert(l2GovernorPaused.proxiableUUID() == bytes32(uint256(keccak256("eip1967.proxy.implementation")) - 1)); | ||
|
||
console2.log("L2GovernorPaused contract successfully deployed!"); | ||
console2.log("L2GovernorPaused (Implementation) address: %s", address(l2GovernorPaused)); | ||
|
||
// write L2GovernorPaused address to l2addresses.json | ||
Utils.L2AddressesConfig memory l2AddressesConfig = utils.readL2AddressesFile(); | ||
l2AddressesConfig.L2GovernorPaused = address(l2GovernorPaused); | ||
utils.writeL2AddressesFile(l2AddressesConfig); | ||
} | ||
} |
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,56 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity 0.8.23; | ||
|
||
import { ERC1967Proxy } from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; | ||
import { Upgrades } from "openzeppelin-foundry-upgrades/Upgrades.sol"; | ||
import { Options } from "openzeppelin-foundry-upgrades/Options.sol"; | ||
import { Script, console2 } from "forge-std/Script.sol"; | ||
import { L2VotingPowerPaused } from "src/L2/paused/L2VotingPowerPaused.sol"; | ||
import "script/contracts/Utils.sol"; | ||
|
||
/// @title L2VotingPowerPausedScript - L2VotingPowerPaused contract deployment script | ||
/// @notice This contract is used to deploy L2VotingPowerPaused contract and write its address to JSON file. | ||
contract L2VotingPowerPausedScript is Script { | ||
/// @notice Utils contract which provides functions to read and write JSON files containing L1 and L2 addresses. | ||
Utils utils; | ||
|
||
function setUp() public { | ||
utils = new Utils(); | ||
} | ||
|
||
/// @notice This function deploys L2VotingPowerPaused contract and writes its address to JSON file. | ||
function run() public { | ||
// Deployer's private key. This key is used to deploy the contract. | ||
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); | ||
|
||
// Validate L2VotingPowerPaused contract if it is implemented correctly so that it may be used as new | ||
// implementation for the proxy contract. | ||
Options memory opts; | ||
opts.referenceContract = "L2VotingPower.sol"; | ||
opts.unsafeAllow = "constructor"; | ||
Upgrades.validateUpgrade("L2VotingPowerPaused.sol", opts); | ||
|
||
console2.log("Deploying L2VotingPowerPaused contract..."); | ||
|
||
// deploy L2VotingPowerPaused contract | ||
vm.startBroadcast(deployerPrivateKey); | ||
L2VotingPowerPaused l2VotingPowerPausedImplementation = new L2VotingPowerPaused(); | ||
vm.stopBroadcast(); | ||
|
||
assert(address(l2VotingPowerPausedImplementation) != address(0)); | ||
|
||
// ERC1967Utils: keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1. | ||
assert( | ||
l2VotingPowerPausedImplementation.proxiableUUID() | ||
== bytes32(uint256(keccak256("eip1967.proxy.implementation")) - 1) | ||
); | ||
|
||
console2.log("L2VotingPowerPaused contract successfully deployed!"); | ||
console2.log("L2VotingPowerPaused (Implementation) address: %s", address(l2VotingPowerPausedImplementation)); | ||
|
||
// write L2VotingPowerPaused address to l2addresses.json | ||
Utils.L2AddressesConfig memory l2AddressesConfig = utils.readL2AddressesFile(); | ||
l2AddressesConfig.L2VotingPowerPaused = address(l2VotingPowerPausedImplementation); | ||
utils.writeL2AddressesFile(l2AddressesConfig); | ||
} | ||
} |
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,68 @@ | ||
#!/usr/bin/env bash | ||
|
||
echo "Instructing the shell to exit immediately if any command returns a non-zero exit status..." | ||
set -e | ||
echo "Done." | ||
|
||
echo "Navigating to the root directory of the project..." | ||
cd ../../ | ||
echo "Done." | ||
|
||
echo "Setting environment variables..." | ||
source .env | ||
echo "Done." | ||
|
||
echo "Creating $NETWORK directory inside deployment directory..." | ||
if [ -z "$NETWORK" ] | ||
then | ||
echo "NETWORK variable inside .env file is not set. Please set NETWORK environment variable." | ||
exit 1 | ||
else | ||
if [ -d "deployment/$NETWORK" ] | ||
then | ||
echo "Directory deployment/$NETWORK already exists." | ||
else | ||
mkdir deployment/$NETWORK | ||
fi | ||
fi | ||
echo "Done." | ||
|
||
echo "Cleaning up the build artifacts to be able to deploy the contract..." | ||
forge clean | ||
echo "Done." | ||
|
||
echo "Deploying and if enabled verifying L2GovernorPaused smart contract..." | ||
if [ -z "$CONTRACT_VERIFIER" ] | ||
then | ||
forge script --rpc-url="$L2_RPC_URL" --broadcast -vvvv script/contracts/L2/paused/L2GovernorPaused.s.sol:L2GovernorPausedScript | ||
else | ||
if [ $CONTRACT_VERIFIER = "blockscout" ] | ||
then | ||
forge script --rpc-url="$L2_RPC_URL" --broadcast --verify --verifier blockscout --verifier-url $L2_VERIFIER_URL -vvvv script/contracts/L2/paused/L2GovernorPaused.s.sol:L2GovernorPausedScript | ||
fi | ||
if [ $CONTRACT_VERIFIER = "etherscan" ] | ||
then | ||
forge script --rpc-url="$L2_RPC_URL" --broadcast --verify --verifier etherscan --etherscan-api-key="$L2_ETHERSCAN_API_KEY" -vvvv script/contracts/L2/paused/L2GovernorPaused.s.sol:L2GovernorPausedScript | ||
fi | ||
fi | ||
echo "Done." | ||
|
||
echo "Cleaning up the build artifacts to be able to deploy the contract..." | ||
forge clean | ||
echo "Done." | ||
|
||
echo "Deploying and if enabled verifying L2VotingPowerPaused smart contract..." | ||
if [ -z "$CONTRACT_VERIFIER" ] | ||
then | ||
forge script --rpc-url="$L2_RPC_URL" --broadcast -vvvv script/contracts/L2/paused/L2VotingPowerPaused.s.sol:L2VotingPowerPausedScript | ||
else | ||
if [ $CONTRACT_VERIFIER = "blockscout" ] | ||
then | ||
forge script --rpc-url="$L2_RPC_URL" --broadcast --verify --verifier blockscout --verifier-url $L2_VERIFIER_URL -vvvv script/contracts/L2/paused/L2VotingPowerPaused.s.sol:L2VotingPowerPausedScript | ||
fi | ||
if [ $CONTRACT_VERIFIER = "etherscan" ] | ||
then | ||
forge script --rpc-url="$L2_RPC_URL" --broadcast --verify --verifier etherscan --etherscan-api-key="$L2_ETHERSCAN_API_KEY" -vvvv script/contracts/L2/paused/L2VotingPowerPaused.s.sol:L2VotingPowerPausedScript | ||
fi | ||
fi | ||
echo "Done." |
Oops, something went wrong.