Skip to content
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
10 changes: 8 additions & 2 deletions .github/workflows/ci-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ jobs:
version: v1.5.1

- name: Run ZKsync OS (L1-L2)
uses: dutterbutter/zksync-server-action@e0401b155b1fa0f4f3629d569db3ae7094383729 # main
uses: dutterbutter/zksync-server-action@54ebddef27a0bd7ef30246f94add1c9091ae23be # v0.2.0
with:
version: v0.15.1
protocol_version: v30.2

- name: Compile test contracts
working-directory: tests/contracts
Expand Down Expand Up @@ -190,7 +193,10 @@ jobs:
version: v1.5.1

- name: Run ZKsync OS (L1-L2)
uses: dutterbutter/zksync-server-action@e0401b155b1fa0f4f3629d569db3ae7094383729 # main
uses: dutterbutter/zksync-server-action@54ebddef27a0bd7ef30246f94add1c9091ae23be # v0.2.0
with:
version: v0.15.1
protocol_version: v30.2

- name: Setup Bun
uses: oven-sh/setup-bun@735343b667d3e6f658f44d0eca948eb6282f2b76 # v2.0.2
Expand Down
15 changes: 14 additions & 1 deletion src/adapters/ethers/e2e/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import { expect } from 'bun:test';
// TODO: make this shared across resources
const L1_RPC_URL = 'http://127.0.0.1:8545';
const L2_RPC_URL = 'http://127.0.0.1:3050';
const PRIVATE_KEY = '0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6';
const PRIVATE_KEY = '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80';
const L2_RICH_PRIVATE_KEY = '0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110';
const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));

export const DEPLOYER_PRIVATE_KEY =
Expand All @@ -37,6 +38,18 @@ export function createTestClientAndSdk() {
return { client, sdk };
}

// Ensure the test signer has enough ETH on L2 for withdrawal tests.
export async function ensureL2Balance(client: any, minBalance: bigint): Promise<void> {
const me = (await client.signer.getAddress()) as Address;
const current = (await client.l2.getBalance(me)) as bigint;
if (current >= minBalance) return;

const topUp = minBalance - current + 1_000_000_000_000_000n; // +0.001 ETH buffer for gas
const funder = new Wallet(L2_RICH_PRIVATE_KEY, client.l2);
const tx = await funder.sendTransaction({ to: me, value: topUp });
await tx.wait();
}

/** Create deployer wallets bound to current providers (same PK on both chains). */
export function makeDeployers(l1: JsonRpcProvider, l2: JsonRpcProvider) {
const baseL1 = new Wallet(DEPLOYER_PRIVATE_KEY, l1);
Expand Down
2 changes: 2 additions & 0 deletions src/adapters/ethers/e2e/withdrawals.eth.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type { Address, Hex } from '../../../core/types/primitives.ts';
import { ETH_ADDRESS } from '../../../core/constants.ts';
import {
createTestClientAndSdk,
ensureL2Balance,
waitUntilReadyToFinalize,
verifyWithdrawalBalancesAfterFinalize,
waitForL2InclusionWithdraw,
Expand All @@ -29,6 +30,7 @@ describe('withdrawals.e2e (ethers): ETH withdrawal', () => {
beforeAll(async () => {
({ client, sdk } = createTestClientAndSdk());
me = (await client.signer.getAddress()) as Address;
await ensureL2Balance(client, WITHDRAW_WEI);

// Ensure L2 has funds to withdraw
const l2Bal = await client.l2.getBalance(me);
Expand Down
24 changes: 23 additions & 1 deletion src/adapters/viem/e2e/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import { createViemSdk } from '../sdk.ts';
// TODO: refactor with shared mocks
const L1_RPC = 'http://127.0.0.1:8545';
const L2_RPC = 'http://127.0.0.1:3050';
const PRIVATE_KEY = '0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6';
const PRIVATE_KEY = '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80';
const L2_RICH_PRIVATE_KEY = '0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110';
const DEPLOYER_PRIVATE_KEY = '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80';
const L1_CHAIN: Chain | undefined = undefined;
const L2_CHAIN: Chain | undefined = undefined;
Expand Down Expand Up @@ -66,6 +67,27 @@ export function createTestClientAndSdk() {
return { client, sdk };
}

// Ensure the test signer has enough ETH on L2 for withdrawal tests.
export async function ensureL2Balance(client: any, minBalance: bigint): Promise<void> {
const me = client.account.address as Address;
const current = (await client.l2.getBalance({ address: me })) as bigint;
if (current >= minBalance) return;

const topUp = minBalance - current + 1_000_000_000_000_000n; // +0.001 ETH buffer for gas
const funderAccount = privateKeyToAccount(L2_RICH_PRIVATE_KEY);
const l2Funder = createWalletClient<Transport, Chain, Account>({
account: funderAccount,
transport: http(L2_RPC),
...(L2_CHAIN ? { chain: L2_CHAIN } : {}),
});
const hash = await l2Funder.sendTransaction({
account: funderAccount,
to: me,
value: topUp,
});
await client.l2.waitForTransactionReceipt({ hash });
}

export function makeDeployers() {
const deployerAccount = privateKeyToAccount(DEPLOYER_PRIVATE_KEY);

Expand Down
2 changes: 2 additions & 0 deletions src/adapters/viem/e2e/withdrawals.eth.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type { Address, Hex } from '../../../core/types/primitives.ts';
import { ETH_ADDRESS } from '../../../core/constants.ts';
import {
createTestClientAndSdk,
ensureL2Balance,
waitForL2InclusionWithdraw,
waitUntilReadyToFinalize,
verifyWithdrawalBalancesAfterFinalize,
Expand All @@ -28,6 +29,7 @@ describe('withdrawals.e2e (viem): ETH withdrawal', () => {
beforeAll(async () => {
({ client, sdk } = createTestClientAndSdk());
me = client.account.address as Address;
await ensureL2Balance(client, WITHDRAW_WEI);

// Ensure L2 has funds to withdraw
const l2Bal = await client.l2.getBalance({ address: me });
Expand Down