Skip to content

Commit

Permalink
fix: bootstrap tests updated
Browse files Browse the repository at this point in the history
  • Loading branch information
call-by committed Jul 22, 2024
1 parent e5b1987 commit 52480ef
Showing 1 changed file with 40 additions and 38 deletions.
78 changes: 40 additions & 38 deletions test/foundry/unit/Bootstrap.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ import {UpgradeableBeacon} from "@openzeppelin/contracts/proxy/beacon/Upgradeabl
import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";

import "@openzeppelin/contracts/utils/Create2.sol";

import "forge-std/Test.sol";
import "forge-std/console.sol";
import "src/libraries/Errors.sol";

import "src/core/BeaconProxyBytecode.sol";
import "src/core/ExoCapsule.sol";
Expand Down Expand Up @@ -165,7 +167,7 @@ contract BootstrapTest is Test {

function test01_AddWhitelistToken_AlreadyExists() public {
vm.startPrank(deployer);
vm.expectRevert("Bootstrap: token should be not whitelisted before");
vm.expectRevert(abi.encodeWithSelector(Errors.BootstrapAlreadyWhitelisted.selector, address(myToken)));
address[] memory addedWhitelistTokens = new address[](1);
addedWhitelistTokens[0] = address(myToken);
bootstrap.addWhitelistTokens(addedWhitelistTokens);
Expand Down Expand Up @@ -350,7 +352,7 @@ contract BootstrapTest is Test {
exo = "exo1wnw7zcl9fy04ax69uffumwkdxftfqsjyj37wt2";
name = "operator1_re";
pubKey = bytes32(0x27165ec2f29a4815b7c29e47d8700845b5ae267f2d61ad29fb3939aec5540783);
vm.expectRevert("Ethereum address already linked to an operator");
vm.expectRevert(abi.encodeWithSelector(Errors.BootstrapOperatorAlreadyHasAddress.selector, addrs[0]));
bootstrap.registerOperator(exo, name, commission, pubKey);
vm.stopPrank();
}
Expand All @@ -368,7 +370,7 @@ contract BootstrapTest is Test {
vm.startPrank(addrs[1]);
name = "operator1_re";
pubKey = bytes32(0x27165ec2f29a4815b7c29e47d8700845b5ae267f2d61ad29fb3939aec5540783);
vm.expectRevert("Operator with this Exocore address is already registered");
vm.expectRevert(Errors.BootstrapOperatorAlreadyRegistered.selector);
bootstrap.registerOperator(exo, name, commission, pubKey);
vm.stopPrank();
}
Expand All @@ -387,7 +389,7 @@ contract BootstrapTest is Test {
vm.startPrank(addrs[1]);
exo = "exo1wnw7zcl9fy04ax69uffumwkdxftfqsjyj37wt2";
name = "operator1_re";
vm.expectRevert("Consensus public key already in use");
vm.expectRevert(abi.encodeWithSelector(Errors.BootstrapConsensusPubkeyAlreadyUsed.selector, pubKey));
bootstrap.registerOperator(exo, name, commission, pubKey);
vm.stopPrank();
}
Expand All @@ -406,7 +408,7 @@ contract BootstrapTest is Test {
vm.startPrank(addrs[1]);
exo = "exo1wnw7zcl9fy04ax69uffumwkdxftfqsjyj37wt2";
pubKey = bytes32(0x27165ec2f29a4815b7c29e47d8700845b5ae267f2d61ad29fb3939aec5540783);
vm.expectRevert("Name already in use");
vm.expectRevert(Errors.BootstrapOperatorNameAlreadyUsed.selector);
bootstrap.registerOperator(exo, name, commission, pubKey);
vm.stopPrank();
}
Expand Down Expand Up @@ -453,7 +455,7 @@ contract BootstrapTest is Test {
// Then change the key
vm.startPrank(addrs[0]);
bytes32 newKey = bytes32(0xe2f00b6510e16fd8cc5802a4011d6f093acbbbca7c284cad6aa2c2e474bb50f9);
vm.expectRevert("Consensus public key already in use");
vm.expectRevert(abi.encodeWithSelector(Errors.BootstrapConsensusPubkeyAlreadyUsed.selector, newKey));
bootstrap.replaceKey(newKey);
vm.stopPrank();
}
Expand All @@ -463,15 +465,15 @@ contract BootstrapTest is Test {
// Then change the key for the same address
vm.startPrank(addrs[1]);
bytes32 newKey = bytes32(0xe2f00b6510e16fd8cc5802a4011d6f093acbbbca7c284cad6aa2c2e474bb50f9);
vm.expectRevert("Consensus public key already in use");
vm.expectRevert(abi.encodeWithSelector(Errors.BootstrapConsensusPubkeyAlreadyUsed.selector, newKey));
bootstrap.replaceKey(newKey);
vm.stopPrank();
}

function test05_ReplaceKey_Unregistered() public {
vm.startPrank(addrs[1]);
bytes32 newKey = bytes32(0xe2f00b6510e16fd8cc5802a4011d6f093acbbbca7c284cad6aa2c2e474bb50f9);
vm.expectRevert("no such operator exists");
vm.expectRevert(Errors.BootstrapOperatorNotExist.selector);
bootstrap.replaceKey(newKey);
vm.stopPrank();
}
Expand Down Expand Up @@ -501,7 +503,7 @@ contract BootstrapTest is Test {
bootstrap.updateRate(1e17);
(, IOperatorRegistry.Commission memory newCommission,) = bootstrap.operators(exo);
assertTrue(newCommission.rate == 1e17);
vm.expectRevert("Commission already edited once");
vm.expectRevert(Errors.BootstrapComissionAlreadyEdited.selector);
bootstrap.updateRate(1e17);
vm.stopPrank();
}
Expand All @@ -514,7 +516,7 @@ contract BootstrapTest is Test {
bytes32 pubKey = bytes32(0x27165ec2f29a4815b7c29e47d8700845b5ae267f2d61ad29fb3939aec5540782);
vm.startPrank(addrs[0]);
bootstrap.registerOperator(exo, name, commission, pubKey);
vm.expectRevert("Rate exceeds max rate");
vm.expectRevert(Errors.BootstrapRateExceedsMaxRate.selector);
bootstrap.updateRate(2e17);
vm.stopPrank();
}
Expand All @@ -528,7 +530,7 @@ contract BootstrapTest is Test {
bytes32 pubKey = bytes32(0x27165ec2f29a4815b7c29e47d8700845b5ae267f2d61ad29fb3939aec5540782);
vm.startPrank(addrs[0]);
bootstrap.registerOperator(exo, name, commission, pubKey);
vm.expectRevert("Rate change exceeds max change rate");
vm.expectRevert(Errors.BootstrapRateChangeExceedsMaxChangeRate.selector);
bootstrap.updateRate(2e16);
vm.stopPrank();
}
Expand All @@ -537,7 +539,7 @@ contract BootstrapTest is Test {
// Register one operator
address addr = address(0x7);
vm.startPrank(addr);
vm.expectRevert("no such operator exists");
vm.expectRevert(Errors.BootstrapOperatorNotExist.selector);
bootstrap.updateRate(1e18);
vm.stopPrank();
}
Expand All @@ -561,7 +563,7 @@ contract BootstrapTest is Test {

function test07_AddWhitelistedToken_AlreadyWhitelisted() public {
vm.startPrank(deployer);
vm.expectRevert("Bootstrap: token should be not whitelisted before");
vm.expectRevert(abi.encodeWithSelector(Errors.BootstrapAlreadyWhitelisted.selector, address(myToken)));
address[] memory addedWhitelistTokens = new address[](1);
addedWhitelistTokens[0] = address(myToken);
bootstrap.addWhitelistTokens(addedWhitelistTokens);
Expand Down Expand Up @@ -629,7 +631,7 @@ contract BootstrapTest is Test {
function test09_DelegateTo_Unregistered() public {
test02_Deposit();
vm.startPrank(addrs[0]);
vm.expectRevert("Operator does not exist");
vm.expectRevert(Errors.BootstrapOperatorNotExist.selector);
bootstrap.delegateTo("exo13hasr43vvq8v44xpzh0l6yuym4kca98f87j7ac", address(myToken), amounts[0]);
}

Expand All @@ -649,7 +651,7 @@ contract BootstrapTest is Test {
bootstrap.addWhitelistTokens(addedWhitelistTokens);
vm.stopPrank();
vm.startPrank(addrs[0]);
vm.expectRevert(bytes("Bootstrap: insufficient withdrawable balance"));
vm.expectRevert(Errors.BootstrapInsufficientWithdrawableBalance.selector);
bootstrap.delegateTo("exo13hasr43vvq8v44xpzh0l6yuym4kca98f87j7ac", address(0xa), amounts[0]);
}

Expand All @@ -664,15 +666,15 @@ contract BootstrapTest is Test {
function test09_DelegateTo_NoDeposits() public {
test03_RegisterOperator();
vm.startPrank(addrs[0]);
vm.expectRevert("Bootstrap: insufficient withdrawable balance");
vm.expectRevert(Errors.BootstrapInsufficientWithdrawableBalance.selector);
bootstrap.delegateTo("exo13hasr43vvq8v44xpzh0l6yuym4kca98f87j7ac", address(myToken), amounts[0]);
}

function test09_DelegateTo_Excess() public {
test03_RegisterOperator();
test02_Deposit();
vm.startPrank(addrs[0]);
vm.expectRevert("Bootstrap: insufficient withdrawable balance");
vm.expectRevert(Errors.BootstrapInsufficientWithdrawableBalance.selector);
bootstrap.delegateTo("exo13hasr43vvq8v44xpzh0l6yuym4kca98f87j7ac", address(myToken), amounts[0] + 1);
}

Expand Down Expand Up @@ -722,7 +724,7 @@ contract BootstrapTest is Test {
function test10_UndelegateFrom_Unregistered() public {
test09_DelegateTo();
vm.startPrank(addrs[0]);
vm.expectRevert("Operator does not exist");
vm.expectRevert(Errors.BootstrapOperatorNotExist.selector);
bootstrap.undelegateFrom("exo1awm72f4sc5yhedurdunx9afcshfq6ymqva8an4", address(myToken), amounts[0]);
}

Expand All @@ -741,7 +743,7 @@ contract BootstrapTest is Test {
bootstrap.addWhitelistTokens(addedWhitelistTokens);
vm.stopPrank();
vm.startPrank(addrs[0]);
vm.expectRevert(bytes("Bootstrap: insufficient delegated balance"));
vm.expectRevert(Errors.BootstrapInsufficientDelegatedBalance.selector);
bootstrap.undelegateFrom("exo13hasr43vvq8v44xpzh0l6yuym4kca98f87j7ac", address(0xa), amounts[0]);
}

Expand All @@ -756,14 +758,14 @@ contract BootstrapTest is Test {
function test10_UndelegateFromOperator_Excess() public {
test09_DelegateTo();
vm.startPrank(addrs[0]);
vm.expectRevert("Bootstrap: insufficient delegated balance");
vm.expectRevert(Errors.BootstrapInsufficientDelegatedBalance.selector);
bootstrap.undelegateFrom("exo13hasr43vvq8v44xpzh0l6yuym4kca98f87j7ac", address(myToken), amounts[0] + 1);
}

function test10_UndelegateFrom_NoDelegation() public {
test03_RegisterOperator();
vm.startPrank(addrs[0]);
vm.expectRevert("Bootstrap: insufficient delegated balance");
vm.expectRevert(Errors.BootstrapInsufficientDelegatedBalance.selector);
bootstrap.undelegateFrom("exo13hasr43vvq8v44xpzh0l6yuym4kca98f87j7ac", address(myToken), amounts[0]);
}

Expand Down Expand Up @@ -809,23 +811,23 @@ contract BootstrapTest is Test {

function test11_WithdrawPrincipalFromExocore_NoDeposits() public {
vm.startPrank(addrs[0]);
vm.expectRevert("Bootstrap: insufficient deposited balance");
vm.expectRevert(Errors.BootstrapInsufficientDepositedBalance.selector);
bootstrap.withdrawPrincipalFromExocore(address(myToken), amounts[0]);
vm.stopPrank();
}

function test11_WithdrawPrincipalFromExocore_Excess() public {
test10_UndelegateFrom();
vm.startPrank(addrs[0]);
vm.expectRevert("Bootstrap: insufficient deposited balance");
vm.expectRevert(Errors.BootstrapInsufficientDepositedBalance.selector);
bootstrap.withdrawPrincipalFromExocore(address(myToken), amounts[0] + 1);
vm.stopPrank();
}

function test11_WithdrawPrincipalFromExocore_ExcessFree() public {
test09_DelegateTo();
vm.startPrank(addrs[0]);
vm.expectRevert("Bootstrap: insufficient withdrawable balance");
vm.expectRevert(Errors.BootstrapInsufficientWithdrawableBalance.selector);
bootstrap.withdrawPrincipalFromExocore(address(myToken), amounts[0]);
vm.stopPrank();
}
Expand Down Expand Up @@ -884,15 +886,15 @@ contract BootstrapTest is Test {
function test12_MarkBootstrapped_DirectCall() public {
vm.startPrank(address(0x20));
vm.warp(spawnTime + 2);
vm.expectRevert("BootstrapLzReceiver: could only be called from this contract itself with low level call");
vm.expectRevert(Errors.BootstrapLzReceiverOnlyCalledFromThis.selector);
bootstrap.markBootstrapped();
vm.stopPrank();
}

function test13_OperationAllowed() public {
vm.warp(spawnTime - offsetDuration);
vm.startPrank(addrs[0]);
vm.expectRevert("Bootstrap: operation not allowed after lock time");
vm.expectRevert(Errors.BootstrapBeforeLocked.selector);
bootstrap.deposit(address(myToken), amounts[0]);
vm.stopPrank();
}
Expand Down Expand Up @@ -942,7 +944,7 @@ contract BootstrapTest is Test {
Bootstrap bootstrapLogic = new Bootstrap(
address(clientChainLzEndpoint), exocoreChainId, address(vaultBeacon), address(beaconProxyBytecode)
);
vm.expectRevert("Bootstrap: owner should not be empty");
vm.expectRevert(Errors.ZeroAddress.selector);
Bootstrap(
payable(
address(
Expand All @@ -965,7 +967,7 @@ contract BootstrapTest is Test {
address(clientChainLzEndpoint), exocoreChainId, address(vaultBeacon), address(beaconProxyBytecode)
);
vm.warp(20);
vm.expectRevert("Bootstrap: spawn time should be in the future");
vm.expectRevert(Errors.BootstrapSpawnTimeAlreadyPast.selector);
Bootstrap(
payable(
address(
Expand All @@ -987,7 +989,7 @@ contract BootstrapTest is Test {
Bootstrap bootstrapLogic = new Bootstrap(
address(clientChainLzEndpoint), exocoreChainId, address(vaultBeacon), address(beaconProxyBytecode)
);
vm.expectRevert("Bootstrap: offset duration should be greater than 0");
vm.expectRevert(Errors.ZeroValue.selector);
Bootstrap(
payable(
address(
Expand All @@ -1008,7 +1010,7 @@ contract BootstrapTest is Test {
Bootstrap bootstrapLogic = new Bootstrap(
address(clientChainLzEndpoint), exocoreChainId, address(vaultBeacon), address(beaconProxyBytecode)
);
vm.expectRevert("Bootstrap: spawn time should be greater than offset duration");
vm.expectRevert(Errors.BootstrapSpawnTimeLessThanDuration.selector);
vm.warp(20);
Bootstrap(
payable(
Expand All @@ -1028,7 +1030,7 @@ contract BootstrapTest is Test {
Bootstrap bootstrapLogic = new Bootstrap(
address(clientChainLzEndpoint), exocoreChainId, address(vaultBeacon), address(beaconProxyBytecode)
);
vm.expectRevert("Bootstrap: lock time should be in the future");
vm.expectRevert(Errors.BootstrapLockTimeAlreadyPast.selector);
vm.warp(20);
Bootstrap(
payable(
Expand All @@ -1048,7 +1050,7 @@ contract BootstrapTest is Test {
Bootstrap bootstrapLogic = new Bootstrap(
address(clientChainLzEndpoint), exocoreChainId, address(vaultBeacon), address(beaconProxyBytecode)
);
vm.expectRevert("Bootstrap: custom proxy admin should not be empty");
vm.expectRevert(Errors.ZeroAddress.selector);
Bootstrap(
payable(
address(
Expand All @@ -1073,21 +1075,21 @@ contract BootstrapTest is Test {
function test16_SetSpawnTime_NotInFuture() public {
vm.startPrank(deployer);
vm.warp(10);
vm.expectRevert("Bootstrap: spawn time should be in the future");
vm.expectRevert(Errors.BootstrapSpawnTimeAlreadyPast.selector);
bootstrap.setSpawnTime(9);
}

function test16_SetSpawnTime_LessThanOffsetDuration() public {
vm.startPrank(deployer);
vm.expectRevert("Bootstrap: spawn time should be greater than offset duration");
vm.expectRevert(Errors.BootstrapSpawnTimeLessThanDuration.selector);
bootstrap.setSpawnTime(offsetDuration - 1);
}

function test16_SetSpawnTime_LockTimeNotInFuture() public {
vm.startPrank(deployer);
vm.warp(offsetDuration - 1);
console.log(block.timestamp, offsetDuration, spawnTime);
vm.expectRevert("Bootstrap: lock time should be in the future");
vm.expectRevert(Errors.BootstrapLockTimeAlreadyPast.selector);
// the initial block.timestamp is 1, so subtract 2 here - 1 for
// the test and 1 for the warp offset above.
bootstrap.setSpawnTime(spawnTime - 2);
Expand All @@ -1101,14 +1103,14 @@ contract BootstrapTest is Test {

function test17_SetOffsetDuration_GTESpawnTime() public {
vm.startPrank(deployer);
vm.expectRevert("Bootstrap: spawn time should be greater than offset duration");
vm.expectRevert(Errors.BootstrapSpawnTimeLessThanDuration.selector);
bootstrap.setOffsetDuration(spawnTime);
}

function test17_SetOffsetDuration_LockTimeNotInFuture() public {
vm.warp(offsetDuration - 1);
vm.startPrank(deployer);
vm.expectRevert("Bootstrap: lock time should be in the future");
vm.expectRevert(Errors.BootstrapLockTimeAlreadyPast.selector);
bootstrap.setOffsetDuration(offsetDuration + 2);
}

Expand Down Expand Up @@ -1144,7 +1146,7 @@ contract BootstrapTest is Test {
function test22_Claim_Excess() public {
test11_WithdrawPrincipalFromExocore();
vm.startPrank(addrs[0]);
vm.expectRevert("Vault: withdrawal amount is larger than depositor's withdrawable balance");
vm.expectRevert(Errors.VaultWithdrawalAmountExceeds.selector);
bootstrap.claim(address(myToken), amounts[0] + 5, addrs[0]);
}

Expand Down

0 comments on commit 52480ef

Please sign in to comment.