Skip to content

Commit

Permalink
chore: update contract name to V1
Browse files Browse the repository at this point in the history
  • Loading branch information
blockgroot committed Jul 9, 2024
1 parent 7a5d7ef commit 487ee50
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface AggregatorV3Interface {
returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);
}

contract ETHxPoolV5 is AccessControlUpgradeable, ReentrancyGuardUpgradeable {
contract ETHxPoolV1 is AccessControlUpgradeable, ReentrancyGuardUpgradeable {
using SafeERC20 for IERC20;

/// @notice Role hash of BRIDGER
Expand Down
84 changes: 42 additions & 42 deletions test/L2/ETHxPoolV5.t.sol → test/L2/ETHxPoolV1.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
pragma solidity 0.8.22;

import { Test } from "forge-std/Test.sol";
import { ETHxPoolV5 } from "../../contracts/L2/ETHxPoolV5.sol";
import { AggregatorV3Interface } from "../../contracts/L2/ETHxPoolV5.sol";
import { ETHxPoolV1 } from "../../contracts/L2/ETHxPoolV1.sol";
import { AggregatorV3Interface } from "../../contracts/L2/ETHxPoolV1.sol";
import { ERC20Mock } from "../mocks/ERC20Mock.sol";

contract ETHxPoolV5Test is Test {
contract ETHxPoolV1Test is Test {
uint256 private constant ETHX_RATE = 1 ether;
uint256 private constant FEE_BPS = 1000;
address private admin;
Expand All @@ -15,7 +15,7 @@ contract ETHxPoolV5Test is Test {
address private oracle;
address private ETHx;

ETHxPoolV5 private eTHxPoolV5;
ETHxPoolV1 private eTHxPoolV1;

function setUp() public {
vm.clearMockedCalls();
Expand All @@ -28,40 +28,40 @@ contract ETHxPoolV5Test is Test {
mockRateOracle(oracle);
mockErc20(ETHx, "ETHx");

eTHxPoolV5 = mockETHxPoolV5(pool, admin, bridger, ETHx, FEE_BPS, oracle);
eTHxPoolV1 = mockETHxPoolV1(pool, admin, bridger, ETHx, FEE_BPS, oracle);
}

function testInitialization() public {
assertEq(address(eTHxPoolV5.ETHx()), ETHx);
assertTrue(eTHxPoolV5.hasRole(keccak256("BRIDGER_ROLE"), bridger));
assertTrue(eTHxPoolV5.hasRole(0x0, admin));
assertEq(address(eTHxPoolV1.ETHx()), ETHx);
assertTrue(eTHxPoolV1.hasRole(keccak256("BRIDGER_ROLE"), bridger));
assertTrue(eTHxPoolV1.hasRole(0x0, admin));
}

function testInitializeDisabled() public {
eTHxPoolV5 = new ETHxPoolV5();
eTHxPoolV1 = new ETHxPoolV1();
vm.expectRevert("Initializable: contract is already initialized");
eTHxPoolV5.initialize(vm.addr(0x100), vm.addr(0x101), vm.addr(0x102), 9000, vm.addr(0x1001));
eTHxPoolV1.initialize(vm.addr(0x100), vm.addr(0x101), vm.addr(0x102), 9000, vm.addr(0x1001));
}

function testETHxNonZeroAddressRequired() public {
address pool = vm.addr(0x1003);
mockProxyDeploy(pool);
eTHxPoolV5 = ETHxPoolV5(pool);
vm.expectRevert(ETHxPoolV5.ZeroAddress.selector);
eTHxPoolV5.initialize(vm.addr(0x100), vm.addr(0x101), vm.addr(0x102), 9000, address(0));
eTHxPoolV1 = ETHxPoolV1(pool);
vm.expectRevert(ETHxPoolV1.ZeroAddress.selector);
eTHxPoolV1.initialize(vm.addr(0x100), vm.addr(0x101), vm.addr(0x102), 9000, address(0));
}

function testSetFeeBps() public {
vm.prank(admin);
eTHxPoolV5.setFeeBps(FEE_BPS);
assertEq(eTHxPoolV5.feeBps(), FEE_BPS);
eTHxPoolV1.setFeeBps(FEE_BPS);
assertEq(eTHxPoolV1.feeBps(), FEE_BPS);
}

function testSetFeeInvalidBps(uint256 feeBps) public {
vm.assume(feeBps > 10_000);
vm.prank(admin);
vm.expectRevert(abi.encodeWithSelector(ETHxPoolV5.InvalidBps.selector));
eTHxPoolV5.setFeeBps(feeBps);
vm.expectRevert(abi.encodeWithSelector(ETHxPoolV1.InvalidBps.selector));
eTHxPoolV1.setFeeBps(feeBps);
}

function testSetFeeAdminRequired() public {
Expand All @@ -70,7 +70,7 @@ contract ETHxPoolV5Test is Test {
vm.expectRevert(
"AccessControl: account 0x85e4e16bd367e4259537269633da9a6aa4cf95a3 is missing role 0x0000000000000000000000000000000000000000000000000000000000000000"
);
eTHxPoolV5.setFeeBps(10_000);
eTHxPoolV1.setFeeBps(10_000);
}

function testOracleAdminRequired() public {
Expand All @@ -80,46 +80,46 @@ contract ETHxPoolV5Test is Test {
vm.expectRevert(
"AccessControl: account 0x85e4e16bd367e4259537269633da9a6aa4cf95a3 is missing role 0x0000000000000000000000000000000000000000000000000000000000000000"
);
eTHxPoolV5.setETHXOracle(oracle_);
eTHxPoolV1.setETHXOracle(oracle_);
}

function testOracleZeroAddressNotAllowed() public {
address oracle_ = address(0);
vm.prank(admin);
vm.expectRevert(abi.encodeWithSelector(ETHxPoolV5.ZeroAddress.selector));
eTHxPoolV5.setETHXOracle(oracle_);
vm.expectRevert(abi.encodeWithSelector(ETHxPoolV1.ZeroAddress.selector));
eTHxPoolV1.setETHXOracle(oracle_);
}

function testOracleSetAddress() public {
vm.prank(admin);
eTHxPoolV5.setETHXOracle(oracle);
assertEq(eTHxPoolV5.ethxOracle(), oracle);
eTHxPoolV1.setETHXOracle(oracle);
assertEq(eTHxPoolV1.ethxOracle(), oracle);
}

function testDepositRequiresNonZeroAmount() public {
vm.prank(admin);
vm.expectRevert(ETHxPoolV5.InvalidAmount.selector);
eTHxPoolV5.swapETHToETHx{ value: 0 }("referral");
vm.expectRevert(ETHxPoolV1.InvalidAmount.selector);
eTHxPoolV1.swapETHToETHx{ value: 0 }("referral");
}

function testSwapETHForETHx(uint256 ethAmount) public {
vm.assume(ethAmount > 0.1 ether && ethAmount < 100 ether);
address user = vm.addr(0x110);
vm.deal(user, ethAmount);
vm.prank(admin);
ERC20Mock(ETHx).mint(address(eTHxPoolV5), ethAmount);
ERC20Mock(ETHx).mint(address(eTHxPoolV1), ethAmount);
vm.prank(user);
eTHxPoolV5.swapETHToETHx{ value: ethAmount }("referral");
eTHxPoolV1.swapETHToETHx{ value: ethAmount }("referral");
uint256 expectedBalance = ethAmount - (ethAmount * FEE_BPS / 10_000);
assertEq(ERC20Mock(ETHx).balanceOf(user), expectedBalance);
(uint256 _amtLessFee,) = eTHxPoolV5.viewSwapETHxAmountAndFee(ethAmount);
(uint256 _amtLessFee,) = eTHxPoolV1.viewSwapETHxAmountAndFee(ethAmount);
assertEq(ERC20Mock(ETHx).balanceOf(user), _amtLessFee);
}

function testViewSwapETHxAmountAndFee(uint256 ethAmount) public {
vm.assume(ethAmount > 0.1 ether && ethAmount < 100 ether);
vm.prank(admin);
(uint256 _amt, uint256 _fee) = eTHxPoolV5.viewSwapETHxAmountAndFee(ethAmount);
(uint256 _amt, uint256 _fee) = eTHxPoolV1.viewSwapETHxAmountAndFee(ethAmount);
uint256 expectFee = ethAmount * FEE_BPS / 1e4;
uint256 expectAmt = (ethAmount - expectFee) * 1e18 / ETHX_RATE;
assertEq(_fee, expectFee);
Expand All @@ -130,42 +130,42 @@ contract ETHxPoolV5Test is Test {
vm.assume(ethAmount > 0.1 ether && ethAmount < 100 ether);
address user = vm.addr(0x110);
vm.prank(admin);
ERC20Mock(ETHx).mint(address(eTHxPoolV5), ethAmount);
ERC20Mock(ETHx).mint(address(eTHxPoolV1), ethAmount);
vm.deal(user, ethAmount);
vm.prank(user);
eTHxPoolV5.swapETHToETHx{ value: ethAmount }("referral");
eTHxPoolV1.swapETHToETHx{ value: ethAmount }("referral");
uint256 expectedBalance = ethAmount - (ethAmount * FEE_BPS / 10_000);
assertEq(ERC20Mock(ETHx).balanceOf(user), expectedBalance);
(, uint256 feeAmnt) = eTHxPoolV5.viewSwapETHxAmountAndFee(ethAmount);
(, uint256 feeAmnt) = eTHxPoolV1.viewSwapETHxAmountAndFee(ethAmount);
address _owner = vm.addr(0x111);
vm.prank(bridger);
eTHxPoolV5.withdrawFees(_owner);
eTHxPoolV1.withdrawFees(_owner);
assertEq(_owner.balance, feeAmnt);
}

function testWithdrawFeesRequiresBridgerRole() public {
vm.expectRevert(
"AccessControl: account 0x7fa9385be102ac3eac297483dd6233d62b3e1496 is missing role 0xc809a7fd521f10cdc3c068621a1c61d5fd9bb3f1502a773e53811bc248d919a8"
);
eTHxPoolV5.withdrawFees(vm.addr(0x111));
eTHxPoolV1.withdrawFees(vm.addr(0x111));
}

function testMoveAssetForBridging(uint256 ethAmount) public {
vm.assume(ethAmount > 0.1 ether && ethAmount < 100 ether);
vm.prank(admin);
address user = vm.addr(0x110);
vm.deal(user, ethAmount);
ERC20Mock(ETHx).mint(address(eTHxPoolV5), ethAmount);
ERC20Mock(ETHx).mint(address(eTHxPoolV1), ethAmount);
vm.prank(user);
eTHxPoolV5.swapETHToETHx{ value: ethAmount }("referral");
uint256 feeEarned = eTHxPoolV5.feeEarnedInETH();
eTHxPoolV1.swapETHToETHx{ value: ethAmount }("referral");
uint256 feeEarned = eTHxPoolV1.feeEarnedInETH();
vm.prank(bridger);
eTHxPoolV5.withdrawCollectedETH();
eTHxPoolV1.withdrawCollectedETH();
assertEq(bridger.balance, ethAmount - feeEarned);
}

function mockProxyDeploy(address ethxPool) private {
ETHxPoolV5 implementation = new ETHxPoolV5();
ETHxPoolV1 implementation = new ETHxPoolV1();
bytes memory code = address(implementation).code;
vm.etch(ethxPool, code);
}
Expand All @@ -186,7 +186,7 @@ contract ETHxPoolV5Test is Test {
vm.etch(ethxMock, code);
}

function mockETHxPoolV5(
function mockETHxPoolV1(
address ethxPool,
address _admin,
address _bridger,
Expand All @@ -195,10 +195,10 @@ contract ETHxPoolV5Test is Test {
address _ethxOracle
)
private
returns (ETHxPoolV5 mock_)
returns (ETHxPoolV1 mock_)
{
mockProxyDeploy(ethxPool);
ETHxPoolV5 mock = ETHxPoolV5(ethxPool);
ETHxPoolV1 mock = ETHxPoolV1(ethxPool);
mock.initialize(_admin, _bridger, _ETHx, _feeBps, _ethxOracle);
return mock;
}
Expand Down

0 comments on commit 487ee50

Please sign in to comment.