Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds tests for script/contracts/Utils.sol #171

Merged
merged 11 commits into from
Jun 21, 2024
2 changes: 1 addition & 1 deletion script/contracts/L1/L1FundVesting.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion script/contracts/L1/L1LiskToken.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
4 changes: 2 additions & 2 deletions script/contracts/L1/L1VestingWallet.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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());
}
}
4 changes: 2 additions & 2 deletions script/contracts/L2/L2Claim.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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());
}
}
2 changes: 1 addition & 1 deletion script/contracts/L2/L2FundRewardContract.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions script/contracts/L2/L2FundVestingAndDAO.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions script/contracts/L2/L2Governor.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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());
}
}
4 changes: 2 additions & 2 deletions script/contracts/L2/L2LiskToken.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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());
}
}
4 changes: 2 additions & 2 deletions script/contracts/L2/L2LockingPosition.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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());
}
}
4 changes: 2 additions & 2 deletions script/contracts/L2/L2Reward.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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());
}
}
4 changes: 2 additions & 2 deletions script/contracts/L2/L2Staking.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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());
}
}
4 changes: 2 additions & 2 deletions script/contracts/L2/L2VestingWallet.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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());
}
}
4 changes: 2 additions & 2 deletions script/contracts/L2/L2VotingPower.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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());
}
}
4 changes: 2 additions & 2 deletions script/contracts/TransferFunds1stBatch.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions script/contracts/TransferFunds2ndBatch.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
64 changes: 36 additions & 28 deletions script/contracts/Utils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Phanco marked this conversation as resolved.
Show resolved Hide resolved
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;

Expand All @@ -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(string.concat("deployment/", network, "/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;

Expand Down Expand Up @@ -222,9 +229,9 @@ contract Utils is Script {
}

/// @notice This function writes L2 addresses to JSON file.
/// @param filePath L2Addresses file path.
Phanco marked this conversation as resolved.
Show resolved Hide resolved
/// @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);
Expand All @@ -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(vm.projectRoot(), "/deployment/", getNetworkType(), "/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.
Expand Down Expand Up @@ -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, "']"));
}

Expand Down
Loading
Loading