Skip to content

Commit

Permalink
test: add test for create eth rollup (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
spsjvc authored Dec 20, 2023
1 parent 8dec14c commit 737175c
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 0 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
ARBISCAN_API_KEY=
PRIVATE_KEY=0xb6b15c8cb491557369f3c7d2c287b053eb229daa9c22138887752191c9520659
33 changes: 33 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,36 @@ jobs:

- name: Test
run: yarn test:unit

test-integration:
name: Test (Integration)
runs-on: ubuntu-latest
needs: install
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 18

- name: Restore node_modules
uses: OffchainLabs/actions/node-modules/restore@main

- name: Set up the local node
uses: OffchainLabs/actions/run-nitro-test-node@main
with:
ref: 'use-tokenbridge-creator'

- name: Copy .env
run: cp ./.env.example ./.env

- name: Generate
run: yarn generate

- name: Build
run: yarn build

- name: Test
run: yarn test:integration
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"dev": "yarn build --watch",
"generate": "wagmi generate",
"test:unit": "vitest unit.test",
"test:integration": "vitest integration.test",
"postinstall": "patch-package"
},
"devDependencies": {
Expand Down
77 changes: 77 additions & 0 deletions src/createRollup.integration.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { it, expect } from 'vitest';
import { createPublicClient, http, parseGwei, zeroAddress } from 'viem';

import { nitroTestnodeL2 } from './chains';
import { generateChainId } from './utils';
import { prepareChainConfig } from './prepareChainConfig';
import { createRollupPrepareConfig } from './createRollupPrepareConfig';
import { createRollupPrepareTransaction } from './createRollupPrepareTransaction';
import { createRollupPrepareTransactionRequest } from './createRollupPrepareTransactionRequest';
import { createRollupPrepareTransactionReceipt } from './createRollupPrepareTransactionReceipt';

import { getTestPrivateKeyAccount } from './testHelpers';

const deployer = getTestPrivateKeyAccount();

const batchPoster = deployer.address;
const validators = [deployer.address];

const publicClient = createPublicClient({
chain: nitroTestnodeL2,
transport: http(),
});

it(`successfully deploys core contracts through rollup creator`, async () => {
// generate a random chain id
const chainId = generateChainId();

// create the chain config
const chainConfig = prepareChainConfig({
chainId,
arbitrum: { InitialChainOwner: deployer.address },
});

const config = createRollupPrepareConfig({
chainId: BigInt(chainId),
owner: deployer.address,
chainConfig,
});

// prepare the transaction for deploying the core contracts
const request = await createRollupPrepareTransactionRequest({
params: {
config,
batchPoster,
validators,
},
account: deployer.address,
publicClient,
});

// sign and send the transaction
const txHash = await publicClient.sendRawTransaction({
serializedTransaction: await deployer.signTransaction(request),
});

// get the transaction
const tx = createRollupPrepareTransaction(
await publicClient.getTransaction({ hash: txHash })
);

const [arg] = tx.getInputs();
// assert all inputs are correct
expect(arg.config).toEqual(config);
expect(arg.batchPoster).toEqual(batchPoster);
expect(arg.validators).toEqual(validators);
expect(arg.maxDataSize).toEqual(104_857n);
expect(arg.nativeToken).toEqual(zeroAddress);
expect(arg.deployFactoriesToL2).toEqual(true);
expect(arg.maxFeePerGasForRetryables).toEqual(parseGwei('0.1'));

// get the transaction receipt after waiting for the transaction to complete
const txReceipt = createRollupPrepareTransactionReceipt(
await publicClient.waitForTransactionReceipt({ hash: txHash })
);

expect(txReceipt.status).toEqual('success');
});
22 changes: 22 additions & 0 deletions src/testHelpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { privateKeyToAccount, PrivateKeyAccount } from 'viem/accounts';
import { config } from 'dotenv';

config();

export function getTestPrivateKeyAccount(): PrivateKeyAccount {
const privateKey = process.env.PRIVATE_KEY;

if (typeof privateKey === 'undefined') {
throw Error(`missing PRIVATE_KEY env variable`);
}

return privateKeyToAccount(sanitizePrivateKey(privateKey));
}

function sanitizePrivateKey(privateKey: string): `0x${string}` {
if (!privateKey.startsWith('0x')) {
return `0x${privateKey}`;
}

return privateKey as `0x${string}`;
}

0 comments on commit 737175c

Please sign in to comment.