diff --git a/.env.example b/.env.example index 10b1a76d..06478f3b 100644 --- a/.env.example +++ b/.env.example @@ -1 +1,2 @@ ARBISCAN_API_KEY= +PRIVATE_KEY=0xb6b15c8cb491557369f3c7d2c287b053eb229daa9c22138887752191c9520659 diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 966b1873..3fc77b41 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -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 diff --git a/package.json b/package.json index 39c9a8a7..e11688c0 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/createRollup.integration.test.ts b/src/createRollup.integration.test.ts new file mode 100644 index 00000000..8cb400d9 --- /dev/null +++ b/src/createRollup.integration.test.ts @@ -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'); +}); diff --git a/src/testHelpers.ts b/src/testHelpers.ts new file mode 100644 index 00000000..9d6bec84 --- /dev/null +++ b/src/testHelpers.ts @@ -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}`; +}