diff --git a/yarn-project/end-to-end/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts b/yarn-project/end-to-end/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts index 168aa7fe72c..887d1c9609c 100644 --- a/yarn-project/end-to-end/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +++ b/yarn-project/end-to-end/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts @@ -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'; @@ -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, @@ -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, ); @@ -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, }; } } diff --git a/yarn-project/end-to-end/src/e2e_cross_chain_messaging/l2_to_l1.test.ts b/yarn-project/end-to-end/src/e2e_cross_chain_messaging/l2_to_l1.test.ts index 782df6f0e9c..60eb205af6e 100644 --- a/yarn-project/end-to-end/src/e2e_cross_chain_messaging/l2_to_l1.test.ts +++ b/yarn-project/end-to-end/src/e2e_cross_chain_messaging/l2_to_l1.test.ts @@ -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'; @@ -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 () => { diff --git a/yarn-project/end-to-end/src/e2e_cross_chain_messaging/token_bridge_public_to_private.test.ts b/yarn-project/end-to-end/src/e2e_cross_chain_messaging/token_bridge_public_to_private.test.ts index 403b712df16..60e71effabe 100644 --- a/yarn-project/end-to-end/src/e2e_cross_chain_messaging/token_bridge_public_to_private.test.ts +++ b/yarn-project/end-to-end/src/e2e_cross_chain_messaging/token_bridge_public_to_private.test.ts @@ -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(); @@ -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 () => { @@ -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); diff --git a/yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts b/yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts index ae8ff816661..3b104a99cf7 100644 --- a/yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts +++ b/yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts @@ -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, @@ -152,32 +144,18 @@ export class CrossChainTestHarness { underlyingERC20Address?: EthAddress, ): Promise { 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( @@ -188,13 +166,9 @@ export class CrossChainTestHarness { bridge, ethAccount, tokenPortalAddress, - tokenPortal, - underlyingERC20, - inbox, - outbox, + underlyingERC20.address, publicClient, walletClient, - owner.address, l1ContractAddresses, wallet, ); @@ -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, @@ -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>, - /** Message Bridge Outbox. */ - public outbox: GetContractReturnType>, + public underlyingERC20Address: EthAddress, /** Viem Public client instance. */ public publicClient: PublicClient, /** Viem Wallet Client instance. */ - public walletClient: any, - - /** Aztec address to use in tests. */ - public ownerAddress: AztecAddress, + public walletClient: WalletClient, /** Deployment addresses for all L1 contracts */ public readonly l1ContractAddresses: L1ContractAddresses, @@ -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) { diff --git a/yarn-project/end-to-end/src/shared/gas_portal_test_harness.ts b/yarn-project/end-to-end/src/shared/gas_portal_test_harness.ts index 28475d9691a..458dede26ed 100644 --- a/yarn-project/end-to-end/src/shared/gas_portal_test_harness.ts +++ b/yarn-project/end-to-end/src/shared/gas_portal_test_harness.ts @@ -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; @@ -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( @@ -84,9 +57,7 @@ export class FeeJuicePortalTestingHarnessFactory { gasL2, ethAccount, feeJuicePortalAddress, - feeJuicePortal, - gasL1, - outbox, + feeJuiceAddress, publicClient, walletClient, ); @@ -121,21 +92,17 @@ export class GasBridgingTestHarness implements IGasBridgingTestHarness { public ethAccount: EthAddress, /** Portal address. */ - public tokenPortalAddress: EthAddress, - /** Token portal instance. */ - public tokenPortal: GetContractReturnType>, + public feeJuicePortalAddress: EthAddress, /** Underlying token for portal tests. */ - public underlyingERC20: GetContractReturnType>, - /** Message Bridge Outbox. */ - public outbox: GetContractReturnType>, + public l1FeeJuiceAddress: EthAddress, /** Viem Public client instance. */ public publicClient: PublicClient, /** Viem Wallet Client instance. */ public walletClient: WalletClient, ) { this.feeJuicePortalManager = new L1FeeJuicePortalManager( - EthAddress.fromString(this.tokenPortal.address), - EthAddress.fromString(this.underlyingERC20.address), + this.feeJuicePortalAddress, + this.l1FeeJuiceAddress, this.publicClient, this.walletClient, this.logger, @@ -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) { diff --git a/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts b/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts index 3a363cc2e23..203ceb9a501 100644 --- a/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts +++ b/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts @@ -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;