From f85aae51c6c58a34783fc7ee038a67eec3aff34d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dragi=C5=A1a=20Spasojevi=C4=87?= Date: Tue, 23 Jan 2024 11:04:17 +0100 Subject: [PATCH] wrap up test --- src/createTokenBridge.integration.test.ts | 29 ++++++++++++++--------- src/createTokenBridge.ts | 5 +++- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/createTokenBridge.integration.test.ts b/src/createTokenBridge.integration.test.ts index 9428a020..eab8faca 100644 --- a/src/createTokenBridge.integration.test.ts +++ b/src/createTokenBridge.integration.test.ts @@ -2,9 +2,10 @@ import { it, expect } from 'vitest'; import { createPublicClient, http } from 'viem'; import { nitroTestnodeL1, nitroTestnodeL2 } from './chains'; -import { getTestPrivateKeyAccount, testSetupCreateRollup } from './testHelpers'; +import { getTestPrivateKeyAccount } from './testHelpers'; import { createTokenBridgePrepareTransactionRequest } from './createTokenBridge'; import { createTokenBridgePrepareTransactionReceipt } from './createTokenBridgePrepareTransactionReceipt'; +import { deployTokenBridgeCreator } from './createTokenBridge-testHelpers'; const deployer = getTestPrivateKeyAccount(); @@ -19,8 +20,14 @@ const nitroTestnodeL2Client = createPublicClient({ }); it(`successfully deploys token bridge contracts through token bridge creator`, async () => { + // deploy a fresh token bridge creator, because it is only possible to deploy one token bridge per rollup per token bridge creator + const tokenBridgeCreator = await deployTokenBridgeCreator({ + publicClient: nitroTestnodeL1Client, + }); + const txRequest = await createTokenBridgePrepareTransactionRequest({ params: { + // this is the rollup for the nitro testnode L2 rollup: '0x05e720d41d78ad9e43cd599e2fbf924dac867124', // https://github.com/OffchainLabs/nitro-testnode/blob/master/test-node.bash#L363 // https://github.com/OffchainLabs/nitro-testnode/blob/master/scripts/accounts.ts#L35 @@ -31,9 +38,12 @@ it(`successfully deploys token bridge contracts through token bridge creator`, a account: deployer.address, }); + // update the transaction request to use the fresh token bridge creator + const txRequestToFreshTokenBridgeCreator = { ...txRequest, to: tokenBridgeCreator }; + // sign and send the transaction const txHash = await nitroTestnodeL1Client.sendRawTransaction({ - serializedTransaction: await deployer.signTransaction(txRequest), + serializedTransaction: await deployer.signTransaction(txRequestToFreshTokenBridgeCreator), }); // get the transaction receipt after waiting for the transaction to complete @@ -41,14 +51,11 @@ it(`successfully deploys token bridge contracts through token bridge creator`, a await nitroTestnodeL1Client.waitForTransactionReceipt({ hash: txHash }), ); - expect(txReceipt.status).toEqual('success'); - - await expect(async () => { - const retryables = await txReceipt.waitForRetryables({ - orbitPublicClient: nitroTestnodeL2Client, - }); + function waitForRetryables() { + return txReceipt.waitForRetryables({ orbitPublicClient: nitroTestnodeL2Client }); + } - console.log(`Retryable 1: ${retryables[0].transactionHash}`); - console.log(`Retryable 2: ${retryables[1].transactionHash}`); - }).rejects.not.toThrowError(); + expect(txReceipt.status).toEqual('success'); + // assert promise is resolved with 2 retryables + await expect(waitForRetryables()).resolves.toHaveLength(2); }); diff --git a/src/createTokenBridge.ts b/src/createTokenBridge.ts index 6b78adb7..ee4888fd 100644 --- a/src/createTokenBridge.ts +++ b/src/createTokenBridge.ts @@ -42,8 +42,11 @@ export async function createTokenBridgePrepareTransactionRequest({ args: [inbox, params.rollupOwner, maxGasForContracts, gasPrice], }), // todo: should be 0 for custom gas token - value: retryableFee, + // todo: add the padding inside "createTokenBridgeGetInputs" + value: retryableFee * BigInt(2), account: account, + // todo: don't hardcode + gas: 6_000_000n, }); return { ...request, chainId };