Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Mar 15, 2024
1 parent 14eb320 commit 7d50548
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ export class MessageStore {

const indexInTheWholeTree = message.blockNumber * BigInt(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP) + message.index;
void this.#l1ToL2MessageIndices.setIfNotExists(message.leaf.toString(), indexInTheWholeTree);
console.log("setting message index", message.leaf.toString());
}

return true;
Expand Down
22 changes: 7 additions & 15 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 @@ -14,9 +14,10 @@ import { keccak, sha256 } from '@aztec/foundation/crypto';
import { serializeToBuffer } from '@aztec/foundation/serialize';
import { TokenBridgeContract, TokenContract } from '@aztec/noir-contracts.js';

import { toFunctionSelector } from 'viem/utils';

import { delay, setup } from './fixtures/utils.js';
import { CrossChainTestHarness } from './shared/cross_chain_test_harness.js';
import { toFunctionSelector } from 'viem/utils';

describe('e2e_cross_chain_messaging', () => {
let logger: DebugLogger;
Expand Down Expand Up @@ -172,19 +173,14 @@ describe('e2e_cross_chain_messaging', () => {
await expect(
l2Bridge
.withWallet(user2Wallet)
.methods.claim_private(
secretHashForL2MessageConsumption,
bridgeAmount,
ethAccount,
secretForL2MessageConsumption,
)
.methods.claim_private(secretHashForL2MessageConsumption, bridgeAmount, secretForL2MessageConsumption)
.simulate(),
).rejects.toThrowError(`Message ${wrongMessage.hash().toString()} not found`);

// send the right one -
const consumptionTx = l2Bridge
.withWallet(user2Wallet)
.methods.claim_private(secretHashForRedeemingMintedNotes, bridgeAmount, ethAccount, secretForL2MessageConsumption)
.methods.claim_private(secretHashForRedeemingMintedNotes, bridgeAmount, secretForL2MessageConsumption)
.send();
const consumptionReceipt = await consumptionTx.wait();
expect(consumptionReceipt.status).toBe(TxStatus.MINED);
Expand Down Expand Up @@ -218,7 +214,7 @@ describe('e2e_cross_chain_messaging', () => {
).rejects.toThrowError(`Unknown auth witness for message hash ${expectedBurnMessageHash.toString()}`);
}, 120_000);

it.only("Can't claim funds publicly if they were deposited privately", async () => {
it("Can't claim funds publicly if they were deposited privately", async () => {
// 1. Mint tokens on L1
const bridgeAmount = 100n;
await crossChainTestHarness.mintTokensOnL1(bridgeAmount);
Expand All @@ -227,11 +223,7 @@ describe('e2e_cross_chain_messaging', () => {
const [secretForL2MessageConsumption, secretHashForL2MessageConsumption] =
crossChainTestHarness.generateClaimSecret();

await crossChainTestHarness.sendTokensToPortalPrivate(
Fr.random(),
bridgeAmount,
secretHashForL2MessageConsumption,
);
await crossChainTestHarness.sendTokensToPortalPrivate(Fr.random(), bridgeAmount, secretHashForL2MessageConsumption);
expect(await crossChainTestHarness.getL1BalanceOf(ethAccount)).toBe(0n);

// Wait for the archiver to process the message
Expand Down Expand Up @@ -259,7 +251,7 @@ describe('e2e_cross_chain_messaging', () => {
await expect(
l2Bridge
.withWallet(user2Wallet)
.methods.claim_public(ownerAddress, bridgeAmount, ethAccount, secretForL2MessageConsumption)
.methods.claim_public(ownerAddress, bridgeAmount, secretForL2MessageConsumption)
.simulate(),
).rejects.toThrowError(`Message ${wrongMessage.hash().toString()} not found`);
}, 120_000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,18 +169,12 @@ describe('e2e_public_cross_chain_messaging', () => {

// user2 tries to consume this message and minting to itself -> should fail since the message is intended to be consumed only by owner.
await expect(
l2Bridge
.withWallet(user2Wallet)
.methods.claim_public(user2Wallet.getAddress(), bridgeAmount, ethAccount, secret)
.simulate(),
l2Bridge.withWallet(user2Wallet).methods.claim_public(user2Wallet.getAddress(), bridgeAmount, secret).simulate(),
).rejects.toThrow(`Message ${wrongMessage.hash().toString()} not found`);

// user2 consumes owner's L1-> L2 message on bridge contract and mints public tokens on L2
logger("user2 consumes owner's message on L2 Publicly");
const tx = l2Bridge
.withWallet(user2Wallet)
.methods.claim_public(ownerAddress, bridgeAmount, ethAccount, secret)
.send();
const tx = l2Bridge.withWallet(user2Wallet).methods.claim_public(ownerAddress, bridgeAmount, secret).send();
const receipt = await tx.wait();
expect(receipt.status).toBe(TxStatus.MINED);
// ensure funds are gone to owner and not user2.
Expand Down Expand Up @@ -234,7 +228,7 @@ describe('e2e_public_cross_chain_messaging', () => {
);

await expect(
l2Bridge.withWallet(user2Wallet).methods.claim_private(secretHash, bridgeAmount, ethAccount, secret).simulate(),
l2Bridge.withWallet(user2Wallet).methods.claim_private(secretHash, bridgeAmount, secret).simulate(),
).rejects.toThrowError(`Message ${wrongMessage.hash().toString()} not found`);
}, 60_000);

Expand Down
10 changes: 3 additions & 7 deletions yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,7 @@ export class CrossChainTestHarness {

// Deposit tokens to the TokenPortal
this.logger('Sending messages to L1 portal to be consumed publicly');
const args = [
this.ownerAddress.toString(),
bridgeAmount,
secretHash.toString(),
] as const;
const args = [this.ownerAddress.toString(), bridgeAmount, secretHash.toString()] as const;
const { result: entryKeyHex } = await this.tokenPortal.simulate.depositToAztecPublic(args, {
account: this.ethAccount.toString(),
} as any);
Expand Down Expand Up @@ -307,7 +303,7 @@ export class CrossChainTestHarness {
this.logger('Consuming messages on L2 secretively');
// Call the mint tokens function on the Aztec.nr contract
const consumptionTx = this.l2Bridge.methods
.claim_private(secretHashForRedeemingMintedNotes, bridgeAmount, this.ethAccount, secretForL2MessageConsumption)
.claim_private(secretHashForRedeemingMintedNotes, bridgeAmount, secretForL2MessageConsumption)
.send();
const consumptionReceipt = await consumptionTx.wait();
expect(consumptionReceipt.status).toBe(TxStatus.MINED);
Expand All @@ -318,7 +314,7 @@ export class CrossChainTestHarness {
async consumeMessageOnAztecAndMintPublicly(bridgeAmount: bigint, secret: Fr) {
this.logger('Consuming messages on L2 Publicly');
// Call the mint tokens function on the Aztec.nr contract
const tx = this.l2Bridge.methods.claim_public(this.ownerAddress, bridgeAmount, this.ethAccount, secret).send();
const tx = this.l2Bridge.methods.claim_public(this.ownerAddress, bridgeAmount, secret).send();
const receipt = await tx.wait();
expect(receipt.status).toBe(TxStatus.MINED);
}
Expand Down
7 changes: 2 additions & 5 deletions yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export const uniswapL1L2TestSuite = (
await cleanup();
});
// docs:start:uniswap_private
it.only('should uniswap trade on L1 from L2 funds privately (swaps WETH -> DAI)', async () => {
it('should uniswap trade on L1 from L2 funds privately (swaps WETH -> DAI)', async () => {
const wethL1BeforeBalance = await wethCrossChainHarness.getL1BalanceOf(ownerEthAddress);

// 1. Approve and deposit weth to the portal and move to L2
Expand Down Expand Up @@ -300,10 +300,7 @@ export const uniswapL1L2TestSuite = (
// 1. Approve and deposit weth to the portal and move to L2
const [secretForMintingWeth, secretHashForMintingWeth] = wethCrossChainHarness.generateClaimSecret();

await wethCrossChainHarness.sendTokensToPortalPublic(
wethAmountToBridge,
secretHashForMintingWeth,
);
await wethCrossChainHarness.sendTokensToPortalPublic(wethAmountToBridge, secretHashForMintingWeth);
// funds transferred from owner to token portal
expect(await wethCrossChainHarness.getL1BalanceOf(ownerEthAddress)).toBe(
wethL1BeforeBalance - wethAmountToBridge,
Expand Down

0 comments on commit 7d50548

Please sign in to comment.