From 18c06003e57c00d53a5d83ba51ab40d4f9e58d2a Mon Sep 17 00:00:00 2001 From: has5aan Date: Tue, 18 Jun 2024 19:49:55 +0200 Subject: [PATCH 01/10] adds tests for script/contracts/Utils --- test/utils/Utils.t.sol | 71 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 test/utils/Utils.t.sol diff --git a/test/utils/Utils.t.sol b/test/utils/Utils.t.sol new file mode 100644 index 00000000..61b45ac1 --- /dev/null +++ b/test/utils/Utils.t.sol @@ -0,0 +1,71 @@ +// SPDX-License-Identifier: Apache-2.0 +pragma solidity 0.8.23; + +import { Test, console2 } from "forge-std/Test.sol"; +import { Utils } from "script/contracts/Utils.sol"; + +contract UtilsTest is Test { + function test_readAndWriteL1AddressesFile() public { + Utils utils = new Utils(); + + Utils.L1AddressesConfig memory config = + Utils.L1AddressesConfig({ L1LiskToken: address(0x1), L1VestingWalletImplementation: address(0x2) }); + + utils.writeL1AddressesFile(config); + + Utils.L1AddressesConfig memory configReadFromFile = utils.readL1AddressesFile(); + + assertEq(configReadFromFile.L1LiskToken, config.L1LiskToken); + assertEq(configReadFromFile.L1VestingWalletImplementation, config.L1VestingWalletImplementation); + } + + function test_readAndWriteL2AddressesFile() public { + Utils utils = new Utils(); + + Utils.L2AddressesConfig memory config = Utils.L2AddressesConfig({ + L2ClaimContract: address(0x01), + L2ClaimImplementation: address(0x02), + L2Governor: address(0x03), + L2GovernorImplementation: address(0x04), + L2LiskToken: address(0x05), + L2LockingPosition: address(0x06), + L2LockingPositionImplementation: address(0x07), + L2Reward: address(0x09), + L2RewardImplementation: address(0x10), + L2Staking: address(0x11), + L2StakingImplementation: address(0x12), + L2TimelockController: address(0x13), + L2VestingWalletImplementation: address(0x14), + L2VotingPower: address(0x15), + L2VotingPowerImplementation: address(0x16) + }); + + utils.writeL2AddressesFile(config); + + Utils.L2AddressesConfig memory configReadFromFile = utils.readL2AddressesFile(); + + assertEq(configReadFromFile.L2ClaimContract, config.L2ClaimContract); + assertEq(configReadFromFile.L2Governor, config.L2Governor); + assertEq(configReadFromFile.L2GovernorImplementation, config.L2GovernorImplementation); + assertEq(configReadFromFile.L2LiskToken, config.L2LiskToken); + assertEq(configReadFromFile.L2LockingPosition, config.L2LockingPosition); + assertEq(configReadFromFile.L2LockingPositionImplementation, config.L2LockingPositionImplementation); + assertEq(configReadFromFile.L2Reward, config.L2Reward); + assertEq(configReadFromFile.L2RewardImplementation, config.L2RewardImplementation); + assertEq(configReadFromFile.L2Staking, config.L2Staking); + assertEq(configReadFromFile.L2StakingImplementation, config.L2StakingImplementation); + assertEq(configReadFromFile.L2TimelockController, config.L2TimelockController); + assertEq(configReadFromFile.L2VestingWalletImplementation, config.L2VestingWalletImplementation); + assertEq(configReadFromFile.L2VotingPower, config.L2VotingPower); + assertEq(configReadFromFile.L2VotingPowerImplementation, config.L2VotingPowerImplementation); + } + + function test_readMerkleRootFile() public { + Utils utils = new Utils(); + + assertEq( + vm.toString(utils.readMerkleRootFile().merkleRoot), + "0x92ebb53b56a4136bfd1ea09a7e2d64f3dc3165020516f6ee5e17aee9f65a7f3b" + ); + } +} From 9af89de3674adb1dc174775f09950efa3ef8ec0b Mon Sep 17 00:00:00 2001 From: has5aan Date: Wed, 19 Jun 2024 11:52:05 +0200 Subject: [PATCH 02/10] Adds tests for Utils --- test/utils/Utils.t.sol | 43 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/test/utils/Utils.t.sol b/test/utils/Utils.t.sol index 61b45ac1..1d23024d 100644 --- a/test/utils/Utils.t.sol +++ b/test/utils/Utils.t.sol @@ -61,11 +61,52 @@ contract UtilsTest is Test { } function test_readMerkleRootFile() public { - Utils utils = new Utils(); + vm.setEnv("NETWORK", "testnet"); + Utils utils = new Utils(); assertEq( vm.toString(utils.readMerkleRootFile().merkleRoot), "0x92ebb53b56a4136bfd1ea09a7e2d64f3dc3165020516f6ee5e17aee9f65a7f3b" ); } + + function test_readWriteVestingWalletsFile() public { + vm.setEnv("NETWORK", "testnet"); + + Utils utils = new Utils(); + + Utils.VestingWallet[] memory vestingWallets = new Utils.VestingWallet[](2); + vestingWallets[0] = Utils.VestingWallet({ name: "wallet1", vestingWalletAddress: address(0x1) }); + vestingWallets[1] = Utils.VestingWallet({ name: "wallet2", vestingWalletAddress: address(0x2) }); + + utils.writeVestingWalletsFile(vestingWallets, "l1"); + + assertEq(utils.readVestingWalletAddress("wallet1", "l1"), address(0x1)); + assertEq(utils.readVestingWalletAddress("wallet2", "l1"), address(0x2)); + } + + function test_readVestingAddress() public { + vm.setEnv("NETWORK", "testnet"); + + Utils utils = new Utils(); + + address team1Address = address(0xE1F2e7E049A8484479f14aF62d831f70476fCDBc); + address team2Address = address(0x74A898371f058056cD94F5D2D24d5d0BFacD3EB9); + + assertEq(utils.readVestingAddress("team1Address", "l1"), team1Address); + assertEq(utils.readVestingAddress("team2Address", "l1"), team2Address); + } + + function test_readAccountsFile() public { + vm.setEnv("NETWORK", "devnet"); + + Utils utils = new Utils(); + + Utils.Accounts memory accountsReadFromFile = utils.readAccountsFile("accounts_1.json"); + + assertEq(accountsReadFromFile.l1Addresses[0].addr, address(0xe708A1b91dDC44576731f7fEb4e193F48923Abba)); + assertEq(accountsReadFromFile.l1Addresses[0].amount, 2000000000000000000000); + assertEq(accountsReadFromFile.l2Addresses[0].addr, address(0x396DF972a284bA7F5a8BEc2D9B9eC2377a099215)); + assertEq(accountsReadFromFile.l2Addresses[0].amount, 3000000000000000000000); + } } From e5a14a599aea6c6c78705a1eb06ce279da8efdc6 Mon Sep 17 00:00:00 2001 From: has5aan Date: Wed, 19 Jun 2024 15:31:20 +0200 Subject: [PATCH 03/10] refactors: NETWORK environment --- test/utils/Utils.t.sol | 47 +++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/test/utils/Utils.t.sol b/test/utils/Utils.t.sol index 1d23024d..d45653fc 100644 --- a/test/utils/Utils.t.sol +++ b/test/utils/Utils.t.sol @@ -5,9 +5,15 @@ import { Test, console2 } from "forge-std/Test.sol"; import { Utils } from "script/contracts/Utils.sol"; contract UtilsTest is Test { - function test_readAndWriteL1AddressesFile() public { - Utils utils = new Utils(); + Utils utils; + + function setUp() public { + vm.setEnv("NETWORK", "testnet"); + + utils = new Utils(); + } + function test_readAndWriteL1AddressesFile() public { Utils.L1AddressesConfig memory config = Utils.L1AddressesConfig({ L1LiskToken: address(0x1), L1VestingWalletImplementation: address(0x2) }); @@ -20,8 +26,6 @@ contract UtilsTest is Test { } function test_readAndWriteL2AddressesFile() public { - Utils utils = new Utils(); - Utils.L2AddressesConfig memory config = Utils.L2AddressesConfig({ L2ClaimContract: address(0x01), L2ClaimImplementation: address(0x02), @@ -60,10 +64,7 @@ contract UtilsTest is Test { assertEq(configReadFromFile.L2VotingPowerImplementation, config.L2VotingPowerImplementation); } - function test_readMerkleRootFile() public { - vm.setEnv("NETWORK", "testnet"); - - Utils utils = new Utils(); + function test_readMerkleRootFile() public view { assertEq( vm.toString(utils.readMerkleRootFile().merkleRoot), "0x92ebb53b56a4136bfd1ea09a7e2d64f3dc3165020516f6ee5e17aee9f65a7f3b" @@ -71,10 +72,6 @@ contract UtilsTest is Test { } function test_readWriteVestingWalletsFile() public { - vm.setEnv("NETWORK", "testnet"); - - Utils utils = new Utils(); - Utils.VestingWallet[] memory vestingWallets = new Utils.VestingWallet[](2); vestingWallets[0] = Utils.VestingWallet({ name: "wallet1", vestingWalletAddress: address(0x1) }); vestingWallets[1] = Utils.VestingWallet({ name: "wallet2", vestingWalletAddress: address(0x2) }); @@ -85,11 +82,7 @@ contract UtilsTest is Test { assertEq(utils.readVestingWalletAddress("wallet2", "l1"), address(0x2)); } - function test_readVestingAddress() public { - vm.setEnv("NETWORK", "testnet"); - - Utils utils = new Utils(); - + function test_readVestingAddress() public view { address team1Address = address(0xE1F2e7E049A8484479f14aF62d831f70476fCDBc); address team2Address = address(0x74A898371f058056cD94F5D2D24d5d0BFacD3EB9); @@ -97,16 +90,18 @@ contract UtilsTest is Test { assertEq(utils.readVestingAddress("team2Address", "l1"), team2Address); } - function test_readAccountsFile() public { - vm.setEnv("NETWORK", "devnet"); - - Utils utils = new Utils(); + function test_readAccountsFile() public view { + Utils.Accounts memory accountsReadFromFile1 = utils.readAccountsFile("accounts_1.json"); - Utils.Accounts memory accountsReadFromFile = utils.readAccountsFile("accounts_1.json"); + assertEq(accountsReadFromFile1.l1Addresses.length, 6); + assertEq(accountsReadFromFile1.l1Addresses[0].addr, address(0x0a5bFdBbF7aDe3042da107EaA726d5A71D2DcbaD)); + assertEq(accountsReadFromFile1.l1Addresses[0].amount, 2000000000000000000000000); + assertEq(accountsReadFromFile1.l2Addresses.length, 0); - assertEq(accountsReadFromFile.l1Addresses[0].addr, address(0xe708A1b91dDC44576731f7fEb4e193F48923Abba)); - assertEq(accountsReadFromFile.l1Addresses[0].amount, 2000000000000000000000); - assertEq(accountsReadFromFile.l2Addresses[0].addr, address(0x396DF972a284bA7F5a8BEc2D9B9eC2377a099215)); - assertEq(accountsReadFromFile.l2Addresses[0].amount, 3000000000000000000000); + Utils.Accounts memory accountsReadFromFile2 = utils.readAccountsFile("accounts_2.json"); + assertEq(accountsReadFromFile2.l1Addresses.length, 0); + assertEq(accountsReadFromFile2.l2Addresses.length, 1); + assertEq(accountsReadFromFile2.l2Addresses[0].addr, address(0x473BbFd3097D597d14466EF19519f406D6f9202d)); + assertEq(accountsReadFromFile2.l2Addresses[0].amount, 51000000000000000000); } } From 084dcea83209e434dd2ce8e6305a60092fb31a6e Mon Sep 17 00:00:00 2001 From: has5aan Date: Wed, 19 Jun 2024 16:17:27 +0200 Subject: [PATCH 04/10] updates signatures --- test/utils/Utils.t.sol | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/utils/Utils.t.sol b/test/utils/Utils.t.sol index d45653fc..1012364d 100644 --- a/test/utils/Utils.t.sol +++ b/test/utils/Utils.t.sol @@ -64,7 +64,7 @@ contract UtilsTest is Test { assertEq(configReadFromFile.L2VotingPowerImplementation, config.L2VotingPowerImplementation); } - function test_readMerkleRootFile() public view { + function test_readMerkleRootFile() public { assertEq( vm.toString(utils.readMerkleRootFile().merkleRoot), "0x92ebb53b56a4136bfd1ea09a7e2d64f3dc3165020516f6ee5e17aee9f65a7f3b" @@ -82,7 +82,7 @@ contract UtilsTest is Test { assertEq(utils.readVestingWalletAddress("wallet2", "l1"), address(0x2)); } - function test_readVestingAddress() public view { + function test_readVestingAddress() public { address team1Address = address(0xE1F2e7E049A8484479f14aF62d831f70476fCDBc); address team2Address = address(0x74A898371f058056cD94F5D2D24d5d0BFacD3EB9); @@ -90,7 +90,7 @@ contract UtilsTest is Test { assertEq(utils.readVestingAddress("team2Address", "l1"), team2Address); } - function test_readAccountsFile() public view { + function test_readAccountsFile() public { Utils.Accounts memory accountsReadFromFile1 = utils.readAccountsFile("accounts_1.json"); assertEq(accountsReadFromFile1.l1Addresses.length, 6); From 9649d0d687e693f13c574ebc99e1e3e6dd0c7bf2 Mon Sep 17 00:00:00 2001 From: has5aan Date: Wed, 19 Jun 2024 23:09:33 +0200 Subject: [PATCH 05/10] updates test_readVestingAddress --- test/utils/Utils.t.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/utils/Utils.t.sol b/test/utils/Utils.t.sol index 1012364d..2c266eaa 100644 --- a/test/utils/Utils.t.sol +++ b/test/utils/Utils.t.sol @@ -86,8 +86,8 @@ contract UtilsTest is Test { address team1Address = address(0xE1F2e7E049A8484479f14aF62d831f70476fCDBc); address team2Address = address(0x74A898371f058056cD94F5D2D24d5d0BFacD3EB9); - assertEq(utils.readVestingAddress("team1Address", "l1"), team1Address); - assertEq(utils.readVestingAddress("team2Address", "l1"), team2Address); + assertEq(utils.readVestingAddress("team1Address", "L1"), team1Address); + assertEq(utils.readVestingAddress("team2Address", "L1"), team2Address); } function test_readAccountsFile() public { From 8316bd75bfb49937bc34acc59f71ce12ce1b4048 Mon Sep 17 00:00:00 2001 From: has5aan Date: Thu, 20 Jun 2024 08:48:42 +0200 Subject: [PATCH 06/10] updates file system permissions for foundry --- foundry.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/foundry.toml b/foundry.toml index 8847712d..d73828cb 100644 --- a/foundry.toml +++ b/foundry.toml @@ -2,7 +2,7 @@ src = "src" out = "out" libs = ["lib"] -fs_permissions = [{ access = "read-write", path = "./" }] +fs_permissions = [{ access = "read-write", path = "./deployment/testnet" }] solc_version = "0.8.23" optimizer = true optimizer_runs = 200 From 369318c3ea842eb79cf984a9c76baa0ebe78f9b5 Mon Sep 17 00:00:00 2001 From: has5aan Date: Thu, 20 Jun 2024 09:43:37 +0200 Subject: [PATCH 07/10] test if pipeline can write --- foundry.toml | 2 +- script/contracts/Utils.sol | 2 +- test/utils/Utils.t.sol | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/foundry.toml b/foundry.toml index d73828cb..8847712d 100644 --- a/foundry.toml +++ b/foundry.toml @@ -2,7 +2,7 @@ src = "src" out = "out" libs = ["lib"] -fs_permissions = [{ access = "read-write", path = "./deployment/testnet" }] +fs_permissions = [{ access = "read-write", path = "./" }] solc_version = "0.8.23" optimizer = true optimizer_runs = 200 diff --git a/script/contracts/Utils.sol b/script/contracts/Utils.sol index 3e03b40a..7116736d 100644 --- a/script/contracts/Utils.sol +++ b/script/contracts/Utils.sol @@ -139,7 +139,7 @@ contract Utils is Script { vm.serializeAddress(json, "L1LiskToken", cfg.L1LiskToken); string memory finalJson = vm.serializeAddress(json, "L1VestingWalletImplementation", cfg.L1VestingWalletImplementation); - finalJson.write(string.concat("deployment/", network, "/l1addresses.json")); + finalJson.write("l1addresses.json"); } /// @notice This function reads L2 addresses from JSON file. diff --git a/test/utils/Utils.t.sol b/test/utils/Utils.t.sol index 2c266eaa..c09ed17a 100644 --- a/test/utils/Utils.t.sol +++ b/test/utils/Utils.t.sol @@ -19,10 +19,10 @@ contract UtilsTest is Test { utils.writeL1AddressesFile(config); - Utils.L1AddressesConfig memory configReadFromFile = utils.readL1AddressesFile(); + // Utils.L1AddressesConfig memory configReadFromFile = utils.readL1AddressesFile(); - assertEq(configReadFromFile.L1LiskToken, config.L1LiskToken); - assertEq(configReadFromFile.L1VestingWalletImplementation, config.L1VestingWalletImplementation); + // assertEq(configReadFromFile.L1LiskToken, config.L1LiskToken); + // assertEq(configReadFromFile.L1VestingWalletImplementation, config.L1VestingWalletImplementation); } function test_readAndWriteL2AddressesFile() public { From b4900ba90b8e3e6be0a408c4f75729aec2e27f67 Mon Sep 17 00:00:00 2001 From: has5aan Date: Thu, 20 Jun 2024 13:18:13 +0200 Subject: [PATCH 08/10] refactor: Utils.sol --- script/contracts/L1/L1FundVesting.s.sol | 2 +- script/contracts/L1/L1LiskToken.s.sol | 2 +- script/contracts/L1/L1VestingWallet.s.sol | 4 +- script/contracts/L2/L2Claim.s.sol | 4 +- .../contracts/L2/L2FundRewardContract.s.sol | 2 +- script/contracts/L2/L2FundVestingAndDAO.s.sol | 4 +- script/contracts/L2/L2Governor.s.sol | 4 +- script/contracts/L2/L2LiskToken.s.sol | 4 +- script/contracts/L2/L2LockingPosition.s.sol | 4 +- script/contracts/L2/L2Reward.s.sol | 4 +- script/contracts/L2/L2Staking.s.sol | 4 +- script/contracts/L2/L2VestingWallet.s.sol | 4 +- script/contracts/L2/L2VotingPower.s.sol | 4 +- script/contracts/TransferFunds1stBatch.s.sol | 4 +- script/contracts/TransferFunds2ndBatch.s.sol | 4 +- script/contracts/Utils.sol | 64 +++++++++++-------- script/example/DemoTransferFunds.s.sol | 2 +- script/example/L2ClaimTokens.s.sol | 2 +- script/example/L2DemoToken.s.sol | 2 +- test/utils/Utils.t.sol | 18 +++--- 20 files changed, 75 insertions(+), 67 deletions(-) diff --git a/script/contracts/L1/L1FundVesting.s.sol b/script/contracts/L1/L1FundVesting.s.sol index c58aa920..225bd822 100644 --- a/script/contracts/L1/L1FundVesting.s.sol +++ b/script/contracts/L1/L1FundVesting.s.sol @@ -23,7 +23,7 @@ contract L1FundVestingScript is Script { uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); // get L1LiskToken contract address - Utils.L1AddressesConfig memory l1AddressesConfig = utils.readL1AddressesFile(); + Utils.L1AddressesConfig memory l1AddressesConfig = utils.readL1AddressesFile(utils.getL1AddressesFilePath()); assert(l1AddressesConfig.L1LiskToken != address(0)); console2.log("L1 Lisk token address: %s", l1AddressesConfig.L1LiskToken); diff --git a/script/contracts/L1/L1LiskToken.s.sol b/script/contracts/L1/L1LiskToken.s.sol index 2d286ed9..3018ae80 100644 --- a/script/contracts/L1/L1LiskToken.s.sol +++ b/script/contracts/L1/L1LiskToken.s.sol @@ -55,6 +55,6 @@ contract L1LiskTokenScript is Script { // write L1LiskToken address to l1addresses.json Utils.L1AddressesConfig memory l1AddressesConfig; l1AddressesConfig.L1LiskToken = address(l1LiskToken); - utils.writeL1AddressesFile(l1AddressesConfig); + utils.writeL1AddressesFile(l1AddressesConfig, utils.getL1AddressesFilePath()); } } diff --git a/script/contracts/L1/L1VestingWallet.s.sol b/script/contracts/L1/L1VestingWallet.s.sol index 9081e0e8..a854bbac 100644 --- a/script/contracts/L1/L1VestingWallet.s.sol +++ b/script/contracts/L1/L1VestingWallet.s.sol @@ -21,7 +21,7 @@ contract L1VestingWalletScript is Script { /// @notice This function deploys L1 Vesting Wallet contract. function run() public { - Utils.L1AddressesConfig memory l1AddressesConfig = utils.readL1AddressesFile(); + Utils.L1AddressesConfig memory l1AddressesConfig = utils.readL1AddressesFile(utils.getL1AddressesFilePath()); // Deployer's private key. Owner of the L1 Vesting Wallet. PRIVATE_KEY is set in .env file. uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); @@ -84,6 +84,6 @@ contract L1VestingWalletScript is Script { // write L1VestingWallet address to l1addresses.json l1AddressesConfig.L1VestingWalletImplementation = address(l1VestingWalletImplementation); - utils.writeL1AddressesFile(l1AddressesConfig); + utils.writeL1AddressesFile(l1AddressesConfig, utils.getL1AddressesFilePath()); } } diff --git a/script/contracts/L2/L2Claim.s.sol b/script/contracts/L2/L2Claim.s.sol index e05b614e..cf273c74 100644 --- a/script/contracts/L2/L2Claim.s.sol +++ b/script/contracts/L2/L2Claim.s.sol @@ -33,7 +33,7 @@ contract L2ClaimScript is Script { console2.log("L2 Claim contract owner address: %s (after ownership will be accepted)", ownerAddress); // get L2LiskToken contract address - Utils.L2AddressesConfig memory l2AddressesConfig = utils.readL2AddressesFile(); + Utils.L2AddressesConfig memory l2AddressesConfig = utils.readL2AddressesFile(utils.getL2AddressesFilePath()); assert(l2AddressesConfig.L2LiskToken != address(0)); console2.log("L2 Lisk token address: %s", l2AddressesConfig.L2LiskToken); @@ -97,6 +97,6 @@ contract L2ClaimScript is Script { // write L2ClaimContract address to l2addresses.json l2AddressesConfig.L2ClaimImplementation = address(l2ClaimImplementation); l2AddressesConfig.L2ClaimContract = address(l2Claim); - utils.writeL2AddressesFile(l2AddressesConfig); + utils.writeL2AddressesFile(l2AddressesConfig, utils.getL2AddressesFilePath()); } } diff --git a/script/contracts/L2/L2FundRewardContract.s.sol b/script/contracts/L2/L2FundRewardContract.s.sol index 2f1f447b..d84a8874 100644 --- a/script/contracts/L2/L2FundRewardContract.s.sol +++ b/script/contracts/L2/L2FundRewardContract.s.sol @@ -29,7 +29,7 @@ contract FundRewardContractScript is Script { console2.log("Transferring deployer's L2 Lisk tokens to the L2Reward contract..."); // get L2LiskToken and L2Reward contracts instances - Utils.L2AddressesConfig memory l2AddressesConfig = utils.readL2AddressesFile(); + Utils.L2AddressesConfig memory l2AddressesConfig = utils.readL2AddressesFile(utils.getL2AddressesFilePath()); assert(l2AddressesConfig.L2LiskToken != address(0)); assert(l2AddressesConfig.L2Reward != address(0)); IL2LiskToken l2LiskToken = IL2LiskToken(l2AddressesConfig.L2LiskToken); diff --git a/script/contracts/L2/L2FundVestingAndDAO.s.sol b/script/contracts/L2/L2FundVestingAndDAO.s.sol index 38562255..a4139714 100644 --- a/script/contracts/L2/L2FundVestingAndDAO.s.sol +++ b/script/contracts/L2/L2FundVestingAndDAO.s.sol @@ -55,12 +55,12 @@ contract FundVestingAndDAOScript is Script { console2.log("Transferring deployer's L1 Lisk tokens to the Vesting and DAO contract..."); // get L1LiskToken contract address - Utils.L1AddressesConfig memory l1AddressesConfig = utils.readL1AddressesFile(); + Utils.L1AddressesConfig memory l1AddressesConfig = utils.readL1AddressesFile(utils.getL1AddressesFilePath()); assert(l1AddressesConfig.L1LiskToken != address(0)); console2.log("L1 Lisk token address: %s", l1AddressesConfig.L1LiskToken); // get L2LiskToken contract address - Utils.L2AddressesConfig memory l2AddressesConfig = utils.readL2AddressesFile(); + Utils.L2AddressesConfig memory l2AddressesConfig = utils.readL2AddressesFile(utils.getL2AddressesFilePath()); assert(l2AddressesConfig.L2LiskToken != address(0)); console2.log("L2 Lisk token address: %s", l2AddressesConfig.L2LiskToken); diff --git a/script/contracts/L2/L2Governor.s.sol b/script/contracts/L2/L2Governor.s.sol index c05079aa..d64fffab 100644 --- a/script/contracts/L2/L2Governor.s.sol +++ b/script/contracts/L2/L2Governor.s.sol @@ -32,7 +32,7 @@ contract L2GovernorScript is Script { console2.log("Deploying L2 TimelockController and Governor contracts..."); // get L2Staking contract address - Utils.L2AddressesConfig memory l2AddressesConfig = utils.readL2AddressesFile(); + Utils.L2AddressesConfig memory l2AddressesConfig = utils.readL2AddressesFile(utils.getL2AddressesFilePath()); assert(l2AddressesConfig.L2Staking != address(0)); console2.log("L2 Staking address: %s", l2AddressesConfig.L2Staking); IL2Staking stakingContract = IL2Staking(l2AddressesConfig.L2Staking); @@ -128,6 +128,6 @@ contract L2GovernorScript is Script { l2AddressesConfig.L2TimelockController = address(timelock); l2AddressesConfig.L2GovernorImplementation = address(l2GovernorImplementation); l2AddressesConfig.L2Governor = address(l2Governor); - utils.writeL2AddressesFile(l2AddressesConfig); + utils.writeL2AddressesFile(l2AddressesConfig, utils.getL2AddressesFilePath()); } } diff --git a/script/contracts/L2/L2LiskToken.s.sol b/script/contracts/L2/L2LiskToken.s.sol index 9f1849cf..33793687 100644 --- a/script/contracts/L2/L2LiskToken.s.sol +++ b/script/contracts/L2/L2LiskToken.s.sol @@ -27,7 +27,7 @@ contract L2LiskTokenScript is Script { console2.log("Deploying L2 Lisk token..."); // get L1LiskToken contract address - Utils.L1AddressesConfig memory l1AddressesConfig = utils.readL1AddressesFile(); + Utils.L1AddressesConfig memory l1AddressesConfig = utils.readL1AddressesFile(utils.getL1AddressesFilePath()); console2.log("L1 Lisk token address: %s", l1AddressesConfig.L1LiskToken); // get salt for L2LiskToken contract @@ -60,6 +60,6 @@ contract L2LiskTokenScript is Script { // write L2LiskToken address to l2addresses.json Utils.L2AddressesConfig memory l2AddressesConfig; l2AddressesConfig.L2LiskToken = address(l2LiskToken); - utils.writeL2AddressesFile(l2AddressesConfig); + utils.writeL2AddressesFile(l2AddressesConfig, utils.getL2AddressesFilePath()); } } diff --git a/script/contracts/L2/L2LockingPosition.s.sol b/script/contracts/L2/L2LockingPosition.s.sol index ca6161a4..657cdc45 100644 --- a/script/contracts/L2/L2LockingPosition.s.sol +++ b/script/contracts/L2/L2LockingPosition.s.sol @@ -25,7 +25,7 @@ contract L2LockingPositionScript is Script { console2.log("Deploying L2 Locking Position..."); // get L2Staking contract address - Utils.L2AddressesConfig memory l2AddressesConfig = utils.readL2AddressesFile(); + Utils.L2AddressesConfig memory l2AddressesConfig = utils.readL2AddressesFile(utils.getL2AddressesFilePath()); assert(l2AddressesConfig.L2Staking != address(0)); console2.log("L2 Staking address: %s", l2AddressesConfig.L2Staking); IL2Staking stakingContract = IL2Staking(l2AddressesConfig.L2Staking); @@ -82,6 +82,6 @@ contract L2LockingPositionScript is Script { // write L2 Locking Position address to l2addresses.json l2AddressesConfig.L2LockingPositionImplementation = address(l2LockingPositionImplementation); l2AddressesConfig.L2LockingPosition = address(l2LockingPosition); - utils.writeL2AddressesFile(l2AddressesConfig); + utils.writeL2AddressesFile(l2AddressesConfig, utils.getL2AddressesFilePath()); } } diff --git a/script/contracts/L2/L2Reward.s.sol b/script/contracts/L2/L2Reward.s.sol index eb7f4d3e..7af25a4c 100644 --- a/script/contracts/L2/L2Reward.s.sol +++ b/script/contracts/L2/L2Reward.s.sol @@ -26,7 +26,7 @@ contract L2RewardScript is Script { console2.log("Deploying L2 Reward..."); // get L2LiskToken contract address - Utils.L2AddressesConfig memory l2AddressesConfig = utils.readL2AddressesFile(); + Utils.L2AddressesConfig memory l2AddressesConfig = utils.readL2AddressesFile(utils.getL2AddressesFilePath()); assert(l2AddressesConfig.L2LiskToken != address(0)); console2.log("L2 Lisk Token address: %s", l2AddressesConfig.L2LiskToken); @@ -90,6 +90,6 @@ contract L2RewardScript is Script { // write L2 Reward address to l2addresses.json l2AddressesConfig.L2RewardImplementation = address(l2RewardImplementation); l2AddressesConfig.L2Reward = address(l2Reward); - utils.writeL2AddressesFile(l2AddressesConfig); + utils.writeL2AddressesFile(l2AddressesConfig, utils.getL2AddressesFilePath()); } } diff --git a/script/contracts/L2/L2Staking.s.sol b/script/contracts/L2/L2Staking.s.sol index 02a734ea..ee82c5b4 100644 --- a/script/contracts/L2/L2Staking.s.sol +++ b/script/contracts/L2/L2Staking.s.sol @@ -24,7 +24,7 @@ contract L2StakingScript is Script { console2.log("Deploying L2 Staking..."); // get L2LiskToken contract address - Utils.L2AddressesConfig memory l2AddressesConfig = utils.readL2AddressesFile(); + Utils.L2AddressesConfig memory l2AddressesConfig = utils.readL2AddressesFile(utils.getL2AddressesFilePath()); assert(l2AddressesConfig.L2LiskToken != address(0)); console2.log("L2 Lisk Token address: %s", l2AddressesConfig.L2LiskToken); @@ -75,6 +75,6 @@ contract L2StakingScript is Script { // write L2 Staking address to l2addresses.json l2AddressesConfig.L2StakingImplementation = address(l2StakingImplementation); l2AddressesConfig.L2Staking = address(l2Staking); - utils.writeL2AddressesFile(l2AddressesConfig); + utils.writeL2AddressesFile(l2AddressesConfig, utils.getL2AddressesFilePath()); } } diff --git a/script/contracts/L2/L2VestingWallet.s.sol b/script/contracts/L2/L2VestingWallet.s.sol index f503993d..de1683f8 100644 --- a/script/contracts/L2/L2VestingWallet.s.sol +++ b/script/contracts/L2/L2VestingWallet.s.sol @@ -21,7 +21,7 @@ contract L2VestingWalletScript is Script { /// @notice This function deploys L2 Vesting Wallet contract. function run() public { - Utils.L2AddressesConfig memory l2AddressesConfig = utils.readL2AddressesFile(); + Utils.L2AddressesConfig memory l2AddressesConfig = utils.readL2AddressesFile(utils.getL2AddressesFilePath()); // Deployer's private key. Owner of the L2 Vesting Wallet. PRIVATE_KEY is set in .env file. uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); @@ -91,6 +91,6 @@ contract L2VestingWalletScript is Script { // write L2VestingWallet address to l2addresses.json l2AddressesConfig.L2VestingWalletImplementation = address(l2VestingWalletImplementation); - utils.writeL2AddressesFile(l2AddressesConfig); + utils.writeL2AddressesFile(l2AddressesConfig, utils.getL2AddressesFilePath()); } } diff --git a/script/contracts/L2/L2VotingPower.s.sol b/script/contracts/L2/L2VotingPower.s.sol index 505b3dd1..5465d17a 100644 --- a/script/contracts/L2/L2VotingPower.s.sol +++ b/script/contracts/L2/L2VotingPower.s.sol @@ -25,7 +25,7 @@ contract L2VotingPowerScript is Script { console2.log("Deploying L2 Voting Power..."); // get L2LockingPosition contract address - Utils.L2AddressesConfig memory l2AddressesConfig = utils.readL2AddressesFile(); + Utils.L2AddressesConfig memory l2AddressesConfig = utils.readL2AddressesFile(utils.getL2AddressesFilePath()); assert(l2AddressesConfig.L2LockingPosition != address(0)); console2.log("L2 Locking Position address: %s", l2AddressesConfig.L2LockingPosition); IL2LockingPosition lockingPositionContract = IL2LockingPosition(l2AddressesConfig.L2LockingPosition); @@ -84,6 +84,6 @@ contract L2VotingPowerScript is Script { // write L2 Voting Power address to l2addresses.json l2AddressesConfig.L2VotingPowerImplementation = address(l2VotingPowerImplementation); l2AddressesConfig.L2VotingPower = address(l2VotingPower); - utils.writeL2AddressesFile(l2AddressesConfig); + utils.writeL2AddressesFile(l2AddressesConfig, utils.getL2AddressesFilePath()); } } diff --git a/script/contracts/TransferFunds1stBatch.s.sol b/script/contracts/TransferFunds1stBatch.s.sol index c0237c6c..2fe5cb0c 100644 --- a/script/contracts/TransferFunds1stBatch.s.sol +++ b/script/contracts/TransferFunds1stBatch.s.sol @@ -55,12 +55,12 @@ contract TransferFunds1stBatchScript is Script { console2.log("Transferring Lisk tokens from L1 to a different addresses on L1 and L2 networks..."); // get L1LiskToken contract address - Utils.L1AddressesConfig memory l1AddressesConfig = utils.readL1AddressesFile(); + Utils.L1AddressesConfig memory l1AddressesConfig = utils.readL1AddressesFile(utils.getL1AddressesFilePath()); assert(l1AddressesConfig.L1LiskToken != address(0)); console2.log("L1 Lisk token address: %s", l1AddressesConfig.L1LiskToken); // get L2LiskToken contract address - Utils.L2AddressesConfig memory l2AddressesConfig = utils.readL2AddressesFile(); + Utils.L2AddressesConfig memory l2AddressesConfig = utils.readL2AddressesFile(utils.getL2AddressesFilePath()); assert(l2AddressesConfig.L2LiskToken != address(0)); console2.log("L2 Lisk token address: %s", l2AddressesConfig.L2LiskToken); diff --git a/script/contracts/TransferFunds2ndBatch.s.sol b/script/contracts/TransferFunds2ndBatch.s.sol index 9ff2a085..16dc56b0 100644 --- a/script/contracts/TransferFunds2ndBatch.s.sol +++ b/script/contracts/TransferFunds2ndBatch.s.sol @@ -52,12 +52,12 @@ contract TransferFunds2ndBatchScript is Script { console2.log("Transferring Lisk tokens from L1 to a different addresses on L1 and L2 networks..."); // get L1LiskToken contract address - Utils.L1AddressesConfig memory l1AddressesConfig = utils.readL1AddressesFile(); + Utils.L1AddressesConfig memory l1AddressesConfig = utils.readL1AddressesFile(utils.getL1AddressesFilePath()); assert(l1AddressesConfig.L1LiskToken != address(0)); console2.log("L1 Lisk token address: %s", l1AddressesConfig.L1LiskToken); // get L2LiskToken and L2Claim contracts addresses - Utils.L2AddressesConfig memory l2AddressesConfig = utils.readL2AddressesFile(); + Utils.L2AddressesConfig memory l2AddressesConfig = utils.readL2AddressesFile(utils.getL2AddressesFilePath()); assert(l2AddressesConfig.L2LiskToken != address(0)); assert(l2AddressesConfig.L2ClaimContract != address(0)); console2.log("L2 Lisk token address: %s", l2AddressesConfig.L2LiskToken); diff --git a/script/contracts/Utils.sol b/script/contracts/Utils.sol index 7116736d..b97eceae 100644 --- a/script/contracts/Utils.sol +++ b/script/contracts/Utils.sol @@ -108,13 +108,22 @@ contract Utils is Script { return network; } + /// @notice This function returns the path for L1 addresses JSON file. + /// @return string containing file path to L1 addresses JSON. + function getL1AddressesFilePath() external view returns (string memory) { + return string.concat(vm.projectRoot(), "/deployment/", getNetworkType(), "/l1addresses.json"); + } + + /// @notice This function returns the path for L2 addresses JSON file. + function getL2AddressesFilePath() external view returns (string memory) { + return string.concat(vm.projectRoot(), "/deployment/", getNetworkType(), "/l2addresses.json"); + } + /// @notice This function reads L1 addresses from JSON file. + /// @param filePath L1Addresses file path. /// @return L1AddressesConfig struct containing L1 addresses. - function readL1AddressesFile() external view returns (L1AddressesConfig memory) { - string memory network = getNetworkType(); - string memory root = vm.projectRoot(); - string memory addressPath = string.concat(root, "/deployment/", network, "/l1addresses.json"); - string memory addressJson = vm.readFile(addressPath); + function readL1AddressesFile(string memory filePath) external view returns (L1AddressesConfig memory) { + string memory addressJson = vm.readFile(filePath); L1AddressesConfig memory l1AddressesConfig; @@ -133,22 +142,20 @@ contract Utils is Script { /// @notice This function writes L1 addresses to JSON file. /// @param cfg L1AddressesConfig struct containing L1 addresses which will be written to JSON file. - function writeL1AddressesFile(L1AddressesConfig memory cfg) external { - string memory network = getNetworkType(); + /// @param filePath L1Addresses file path. + function writeL1AddressesFile(L1AddressesConfig memory cfg, string memory filePath) external { string memory json = ""; vm.serializeAddress(json, "L1LiskToken", cfg.L1LiskToken); string memory finalJson = vm.serializeAddress(json, "L1VestingWalletImplementation", cfg.L1VestingWalletImplementation); - finalJson.write("l1addresses.json"); + finalJson.write(filePath); } /// @notice This function reads L2 addresses from JSON file. + /// @param filePath L2Addresses file path. /// @return L2AddressesConfig struct containing L2 addresses. - function readL2AddressesFile() external view returns (L2AddressesConfig memory) { - string memory network = getNetworkType(); - string memory root = vm.projectRoot(); - string memory addressPath = string.concat(root, "/deployment/", network, "/l2addresses.json"); - string memory addressJson = vm.readFile(addressPath); + function readL2AddressesFile(string memory filePath) external view returns (L2AddressesConfig memory) { + string memory addressJson = vm.readFile(filePath); L2AddressesConfig memory l2AddressesConfig; @@ -222,9 +229,9 @@ contract Utils is Script { } /// @notice This function writes L2 addresses to JSON file. + /// @param filePath L2Addresses file path. /// @param cfg L2AddressesConfig struct containing L2 addresses which will be written to JSON file. - function writeL2AddressesFile(L2AddressesConfig memory cfg) external { - string memory network = getNetworkType(); + function writeL2AddressesFile(L2AddressesConfig memory cfg, string memory filePath) external { string memory json = ""; vm.serializeAddress(json, "L2ClaimContract", cfg.L2ClaimContract); vm.serializeAddress(json, "L2ClaimImplementation", cfg.L2ClaimImplementation); @@ -243,22 +250,27 @@ contract Utils is Script { string memory finalJson = vm.serializeAddress(json, "L2VotingPowerImplementation", cfg.L2VotingPowerImplementation); - finalJson.write(string.concat("deployment/", network, "/l2addresses.json")); + finalJson.write(filePath); + } + + /// @notice This function returns the path for the vesting wallets JSON file for the provided network layer. + /// @param _layer Network layer of the runnins script, either be "L1" or "L2". + /// @return string containing file path to vesting wallets. + function getVestingWalletsFilePath(string memory _layer) external returns (string memory) { + return string.concat("deployment/", getNetworkType(), string.concat("/vestingWallets_", _layer, ".json")); } /// @notice This function writes Vesting Wallets to JSON file. /// @param _vestingWallets Array of Vesting Wallets which will be written to JSON file. - /// @param _layer Network layer of the running script, either be "L1" or "L2" - function writeVestingWalletsFile(VestingWallet[] memory _vestingWallets, string memory _layer) external { - string memory network = getNetworkType(); - + /// @param _filePath VestingWallets file path. + function writeVestingWalletsFile(VestingWallet[] memory _vestingWallets, string memory _filePath) external { string memory json = "vestingWallets"; string memory finalJson; for (uint256 i = 0; i < _vestingWallets.length; i++) { VestingWallet memory vestingWallet = _vestingWallets[i]; finalJson = vm.serializeAddress(json, vestingWallet.name, vestingWallet.vestingWalletAddress); } - finalJson.write(string.concat("deployment/", network, string.concat("/vestingWallets_", _layer, ".json"))); + finalJson.write(_filePath); } /// @notice This function reads MerkleRoot from JSON file. @@ -321,21 +333,17 @@ contract Utils is Script { /// @notice This function reads Vesting Wallet Address from JSON file. /// @param _vestingWalletName Name of the Vesting Wallet. - /// @param _layer Network layer of the running script, either be "L1" or "L2" + /// @param _filePath VestingWallets file path. /// @return Vesting Wallet Address. function readVestingWalletAddress( string memory _vestingWalletName, - string memory _layer + string memory _filePath ) external view returns (address) { - string memory network = getNetworkType(); - string memory root = vm.projectRoot(); - string memory vestingWalletsPath = - string.concat(root, "/deployment/", network, string.concat("/vestingWallets_", _layer, ".json")); - string memory vestingWalletsJson = vm.readFile(vestingWalletsPath); + string memory vestingWalletsJson = vm.readFile(_filePath); return vm.parseJsonAddress(vestingWalletsJson, string.concat(".['", _vestingWalletName, "']")); } diff --git a/script/example/DemoTransferFunds.s.sol b/script/example/DemoTransferFunds.s.sol index 80b0815b..9a5b6e44 100644 --- a/script/example/DemoTransferFunds.s.sol +++ b/script/example/DemoTransferFunds.s.sol @@ -23,7 +23,7 @@ contract DemoTransferFundsScript is Script { uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); // read L2LiskToken address from l2addresses.json - Utils.L2AddressesConfig memory l2AddressesConfig = utils.readL2AddressesFile(); + Utils.L2AddressesConfig memory l2AddressesConfig = utils.readL2AddressesFile(utils.getL2AddressesFilePath()); IERC20 lsk = IERC20(l2AddressesConfig.L2LiskToken); vm.startBroadcast(deployerPrivateKey); diff --git a/script/example/L2ClaimTokens.s.sol b/script/example/L2ClaimTokens.s.sol index a7324765..a0126402 100644 --- a/script/example/L2ClaimTokens.s.sol +++ b/script/example/L2ClaimTokens.s.sol @@ -49,7 +49,7 @@ contract L2ClaimTokensScript is Script { function setUp() public { utils = new Utils(); - Utils.L2AddressesConfig memory l2AddressesConfig = utils.readL2AddressesFile(); + Utils.L2AddressesConfig memory l2AddressesConfig = utils.readL2AddressesFile(utils.getL2AddressesFilePath()); lsk = IERC20(l2AddressesConfig.L2LiskToken); l2Claim = L2Claim(l2AddressesConfig.L2ClaimContract); diff --git a/script/example/L2DemoToken.s.sol b/script/example/L2DemoToken.s.sol index 59592f6c..db7ee102 100644 --- a/script/example/L2DemoToken.s.sol +++ b/script/example/L2DemoToken.s.sol @@ -43,6 +43,6 @@ contract L2DemoTokenScript is Script { // write L2LiskToken address to l2addresses.json Utils.L2AddressesConfig memory l2AddressesConfig; l2AddressesConfig.L2LiskToken = address(lsk); - utils.writeL2AddressesFile(l2AddressesConfig); + utils.writeL2AddressesFile(l2AddressesConfig, utils.getL2AddressesFilePath()); } } diff --git a/test/utils/Utils.t.sol b/test/utils/Utils.t.sol index c09ed17a..2ae94e8e 100644 --- a/test/utils/Utils.t.sol +++ b/test/utils/Utils.t.sol @@ -17,12 +17,12 @@ contract UtilsTest is Test { Utils.L1AddressesConfig memory config = Utils.L1AddressesConfig({ L1LiskToken: address(0x1), L1VestingWalletImplementation: address(0x2) }); - utils.writeL1AddressesFile(config); + utils.writeL1AddressesFile(config, "./l1Addresses.json"); - // Utils.L1AddressesConfig memory configReadFromFile = utils.readL1AddressesFile(); + Utils.L1AddressesConfig memory configReadFromFile = utils.readL1AddressesFile("./l1Addresses.json"); - // assertEq(configReadFromFile.L1LiskToken, config.L1LiskToken); - // assertEq(configReadFromFile.L1VestingWalletImplementation, config.L1VestingWalletImplementation); + assertEq(configReadFromFile.L1LiskToken, config.L1LiskToken); + assertEq(configReadFromFile.L1VestingWalletImplementation, config.L1VestingWalletImplementation); } function test_readAndWriteL2AddressesFile() public { @@ -44,9 +44,9 @@ contract UtilsTest is Test { L2VotingPowerImplementation: address(0x16) }); - utils.writeL2AddressesFile(config); + utils.writeL2AddressesFile(config, "./l2Addresses.json"); - Utils.L2AddressesConfig memory configReadFromFile = utils.readL2AddressesFile(); + Utils.L2AddressesConfig memory configReadFromFile = utils.readL2AddressesFile("./l2addresses.json"); assertEq(configReadFromFile.L2ClaimContract, config.L2ClaimContract); assertEq(configReadFromFile.L2Governor, config.L2Governor); @@ -76,10 +76,10 @@ contract UtilsTest is Test { vestingWallets[0] = Utils.VestingWallet({ name: "wallet1", vestingWalletAddress: address(0x1) }); vestingWallets[1] = Utils.VestingWallet({ name: "wallet2", vestingWalletAddress: address(0x2) }); - utils.writeVestingWalletsFile(vestingWallets, "l1"); + utils.writeVestingWalletsFile(vestingWallets, "./vestingWallets.json"); - assertEq(utils.readVestingWalletAddress("wallet1", "l1"), address(0x1)); - assertEq(utils.readVestingWalletAddress("wallet2", "l1"), address(0x2)); + assertEq(utils.readVestingWalletAddress("wallet1", "./vestingWallets.json"), address(0x1)); + assertEq(utils.readVestingWalletAddress("wallet2", "./vestingWallets.json"), address(0x2)); } function test_readVestingAddress() public { From eba0a0158002e09f3f859ef4e8e9b24eed3a23d3 Mon Sep 17 00:00:00 2001 From: has5aan Date: Thu, 20 Jun 2024 13:31:54 +0200 Subject: [PATCH 09/10] refactor Utils and adds more test to verify paths. --- script/contracts/Utils.sol | 2 +- test/utils/Utils.t.sol | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/script/contracts/Utils.sol b/script/contracts/Utils.sol index b97eceae..b79b5ada 100644 --- a/script/contracts/Utils.sol +++ b/script/contracts/Utils.sol @@ -257,7 +257,7 @@ contract Utils is Script { /// @param _layer Network layer of the runnins script, either be "L1" or "L2". /// @return string containing file path to vesting wallets. function getVestingWalletsFilePath(string memory _layer) external returns (string memory) { - return string.concat("deployment/", getNetworkType(), string.concat("/vestingWallets_", _layer, ".json")); + return string.concat(vm.projectRoot(), "/deployment/", getNetworkType(), "/vestingWallets_", _layer, ".json"); } /// @notice This function writes Vesting Wallets to JSON file. diff --git a/test/utils/Utils.t.sol b/test/utils/Utils.t.sol index 2ae94e8e..6d5a4eab 100644 --- a/test/utils/Utils.t.sol +++ b/test/utils/Utils.t.sol @@ -46,7 +46,7 @@ contract UtilsTest is Test { utils.writeL2AddressesFile(config, "./l2Addresses.json"); - Utils.L2AddressesConfig memory configReadFromFile = utils.readL2AddressesFile("./l2addresses.json"); + Utils.L2AddressesConfig memory configReadFromFile = utils.readL2AddressesFile("./l2Addresses.json"); assertEq(configReadFromFile.L2ClaimContract, config.L2ClaimContract); assertEq(configReadFromFile.L2Governor, config.L2Governor); @@ -104,4 +104,23 @@ contract UtilsTest is Test { assertEq(accountsReadFromFile2.l2Addresses[0].addr, address(0x473BbFd3097D597d14466EF19519f406D6f9202d)); assertEq(accountsReadFromFile2.l2Addresses[0].amount, 51000000000000000000); } + + function test_getL1AddressesFilePath() public { + assertEq( + utils.getL1AddressesFilePath(), string.concat(vm.projectRoot(), "/deployment/testnet/l1addresses.json") + ); + } + + function test_getL2AddressesFilePath() public { + assertEq( + utils.getL2AddressesFilePath(), string.concat(vm.projectRoot(), "/deployment/testnet/l2addresses.json") + ); + } + + function test_getVestingWalletsFilePath() public { + assertEq( + utils.getVestingWalletsFilePath("l1"), + string.concat(vm.projectRoot(), "/deployment/testnet/vestingWallets_l1.json") + ); + } } From c96ceb975857f4b81701091122c78ba6a142d513 Mon Sep 17 00:00:00 2001 From: has5aan Date: Fri, 21 Jun 2024 09:02:25 +0200 Subject: [PATCH 10/10] adds tests and addresses suggestions --- script/contracts/Utils.sol | 3 +- test/utils/Utils.t.sol | 76 +++++++++++++++++++++++++++----------- 2 files changed, 56 insertions(+), 23 deletions(-) diff --git a/script/contracts/Utils.sol b/script/contracts/Utils.sol index b79b5ada..9f382e42 100644 --- a/script/contracts/Utils.sol +++ b/script/contracts/Utils.sol @@ -115,6 +115,7 @@ contract Utils is Script { } /// @notice This function returns the path for L2 addresses JSON file. + /// @return string containing file path to L2 addresses JSON. function getL2AddressesFilePath() external view returns (string memory) { return string.concat(vm.projectRoot(), "/deployment/", getNetworkType(), "/l2addresses.json"); } @@ -229,8 +230,8 @@ contract Utils is Script { } /// @notice This function writes L2 addresses to JSON file. - /// @param filePath L2Addresses file path. /// @param cfg L2AddressesConfig struct containing L2 addresses which will be written to JSON file. + /// @param filePath L2Addresses file path. function writeL2AddressesFile(L2AddressesConfig memory cfg, string memory filePath) external { string memory json = ""; vm.serializeAddress(json, "L2ClaimContract", cfg.L2ClaimContract); diff --git a/test/utils/Utils.t.sol b/test/utils/Utils.t.sol index 6d5a4eab..edfe51da 100644 --- a/test/utils/Utils.t.sol +++ b/test/utils/Utils.t.sol @@ -6,10 +6,14 @@ import { Utils } from "script/contracts/Utils.sol"; contract UtilsTest is Test { Utils utils; - - function setUp() public { - vm.setEnv("NETWORK", "testnet"); - + string network; + string salt; + + function setUp() public virtual { + network = "testnet"; + salt = "salty_the_salt"; + vm.setEnv("DETERMINISTIC_ADDRESS_SALT", salt); + vm.setEnv("NETWORK", network); utils = new Utils(); } @@ -26,22 +30,23 @@ contract UtilsTest is Test { } function test_readAndWriteL2AddressesFile() public { + uint160 index = 1; Utils.L2AddressesConfig memory config = Utils.L2AddressesConfig({ - L2ClaimContract: address(0x01), - L2ClaimImplementation: address(0x02), - L2Governor: address(0x03), - L2GovernorImplementation: address(0x04), - L2LiskToken: address(0x05), - L2LockingPosition: address(0x06), - L2LockingPositionImplementation: address(0x07), - L2Reward: address(0x09), - L2RewardImplementation: address(0x10), - L2Staking: address(0x11), - L2StakingImplementation: address(0x12), - L2TimelockController: address(0x13), - L2VestingWalletImplementation: address(0x14), - L2VotingPower: address(0x15), - L2VotingPowerImplementation: address(0x16) + L2ClaimContract: address(index++), + L2ClaimImplementation: address(index++), + L2Governor: address(index++), + L2GovernorImplementation: address(index++), + L2LiskToken: address(index++), + L2LockingPosition: address(index++), + L2LockingPositionImplementation: address(index++), + L2Reward: address(index++), + L2RewardImplementation: address(index++), + L2Staking: address(index++), + L2StakingImplementation: address(index++), + L2TimelockController: address(index++), + L2VestingWalletImplementation: address(index++), + L2VotingPower: address(index++), + L2VotingPowerImplementation: address(index++) }); utils.writeL2AddressesFile(config, "./l2Addresses.json"); @@ -105,22 +110,49 @@ contract UtilsTest is Test { assertEq(accountsReadFromFile2.l2Addresses[0].amount, 51000000000000000000); } + function test_readVestingPlansFile() public { + Utils.VestingPlan[] memory vestingPlans = utils.readVestingPlansFile("L1"); + + assertEq(vestingPlans.length, 5); + assertEq(vestingPlans[0].name, "Team I"); + assertEq(vestingPlans[0].beneficiaryAddressTag, "team1Address"); + assertEq(vestingPlans[0].startTimestamp, 1735689600); + assertEq(vestingPlans[0].durationDays, 1461); + assertEq(vestingPlans[0].amount, 5500000000000000000000000); + } + function test_getL1AddressesFilePath() public { assertEq( - utils.getL1AddressesFilePath(), string.concat(vm.projectRoot(), "/deployment/testnet/l1addresses.json") + utils.getL1AddressesFilePath(), + string.concat(vm.projectRoot(), "/deployment/", network, "/l1addresses.json") ); } function test_getL2AddressesFilePath() public { assertEq( - utils.getL2AddressesFilePath(), string.concat(vm.projectRoot(), "/deployment/testnet/l2addresses.json") + utils.getL2AddressesFilePath(), + string.concat(vm.projectRoot(), "/deployment/", network, "/l2addresses.json") ); } function test_getVestingWalletsFilePath() public { assertEq( utils.getVestingWalletsFilePath("l1"), - string.concat(vm.projectRoot(), "/deployment/testnet/vestingWallets_l1.json") + string.concat(vm.projectRoot(), "/deployment/", network, "/vestingWallets_l1.json") ); } + + function test_getPreHashSalt() public { + string memory contractName = "contract"; + assertEq(utils.getPreHashedSalt(contractName), string.concat(salt, "_", contractName)); + } + + function test_getSalt() public { + string memory contractName = "contract"; + assertEq(utils.getSalt(contractName), keccak256(abi.encodePacked(string.concat(salt, "_", contractName)))); + } + + function test_getNetworkType() public { + assertEq(utils.getNetworkType(), network); + } }