Skip to content

Commit

Permalink
Clean up unused fields in harnesses
Browse files Browse the repository at this point in the history
  • Loading branch information
spalladino committed Oct 30, 2024
1 parent 240faf8 commit 504b15a
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
createDebugLogger,
} from '@aztec/aztec.js';
import { createL1Clients } from '@aztec/ethereum';
import { InboxAbi, OutboxAbi, RollupAbi, TestERC20Abi, TokenPortalAbi } from '@aztec/l1-artifacts';
import { InboxAbi, OutboxAbi, RollupAbi } from '@aztec/l1-artifacts';
import { TokenBridgeContract, TokenContract } from '@aztec/noir-contracts.js';

import { type Chain, type HttpTransport, type PublicClient, getContract } from 'viem';
Expand Down Expand Up @@ -151,17 +151,6 @@ export class CrossChainMessagingTest {
client: walletClient,
});

const tokenPortal = getContract({
address: tokenPortalAddress.toString(),
abi: TokenPortalAbi,
client: walletClient,
});
const underlyingERC20 = getContract({
address: crossChainContext.underlying.toString(),
abi: TestERC20Abi,
client: walletClient,
});

this.crossChainTestHarness = new CrossChainTestHarness(
this.aztecNode,
this.pxe,
Expand All @@ -170,13 +159,9 @@ export class CrossChainMessagingTest {
this.l2Bridge,
this.ethAccount,
tokenPortalAddress,
tokenPortal,
underlyingERC20,
inbox,
outbox,
crossChainContext.underlying,
publicClient,
walletClient,
this.ownerAddress,
this.aztecNodeConfig.l1Contracts,
this.user1Wallet,
);
Expand All @@ -192,12 +177,12 @@ export class CrossChainMessagingTest {
return {
l2Token: this.crossChainTestHarness.l2Token.address,
l2Bridge: this.crossChainTestHarness.l2Bridge.address,
tokenPortal: this.crossChainTestHarness.tokenPortal.address,
underlying: EthAddress.fromString(this.crossChainTestHarness.underlyingERC20.address),
tokenPortal: this.crossChainTestHarness.tokenPortalAddress,
underlying: this.crossChainTestHarness.underlyingERC20Address,
ethAccount: this.crossChainTestHarness.ethAccount,
ownerAddress: this.crossChainTestHarness.ownerAddress,
inbox: EthAddress.fromString(this.crossChainTestHarness.inbox.address),
outbox: EthAddress.fromString(this.crossChainTestHarness.outbox.address),
inbox: this.crossChainTestHarness.l1ContractAddresses.inboxAddress,
outbox: this.crossChainTestHarness.l1ContractAddresses.outboxAddress,
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { sha256ToField } from '@aztec/foundation/crypto';
import { OutboxAbi } from '@aztec/l1-artifacts';
import { TestContract } from '@aztec/noir-contracts.js';

import { type Hex, decodeEventLog } from 'viem';
import { type Hex, decodeEventLog, getContract } from 'viem';

import { CrossChainMessagingTest } from './cross_chain_messaging_test.js';

Expand All @@ -20,7 +20,11 @@ describe('e2e_cross_chain_messaging l2_to_l1', () => {

aztecNode = crossChainTestHarness.aztecNode;

outbox = crossChainTestHarness.outbox;
outbox = getContract({
address: crossChainTestHarness.l1ContractAddresses.outboxAddress.toString(),
abi: OutboxAbi,
client: crossChainTestHarness.walletClient,
});
}, 300_000);

afterAll(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ describe('e2e_cross_chain_messaging token_bridge_public_to_private', () => {
const t = new CrossChainMessagingTest('token_bridge_public_to_private');

let { crossChainTestHarness, ethAccount, aztecNode, ownerAddress } = t;
let underlyingERC20: any;

beforeEach(async () => {
await t.applyBaseSnapshots();
Expand All @@ -17,7 +16,6 @@ describe('e2e_cross_chain_messaging token_bridge_public_to_private', () => {
ethAccount = crossChainTestHarness.ethAccount;
aztecNode = crossChainTestHarness.aztecNode;
ownerAddress = crossChainTestHarness.ownerAddress;
underlyingERC20 = crossChainTestHarness.underlyingERC20;
}, 300_000);

afterEach(async () => {
Expand All @@ -32,7 +30,7 @@ describe('e2e_cross_chain_messaging token_bridge_public_to_private', () => {
await crossChainTestHarness.mintTokensOnL1(l1TokenBalance);
const claim = await crossChainTestHarness.sendTokensToPortalPublic(bridgeAmount);
const msgHash = Fr.fromString(claim.messageHash);
expect(await underlyingERC20.read.balanceOf([ethAccount.toString()])).toBe(l1TokenBalance - bridgeAmount);
expect(await crossChainTestHarness.getL1BalanceOf(ethAccount)).toEqual(l1TokenBalance - bridgeAmount);

await crossChainTestHarness.makeMessageConsumable(msgHash);

Expand Down
68 changes: 18 additions & 50 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 @@ -21,21 +21,13 @@ import {
retryUntil,
} from '@aztec/aztec.js';
import { type L1ContractAddresses } from '@aztec/ethereum';
import {
InboxAbi,
OutboxAbi,
TestERC20Abi,
TestERC20Bytecode,
TokenPortalAbi,
TokenPortalBytecode,
} from '@aztec/l1-artifacts';
import { TestERC20Abi, TestERC20Bytecode, TokenPortalAbi, TokenPortalBytecode } from '@aztec/l1-artifacts';
import { TokenContract } from '@aztec/noir-contracts.js/Token';
import { TokenBridgeContract } from '@aztec/noir-contracts.js/TokenBridge';

import {
type Account,
type Chain,
type GetContractReturnType,
type Hex,
type HttpTransport,
type PublicClient,
Expand Down Expand Up @@ -152,32 +144,18 @@ export class CrossChainTestHarness {
underlyingERC20Address?: EthAddress,
): Promise<CrossChainTestHarness> {
const ethAccount = EthAddress.fromString((await walletClient.getAddresses())[0]);
const owner = wallet.getCompleteAddress();
const l1ContractAddresses = (await pxeService.getNodeInfo()).l1ContractAddresses;

const inbox = getContract({
address: l1ContractAddresses.inboxAddress.toString(),
abi: InboxAbi,
client: walletClient,
});

const outbox = getContract({
address: l1ContractAddresses.outboxAddress.toString(),
abi: OutboxAbi,
client: walletClient,
});

// Deploy and initialize all required contracts
logger.info('Deploying and initializing token, portal and its bridge...');
const { token, bridge, tokenPortalAddress, tokenPortal, underlyingERC20 } =
await deployAndInitializeTokenAndBridgeContracts(
wallet,
walletClient,
publicClient,
l1ContractAddresses.registryAddress,
owner.address,
underlyingERC20Address,
);
const { token, bridge, tokenPortalAddress, underlyingERC20 } = await deployAndInitializeTokenAndBridgeContracts(
wallet,
walletClient,
publicClient,
l1ContractAddresses.registryAddress,
wallet.getAddress(),
underlyingERC20Address,
);
logger.info('Deployed and initialized token, portal and its bridge.');

return new CrossChainTestHarness(
Expand All @@ -188,13 +166,9 @@ export class CrossChainTestHarness {
bridge,
ethAccount,
tokenPortalAddress,
tokenPortal,
underlyingERC20,
inbox,
outbox,
underlyingERC20.address,
publicClient,
walletClient,
owner.address,
l1ContractAddresses,
wallet,
);
Expand All @@ -203,6 +177,8 @@ export class CrossChainTestHarness {
private readonly l1TokenManager: L1TokenManager;
private readonly l1TokenPortalManager: L1TokenPortalManager;

public readonly ownerAddress: AztecAddress;

constructor(
/** Aztec node instance. */
public aztecNode: AztecNode,
Expand All @@ -221,21 +197,12 @@ export class CrossChainTestHarness {

/** Portal address. */
public tokenPortalAddress: EthAddress,
/** Token portal instance. */
public tokenPortal: any,
/** Underlying token for portal tests. */
public underlyingERC20: any,
/** Message Bridge Inbox. */
public inbox: GetContractReturnType<typeof InboxAbi, WalletClient<HttpTransport, Chain, Account>>,
/** Message Bridge Outbox. */
public outbox: GetContractReturnType<typeof OutboxAbi, WalletClient<HttpTransport, Chain, Account>>,
public underlyingERC20Address: EthAddress,
/** Viem Public client instance. */
public publicClient: PublicClient<HttpTransport, Chain>,
/** Viem Wallet Client instance. */
public walletClient: any,

/** Aztec address to use in tests. */
public ownerAddress: AztecAddress,
public walletClient: WalletClient<HttpTransport, Chain, Account>,

/** Deployment addresses for all L1 contracts */
public readonly l1ContractAddresses: L1ContractAddresses,
Expand All @@ -244,14 +211,15 @@ export class CrossChainTestHarness {
public readonly ownerWallet: Wallet,
) {
this.l1TokenPortalManager = new L1TokenPortalManager(
EthAddress.fromString(this.tokenPortal.address),
EthAddress.fromString(this.underlyingERC20.address),
EthAddress.fromString(this.outbox.address),
this.tokenPortalAddress,
this.underlyingERC20Address,
this.l1ContractAddresses.outboxAddress,
this.publicClient,
this.walletClient,
this.logger,
);
this.l1TokenManager = this.l1TokenPortalManager.getTokenManager();
this.ownerAddress = this.ownerWallet.getAddress();
}

async mintTokensOnL1(amount: bigint) {
Expand Down
53 changes: 8 additions & 45 deletions yarn-project/end-to-end/src/shared/gas_portal_test_harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,10 @@ import {
type PXE,
type Wallet,
} from '@aztec/aztec.js';
import { FeeJuicePortalAbi, OutboxAbi, TestERC20Abi } from '@aztec/l1-artifacts';
import { FeeJuiceContract } from '@aztec/noir-contracts.js';
import { ProtocolContractAddress } from '@aztec/protocol-contracts';

import {
type Account,
type Chain,
type GetContractReturnType,
type HttpTransport,
type PublicClient,
type WalletClient,
getContract,
} from 'viem';
import { type Account, type Chain, type HttpTransport, type PublicClient, type WalletClient } from 'viem';

export interface IGasBridgingTestHarness {
getL1FeeJuiceBalance(address: EthAddress): Promise<bigint>;
Expand Down Expand Up @@ -57,24 +48,6 @@ export class FeeJuicePortalTestingHarnessFactory {
throw new Error('Fee Juice portal not deployed on L1');
}

const outbox = getContract({
address: l1ContractAddresses.outboxAddress.toString(),
abi: OutboxAbi,
client: walletClient,
});

const gasL1 = getContract({
address: feeJuiceAddress.toString(),
abi: TestERC20Abi,
client: walletClient,
});

const feeJuicePortal = getContract({
address: feeJuicePortalAddress.toString(),
abi: FeeJuicePortalAbi,
client: walletClient,
});

const gasL2 = await FeeJuiceContract.at(ProtocolContractAddress.FeeJuice, wallet);

return new GasBridgingTestHarness(
Expand All @@ -84,9 +57,7 @@ export class FeeJuicePortalTestingHarnessFactory {
gasL2,
ethAccount,
feeJuicePortalAddress,
feeJuicePortal,
gasL1,
outbox,
feeJuiceAddress,
publicClient,
walletClient,
);
Expand Down Expand Up @@ -121,21 +92,17 @@ export class GasBridgingTestHarness implements IGasBridgingTestHarness {
public ethAccount: EthAddress,

/** Portal address. */
public tokenPortalAddress: EthAddress,
/** Token portal instance. */
public tokenPortal: GetContractReturnType<typeof FeeJuicePortalAbi, WalletClient<HttpTransport, Chain, Account>>,
public feeJuicePortalAddress: EthAddress,
/** Underlying token for portal tests. */
public underlyingERC20: GetContractReturnType<typeof TestERC20Abi, WalletClient<HttpTransport, Chain, Account>>,
/** Message Bridge Outbox. */
public outbox: GetContractReturnType<typeof OutboxAbi, PublicClient<HttpTransport, Chain>>,
public l1FeeJuiceAddress: EthAddress,
/** Viem Public client instance. */
public publicClient: PublicClient<HttpTransport, Chain>,
/** Viem Wallet Client instance. */
public walletClient: WalletClient<HttpTransport, Chain, Account>,
) {
this.feeJuicePortalManager = new L1FeeJuicePortalManager(
EthAddress.fromString(this.tokenPortal.address),
EthAddress.fromString(this.underlyingERC20.address),
this.feeJuicePortalAddress,
this.l1FeeJuiceAddress,
this.publicClient,
this.walletClient,
this.logger,
Expand All @@ -144,14 +111,10 @@ export class GasBridgingTestHarness implements IGasBridgingTestHarness {
this.l1TokenManager = this.feeJuicePortalManager.getTokenManager();
}

get l1FeeJuiceAddress() {
return EthAddress.fromString(this.underlyingERC20.address);
}

async mintTokensOnL1(amount: bigint, to: EthAddress = this.ethAccount) {
const balanceBefore = await this.underlyingERC20.read.balanceOf([to.toString()]);
const balanceBefore = await this.l1TokenManager.getL1TokenBalance(to.toString());
await this.l1TokenManager.mint(amount, to.toString());
expect(await this.underlyingERC20.read.balanceOf([to.toString()])).toBe(balanceBefore + amount);
expect(await this.l1TokenManager.getL1TokenBalance(to.toString())).toEqual(balanceBefore + amount);
}

async getL1FeeJuiceBalance(address: EthAddress) {
Expand Down
3 changes: 2 additions & 1 deletion yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,8 @@ export const uniswapL1L2TestSuite = (
});

// We get the msg leaf from event so that we can later wait for it to be available for consumption
const txLog = extractEvent(txReceipt.logs, daiCrossChainHarness.inbox.address, InboxAbi, 'MessageSent');
const inboxAddress = daiCrossChainHarness.l1ContractAddresses.inboxAddress.toString();
const txLog = extractEvent(txReceipt.logs, inboxAddress, InboxAbi, 'MessageSent');
const tokenOutMsgHash = Fr.fromString(txLog.args.hash);
const tokenOutMsgIndex = txLog.args.index;

Expand Down

0 comments on commit 504b15a

Please sign in to comment.