Skip to content

Commit

Permalink
refactor: address proven requirements for outbox
Browse files Browse the repository at this point in the history
  • Loading branch information
LHerskind committed Aug 14, 2024
1 parent f047ad2 commit d0f3a87
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const testSetup = async (): Promise<UniswapSetupContext> => {

teardown = teardown_;

return { aztecNode, pxe, logger, publicClient, walletClient, ownerWallet, sponsorWallet };
return { aztecNode, pxe, logger, publicClient, walletClient, ownerWallet, sponsorWallet, deployL1ContractsValues };
};
// docs:end:uniswap_setup

Expand Down
12 changes: 12 additions & 0 deletions yarn-project/end-to-end/src/e2e_cross_chain_messaging.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import {
computeAuthWitMessageHash,
} from '@aztec/aztec.js';
import { sha256ToField } from '@aztec/foundation/crypto';
import { RollupAbi } from '@aztec/l1-artifacts';
import { type TokenBridgeContract, type TokenContract } from '@aztec/noir-contracts.js';

import { getContract } from 'viem';
import { toFunctionSelector } from 'viem/utils';

import { NO_L1_TO_L2_MSG_ERROR } from './fixtures/fixtures.js';
Expand All @@ -32,6 +34,7 @@ describe('e2e_cross_chain_messaging', () => {
let crossChainTestHarness: CrossChainTestHarness;
let l2Token: TokenContract;
let l2Bridge: TokenBridgeContract;
let rollup: any;

beforeEach(async () => {
const {
Expand All @@ -52,6 +55,12 @@ describe('e2e_cross_chain_messaging', () => {
logger_,
);

rollup = getContract({
address: deployL1ContractsValues.l1ContractAddresses.rollupAddress.toString(),
abi: RollupAbi,
client: deployL1ContractsValues.walletClient,
});

l2Token = crossChainTestHarness.l2Token;
l2Bridge = crossChainTestHarness.l2Bridge;
ethAccount = crossChainTestHarness.ethAccount;
Expand Down Expand Up @@ -124,6 +133,9 @@ describe('e2e_cross_chain_messaging', () => {
l2ToL1Message,
);

// Since the outbox is only consumable when the block is proven, we need to set the block to be proven
await rollup.write.setAssumeProvenUntilBlockNumber([await rollup.read.pendingBlockCount()]);

// Check balance before and after exit.
expect(await crossChainTestHarness.getL1BalanceOf(ethAccount)).toBe(l1TokenBalance - bridgeAmount);
await crossChainTestHarness.withdrawFundsFromBridgeOnL1(
Expand Down
16 changes: 15 additions & 1 deletion yarn-project/end-to-end/src/e2e_outbox.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '@aztec/aztec.js';
import { sha256ToField } from '@aztec/foundation/crypto';
import { truncateAndPad } from '@aztec/foundation/serialize';
import { OutboxAbi } from '@aztec/l1-artifacts';
import { OutboxAbi, RollupAbi } from '@aztec/l1-artifacts';
import { SHA256 } from '@aztec/merkle-tree';
import { TestContract } from '@aztec/noir-contracts.js';

Expand All @@ -26,6 +26,7 @@ describe('E2E Outbox Tests', () => {
let wallets: AccountWalletWithSecretKey[];
let deployL1ContractsValues: DeployL1Contracts;
let outbox: any;
let rollup: any;

beforeEach(async () => {
({ teardown, aztecNode, wallets, deployL1ContractsValues } = await setup(1));
Expand All @@ -37,6 +38,12 @@ describe('E2E Outbox Tests', () => {

const receipt = await TestContract.deploy(wallets[0]).send({ contractAddressSalt: Fr.ZERO }).wait();
contract = receipt.contract;

rollup = getContract({
address: deployL1ContractsValues.l1ContractAddresses.rollupAddress.toString(),
abi: RollupAbi,
client: deployL1ContractsValues.walletClient,
});
});

afterAll(() => teardown());
Expand Down Expand Up @@ -92,6 +99,9 @@ describe('E2E Outbox Tests', () => {

// Outbox L1 tests

// Since the outbox is only consumable when the block is proven, we need to set the block to be proven
await rollup.write.setAssumeProvenUntilBlockNumber([1 + (txReceipt.blockNumber ?? 0)]);

// Check L1 has expected message tree
const [l1Root, l1MinHeight] = await outbox.read.getRootData([txReceipt.blockNumber]);
expect(l1Root).toEqual(`0x${block?.header.contentCommitment.outHash.toString('hex')}`);
Expand Down Expand Up @@ -207,6 +217,8 @@ describe('E2E Outbox Tests', () => {
expect(siblingPath2.pathSize).toBe(3);

// Outbox L1 tests
// Since the outbox is only consumable when the block is proven, we need to set the block to be proven
await rollup.write.setAssumeProvenUntilBlockNumber([1 + (l2TxReceipt0.blockNumber ?? 0)]);

// Check L1 has expected message tree
const [l1Root, l1MinHeight] = await outbox.read.getRootData([l2TxReceipt0.blockNumber]);
Expand Down Expand Up @@ -323,6 +335,8 @@ describe('E2E Outbox Tests', () => {
expect(index2).toBe(2n);

// Outbox L1 tests
// Since the outbox is only consumable when the block is proven, we need to set the block to be proven
await rollup.write.setAssumeProvenUntilBlockNumber([1 + (l2TxReceipt0.blockNumber ?? 0)]);

// Check L1 has expected message tree
const [l1Root, l1MinHeight] = await outbox.read.getRootData([l2TxReceipt0.blockNumber]);
Expand Down
26 changes: 23 additions & 3 deletions yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import {
type PXE,
computeAuthWitMessageHash,
} from '@aztec/aztec.js';
import { deployL1Contract } from '@aztec/ethereum';
import { type DeployL1Contracts, deployL1Contract } from '@aztec/ethereum';
import { sha256ToField } from '@aztec/foundation/crypto';
import { InboxAbi, UniswapPortalAbi, UniswapPortalBytecode } from '@aztec/l1-artifacts';
import { InboxAbi, RollupAbi, UniswapPortalAbi, UniswapPortalBytecode } from '@aztec/l1-artifacts';
import { UniswapContract } from '@aztec/noir-contracts.js/Uniswap';

import { jest } from '@jest/globals';
Expand Down Expand Up @@ -56,6 +56,8 @@ export type UniswapSetupContext = {
ownerWallet: AccountWallet;
/** The sponsor wallet. */
sponsorWallet: AccountWallet;
/** */
deployL1ContractsValues: DeployL1Contracts;
};
// docs:end:uniswap_l1_l2_test_setup_const

Expand Down Expand Up @@ -88,6 +90,8 @@ export const uniswapL1L2TestSuite = (
let daiCrossChainHarness: CrossChainTestHarness;
let wethCrossChainHarness: CrossChainTestHarness;

let deployL1ContractsValues: DeployL1Contracts;
let rollup: any;
let uniswapPortal: GetContractReturnType<typeof UniswapPortalAbi, WalletClient<HttpTransport, Chain>>;
let uniswapPortalAddress: EthAddress;
let uniswapL2Contract: UniswapContract;
Expand All @@ -97,12 +101,19 @@ export const uniswapL1L2TestSuite = (
const minimumOutputAmount = 0n;

beforeAll(async () => {
({ aztecNode, pxe, logger, publicClient, walletClient, ownerWallet, sponsorWallet } = await setup());
({ aztecNode, pxe, logger, publicClient, walletClient, ownerWallet, sponsorWallet, deployL1ContractsValues } =
await setup());

if (Number(await publicClient.getBlockNumber()) < expectedForkBlockNumber) {
throw new Error('This test must be run on a fork of mainnet with the expected fork block');
}

rollup = getContract({
address: deployL1ContractsValues.l1ContractAddresses.rollupAddress.toString(),
abi: RollupAbi,
client: deployL1ContractsValues.walletClient,
});

ownerAddress = ownerWallet.getAddress();
// sponsorAddress = sponsorWallet.getAddress();
ownerEthAddress = EthAddress.fromString((await walletClient.getAddresses())[0]);
Expand Down Expand Up @@ -285,6 +296,9 @@ export const uniswapL1L2TestSuite = (
// ensure that uniswap contract didn't eat the funds.
await wethCrossChainHarness.expectPublicBalanceOnL2(uniswapL2Contract.address, 0n);

// Since the outbox is only consumable when the block is proven, we need to set the block to be proven
await rollup.write.setAssumeProvenUntilBlockNumber([await rollup.read.pendingBlockCount()]);

// 5. Consume L2 to L1 message by calling uniswapPortal.swap_private()
logger.info('Execute withdraw and swap on the uniswapPortal!');
const daiL1BalanceOfPortalBeforeSwap = await daiCrossChainHarness.getL1BalanceOf(
Expand Down Expand Up @@ -917,6 +931,9 @@ export const uniswapL1L2TestSuite = (
// ensure that user's funds were burnt
await wethCrossChainHarness.expectPrivateBalanceOnL2(ownerAddress, wethL2BalanceBeforeSwap - wethAmountToBridge);

// Since the outbox is only consumable when the block is proven, we need to set the block to be proven
await rollup.write.setAssumeProvenUntilBlockNumber([await rollup.read.pendingBlockCount()]);

// On L1 call swap_public!
logger.info('call swap_public on L1');
const swapArgs = [
Expand Down Expand Up @@ -1048,6 +1065,9 @@ export const uniswapL1L2TestSuite = (
// check weth balance of owner on L2 (we first bridged `wethAmountToBridge` into L2 and now withdrew it!)
await wethCrossChainHarness.expectPublicBalanceOnL2(ownerAddress, 0n);

// Since the outbox is only consumable when the block is proven, we need to set the block to be proven
await rollup.write.setAssumeProvenUntilBlockNumber([await rollup.read.pendingBlockCount()]);

// Call swap_private on L1
const secretHashForRedeemingDai = Fr.random(); // creating my own secret hash
logger.info('Execute withdraw and swap on the uniswapPortal!');
Expand Down

0 comments on commit d0f3a87

Please sign in to comment.