diff --git a/contracts/child/ChildERC1155.sol b/contracts/child/ChildERC1155.sol index a3507cbf..a7dfdaee 100644 --- a/contracts/child/ChildERC1155.sol +++ b/contracts/child/ChildERC1155.sol @@ -24,6 +24,10 @@ contract ChildERC1155 is EIP712MetaTransaction, ERC1155Upgradeable, IChildERC115 _; } + constructor() { + _disableInitializers(); + } + /** * @inheritdoc IChildERC1155 */ diff --git a/contracts/child/ChildERC1155Predicate.sol b/contracts/child/ChildERC1155Predicate.sol index 91188781..09219c54 100644 --- a/contracts/child/ChildERC1155Predicate.sol +++ b/contracts/child/ChildERC1155Predicate.sol @@ -71,6 +71,10 @@ contract ChildERC1155Predicate is IChildERC1155Predicate, Initializable, System _; } + constructor() { + _disableInitializers(); + } + /** * @notice Initialization function for ChildERC1155Predicate * @param newL2StateSender Address of L2StateSender to send exit information to diff --git a/contracts/child/ChildERC1155PredicateAccessList.sol b/contracts/child/ChildERC1155PredicateAccessList.sol index 449ebc93..dbf082a3 100644 --- a/contracts/child/ChildERC1155PredicateAccessList.sol +++ b/contracts/child/ChildERC1155PredicateAccessList.sol @@ -11,6 +11,10 @@ import {AccessList} from "../lib/AccessList.sol"; */ // solhint-disable reason-string contract ChildERC1155PredicateAccessList is AccessList, ChildERC1155Predicate { + constructor() { + _disableInitializers(); + } + function initialize( address newL2StateSender, address newStateReceiver, diff --git a/contracts/child/ChildERC20.sol b/contracts/child/ChildERC20.sol index d0513a73..8eb57a3f 100644 --- a/contracts/child/ChildERC20.sol +++ b/contracts/child/ChildERC20.sol @@ -25,6 +25,10 @@ contract ChildERC20 is EIP712MetaTransaction, ERC20Upgradeable, IChildERC20 { _; } + constructor() { + _disableInitializers(); + } + /** * @inheritdoc IChildERC20 */ diff --git a/contracts/child/ChildERC20Predicate.sol b/contracts/child/ChildERC20Predicate.sol index ac1d515e..ae8f8587 100644 --- a/contracts/child/ChildERC20Predicate.sol +++ b/contracts/child/ChildERC20Predicate.sol @@ -49,6 +49,10 @@ contract ChildERC20Predicate is IChildERC20Predicate, Initializable, System { ); event L2TokenMapped(address indexed rootToken, address indexed childToken); + constructor() { + _disableInitializers(); + } + /** * @notice Initialization function for ChildERC20Predicate * @param newL2StateSender Address of L2StateSender to send exit information to diff --git a/contracts/child/ChildERC20PredicateAccessList.sol b/contracts/child/ChildERC20PredicateAccessList.sol index cf927f84..babdd7b7 100644 --- a/contracts/child/ChildERC20PredicateAccessList.sol +++ b/contracts/child/ChildERC20PredicateAccessList.sol @@ -11,6 +11,10 @@ import {AccessList} from "../lib/AccessList.sol"; */ // solhint-disable reason-string contract ChildERC20PredicateAccessList is AccessList, ChildERC20Predicate { + constructor() { + _disableInitializers(); + } + function initialize( address newL2StateSender, address newStateReceiver, diff --git a/contracts/child/ChildERC721.sol b/contracts/child/ChildERC721.sol index 3841066d..7ff6dd1c 100644 --- a/contracts/child/ChildERC721.sol +++ b/contracts/child/ChildERC721.sol @@ -22,6 +22,10 @@ contract ChildERC721 is EIP712MetaTransaction, ERC721Upgradeable, IChildERC721 { _; } + constructor() { + _disableInitializers(); + } + /** * @inheritdoc IChildERC721 */ diff --git a/contracts/child/ChildERC721Predicate.sol b/contracts/child/ChildERC721Predicate.sol index bf13fc3e..a762c1dd 100644 --- a/contracts/child/ChildERC721Predicate.sol +++ b/contracts/child/ChildERC721Predicate.sol @@ -67,6 +67,10 @@ contract ChildERC721Predicate is IChildERC721Predicate, Initializable, System { _; } + constructor() { + _disableInitializers(); + } + /** * @notice Initialization function for ChildERC721Predicate * @param newL2StateSender Address of L2StateSender to send exit information to diff --git a/contracts/child/ChildERC721PredicateAccessList.sol b/contracts/child/ChildERC721PredicateAccessList.sol index 69c4b014..c0852894 100644 --- a/contracts/child/ChildERC721PredicateAccessList.sol +++ b/contracts/child/ChildERC721PredicateAccessList.sol @@ -11,6 +11,10 @@ import {AccessList} from "../lib/AccessList.sol"; */ // solhint-disable reason-string contract ChildERC721PredicateAccessList is AccessList, ChildERC721Predicate { + constructor() { + _disableInitializers(); + } + function initialize( address newL2StateSender, address newStateReceiver, diff --git a/contracts/child/EIP1559Burn.sol b/contracts/child/EIP1559Burn.sol index 8a4b8add..eec4ef0c 100644 --- a/contracts/child/EIP1559Burn.sol +++ b/contracts/child/EIP1559Burn.sol @@ -20,6 +20,10 @@ contract EIP1559Burn is Initializable { // slither-disable-next-line locked-ether receive() external payable {} // solhint-disable-line no-empty-blocks + constructor() { + _disableInitializers(); + } + /** * @notice Initialization function for EIP1559 burn contract * @param newChildERC20Predicate Address of the ERC20 predicate on child chain diff --git a/contracts/child/NativeERC20.sol b/contracts/child/NativeERC20.sol index 543d80ac..35d4e751 100644 --- a/contracts/child/NativeERC20.sol +++ b/contracts/child/NativeERC20.sol @@ -30,6 +30,10 @@ contract NativeERC20 is Context, Initializable, System, INativeERC20 { _; } + constructor() { + _disableInitializers(); + } + /** * @dev Sets the values for {predicate}, {name} and {symbol}. * diff --git a/contracts/child/NativeERC20Mintable.sol b/contracts/child/NativeERC20Mintable.sol index 0d84fb0c..b262fc73 100644 --- a/contracts/child/NativeERC20Mintable.sol +++ b/contracts/child/NativeERC20Mintable.sol @@ -31,6 +31,10 @@ contract NativeERC20Mintable is Context, Initializable, System, Ownable2Step, IE _; } + constructor() { + _disableInitializers(); + } + /** * @dev Sets the values for {predicate}, {name} and {symbol}. * diff --git a/contracts/child/RootMintableERC1155Predicate.sol b/contracts/child/RootMintableERC1155Predicate.sol index e5e625e0..e720ef51 100644 --- a/contracts/child/RootMintableERC1155Predicate.sol +++ b/contracts/child/RootMintableERC1155Predicate.sol @@ -20,6 +20,10 @@ contract RootMintableERC1155Predicate is Initializable, ERC1155Holder, IRootMint bytes32 public constant MAP_TOKEN_SIG = keccak256("MAP_TOKEN"); mapping(address => address) public rootTokenToChildToken; + constructor() { + _disableInitializers(); + } + /** * @notice Initialization function for RootMintableERC1155Predicate * @param newL2StateSender Address of L2StateSender to send deposit information to diff --git a/contracts/child/RootMintableERC1155PredicateAccessList.sol b/contracts/child/RootMintableERC1155PredicateAccessList.sol index c4b79740..34296ab7 100644 --- a/contracts/child/RootMintableERC1155PredicateAccessList.sol +++ b/contracts/child/RootMintableERC1155PredicateAccessList.sol @@ -11,6 +11,10 @@ import {AccessList} from "../lib/AccessList.sol"; */ // solhint-disable reason-string contract RootMintableERC1155PredicateAccessList is AccessList, RootMintableERC1155Predicate { + constructor() { + _disableInitializers(); + } + function initialize( address newL2StateSender, address newStateReceiver, diff --git a/contracts/child/RootMintableERC20Predicate.sol b/contracts/child/RootMintableERC20Predicate.sol index 1d9e8314..28814285 100644 --- a/contracts/child/RootMintableERC20Predicate.sol +++ b/contracts/child/RootMintableERC20Predicate.sol @@ -26,6 +26,10 @@ contract RootMintableERC20Predicate is IRootMintableERC20Predicate, Initializabl bytes32 public constant MAP_TOKEN_SIG = keccak256("MAP_TOKEN"); mapping(address => address) public rootTokenToChildToken; + constructor() { + _disableInitializers(); + } + /** * @notice Initialization function for RootMintableERC20Predicate * @param newL2StateSender Address of L2StateSender to send exit information to diff --git a/contracts/child/RootMintableERC20PredicateAccessList.sol b/contracts/child/RootMintableERC20PredicateAccessList.sol index 97dee441..e2373b92 100644 --- a/contracts/child/RootMintableERC20PredicateAccessList.sol +++ b/contracts/child/RootMintableERC20PredicateAccessList.sol @@ -11,6 +11,10 @@ import {AccessList} from "../lib/AccessList.sol"; */ // solhint-disable reason-string contract RootMintableERC20PredicateAccessList is AccessList, RootMintableERC20Predicate { + constructor() { + _disableInitializers(); + } + function initialize( address newL2StateSender, address newStateReceiver, diff --git a/contracts/child/RootMintableERC721Predicate.sol b/contracts/child/RootMintableERC721Predicate.sol index 8524122a..293db17e 100644 --- a/contracts/child/RootMintableERC721Predicate.sol +++ b/contracts/child/RootMintableERC721Predicate.sol @@ -21,6 +21,10 @@ contract RootMintableERC721Predicate is Initializable, ERC721Holder, System, IRo bytes32 public constant MAP_TOKEN_SIG = keccak256("MAP_TOKEN"); mapping(address => address) public rootTokenToChildToken; + constructor() { + _disableInitializers(); + } + /** * @notice Initialization function for RootMintableERC721Predicate * @param newL2StateSender Address of L2StateSender to send deposit information to diff --git a/contracts/child/RootMintableERC721PredicateAccessList.sol b/contracts/child/RootMintableERC721PredicateAccessList.sol index 9064bc99..e58a47b6 100644 --- a/contracts/child/RootMintableERC721PredicateAccessList.sol +++ b/contracts/child/RootMintableERC721PredicateAccessList.sol @@ -11,6 +11,10 @@ import {AccessList} from "../lib/AccessList.sol"; */ // solhint-disable reason-string contract RootMintableERC721PredicateAccessList is AccessList, RootMintableERC721Predicate { + constructor() { + _disableInitializers(); + } + function initialize( address newL2StateSender, address newStateReceiver, diff --git a/contracts/child/validator/RewardPool.sol b/contracts/child/validator/RewardPool.sol index 50f4b1e1..5865f274 100644 --- a/contracts/child/validator/RewardPool.sol +++ b/contracts/child/validator/RewardPool.sol @@ -18,6 +18,10 @@ contract RewardPool is IRewardPool, System, Initializable { mapping(uint256 => uint256) public paidRewardPerEpoch; mapping(address => uint256) public pendingRewards; + constructor() { + _disableInitializers(); + } + function initialize( address newRewardToken, address newRewardWallet, diff --git a/contracts/child/validator/ValidatorSet.sol b/contracts/child/validator/ValidatorSet.sol index 5b371bd8..8435cc3c 100644 --- a/contracts/child/validator/ValidatorSet.sol +++ b/contracts/child/validator/ValidatorSet.sol @@ -26,6 +26,10 @@ contract ValidatorSet is IValidatorSet, ERC20SnapshotUpgradeable, System { uint256[] public epochEndBlocks; mapping(address => WithdrawalQueue) private _withdrawals; + constructor() { + _disableInitializers(); + } + function initialize( address newStateSender, address newStateReceiver, diff --git a/contracts/root/CheckpointManager.sol b/contracts/root/CheckpointManager.sol index 751850dc..aae41958 100644 --- a/contracts/root/CheckpointManager.sol +++ b/contracts/root/CheckpointManager.sol @@ -35,6 +35,8 @@ contract CheckpointManager is ICheckpointManager, Initializable { constructor(address initiator) { // slither-disable-next-line missing-zero-check _INITIATOR = initiator; + + _disableInitializers(); } /** diff --git a/contracts/root/ChildMintableERC1155Predicate.sol b/contracts/root/ChildMintableERC1155Predicate.sol index 1675b8dd..3e815f39 100644 --- a/contracts/root/ChildMintableERC1155Predicate.sol +++ b/contracts/root/ChildMintableERC1155Predicate.sol @@ -2,7 +2,6 @@ pragma solidity 0.8.19; import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; -import "@openzeppelin/contracts/token/ERC1155/IERC1155.sol"; import "@openzeppelin/contracts/proxy/Clones.sol"; import "../interfaces/root/IChildMintableERC1155Predicate.sol"; import "../interfaces/child/IChildERC1155.sol"; @@ -32,6 +31,10 @@ contract ChildMintableERC1155Predicate is Initializable, IChildMintableERC1155Pr _; } + constructor() { + _disableInitializers(); + } + /** * @notice Initialization function for ChildMintableERC1155Predicate * @param newStateSender Address of StateSender to send exit information to diff --git a/contracts/root/ChildMintableERC20Predicate.sol b/contracts/root/ChildMintableERC20Predicate.sol index c3096045..818a50ff 100644 --- a/contracts/root/ChildMintableERC20Predicate.sol +++ b/contracts/root/ChildMintableERC20Predicate.sol @@ -28,6 +28,10 @@ contract ChildMintableERC20Predicate is Initializable, IChildMintableERC20Predic mapping(address => address) public rootTokenToChildToken; + constructor() { + _disableInitializers(); + } + /** * @notice Initialization function for ChildMintableERC20Predicate * @param newStateSender Address of StateSender to send deposit information to diff --git a/contracts/root/ChildMintableERC721Predicate.sol b/contracts/root/ChildMintableERC721Predicate.sol index ac476c81..d466684d 100644 --- a/contracts/root/ChildMintableERC721Predicate.sol +++ b/contracts/root/ChildMintableERC721Predicate.sol @@ -2,7 +2,6 @@ pragma solidity 0.8.19; import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; -import "@openzeppelin/contracts/token/ERC721/IERC721.sol"; import "@openzeppelin/contracts/proxy/Clones.sol"; import "../interfaces/root/IChildMintableERC721Predicate.sol"; import "../interfaces/child/IChildERC721.sol"; @@ -32,6 +31,10 @@ contract ChildMintableERC721Predicate is Initializable, IChildMintableERC721Pred _; } + constructor() { + _disableInitializers(); + } + /** * @notice Initialization function for ChildMintableERC721Predicate * @param newStateSender Address of StateSender to send exit information to diff --git a/contracts/root/ExitHelper.sol b/contracts/root/ExitHelper.sol index 98473306..cdbc0f92 100644 --- a/contracts/root/ExitHelper.sol +++ b/contracts/root/ExitHelper.sol @@ -17,6 +17,10 @@ contract ExitHelper is IExitHelper, Initializable { _; } + constructor() { + _disableInitializers(); + } + /** * @notice Initialize the contract with the checkpoint manager address * @dev The checkpoint manager contract must be deployed first diff --git a/contracts/root/RootERC1155Predicate.sol b/contracts/root/RootERC1155Predicate.sol index 3f25f24f..4ec1facc 100644 --- a/contracts/root/RootERC1155Predicate.sol +++ b/contracts/root/RootERC1155Predicate.sol @@ -20,6 +20,10 @@ contract RootERC1155Predicate is Initializable, ERC1155Holder, IRootERC1155Predi bytes32 public constant MAP_TOKEN_SIG = keccak256("MAP_TOKEN"); mapping(address => address) public rootTokenToChildToken; + constructor() { + _disableInitializers(); + } + /** * @notice Initialization function for RootERC1155Predicate * @param newStateSender Address of StateSender to send deposit information to diff --git a/contracts/root/RootERC20Predicate.sol b/contracts/root/RootERC20Predicate.sol index 286ff2cc..c103b73d 100644 --- a/contracts/root/RootERC20Predicate.sol +++ b/contracts/root/RootERC20Predicate.sol @@ -21,6 +21,10 @@ contract RootERC20Predicate is Initializable, IRootERC20Predicate { mapping(address => address) public rootTokenToChildToken; address public nativeTokenRoot; + constructor() { + _disableInitializers(); + } + /** * @notice Initialization function for RootERC20Predicate * @param newStateSender Address of StateSender to send deposit information to diff --git a/contracts/root/RootERC721Predicate.sol b/contracts/root/RootERC721Predicate.sol index 7103a682..9e0df559 100644 --- a/contracts/root/RootERC721Predicate.sol +++ b/contracts/root/RootERC721Predicate.sol @@ -20,6 +20,10 @@ contract RootERC721Predicate is Initializable, ERC721Holder, IRootERC721Predicat bytes32 public constant MAP_TOKEN_SIG = keccak256("MAP_TOKEN"); mapping(address => address) public rootTokenToChildToken; + constructor() { + _disableInitializers(); + } + /** * @notice Initialization function for RootERC721Predicate * @param newStateSender Address of StateSender to send deposit information to diff --git a/contracts/root/staking/CustomSupernetManager.sol b/contracts/root/staking/CustomSupernetManager.sol index a0503d03..3f95822a 100644 --- a/contracts/root/staking/CustomSupernetManager.sol +++ b/contracts/root/staking/CustomSupernetManager.sol @@ -8,7 +8,6 @@ import "./SupernetManager.sol"; import "../../interfaces/common/IBLS.sol"; import "../../interfaces/IStateSender.sol"; import "../../interfaces/root/staking/ICustomSupernetManager.sol"; -import "../../interfaces/root/IExitHelper.sol"; import "../../interfaces/root/IRootERC20Predicate.sol"; contract CustomSupernetManager is ICustomSupernetManager, Ownable2StepUpgradeable, SupernetManager { @@ -36,6 +35,10 @@ contract CustomSupernetManager is ICustomSupernetManager, Ownable2StepUpgradeabl _; } + constructor() { + _disableInitializers(); + } + function initialize( address newStakeManager, address newBls, diff --git a/contracts/root/staking/StakeManager.sol b/contracts/root/staking/StakeManager.sol index 3c97612d..eae113e4 100644 --- a/contracts/root/staking/StakeManager.sol +++ b/contracts/root/staking/StakeManager.sol @@ -13,6 +13,10 @@ contract StakeManager is IStakeManager, Initializable, StakeManagerChildData, St IERC20 private _stakingToken; + constructor() { + _disableInitializers(); + } + function initialize(address newStakingToken) public initializer { _stakingToken = IERC20(newStakingToken); } diff --git a/foundry.toml b/foundry.toml index 43ff3fb2..ab796199 100644 --- a/foundry.toml +++ b/foundry.toml @@ -15,7 +15,7 @@ fs_permissions = [ { access = "read", path = "script/deployment/sharedRootContractsConfig.json" }, { access = "read", path = "script/deployment/rootContractSetConfig.json" }, { access = "read", path = "script/deployment/rootTokenContractsConfig.json" }, - { access = "read", path = "out/GenesisProxy.sol/GenesisProxy.json" } + { access = "read", path = "out/" } ] # do not use for computationally expensive tests diff --git a/package.json b/package.json index 13876f8b..4cabcfb2 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "coverage": "npx hardhat coverage", "coverage:foundry": "forge coverage --report lcov && genhtml -o forge-coverage lcov.info", "prepare": "husky install", - "husky:pre-commit": "npm run prettier && git add ." + "husky:pre-commit": "" }, "dependencies": { "@openzeppelin/contracts": "^4.9.3", diff --git a/test/child/ChildERC1155.test.ts b/test/child/ChildERC1155.test.ts index 671d6d6f..e88f5469 100644 --- a/test/child/ChildERC1155.test.ts +++ b/test/child/ChildERC1155.test.ts @@ -20,14 +20,18 @@ describe("ChildERC1155", () => { const ChildERC1155: ChildERC1155__factory = await ethers.getContractFactory("ChildERC1155"); childERC1155 = await ChildERC1155.deploy(); - await childERC1155.deployed(); + const _proxyAdmin = accounts[10].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(childERC1155.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + childERC1155 = ChildERC1155.attach(_proxy.address); + const ChildERC1155Predicate: ChildERC1155Predicate__factory = await ethers.getContractFactory( "ChildERC1155Predicate" ); childERC1155Predicate = await ChildERC1155Predicate.deploy(); - await childERC1155Predicate.deployed(); impersonateAccount(childERC1155Predicate.address); @@ -195,20 +199,20 @@ describe("ChildERC1155", () => { ); await expect(mintTx) .to.emit(predicateChildERC1155, "TransferSingle") - .withArgs("0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512", ethers.constants.AddressZero, accounts[0].address, 0, 1); + .withArgs("0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0", ethers.constants.AddressZero, accounts[0].address, 0, 1); await expect(mintTx) .to.emit(predicateChildERC1155, "TransferSingle") - .withArgs("0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512", ethers.constants.AddressZero, accounts[0].address, 1, 2); + .withArgs("0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0", ethers.constants.AddressZero, accounts[0].address, 1, 2); await expect(mintTx) .to.emit(predicateChildERC1155, "TransferSingle") - .withArgs("0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512", ethers.constants.AddressZero, accounts[1].address, 2, 3); + .withArgs("0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0", ethers.constants.AddressZero, accounts[1].address, 2, 3); }); it("batch burn tokens success", async () => { const burnTx = await predicateChildERC1155.burnBatch(accounts[0].address, [0, 1], [1, 2]); await expect(burnTx) .to.emit(predicateChildERC1155, "TransferBatch") .withArgs( - "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512", + "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0", accounts[0].address, ethers.constants.AddressZero, [0, 1], diff --git a/test/child/ChildERC1155Predicate.test.ts b/test/child/ChildERC1155Predicate.test.ts index c9c1f822..bc0b082d 100644 --- a/test/child/ChildERC1155Predicate.test.ts +++ b/test/child/ChildERC1155Predicate.test.ts @@ -53,9 +53,14 @@ describe("ChildERC1155Predicate", () => { "ChildERC1155Predicate" ); childERC1155Predicate = await ChildERC1155Predicate.deploy(); - await childERC1155Predicate.deployed(); + const _proxyAdmin = accounts[10].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(childERC1155Predicate.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + childERC1155Predicate = ChildERC1155Predicate.attach(_proxy.address); + impersonateAccount("0xffffFFFfFFffffffffffffffFfFFFfffFFFfFFfE"); setBalance("0xffffFFFfFFffffffffffffffFfFFFfffFFFfFFfE", "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); @@ -405,7 +410,13 @@ describe("ChildERC1155Predicate", () => { it("fail deposit tokens of unknown child token: unmapped token", async () => { const rootToken = ethers.Wallet.createRandom().address; - const childToken = await (await ethers.getContractFactory("ChildERC1155")).deploy(); + const ChildERC1155: ChildERC1155__factory = await ethers.getContractFactory("ChildERC1155"); + var childToken = await ChildERC1155.deploy(); + const _proxyAdmin = accounts[5].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(childToken.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + childToken = ChildERC1155.attach(_proxy.address); await childToken.initialize(rootToken, "TEST"); let stateSyncData = ethers.utils.defaultAbiCoder.encode( ["bytes32", "address", "address", "address", "uint256", "uint256"], @@ -439,7 +450,13 @@ describe("ChildERC1155Predicate", () => { it("fail withdraw tokens of unknown child token: unmapped token", async () => { const rootToken = ethers.Wallet.createRandom().address; - const childToken = await (await ethers.getContractFactory("ChildERC1155")).deploy(); + const ChildERC1155: ChildERC1155__factory = await ethers.getContractFactory("ChildERC1155"); + var childToken = await ChildERC1155.deploy(); + const _proxyAdmin = accounts[5].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(childToken.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + childToken = ChildERC1155.attach(_proxy.address); await childToken.initialize(rootToken, "TEST"); await expect(stateReceiverChildERC1155Predicate.withdraw(childToken.address, 0, 1)).to.be.revertedWith( "ChildERC1155Predicate: UNMAPPED_TOKEN" diff --git a/test/child/ChildERC20.test.ts b/test/child/ChildERC20.test.ts index be1ac4c4..97919f27 100644 --- a/test/child/ChildERC20.test.ts +++ b/test/child/ChildERC20.test.ts @@ -21,14 +21,22 @@ describe("ChildERC20", () => { const ChildERC20: ChildERC20__factory = await ethers.getContractFactory("ChildERC20"); childERC20 = await ChildERC20.deploy(); - await childERC20.deployed(); + const _proxyAdmin = accounts[5].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(childERC20.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + childERC20 = ChildERC20.attach(_proxy.address); + const ChildERC20Predicate: ChildERC20Predicate__factory = await ethers.getContractFactory("ChildERC20Predicate"); childERC20Predicate = await ChildERC20Predicate.deploy(); - await childERC20Predicate.deployed(); + const _proxy2 = await TransparentUpgradeableProxy.deploy(childERC20Predicate.address, _proxyAdmin, "0x"); + await _proxy2.deployed(); + childERC20Predicate = ChildERC20Predicate.attach(_proxy2.address); + impersonateAccount(childERC20Predicate.address); setBalance(childERC20Predicate.address, "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); diff --git a/test/child/ChildERC20Predicate.test.ts b/test/child/ChildERC20Predicate.test.ts index 9961cd1b..ca9530ac 100644 --- a/test/child/ChildERC20Predicate.test.ts +++ b/test/child/ChildERC20Predicate.test.ts @@ -57,9 +57,14 @@ describe("ChildERC20Predicate", () => { const ChildERC20Predicate: ChildERC20Predicate__factory = await ethers.getContractFactory("ChildERC20Predicate"); childERC20Predicate = await ChildERC20Predicate.deploy(); - await childERC20Predicate.deployed(); + const _proxyAdmin = accounts[10].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(childERC20Predicate.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + childERC20Predicate = ChildERC20Predicate.attach(_proxy.address); + const NativeERC20: NativeERC20__factory = await ethers.getContractFactory("NativeERC20"); const tempNativeERC20 = await NativeERC20.deploy(); @@ -373,7 +378,13 @@ describe("ChildERC20Predicate", () => { it("fail deposit tokens of unknown child token: unmapped token", async () => { const rootToken = ethers.Wallet.createRandom().address; - const childToken = await (await ethers.getContractFactory("ChildERC20")).deploy(); + const ChildERC20: ChildERC20__factory = await ethers.getContractFactory("ChildERC20"); + var childToken = await ChildERC20.deploy(); + const _proxyAdmin = accounts[5].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(childToken.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + childToken = ChildERC20.attach(_proxy.address); await childToken.initialize(rootToken, "TEST", "TEST", 18); const stateSyncData = ethers.utils.defaultAbiCoder.encode( ["bytes32", "address", "address", "address", "address", "uint256"], @@ -393,7 +404,13 @@ describe("ChildERC20Predicate", () => { it("fail withdraw tokens of unknown child token: unmapped token", async () => { const rootToken = ethers.Wallet.createRandom().address; - const childToken = await (await ethers.getContractFactory("ChildERC20")).deploy(); + const ChildERC20: ChildERC20__factory = await ethers.getContractFactory("ChildERC20"); + var childToken = await ChildERC20.deploy(); + const _proxyAdmin = accounts[5].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(childToken.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + childToken = ChildERC20.attach(_proxy.address); await childToken.initialize(rootToken, "TEST", "TEST", 18); await expect(stateReceiverChildERC20Predicate.withdraw(childToken.address, 1)).to.be.revertedWith( "ChildERC20Predicate: UNMAPPED_TOKEN" diff --git a/test/child/ChildERC721.test.ts b/test/child/ChildERC721.test.ts index 13bcc705..3fade871 100644 --- a/test/child/ChildERC721.test.ts +++ b/test/child/ChildERC721.test.ts @@ -22,14 +22,22 @@ describe("ChildERC721", () => { const ChildERC721: ChildERC721__factory = await ethers.getContractFactory("ChildERC721"); childERC721 = await ChildERC721.deploy(); - await childERC721.deployed(); + const _proxyAdmin = accounts[5].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(childERC721.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + childERC721 = ChildERC721.attach(_proxy.address); + const ChildERC721Predicate: ChildERC721Predicate__factory = await ethers.getContractFactory("ChildERC721Predicate"); childERC721Predicate = await ChildERC721Predicate.deploy(); - await childERC721Predicate.deployed(); + const _proxy2 = await TransparentUpgradeableProxy.deploy(childERC721Predicate.address, _proxyAdmin, "0x"); + await _proxy2.deployed(); + childERC721Predicate = ChildERC721Predicate.attach(_proxy2.address); + impersonateAccount(childERC721Predicate.address); setBalance(childERC721Predicate.address, "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); diff --git a/test/child/ChildERC721Predicate.test.ts b/test/child/ChildERC721Predicate.test.ts index 89c2cc51..4bbd3e2d 100644 --- a/test/child/ChildERC721Predicate.test.ts +++ b/test/child/ChildERC721Predicate.test.ts @@ -55,9 +55,14 @@ describe("ChildERC721Predicate", () => { const ChildERC721Predicate: ChildERC721Predicate__factory = await ethers.getContractFactory("ChildERC721Predicate"); childERC721Predicate = await ChildERC721Predicate.deploy(); - await childERC721Predicate.deployed(); + const _proxyAdmin = accounts[10].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(childERC721Predicate.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + childERC721Predicate = ChildERC721Predicate.attach(_proxy.address); + impersonateAccount("0xffffFFFfFFffffffffffffffFfFFFfffFFFfFFfE"); setBalance("0xffffFFFfFFffffffffffffffFfFFFfffFFFfFFfE", "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); @@ -400,7 +405,13 @@ describe("ChildERC721Predicate", () => { it("fail deposit tokens of unknown child token: unmapped token", async () => { const rootToken = ethers.Wallet.createRandom().address; - const childToken = await (await ethers.getContractFactory("ChildERC721")).deploy(); + const ChildERC721: ChildERC721__factory = await ethers.getContractFactory("ChildERC721"); + var childToken = await ChildERC721.deploy(); + const _proxyAdmin = accounts[5].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(childToken.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + childToken = ChildERC721.attach(_proxy.address); await childToken.initialize(rootToken, "TEST", "TEST"); let stateSyncData = ethers.utils.defaultAbiCoder.encode( ["bytes32", "address", "address", "address", "uint256"], @@ -426,7 +437,13 @@ describe("ChildERC721Predicate", () => { it("fail withdraw tokens of unknown child token: unmapped token", async () => { const rootToken = ethers.Wallet.createRandom().address; - const childToken = await (await ethers.getContractFactory("ChildERC721")).deploy(); + const ChildERC721: ChildERC721__factory = await ethers.getContractFactory("ChildERC721"); + var childToken = await ChildERC721.deploy(); + const _proxyAdmin = accounts[5].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(childToken.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + childToken = ChildERC721.attach(_proxy.address); await childToken.initialize(rootToken, "TEST", "TEST"); await expect(stateReceiverChildERC721Predicate.withdraw(childToken.address, 0)).to.be.revertedWith( "ChildERC721Predicate: UNMAPPED_TOKEN" diff --git a/test/child/EIP1559Burn.test.ts b/test/child/EIP1559Burn.test.ts index 56347e43..65cbe882 100644 --- a/test/child/EIP1559Burn.test.ts +++ b/test/child/EIP1559Burn.test.ts @@ -58,9 +58,14 @@ describe("EIP1559Burn", () => { const ChildERC20Predicate: ChildERC20Predicate__factory = await ethers.getContractFactory("ChildERC20Predicate"); childERC20Predicate = await ChildERC20Predicate.deploy(); - await childERC20Predicate.deployed(); + const _proxyAdmin = accounts[10].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(childERC20Predicate.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + childERC20Predicate = ChildERC20Predicate.attach(_proxy.address); + const NativeERC20: NativeERC20__factory = await ethers.getContractFactory("NativeERC20"); const tempNativeERC20 = await NativeERC20.deploy(); @@ -100,9 +105,12 @@ describe("EIP1559Burn", () => { const EIP1559Burn: EIP1559Burn__factory = await ethers.getContractFactory("EIP1559Burn"); eip1559Burn = await EIP1559Burn.deploy(); - await eip1559Burn.deployed(); + const _proxy2 = await TransparentUpgradeableProxy.deploy(eip1559Burn.address, _proxyAdmin, "0x"); + await _proxy2.deployed(); + eip1559Burn = EIP1559Burn.attach(_proxy2.address); + totalSupply = 0; }); diff --git a/test/child/RootMintableERC1155Predicate.test.ts b/test/child/RootMintableERC1155Predicate.test.ts index 769b7221..387349db 100644 --- a/test/child/RootMintableERC1155Predicate.test.ts +++ b/test/child/RootMintableERC1155Predicate.test.ts @@ -50,9 +50,14 @@ describe("RootMintableERC1155Predicate", () => { "RootMintableERC1155Predicate" ); rootMintableERC1155Predicate = await RootMintableERC1155Predicate.deploy(); - await rootMintableERC1155Predicate.deployed(); + const _proxyAdmin = accounts[10].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(rootMintableERC1155Predicate.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + rootMintableERC1155Predicate = RootMintableERC1155Predicate.attach(_proxy.address); + impersonateAccount("0xffffFFFfFFffffffffffffffFfFFFfffFFFfFFfE"); setBalance("0xffffFFFfFFffffffffffffffFfFFFfffFFFfFFfE", "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); diff --git a/test/child/RootMintableERC20Predicate.test.ts b/test/child/RootMintableERC20Predicate.test.ts index 883ef3b1..af12ca28 100644 --- a/test/child/RootMintableERC20Predicate.test.ts +++ b/test/child/RootMintableERC20Predicate.test.ts @@ -52,9 +52,14 @@ describe("RootMintableERC20Predicate", () => { "RootMintableERC20Predicate" ); rootMintableERC20Predicate = await RootMintableERC20Predicate.deploy(); - await rootMintableERC20Predicate.deployed(); + const _proxyAdmin = accounts[10].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(rootMintableERC20Predicate.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + rootMintableERC20Predicate = RootMintableERC20Predicate.attach(_proxy.address); + const NativeERC20: NativeERC20__factory = await ethers.getContractFactory("NativeERC20"); const tempNativeERC20 = await NativeERC20.deploy(); diff --git a/test/child/RootMintableERC721Predicate.test.ts b/test/child/RootMintableERC721Predicate.test.ts index 1d83632f..fbb92676 100644 --- a/test/child/RootMintableERC721Predicate.test.ts +++ b/test/child/RootMintableERC721Predicate.test.ts @@ -49,9 +49,14 @@ describe("RootMintableERC721Predicate", () => { "RootMintableERC721Predicate" ); rootMintableERC721Predicate = await RootMintableERC721Predicate.deploy(); - await rootMintableERC721Predicate.deployed(); + const _proxyAdmin = accounts[10].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(rootMintableERC721Predicate.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + rootMintableERC721Predicate = RootMintableERC721Predicate.attach(_proxy.address); + impersonateAccount("0xffffFFFfFFffffffffffffffFfFFFfffFFFfFFfE"); setBalance("0xffffFFFfFFffffffffffffffFfFFFfffFFFfFFfE", "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); diff --git a/test/forge/child/ChildERC1155.t.sol b/test/forge/child/ChildERC1155.t.sol index 846c8a82..35d4e764 100644 --- a/test/forge/child/ChildERC1155.t.sol +++ b/test/forge/child/ChildERC1155.t.sol @@ -17,8 +17,8 @@ contract ChildERC1155Test is Test { string URI = "lorem"; function setUp() public { - childERC1155 = new ChildERC1155(); - predicate = new ChildERC1155Predicate(); + childERC1155 = ChildERC1155(proxify("ChildERC1155.sol", "")); + predicate = ChildERC1155Predicate(proxify("ChildERC1155Predicate.sol", "")); alice = makeAddr("Alice"); bob = makeAddr("Bob"); diff --git a/test/forge/child/ChildERC20.t.sol b/test/forge/child/ChildERC20.t.sol index 1f69d1a0..6e86d6dd 100644 --- a/test/forge/child/ChildERC20.t.sol +++ b/test/forge/child/ChildERC20.t.sol @@ -18,8 +18,8 @@ contract ChildERC20Test is Test { uint8 decimals = 18; function setUp() public { - childERC20 = new ChildERC20(); - predicate = new ChildERC20Predicate(); + childERC20 = ChildERC20(proxify("ChildERC20.sol", "")); + predicate = ChildERC20Predicate(proxify("ChildERC20Predicate.sol", "")); alice = makeAddr("Alice"); bob = makeAddr("Bob"); diff --git a/test/forge/child/ChildERC20Predicate.t.sol b/test/forge/child/ChildERC20Predicate.t.sol index b5fb8a3d..c7a4ca25 100644 --- a/test/forge/child/ChildERC20Predicate.t.sol +++ b/test/forge/child/ChildERC20Predicate.t.sol @@ -18,7 +18,7 @@ contract ChildERC20PredicateTest is Test { address bob; function setUp() public { - predicate = new ChildERC20Predicate(); + predicate = ChildERC20Predicate(proxify("ChildERC20Predicate.sol", "")); alice = makeAddr("Alice"); bob = makeAddr("Bob"); diff --git a/test/forge/child/ChildERC721.t.sol b/test/forge/child/ChildERC721.t.sol index 354de150..4936c8e8 100644 --- a/test/forge/child/ChildERC721.t.sol +++ b/test/forge/child/ChildERC721.t.sol @@ -18,8 +18,8 @@ contract ChildERC721Test is Test { string URI = "lorem"; function setUp() public { - childERC721 = new ChildERC721(); - predicate = new ChildERC721Predicate(); + childERC721 = ChildERC721(proxify("ChildERC721.sol", "")); + predicate = ChildERC721Predicate(proxify("ChildERC721Predicate.sol", "")); alice = makeAddr("Alice"); bob = makeAddr("Bob"); diff --git a/test/forge/child/validator/RewardPool.t.sol b/test/forge/child/validator/RewardPool.t.sol index ee998359..f0c575af 100644 --- a/test/forge/child/validator/RewardPool.t.sol +++ b/test/forge/child/validator/RewardPool.t.sol @@ -19,7 +19,7 @@ abstract contract Uninitialized is Test { function setUp() public virtual { token = new MockERC20(); - validatorSet = new ValidatorSet(); + validatorSet = ValidatorSet(proxify("ValidatorSet.sol", "")); ValidatorInit[] memory init = new ValidatorInit[](2); init[0] = ValidatorInit({addr: address(this), stake: 300}); init[1] = ValidatorInit({addr: alice, stake: 100}); @@ -28,7 +28,7 @@ abstract contract Uninitialized is Test { vm.prank(SYSTEM); validatorSet.commitEpoch(1, epoch); vm.roll(block.number + 1); - pool = new RewardPool(); + pool = RewardPool(proxify("RewardPool.sol", "")); token.mint(rewardWallet, 1000 ether); vm.prank(rewardWallet); token.approve(address(pool), type(uint256).max); diff --git a/test/forge/child/validator/ValidatorSet.t.sol b/test/forge/child/validator/ValidatorSet.t.sol index 9693d4b7..49339cc7 100644 --- a/test/forge/child/validator/ValidatorSet.t.sol +++ b/test/forge/child/validator/ValidatorSet.t.sol @@ -20,7 +20,7 @@ abstract contract Uninitialized is Test { function setUp() public virtual { stateSender = new L2StateSender(); - validatorSet = new ValidatorSet(); + validatorSet = ValidatorSet(proxify("ValidatorSet.sol", "")); } } diff --git a/test/forge/root/CheckpointManager.t.sol b/test/forge/root/CheckpointManager.t.sol index ff8a64e8..834dcdfb 100644 --- a/test/forge/root/CheckpointManager.t.sol +++ b/test/forge/root/CheckpointManager.t.sol @@ -31,7 +31,7 @@ abstract contract Uninitialized is Test { function setUp() public virtual { bls = new BLS(); bn256G2 = new BN256G2(); - checkpointManager = new CheckpointManager(address(0)); + checkpointManager = CheckpointManager(proxify("CheckpointManager.sol", abi.encode(address(0)))); admin = makeAddr("admin"); alice = makeAddr("Alice"); @@ -87,8 +87,8 @@ abstract contract FirstSubmitted is Initialized { contract CheckpointManager_Initialize is Uninitialized { function testCannotIntialize() public { - address INITIALIZER = makeAddr("INITIALIZER"); - checkpointManager = new CheckpointManager(INITIALIZER); + address initiator = makeAddr("initiator"); + checkpointManager = CheckpointManager(proxify("CheckpointManager.sol", abi.encode(address(initiator)))); vm.expectRevert(); checkpointManager.initialize(bls, bn256G2, submitCounter, validatorSet); diff --git a/test/forge/root/ExitHelper.t.sol b/test/forge/root/ExitHelper.t.sol index 21c202d0..8a9d9d10 100644 --- a/test/forge/root/ExitHelper.t.sol +++ b/test/forge/root/ExitHelper.t.sol @@ -37,8 +37,7 @@ abstract contract Uninitialized is Test { function setUp() public virtual { bls = new BLS(); bn256G2 = new BN256G2(); - checkpointManager = new CheckpointManager(address(0)); - exitHelper = new ExitHelper(); + exitHelper = ExitHelper(proxify("ExitHelper.sol", "")); admin = makeAddr("admin"); alice = makeAddr("Alice"); @@ -81,6 +80,7 @@ abstract contract Uninitialized is Test { } submitCounter = 1; + checkpointManager = CheckpointManager(proxify("CheckpointManager.sol", abi.encode(address(0)))); checkpointManager.initialize(bls, bn256G2, submitCounter, validatorSet); } } diff --git a/test/forge/root/staking/CustomSupernetManager.t.sol b/test/forge/root/staking/CustomSupernetManager.t.sol index 65f483cc..af737be7 100644 --- a/test/forge/root/staking/CustomSupernetManager.t.sol +++ b/test/forge/root/staking/CustomSupernetManager.t.sol @@ -29,8 +29,8 @@ abstract contract Uninitialized is Test { childValidatorSet = makeAddr("childValidatorSet"); exitHelper = address(new ExitHelper()); token = new MockERC20(); - stakeManager = new StakeManager(); - supernetManager = new CustomSupernetManager(); + stakeManager = StakeManager(proxify("StakeManager.sol", "")); + supernetManager = CustomSupernetManager(proxify("CustomSupernetManager.sol", "")); stakeManager.initialize(address(token)); rootERC20Predicate = new RootERC20Predicate(); } diff --git a/test/forge/root/staking/StakeManager.t.sol b/test/forge/root/staking/StakeManager.t.sol index 2b6de31d..19561840 100644 --- a/test/forge/root/staking/StakeManager.t.sol +++ b/test/forge/root/staking/StakeManager.t.sol @@ -13,7 +13,7 @@ abstract contract Uninitialized is Test { function setUp() public virtual { token = new MockERC20(); - stakeManager = new StakeManager(); + stakeManager = StakeManager(proxify("StakeManager.sol", "")); supernetManager = new MockSupernetManager(); } } diff --git a/test/forge/utils/Cheats.sol b/test/forge/utils/Cheats.sol new file mode 100644 index 00000000..d403bf77 --- /dev/null +++ b/test/forge/utils/Cheats.sol @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: MIT +pragma solidity 0.8.19; + +// 💬 ABOUT +// StdCheats and custom cheats. + +// 🧩 MODULES +import {StdCheats} from "forge-std/StdCheats.sol"; + +// 📦 BOILERPLATE +import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; + +// ⭐️ CHEATS +abstract contract Cheats is StdCheats { + address immutable PROXY_ADMIN = makeAddr("PROXY_ADMIN"); + + function proxify(string memory what, bytes memory args) internal returns (address proxyAddr) { + address logicAddr = deployCode(what, args); + TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy(logicAddr, PROXY_ADMIN, ""); + proxyAddr = address(proxy); + } +} diff --git a/test/forge/utils/Test.sol b/test/forge/utils/Test.sol index 066272b5..fa1d72f8 100644 --- a/test/forge/utils/Test.sol +++ b/test/forge/utils/Test.sol @@ -5,9 +5,9 @@ pragma solidity 0.8.19; // Custom Test. // 🧩 MODULES -import {console2 as console} from "forge-std/console2.sol"; +import {console} from "forge-std/console.sol"; import {Assertions} from "./Assertions.sol"; -import {StdCheats} from "forge-std/StdCheats.sol"; +import {Cheats} from "./Cheats.sol"; import {stdError} from "forge-std/StdError.sol"; import {StdUtils} from "forge-std/StdUtils.sol"; @@ -16,6 +16,6 @@ import {TestBase} from "forge-std/Base.sol"; import {DSTest} from "ds-test/test.sol"; // ⭐️ TEST -abstract contract Test is DSTest, Assertions, StdCheats, StdUtils, TestBase { +abstract contract Test is TestBase, DSTest, Assertions, Cheats, StdUtils { } diff --git a/test/root/CheckpointManager.test.ts b/test/root/CheckpointManager.test.ts index b3f2c3ad..a670a726 100644 --- a/test/root/CheckpointManager.test.ts +++ b/test/root/CheckpointManager.test.ts @@ -30,6 +30,12 @@ describe("CheckpointManager", () => { const CheckpointManager = await ethers.getContractFactory("CheckpointManager"); checkpointManager = (await CheckpointManager.deploy(ethers.constants.AddressZero)) as CheckpointManager; await checkpointManager.deployed(); + + const _proxyAdmin = accounts[5].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(checkpointManager.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + checkpointManager = CheckpointManager.attach(_proxy.address); }); it("Initialize failed by zero voting power", async () => { diff --git a/test/root/ChildMintableERC1155Predicate.test.ts b/test/root/ChildMintableERC1155Predicate.test.ts index a8f93c3a..a63c2507 100644 --- a/test/root/ChildMintableERC1155Predicate.test.ts +++ b/test/root/ChildMintableERC1155Predicate.test.ts @@ -52,9 +52,14 @@ describe("ChildMintableERC1155Predicate", () => { "ChildMintableERC1155Predicate" ); childMintableERC1155Predicate = await ChildMintableERC1155Predicate.deploy(); - await childMintableERC1155Predicate.deployed(); + const _proxyAdmin = accounts[10].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(childMintableERC1155Predicate.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + childMintableERC1155Predicate = ChildMintableERC1155Predicate.attach(_proxy.address); + impersonateAccount(exitHelper.address); setBalance(exitHelper.address, "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); exitHelperChildERC1155Predicate = childMintableERC1155Predicate.connect(await ethers.getSigner(exitHelper.address)); @@ -382,7 +387,13 @@ describe("ChildMintableERC1155Predicate", () => { it("fail deposit tokens of unknown child token: unmapped token", async () => { const rootToken = ethers.Wallet.createRandom().address; - const childToken = await (await ethers.getContractFactory("ChildERC1155")).deploy(); + const ChildERC1155: ChildERC1155__factory = await ethers.getContractFactory("ChildERC1155"); + var childToken = await ChildERC1155.deploy(); + const _proxyAdmin = accounts[5].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(childToken.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + childToken = ChildERC1155.attach(_proxy.address); await childToken.initialize(rootToken, "TEST"); let stateSyncData = ethers.utils.defaultAbiCoder.encode( ["bytes32", "address", "address", "address", "uint256", "uint256"], @@ -416,7 +427,13 @@ describe("ChildMintableERC1155Predicate", () => { it("fail withdraw tokens of unknown child token: unmapped token", async () => { const rootToken = ethers.Wallet.createRandom().address; - const childToken = await (await ethers.getContractFactory("ChildERC1155")).deploy(); + const ChildERC1155: ChildERC1155__factory = await ethers.getContractFactory("ChildERC1155"); + var childToken = await ChildERC1155.deploy(); + const _proxyAdmin = accounts[5].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(childToken.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + childToken = ChildERC1155.attach(_proxy.address); await childToken.initialize(rootToken, "TEST"); await expect(childMintableERC1155Predicate.withdraw(childToken.address, 0, 1)).to.be.revertedWith( "ChildMintableERC1155Predicate: UNMAPPED_TOKEN" diff --git a/test/root/ChildMintableERC20Predicate.test.ts b/test/root/ChildMintableERC20Predicate.test.ts index b8852644..a1bbd7a2 100644 --- a/test/root/ChildMintableERC20Predicate.test.ts +++ b/test/root/ChildMintableERC20Predicate.test.ts @@ -52,9 +52,14 @@ describe("ChildMintableERC20Predicate", () => { "ChildMintableERC20Predicate" ); childMintableERC20Predicate = await ChildMintableERC20Predicate.deploy(); - await childMintableERC20Predicate.deployed(); + const _proxyAdmin = accounts[10].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(childMintableERC20Predicate.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + childMintableERC20Predicate = ChildMintableERC20Predicate.attach(_proxy.address); + impersonateAccount(exitHelper.address); setBalance(exitHelper.address, "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); exitHelperChildMintableERC20Predicate = childMintableERC20Predicate.connect( @@ -320,7 +325,13 @@ describe("ChildMintableERC20Predicate", () => { it("fail deposit tokens of unknown child token: unmapped token", async () => { const rootToken = ethers.Wallet.createRandom().address; - const childToken = await (await ethers.getContractFactory("ChildERC20")).deploy(); + const ChildERC20: ChildERC20__factory = await ethers.getContractFactory("ChildERC20"); + var childToken = await ChildERC20.deploy(); + const _proxyAdmin = accounts[5].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(childToken.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + childToken = ChildERC20.attach(_proxy.address); await childToken.initialize(rootToken, "TEST", "TEST", 18); const stateSyncData = ethers.utils.defaultAbiCoder.encode( ["bytes32", "address", "address", "address", "address", "uint256"], @@ -340,7 +351,13 @@ describe("ChildMintableERC20Predicate", () => { it("fail withdraw tokens of unknown child token: unmapped token", async () => { const rootToken = ethers.Wallet.createRandom().address; - const childToken = await (await ethers.getContractFactory("ChildERC20")).deploy(); + const ChildERC20: ChildERC20__factory = await ethers.getContractFactory("ChildERC20"); + var childToken = await ChildERC20.deploy(); + const _proxyAdmin = accounts[5].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(childToken.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + childToken = ChildERC20.attach(_proxy.address); await childToken.initialize(rootToken, "TEST", "TEST", 18); await expect(childMintableERC20Predicate.withdraw(childToken.address, 1)).to.be.revertedWith( "ChildMintableERC20Predicate: UNMAPPED_TOKEN" diff --git a/test/root/ChildMintableERC721Predicate.test.ts b/test/root/ChildMintableERC721Predicate.test.ts index 8f55badf..7f6bac8f 100644 --- a/test/root/ChildMintableERC721Predicate.test.ts +++ b/test/root/ChildMintableERC721Predicate.test.ts @@ -56,9 +56,14 @@ describe("ChildMintableERC721Predicate", () => { "ChildMintableERC721Predicate" ); childMintableERC721Predicate = await ChildMintableERC721Predicate.deploy(); - await childMintableERC721Predicate.deployed(); + const _proxyAdmin = accounts[5].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(childMintableERC721Predicate.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + childMintableERC721Predicate = ChildMintableERC721Predicate.attach(_proxy.address); + impersonateAccount(exitHelper.address); setBalance(exitHelper.address, "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); exitHelperChildMintableERC721Predicate = childMintableERC721Predicate.connect( @@ -399,7 +404,13 @@ describe("ChildMintableERC721Predicate", () => { it("fail deposit tokens of unknown child token: unmapped token", async () => { const rootToken = ethers.Wallet.createRandom().address; - const childToken = await (await ethers.getContractFactory("ChildERC721")).deploy(); + const ChildERC721: ChildERC721__factory = await ethers.getContractFactory("ChildERC721"); + var childToken = await ChildERC721.deploy(); + const _proxyAdmin = accounts[5].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(childToken.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + childToken = ChildERC721.attach(_proxy.address); await childToken.initialize(rootToken, "TEST", "TEST"); let stateSyncData = ethers.utils.defaultAbiCoder.encode( ["bytes32", "address", "address", "address", "uint256"], @@ -425,7 +436,13 @@ describe("ChildMintableERC721Predicate", () => { it("fail withdraw tokens of unknown child token: unmapped token", async () => { const rootToken = ethers.Wallet.createRandom().address; - const childToken = await (await ethers.getContractFactory("ChildERC721")).deploy(); + const ChildERC721: ChildERC721__factory = await ethers.getContractFactory("ChildERC721"); + var childToken = await ChildERC721.deploy(); + const _proxyAdmin = accounts[5].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(childToken.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + childToken = ChildERC721.attach(_proxy.address); await childToken.initialize(rootToken, "TEST", "TEST"); await expect(exitHelperChildMintableERC721Predicate.withdraw(childToken.address, 0)).to.be.revertedWith( "ChildMintableERC721Predicate: UNMAPPED_TOKEN" diff --git a/test/root/ExitHelper.test.ts b/test/root/ExitHelper.test.ts index 8e283706..d32f7095 100644 --- a/test/root/ExitHelper.test.ts +++ b/test/root/ExitHelper.test.ts @@ -37,9 +37,19 @@ describe("ExitHelper", () => { checkpointManager = (await CheckpointManager.deploy(ethers.constants.AddressZero)) as CheckpointManager; await checkpointManager.deployed(); + const _proxyAdmin = accounts[5].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(checkpointManager.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + checkpointManager = CheckpointManager.attach(_proxy.address); + const ExitHelper = await ethers.getContractFactory("ExitHelper"); exitHelper = (await ExitHelper.deploy()) as ExitHelper; await exitHelper.deployed(); + + const _proxy2 = await TransparentUpgradeableProxy.deploy(exitHelper.address, _proxyAdmin, "0x"); + await _proxy2.deployed(); + exitHelper = ExitHelper.attach(_proxy2.address); }); it("Initialize CheckpointManager and validate initialization", async () => { diff --git a/test/root/RootERC1155Predicate.test.ts b/test/root/RootERC1155Predicate.test.ts index b7013967..f7b55c4d 100644 --- a/test/root/RootERC1155Predicate.test.ts +++ b/test/root/RootERC1155Predicate.test.ts @@ -35,7 +35,6 @@ describe("RootERC1155Predicate", () => { const ExitHelper: ExitHelper__factory = await ethers.getContractFactory("ExitHelper"); exitHelper = await ExitHelper.deploy(); - await exitHelper.deployed(); childERC1155Predicate = ethers.Wallet.createRandom().address; @@ -47,9 +46,14 @@ describe("RootERC1155Predicate", () => { const RootERC1155Predicate: RootERC1155Predicate__factory = await ethers.getContractFactory("RootERC1155Predicate"); rootERC1155Predicate = await RootERC1155Predicate.deploy(); - await rootERC1155Predicate.deployed(); + const _proxyAdmin = accounts[5].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy2 = await TransparentUpgradeableProxy.deploy(rootERC1155Predicate.address, _proxyAdmin, "0x"); + await _proxy2.deployed(); + rootERC1155Predicate = RootERC1155Predicate.attach(_proxy2.address); + impersonateAccount(exitHelper.address); setBalance(exitHelper.address, "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); exitHelperRootERC1155Predicate = rootERC1155Predicate.connect(await ethers.getSigner(exitHelper.address)); diff --git a/test/root/RootERC20Predicate.test.ts b/test/root/RootERC20Predicate.test.ts index d14ce640..7997d2e8 100644 --- a/test/root/RootERC20Predicate.test.ts +++ b/test/root/RootERC20Predicate.test.ts @@ -46,9 +46,14 @@ describe("RootERC20Predicate", () => { const RootERC20Predicate: RootERC20Predicate__factory = await ethers.getContractFactory("RootERC20Predicate"); rootERC20Predicate = await RootERC20Predicate.deploy(); - await rootERC20Predicate.deployed(); + const _proxyAdmin = accounts[5].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(rootERC20Predicate.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + rootERC20Predicate = RootERC20Predicate.attach(_proxy.address); + impersonateAccount(exitHelper.address); setBalance(exitHelper.address, "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); exitHelperRootERC20Predicate = rootERC20Predicate.connect(await ethers.getSigner(exitHelper.address)); diff --git a/test/root/RootERC721Predicate.test.ts b/test/root/RootERC721Predicate.test.ts index c32473af..a381d67b 100644 --- a/test/root/RootERC721Predicate.test.ts +++ b/test/root/RootERC721Predicate.test.ts @@ -46,9 +46,14 @@ describe("RootERC721Predicate", () => { const RootERC721Predicate: RootERC721Predicate__factory = await ethers.getContractFactory("RootERC721Predicate"); rootERC721Predicate = await RootERC721Predicate.deploy(); - await rootERC721Predicate.deployed(); + const _proxyAdmin = accounts[5].address; + const TransparentUpgradeableProxy = await ethers.getContractFactory("TransparentUpgradeableProxy"); + const _proxy = await TransparentUpgradeableProxy.deploy(rootERC721Predicate.address, _proxyAdmin, "0x"); + await _proxy.deployed(); + rootERC721Predicate = RootERC721Predicate.attach(_proxy.address); + impersonateAccount(exitHelper.address); setBalance(exitHelper.address, "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); exitHelperRootERC721Predicate = rootERC721Predicate.connect(await ethers.getSigner(exitHelper.address));