Skip to content

Commit

Permalink
add test for push token rate method
Browse files Browse the repository at this point in the history
  • Loading branch information
kovalgek committed Jan 9, 2024
1 parent 6174943 commit f0b891a
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 3 deletions.
10 changes: 7 additions & 3 deletions contracts/optimism/L1ERC20TokenBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,13 @@ contract L1ERC20TokenBridge is
l2TokenBridge = l2TokenBridge_;
}

function pushTokenRate(uint32 l2Gas_) external {
bytes memory empty = new bytes(0);
_depositERC20To(l1TokenRebasable, l2TokenRebasable, l2TokenBridge, 0, l2Gas_, empty);
/// @notice Pushes token rate to L2 by depositing zero tokens.
/// @param l2Gas_ Gas limit required to complete the deposit on L2.
function pushTokenRate(uint32 l2Gas_)
external
whenDepositsEnabled
{
_depositERC20To(l1TokenRebasable, l2TokenRebasable, l2TokenBridge, 0, l2Gas_, "");
}

/// @inheritdoc IL1ERC20Bridge
Expand Down
69 changes: 69 additions & 0 deletions test/optimism/bridging-rebase.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,75 @@ scenario("Optimism :: Bridging integration test", ctxFactory)
);
})

.step("Push token rate to L2", async (ctx) => {
const {
l1Token,
l1TokenRebasable,
l1ERC20TokenBridge,
l2TokenRebasable,
l1CrossDomainMessenger,
l2ERC20TokenBridge,
l1Provider
} = ctx;

const { l1Stranger } = ctx.accounts;

const tokenHolderStrangerBalanceBefore = await l1TokenRebasable.balanceOf(
l1Stranger.address
);

const l1ERC20TokenBridgeBalanceBefore = await l1TokenRebasable.balanceOf(
l1ERC20TokenBridge.address
);

const tx = await l1ERC20TokenBridge
.connect(l1Stranger)
.pushTokenRate(200_000);

const dataToSend = await packedTokenRateAndTimestamp(l1Provider, l1Token);

await assert.emits(l1ERC20TokenBridge, tx, "ERC20DepositInitiated", [
l1TokenRebasable.address,
l2TokenRebasable.address,
l1Stranger.address,
l2ERC20TokenBridge.address,
0,
dataToSend,
]);

const l2DepositCalldata = l2ERC20TokenBridge.interface.encodeFunctionData(
"finalizeDeposit",
[
l1TokenRebasable.address,
l2TokenRebasable.address,
l1Stranger.address,
l2ERC20TokenBridge.address,
0,
dataToSend,
]
);

const messageNonce = await l1CrossDomainMessenger.messageNonce();

await assert.emits(l1CrossDomainMessenger, tx, "SentMessage", [
l2ERC20TokenBridge.address,
l1ERC20TokenBridge.address,
l2DepositCalldata,
messageNonce,
200_000,
]);

assert.equalBN(
await l1Token.balanceOf(l1ERC20TokenBridge.address),
l1ERC20TokenBridgeBalanceBefore
);

assert.equalBN(
await l1TokenRebasable.balanceOf(l1Stranger.address),
tokenHolderStrangerBalanceBefore
);
})

.step("L1 -> L2 deposit zero tokens via depositERC20() method", async (ctx) => {
const {
l1Token,
Expand Down

0 comments on commit f0b891a

Please sign in to comment.