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

refactor tests #104

Merged
merged 2 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 9 additions & 64 deletions test/Admin.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,69 +2,24 @@
pragma solidity ^0.8.18;
pragma abicoder v2;

import {InvestmentManager} from "src/InvestmentManager.sol";
import {PoolManager} from "src/PoolManager.sol";
import {Gateway} from "src/gateway/Gateway.sol";
import {Root} from "src/Root.sol";
import {Escrow} from "src/Escrow.sol";
import "./TestSetup.t.sol";
import {PauseAdmin} from "src/admins/PauseAdmin.sol";
import {DelayedAdmin} from "src/admins/DelayedAdmin.sol";
import {LiquidityPoolFactory, TrancheTokenFactory} from "src/util/Factory.sol";
import {ERC20} from "src/token/ERC20.sol";
import {MemberlistLike, Memberlist} from "src/token/Memberlist.sol";
import {MockHomeLiquidityPools} from "./mock/MockHomeLiquidityPools.sol";
import {MockXcmRouter} from "./mock/MockXcmRouter.sol";
import {Messages} from "src/gateway/Messages.sol";
import "forge-std/Test.sol";

interface EscrowLike_ {
function approve(address token, address spender, uint256 value) external;
function rely(address usr) external;
}

contract AdminTest is Test {
InvestmentManager evmInvestmentManager;
PoolManager evmPoolManager;
Root root;
Gateway gateway;
MockHomeLiquidityPools centChainLiquidityPools;
MockXcmRouter mockXcmRouter;
contract AdminTest is TestSetup {
PauseAdmin pauseAdmin;
DelayedAdmin delayedAdmin;
uint256 timelock;

function setUp() public {
function setUp() public override {
super.setUp();
timelock = 48 hours;
address escrow_ = address(new Escrow());
root = new Root(address(escrow_), 48 hours);
LiquidityPoolFactory liquidityPoolFactory_ = new LiquidityPoolFactory(address(root));
TrancheTokenFactory trancheTokenFactory_ = new TrancheTokenFactory(address(root));

evmInvestmentManager = new InvestmentManager(escrow_);
evmPoolManager = new PoolManager(escrow_, address(liquidityPoolFactory_), address(trancheTokenFactory_));
liquidityPoolFactory_.rely(address(evmPoolManager));
trancheTokenFactory_.rely(address(evmPoolManager));

mockXcmRouter = new MockXcmRouter(address(evmInvestmentManager));

centChainLiquidityPools = new MockHomeLiquidityPools(address(mockXcmRouter));
pauseAdmin = new PauseAdmin(address(root));
delayedAdmin = new DelayedAdmin(address(root));
pauseAdmin.addPauser(address(this));
root.rely(address(pauseAdmin));
root.rely(address(delayedAdmin));

gateway =
new Gateway(address(root), address(evmInvestmentManager), address(evmPoolManager), address(mockXcmRouter));
evmInvestmentManager.file("gateway", address(gateway));
evmInvestmentManager.file("poolManager", address(evmPoolManager));
evmPoolManager.file("gateway", address(gateway));
evmPoolManager.file("investmentManager", address(evmInvestmentManager));
EscrowLike_(escrow_).rely(address(evmInvestmentManager));
EscrowLike_(escrow_).rely(address(evmPoolManager));
mockXcmRouter.file("gateway", address(gateway));
evmInvestmentManager.rely(address(gateway));
Escrow(escrow_).rely(address(gateway));
}

//------ PauseAdmin tests ------//
Expand Down Expand Up @@ -99,7 +54,7 @@ contract AdminTest is Test {
vm.assume(recipient != address(0));

ERC20 erc20 = newErc20(tokenName, tokenSymbol, decimals);
centChainLiquidityPools.addCurrency(currency, address(erc20));
homePools.addCurrency(currency, address(erc20));

// First, an outgoing transfer must take place which has funds currency of the currency moved to
// the escrow account, from which funds are moved from into the recipient on an incoming transfer.
Expand All @@ -126,7 +81,7 @@ contract AdminTest is Test {
vm.assume(recipient != address(0));

ERC20 erc20 = newErc20(tokenName, tokenSymbol, decimals);
centChainLiquidityPools.addCurrency(currency, address(erc20));
homePools.addCurrency(currency, address(erc20));

// First, an outgoing transfer must take place which has funds currency of the currency moved to
// the escrow account, from which funds are moved from into the recipient on an incoming transfer.
Expand All @@ -137,7 +92,7 @@ contract AdminTest is Test {

pauseAdmin.pause();
vm.expectRevert("Gateway/paused");
centChainLiquidityPools.incomingTransfer(currency, sender, bytes32(bytes20(recipient)), amount);
homePools.incomingTransfer(currency, sender, bytes32(bytes20(recipient)), amount);
}

function testUnpausingResumesFunctionality(
Expand All @@ -158,7 +113,7 @@ contract AdminTest is Test {

ERC20 erc20 = newErc20(tokenName, tokenSymbol, decimals);
vm.assume(recipient != address(erc20));
centChainLiquidityPools.addCurrency(currency, address(erc20));
homePools.addCurrency(currency, address(erc20));

// First, an outgoing transfer must take place which has funds currency of the currency moved to
// the escrow account, from which funds are moved from into the recipient on an incoming transfer.
Expand All @@ -169,7 +124,7 @@ contract AdminTest is Test {
evmPoolManager.transfer(address(erc20), bytes32(bytes20(recipient)), amount);
assertEq(erc20.balanceOf(address(evmPoolManager.escrow())), amount);

centChainLiquidityPools.incomingTransfer(currency, sender, bytes32(bytes20(recipient)), amount);
homePools.incomingTransfer(currency, sender, bytes32(bytes20(recipient)), amount);
assertEq(erc20.balanceOf(address(evmPoolManager.escrow())), 0);
assertEq(erc20.balanceOf(recipient), amount);
}
Expand Down Expand Up @@ -209,14 +164,4 @@ contract AdminTest is Test {
vm.prank(spell);
delayedAdmin.cancelRely(spell);
}

//------ helpers ------//

function newErc20(string memory name, string memory symbol, uint8 decimals) internal returns (ERC20) {
ERC20 erc20 = new ERC20(decimals);
erc20.file("name", name);
erc20.file("symbol", symbol);

return erc20;
}
}
Loading