-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add test for create eth rollup (#24)
- Loading branch information
Showing
5 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
ARBISCAN_API_KEY= | ||
PRIVATE_KEY=0xb6b15c8cb491557369f3c7d2c287b053eb229daa9c22138887752191c9520659 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`; | ||
} |