Skip to content

Commit

Permalink
Add AbstractForkTest
Browse files Browse the repository at this point in the history
  • Loading branch information
shahthepro committed Jul 2, 2024
1 parent 7408035 commit 7f692a0
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 41 deletions.
18 changes: 18 additions & 0 deletions test/AbstractForkTest.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import {Test} from "forge-std/Test.sol";

import {DeployManager} from "script/deploy/DeployManager.sol";

abstract contract AbstractForkTest is Test {
DeployManager internal deployManager;

constructor() {
deployManager = new DeployManager();

// Run deployments
deployManager.setUp();
deployManager.run();
}
}
23 changes: 13 additions & 10 deletions test/OethARM.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,30 @@
pragma solidity ^0.8.23;

import {Test, console2} from "forge-std/Test.sol";
import {AbstractForkTest} from "./AbstractForkTest.sol";

import {IERC20} from "contracts/Interfaces.sol";
import {OEthARM} from "contracts/OethARM.sol";
import {Proxy} from "contracts/Proxy.sol";
import {Addresses} from "contracts/utils/Addresses.sol";

contract OethARMTest is Test {
IERC20 weth = IERC20(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);
IERC20 oeth = IERC20(0x856c4Efb76C1D1AE02e20CEB03A2A6a08b0b8dC3);
contract OethARMTest is AbstractForkTest {
IERC20 constant weth = IERC20(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);
IERC20 constant oeth = IERC20(0x856c4Efb76C1D1AE02e20CEB03A2A6a08b0b8dC3);
IERC20 BAD_TOKEN = IERC20(makeAddr("bad token"));

address operator = makeAddr("operator");
address constant operator = Addresses.STRATEGIST;

Proxy proxy;
OEthARM oethARM;

function setUp() public {
OEthARM implementation = new OEthARM();
proxy = new Proxy();
proxy.initialize(address(implementation), address(this), "");
oethARM = OEthARM(address(proxy));
proxy = Proxy(deployManager.getDeployment("OETH_ARM"));
oethARM = OEthARM(deployManager.getDeployment("OETH_ARM"));

_dealWETH(address(oethARM), 100 ether);
_dealOETH(address(oethARM), 100 ether);

// Set operator
oethARM.setOperator(operator);
vm.label(address(weth), "WETH");
vm.label(address(oeth), "OETH");

Expand Down Expand Up @@ -146,13 +144,17 @@ contract OethARMTest is Test {
}

function test_collectTokens() external {
vm.startPrank(Addresses.TIMELOCK);

oethARM.transferToken(address(weth), address(this), weth.balanceOf(address(oethARM)));
assertGt(weth.balanceOf(address(this)), 50 ether);
assertEq(weth.balanceOf(address(oethARM)), 0);

oethARM.transferToken(address(oeth), address(this), oeth.balanceOf(address(oethARM)));
assertGt(oeth.balanceOf(address(this)), 50 ether);
assertLt(oeth.balanceOf(address(oethARM)), 3);

vm.stopPrank();
}

function _dealOETH(address to, uint256 amount) internal {
Expand All @@ -167,6 +169,7 @@ contract OethARMTest is Test {
/* Operator Tests */

function test_setOperator() external {
vm.prank(Addresses.TIMELOCK);
oethARM.setOperator(address(this));
assertEq(oethARM.operator(), address(this));
}
Expand Down
19 changes: 11 additions & 8 deletions test/OethLiquidityManager.t.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import {Test, console2} from "forge-std/Test.sol";
import {console2} from "forge-std/Test.sol";
import {AbstractForkTest} from "./AbstractForkTest.sol";

import {IERC20, IOethARM, IOETHVault} from "contracts/Interfaces.sol";
import {OEthARM} from "contracts/OethARM.sol";
import {Proxy} from "contracts/Proxy.sol";
import {Addresses} from "contracts/utils/Addresses.sol";

contract OethLiquidityManagerTest is Test {
contract OethLiquidityManagerTest is AbstractForkTest {
address constant RANDOM_ADDRESS = 0xfEEDBeef00000000000000000000000000000000;

address constant WETH = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
Expand All @@ -20,16 +22,14 @@ contract OethLiquidityManagerTest is Test {
Proxy proxy;
OEthARM oethARM;

address constant operator = Addresses.STRATEGIST;

function setUp() public {
vm.label(WETH, "WETH");
vm.label(OETH, "OETH");

OEthARM implementation = new OEthARM();
proxy = new Proxy();
proxy.initialize(address(implementation), address(this), "");
oethARM = OEthARM(address(proxy));

oethARM.setOperator(address(this));
proxy = Proxy(deployManager.getDeployment("OETH_ARM"));
oethARM = OEthARM(deployManager.getDeployment("OETH_ARM"));
}

function test_withdrawal() external {
Expand All @@ -38,6 +38,7 @@ contract OethLiquidityManagerTest is Test {
// put some WETH in the vault
_dealWEth(address(vault), 10 ether);

vm.startPrank(operator);
(uint256 requestId, uint256 queued) = oethARM.requestWithdrawal(1 ether);

// Snapshot WETH balance
Expand All @@ -50,6 +51,8 @@ contract OethLiquidityManagerTest is Test {

// Ensure the balance increased.
assertGt(weth.balanceOf(address(oethARM)), startBalance, "Withdrawal did not increase WETH balance");

vm.stopPrank();
}

/*
Expand Down
42 changes: 25 additions & 17 deletions test/Proxy.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,42 @@
pragma solidity ^0.8.23;

import {Vm} from "forge-std/Vm.sol";
import {Test, console2} from "forge-std/Test.sol";
import {console2} from "forge-std/Test.sol";
import {AbstractForkTest} from "./AbstractForkTest.sol";

import {OEthARM} from "contracts/OethARM.sol";
import {Proxy} from "contracts/Proxy.sol";
import {Addresses} from "contracts/utils/Addresses.sol";

contract ProxyTest is Test {
contract ProxyTest is AbstractForkTest {
address constant RANDOM_ADDRESS = 0xfEEDBeef00000000000000000000000000000000;

Proxy proxy;
OEthARM oethARM;

address weth = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
address oeth = 0x856c4Efb76C1D1AE02e20CEB03A2A6a08b0b8dC3;
address constant weth = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
address constant oeth = 0x856c4Efb76C1D1AE02e20CEB03A2A6a08b0b8dC3;

address constant owner = Addresses.TIMELOCK;
address constant operator = Addresses.STRATEGIST;

function setUp() public {
// Deploy a OSwap contract implementation and a proxy.
OEthARM implementation = new OEthARM();
proxy = new Proxy();
proxy.initialize(address(implementation), address(this), "");
vm.label(weth, "WETH");
vm.label(oeth, "OETH");

oethARM = OEthARM(address(proxy));
proxy = Proxy(deployManager.getDeployment("OETH_ARM"));
oethARM = OEthARM(deployManager.getDeployment("OETH_ARM"));
}

function test_upgrade() external {
OEthARM newImplementation1 = new OEthARM();
vm.prank(owner);
proxy.upgradeTo(address(newImplementation1));
assertEq(proxy.implementation(), address(newImplementation1));

// Ensure ownership was preserved.
assertEq(proxy.owner(), address(this));
assertEq(oethARM.owner(), address(this));
assertEq(proxy.owner(), owner);
assertEq(oethARM.owner(), owner);

// Ensure the storage was preserved through the upgrade.
assertEq(address(oethARM.token0()), oeth);
Expand All @@ -41,24 +46,27 @@ contract ProxyTest is Test {

function test_upgradeAndCall() external {
OEthARM newImplementation2 = new OEthARM();
bytes memory data = abi.encodeWithSignature("setOperator(address)", address(this));
bytes memory data = abi.encodeWithSignature("setOperator(address)", address(0x123));

vm.prank(owner);
proxy.upgradeToAndCall(address(newImplementation2), data);
assertEq(proxy.implementation(), address(newImplementation2));

// Ensure ownership was preserved.
assertEq(proxy.owner(), address(this));
assertEq(oethARM.owner(), address(this));
assertEq(proxy.owner(), owner);
assertEq(oethARM.owner(), owner);

// Ensure the post upgrade code was run
assertEq(oethARM.operator(), address(this));
assertEq(oethARM.operator(), address(0x123));
}

function test_setOwner() external {
assertEq(proxy.owner(), address(this));
assertEq(oethARM.owner(), address(this));
assertEq(proxy.owner(), owner);
assertEq(oethARM.owner(), owner);

// Update the owner.
address newOwner = RANDOM_ADDRESS;
vm.prank(owner);
proxy.setOwner(newOwner);
assertEq(proxy.owner(), newOwner);
assertEq(oethARM.owner(), newOwner);
Expand Down
13 changes: 7 additions & 6 deletions test/UniswapV2.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,26 @@
pragma solidity ^0.8.23;

import {Test, console2} from "forge-std/Test.sol";
import {AbstractForkTest} from "./AbstractForkTest.sol";

import {IERC20} from "contracts/Interfaces.sol";
import {OEthARM} from "contracts/OethARM.sol";
import {Proxy} from "contracts/Proxy.sol";
import {Addresses} from "contracts/utils/Addresses.sol";

// Tests for the Uniswap V2 Router compatible interface of OSwap.
contract UniswapV2Test is Test {
contract UniswapV2Test is AbstractForkTest {
IERC20 weth = IERC20(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);
IERC20 oeth = IERC20(0x856c4Efb76C1D1AE02e20CEB03A2A6a08b0b8dC3);

address constant operator = Addresses.STRATEGIST;

Proxy proxy;
OEthARM oethARM;

function setUp() public {
OEthARM implementation = new OEthARM();
proxy = new Proxy();
proxy.initialize(address(implementation), address(this), "");

oethARM = OEthARM(address(proxy));
proxy = Proxy(deployManager.getDeployment("OETH_ARM"));
oethARM = OEthARM(deployManager.getDeployment("OETH_ARM"));

// Add liquidity to the test contract.
_dealWETH(address(this), 120 ether);
Expand Down

0 comments on commit 7f692a0

Please sign in to comment.