Skip to content

Commit

Permalink
chore: Fix and reenable e2e account init fees test (#5878)
Browse files Browse the repository at this point in the history
Similar fix to #5877.
  • Loading branch information
spalladino authored Apr 22, 2024
1 parent ce84161 commit cec8191
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import { GasPortalTestingHarnessFactory, type IGasBridgingTestHarness } from './
const TOKEN_NAME = 'BananaCoin';
const TOKEN_SYMBOL = 'BC';
const TOKEN_DECIMALS = 18n;
const BRIDGED_FPC_GAS = 444n;
const BRIDGED_FPC_GAS = BigInt(10e12);

jest.setTimeout(1000_000);

Expand Down Expand Up @@ -125,13 +125,8 @@ describe('e2e_fees_account_init', () => {
afterAll(() => ctx.teardown());

beforeEach(() => {
gasSettings = GasSettings.from({
gasLimits: { daGas: 2, l1Gas: 2, l2Gas: 2 },
teardownGasLimits: { daGas: 1, l1Gas: 1, l2Gas: 1 },
maxFeesPerGas: { feePerDaGas: Fr.ONE, feePerL1Gas: Fr.ONE, feePerL2Gas: Fr.ONE },
inclusionFee: new Fr(5),
});
maxFee = 3n * 3n + 5n;
gasSettings = GasSettings.default();
maxFee = gasSettings.getFeeLimit().toBigInt();
actualFee = 1n;
bobsSecretKey = Fr.random();
bobsPrivateSigningKey = Fq.random();
Expand Down Expand Up @@ -168,7 +163,7 @@ describe('e2e_fees_account_init', () => {
describe('privately through an FPC', () => {
let mintedPrivateBananas: bigint;
beforeEach(async () => {
mintedPrivateBananas = 42n;
mintedPrivateBananas = BigInt(1e12);

// TODO the following sequence of events ends in a timeout
// 1. pxe.registerRecipient (aka just add the public key so pxe can encrypt notes)
Expand Down Expand Up @@ -243,7 +238,7 @@ describe('e2e_fees_account_init', () => {
let mintedPublicBananas: bigint;

beforeEach(async () => {
mintedPublicBananas = 37n;
mintedPublicBananas = BigInt(1e12);
await bananaCoin.methods.mint_public(bobsAddress, mintedPublicBananas).send().wait();
});

Expand Down
44 changes: 12 additions & 32 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 @@ -138,15 +138,15 @@ class GasBridgingTestHarness implements IGasBridgingTestHarness {
/** Portal address. */
public tokenPortalAddress: EthAddress,
/** Token portal instance. */
public tokenPortal: any,
public tokenPortal: GetContractReturnType<typeof GasPortalAbi, WalletClient<HttpTransport, Chain, Account>>,
/** Underlying token for portal tests. */
public underlyingERC20: any,
public underlyingERC20: GetContractReturnType<typeof PortalERC20Abi, WalletClient<HttpTransport, Chain, Account>>,
/** Message Bridge Outbox. */
public outbox: GetContractReturnType<typeof OutboxAbi, PublicClient<HttpTransport, Chain>>,
/** Viem Public client instance. */
public publicClient: PublicClient<HttpTransport, Chain>,
/** Viem Wallet Client instance. */
public walletClient: any,
public walletClient: WalletClient,
) {}

generateClaimSecret(): [Fr, Fr] {
Expand All @@ -159,7 +159,9 @@ class GasBridgingTestHarness implements IGasBridgingTestHarness {

async mintTokensOnL1(amount: bigint) {
this.logger.info('Minting tokens on L1');
await this.underlyingERC20.write.mint([this.ethAccount.toString(), amount], {} as any);
await this.publicClient.waitForTransactionReceipt({
hash: await this.underlyingERC20.write.mint([this.ethAccount.toString(), amount]),
});
expect(await this.underlyingERC20.read.balanceOf([this.ethAccount.toString()])).toBe(amount);
}

Expand All @@ -168,41 +170,19 @@ class GasBridgingTestHarness implements IGasBridgingTestHarness {
}

async sendTokensToPortalPublic(bridgeAmount: bigint, l2Address: AztecAddress, secretHash: Fr) {
await this.underlyingERC20.write.approve([this.tokenPortalAddress.toString(), bridgeAmount], {} as any);
await this.publicClient.waitForTransactionReceipt({
hash: await this.underlyingERC20.write.approve([this.tokenPortalAddress.toString(), bridgeAmount]),
});

// Deposit tokens to the TokenPortal
this.logger.info('Sending messages to L1 portal to be consumed publicly');
const args = [l2Address.toString(), bridgeAmount, secretHash.toString()] as const;
const { result: messageHash } = await this.tokenPortal.simulate.depositToAztecPublic(args, {
account: this.ethAccount.toString(),
} as any);
await this.tokenPortal.write.depositToAztecPublic(args, {} as any);

return Fr.fromString(messageHash);
}

async sendTokensToPortalPrivate(
secretHashForRedeemingMintedNotes: Fr,
bridgeAmount: bigint,
secretHashForL2MessageConsumption: Fr,
) {
await this.underlyingERC20.write.approve([this.tokenPortalAddress.toString(), bridgeAmount], {} as any);

// Deposit tokens to the TokenPortal
const deadline = 2 ** 32 - 1; // max uint32

this.logger.info('Sending messages to L1 portal to be consumed privately');
const args = [
secretHashForRedeemingMintedNotes.toString(),
bridgeAmount,
this.ethAccount.toString(),
deadline,
secretHashForL2MessageConsumption.toString(),
] as const;
const { result: messageHash } = await this.tokenPortal.simulate.depositToAztecPrivate(args, {
account: this.ethAccount.toString(),
} as any);
await this.tokenPortal.write.depositToAztecPrivate(args, {} as any);
await this.publicClient.waitForTransactionReceipt({
hash: await this.tokenPortal.write.depositToAztecPublic(args),
});

return Fr.fromString(messageHash);
}
Expand Down

0 comments on commit cec8191

Please sign in to comment.