Skip to content

Commit

Permalink
wrap up test
Browse files Browse the repository at this point in the history
  • Loading branch information
spsjvc committed Jan 23, 2024
1 parent c028ce7 commit f85aae5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
29 changes: 18 additions & 11 deletions src/createTokenBridge.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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
Expand All @@ -31,24 +38,24 @@ 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
const txReceipt = createTokenBridgePrepareTransactionReceipt(
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);
});
5 changes: 4 additions & 1 deletion src/createTokenBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down

0 comments on commit f85aae5

Please sign in to comment.