Skip to content

Commit

Permalink
Test re-register token to same address
Browse files Browse the repository at this point in the history
  • Loading branch information
gvladika committed Jan 26, 2024
1 parent 564fdd7 commit 8170196
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
39 changes: 39 additions & 0 deletions test-foundry/L1CustomGateway.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,45 @@ contract L1CustomGatewayTest is L1ArbitrumExtendedGatewayTest {
);
}

function test_registerTokenToL2_UpdateToSameAddress(address l1Token, address l2Token)
public
virtual
{
vm.assume(l1Token != FOUNDRY_CHEATCODE_ADDRESS && l2Token != FOUNDRY_CHEATCODE_ADDRESS);
vm.deal(l1Token, 100 ether);

address[] memory l1Tokens = new address[](1);
l1Tokens[0] = address(l1Token);
address[] memory l2Tokens = new address[](1);
l2Tokens[0] = address(l2Token);

// register token to gateway
vm.mockCall(
address(l1Token),
abi.encodeWithSignature("isArbitrumEnabled()"),
abi.encode(uint8(0xb1))
);
vm.prank(address(l1Token));
L1CustomGateway(address(l1Gateway)).registerTokenToL2{value: retryableCost}(
l2Token, maxGas, gasPriceBid, maxSubmissionCost
);

// re-register
vm.mockCall(
address(l1Token),
abi.encodeWithSignature("isArbitrumEnabled()"),
abi.encode(uint8(0xb1))
);
vm.prank(address(l1Token));
L1CustomGateway(address(l1Gateway)).registerTokenToL2{value: retryableCost}(
l2Token, maxGas, gasPriceBid, maxSubmissionCost
);

assertEq(
L1CustomGateway(address(l1Gateway)).l1ToL2Token(l1Token), l2Token, "Invalid L2 token"
);
}

function test_registerTokenToL2_revert_NotArbEnabled() public virtual {
// wrong answer
vm.mockCall(
Expand Down
52 changes: 52 additions & 0 deletions test-foundry/L1OrbitCustomGateway.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,58 @@ contract L1OrbitCustomGatewayTest is L1CustomGatewayTest {
);
}

function test_registerTokenToL2_UpdateToSameAddress(address l1Token, address l2Token)
public
virtual
override
{
vm.assume(
l1Token != FOUNDRY_CHEATCODE_ADDRESS && l2Token != FOUNDRY_CHEATCODE_ADDRESS
&& l1Token != address(0)
);
vm.deal(l1Token, 100 ether);

// approve fees
ERC20PresetMinterPauser(address(nativeToken)).mint(
address(l1Token), nativeTokenTotalFee * 4
);
vm.prank(address(l1Token));
nativeToken.approve(address(l1Gateway), nativeTokenTotalFee * 4);

address[] memory l1Tokens = new address[](1);
l1Tokens[0] = address(l1Token);
address[] memory l2Tokens = new address[](1);
l2Tokens[0] = address(l2Token);

// register token to gateway
vm.mockCall(
address(l1Token),
abi.encodeWithSignature("isArbitrumEnabled()"),
abi.encode(uint8(0xb1))
);
vm.prank(address(l1Token));
L1OrbitCustomGateway(address(l1Gateway)).registerTokenToL2(
l2Token, maxGas, gasPriceBid, maxSubmissionCost, nativeTokenTotalFee
);

// re-register
vm.mockCall(
address(l1Token),
abi.encodeWithSignature("isArbitrumEnabled()"),
abi.encode(uint8(0xb1))
);
vm.prank(address(l1Token));
L1OrbitCustomGateway(address(l1Gateway)).registerTokenToL2(
l2Token, maxGas, gasPriceBid, maxSubmissionCost, nativeTokenTotalFee
);

assertEq(
L1OrbitCustomGateway(address(l1Gateway)).l1ToL2Token(l1Token),
l2Token,
"Invalid L2 token"
);
}

function test_registerTokenToL2_revert_NotArbEnabled() public override {
// wrong answer
vm.mockCall(
Expand Down

0 comments on commit 8170196

Please sign in to comment.