Skip to content

Commit

Permalink
test WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
proletesseract committed Nov 14, 2023
1 parent ef8f6d4 commit a1ea466
Showing 1 changed file with 73 additions and 6 deletions.
79 changes: 73 additions & 6 deletions test/unit/root/flowrate/RootERC20BridgeFlowRate.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,37 @@ contract RootERC20BridgeFlowRateUnitTest is
uint256 constant CAPACITY = 1000000;
uint256 constant REFILL_RATE = 277; // Refill each hour.
uint256 constant LARGE = 100000;

uint256 constant CAPACITY_ETH = 1000000 ether;
uint256 constant REFILL_RATE_ETH = 277 ether; // Refill each hour.
uint256 constant LARGE_ETH = 100000 ether;

bytes32 internal constant RATE_CONTROL_ROLE = keccak256("RATE");

address rateAdmin;
address pauseAdmin;
address nonAdmin;
uint256 withdrawalDelay;

ERC20PresetMinterPauser public token;
ERC20PresetMinterPauser public imxToken;
RootERC20BridgeFlowRate public rootBridgeFlowRate;
MockAdaptor public mockAxelarAdaptor;
MockAxelarGateway public mockAxelarGateway;
MockAxelarGasService public axelarGasService;

function setUp() public {
token = new ERC20PresetMinterPauser("Test", "TST");
token.mint(address(this), 100 ether);
deployCodeTo("ERC20PresetMinterPauser.sol", abi.encode("ImmutableX", "IMX"), IMX_TOKEN);
imxToken = ERC20PresetMinterPauser(IMX_TOKEN);
imxToken.mint(address(this), 100 ether);

deployCodeTo("WETH.sol", abi.encode("Wrapped ETH", "WETH"), WRAPPED_ETH);

rateAdmin = makeAddr("rateadmin");
pauseAdmin = makeAddr("pauseadmin");

nonAdmin = makeAddr("nonadmin");

rootBridgeFlowRate = new RootERC20BridgeFlowRate();
Expand All @@ -66,8 +78,8 @@ contract RootERC20BridgeFlowRateUnitTest is

IRootERC20Bridge.InitializationRoles memory roles = IRootERC20Bridge.InitializationRoles({
defaultAdmin: address(this),
pauser: address(this),
unpauser: address(this),
pauser: pauseAdmin,
unpauser: pauseAdmin,
variableManager: address(this),
adaptorManager: address(this)
});
Expand All @@ -94,6 +106,13 @@ contract RootERC20BridgeFlowRateUnitTest is
rootBridgeFlowRate.activateWithdrawalQueue();
}

function configureFlowRate() internal {
vm.startPrank(rateAdmin);
rootBridgeFlowRate.setRateControlThreshold(address(token), CAPACITY, REFILL_RATE, LARGE);
rootBridgeFlowRate.setRateControlThreshold(NATIVE_ETH, CAPACITY_ETH, REFILL_RATE_ETH, LARGE_ETH);
vm.stopPrank();
}

/**
* INITIALIZE
*/
Expand Down Expand Up @@ -133,6 +152,33 @@ contract RootERC20BridgeFlowRateUnitTest is
);
}

function test_RevertIfRootBridgeInitializedDirectly() public {
IRootERC20Bridge.InitializationRoles memory roles = IRootERC20Bridge.InitializationRoles({
defaultAdmin: address(this),
pauser: address(this),
unpauser: address(this),
variableManager: address(this),
adaptorManager: address(this)
});

vm.expectRevert(WrongInitializer.selector);
rootBridgeFlowRate.initialize(
roles,
address(mockAxelarAdaptor),
CHILD_BRIDGE,
CHILD_BRIDGE_ADAPTOR_STRING,
address(token),
IMX_TOKEN,
WRAPPED_ETH,
CHILD_CHAIN_NAME,
UNLIMITED_IMX_DEPOSITS
);
}

/**
* RATE ROLE ACTIONS
*/

function testActivateWithdrawalQueue() public {
vm.prank(rateAdmin);
rootBridgeFlowRate.activateWithdrawalQueue();
Expand Down Expand Up @@ -192,11 +238,32 @@ contract RootERC20BridgeFlowRateUnitTest is
rootBridgeFlowRate.setRateControlThreshold(address(token), CAPACITY, REFILL_RATE, LARGE);
}

//RootBridge initialiser should revert
/**
* FLOW RATE WITHDRAW
*/

// function testWithdrawalWhenPaused() public {

// // Need to first map the token.
// rootBridgeFlowRate.mapToken(token);
// // And give the bridge some tokens
// token.transfer(address(rootBridgeFlowRate), 100 ether);

// configureFlowRate();

// uint256 amount = 5 ether;

//Flow rate settings with roles
// // Fake a crosschain transfer from the child chain to the root chain.
// bytes memory data = abi.encode(WITHDRAW_SIG, token, address(this), address(this), amount);

//Flow rate withdraw

//Processing the queued withdraws
// vm.prank(address(mockAxelarAdaptor));
// rootBridgeFlowRate.onMessageReceive(CHILD_CHAIN_NAME, CHILD_BRIDGE_ADAPTOR_STRING, data);
// }


/**
* PROCESS QUEUED WITHDRAWALS
*/

}

0 comments on commit a1ea466

Please sign in to comment.