Skip to content

Commit f1acdad

Browse files
authored
Merge pull request #219 from AztecProtocol/jc/fix-accounts-test
fix accounts test and cleanup
2 parents e25ca1c + ef4ffc8 commit f1acdad

File tree

3 files changed

+39
-82
lines changed

3 files changed

+39
-82
lines changed

scripts/fees.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { FPCContract } from "@aztec/noir-contracts.js/FPC";
99
import { PrivateVotingContract } from "../src/artifacts/PrivateVoting.js"
1010
import { TokenContract } from "@aztec/noir-contracts.js/Token";
1111
import { SponsoredFeePaymentMethod } from '@aztec/aztec.js/fee/testing'
12-
import { getDeployedSponsoredFPCAddress, getSponsoredFPCInstance } from "../src/utils/sponsored_fpc.js";
12+
import { getSponsoredFPCInstance } from "../src/utils/sponsored_fpc.js";
1313
import { createEthereumChain, createExtendedL1Client } from "@aztec/ethereum";
1414
import { deploySchnorrAccount } from "../src/utils/deploy_account.js";
1515
import { setupWallet } from "../src/utils/setup_wallet.js";

src/test/e2e/accounts.test.ts

Lines changed: 38 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ import { TxStatus } from "@aztec/stdlib/tx";
2020
import { AccountManager } from "@aztec/aztec.js/wallet";
2121
import { getCanonicalFeeJuice } from '@aztec/protocol-contracts/fee-juice';
2222
import { FeeJuicePaymentMethodWithClaim, PrivateFeePaymentMethod, PublicFeePaymentMethod } from "@aztec/aztec.js/fee";
23-
import { GasFees, GasSettings } from "@aztec/stdlib/gas";
24-
25-
const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
2623

2724
describe("Accounts", () => {
2825
let wallet: TestWallet;
@@ -70,8 +67,7 @@ describe("Accounts", () => {
7067
let signingKey = GrumpkinScalar.random();
7168
let salt = Fr.random();
7269
ownerAccount = await wallet.createSchnorrAccount(secretKey, salt, signingKey);
73-
(await ownerAccount.getDeployMethod()).send({ from: AztecAddress.ZERO, fee: { paymentMethod: sponsoredPaymentMethod } }).wait({ timeout: getTimeouts().deployTimeout });
74-
await wallet.registerSender(ownerAccount.address);
70+
await (await ownerAccount.getDeployMethod()).send({ from: AztecAddress.ZERO, fee: { paymentMethod: sponsoredPaymentMethod } }).wait({ timeout: getTimeouts().deployTimeout });
7571

7672
// Set up fee juice contract
7773
const feeJuiceInstance = await getCanonicalFeeJuice();
@@ -92,78 +88,51 @@ describe("Accounts", () => {
9288
it("Creates accounts with fee juice", async () => {
9389
if (getEnv() === 'devnet') return;
9490

95-
// TODO: fix
96-
97-
// console.log('Starting "Creates accounts with fee juice" test');
98-
// console.log(`Random addresses: ${randomAddresses.map(a => a.toString()).join(', ')}`);
91+
console.log('Starting "Creates accounts with fee juice" test');
92+
console.log(`Random addresses: ${randomAddresses.map(a => a.toString()).join(', ')}`);
9993

10094
// balance of each random account is 0 before bridge
101-
// console.log('Checking initial balances...');
102-
// let balances = await Promise.all(randomAddresses.map(async a =>
103-
// await feeJuiceContract.methods.balance_of_public(a).simulate({ from: ownerAccount.address })
104-
// ));
105-
// console.log(`Initial balances: ${balances.join(', ')}`);
106-
// balances.forEach(b => expect(b).toBe(0n));
95+
console.log('Checking initial balances...');
96+
let balances = await Promise.all(randomAddresses.map(async a =>
97+
await feeJuiceContract.methods.balance_of_public(a).simulate({ from: ownerAccount.address })
98+
));
99+
console.log(`Initial balances: ${balances.join(', ')}`);
100+
balances.forEach(b => expect(b).toBe(0n));
107101

108102
// bridge funds to unfunded random addresses
109-
// const claimAmount = await l1PortalManager.getTokenManager().getMintAmount();
110-
// console.log(`Claim amount: ${claimAmount}`);
111-
// let claims: L2AmountClaim[] = [];
112-
// bridge sequentially to avoid l1 txs (nonces) being processed out of order
113-
// for (let i = 0; i < randomAddresses.length; i++) {
114-
// console.log(`Bridging tokens for address ${i}: ${randomAddresses[i].toString()}`);
115-
// const claim = await l1PortalManager.bridgeTokensPublic(randomAddresses[i], claimAmount, true);
116-
// claims.push(claim);
117-
// console.log(`Bridge complete for address ${i}`);
118-
// console.log(` - claimAmount: ${claim.claimAmount.toString()}`);
119-
// console.log(` - claimSecret: ${claim.claimSecret.toString()}`);
120-
// console.log(` - messageLeafIndex: ${claim.messageLeafIndex.toString()}`);
121-
// }
122-
// console.log(`Total claims created: ${claims.length}`);
103+
const claimAmount = await l1PortalManager.getTokenManager().getMintAmount();
104+
console.log(`Claim amount: ${claimAmount}`);
105+
let claims: L2AmountClaim[] = [];
106+
// bridge sequentially to avoid l1 txs(nonces) being processed out of order
107+
for (let i = 0; i < randomAddresses.length; i++) {
108+
console.log(`Bridging tokens for address ${i}: ${randomAddresses[i].toString()}`);
109+
const claim = await l1PortalManager.bridgeTokensPublic(randomAddresses[i], claimAmount, true);
110+
claims.push(claim);
111+
}
112+
console.log(`Total claims created: ${claims.length}`);
123113

124114
// arbitrary transactions to progress 2 blocks, and have fee juice on Aztec ready to claim
125-
// console.log('Deploying first PrivateVotingContract to progress blocks...');
126-
// await PrivateVotingContract.deploy(wallet, ownerAccount.address).send({
127-
// from: ownerAccount.address,
128-
// fee: { paymentMethod: sponsoredPaymentMethod }
129-
// }).deployed({ timeout: getTimeouts().deployTimeout }); // deploy contract with first funded wallet
130-
// console.log('First PrivateVotingContract deployed');
131-
132-
// console.log('Deploying second PrivateVotingContract to progress blocks...');
133-
// await PrivateVotingContract.deploy(wallet, ownerAccount.address).send({
134-
// from: ownerAccount.address,
135-
// fee: { paymentMethod: sponsoredPaymentMethod }
136-
// }).deployed({ timeout: getTimeouts().deployTimeout }); // deploy contract with first funded wallet
137-
// console.log('Second PrivateVotingContract deployed');
138-
139-
// Manually claim fee juice for each random account first
140-
// logger.info('Starting fee juice claims...');
141-
// for (let i = 0; i < randomAccountManagers.length; i++) {
142-
// logger.info(`Claiming fee juice for address ${i}: ${randomAddresses[i].toString()}`);
143-
// await feeJuiceContract.methods.claim(
144-
// randomAddresses[i],
145-
// claims[i].claimAmount,
146-
// claims[i].claimSecret,
147-
// claims[i].messageLeafIndex
148-
// ).send({ from: ownerAccount.address, fee: { paymentMethod: sponsoredPaymentMethod } }).wait({ timeout: getTimeouts().txTimeout });
149-
// logger.info(`Claim successful for address ${i}`);
150-
// }
151-
// logger.info('All fee juice claims completed');
115+
console.log('Deploying first PrivateVotingContract to progress blocks...');
116+
await PrivateVotingContract.deploy(wallet, ownerAccount.address).send({
117+
from: ownerAccount.address,
118+
fee: { paymentMethod: sponsoredPaymentMethod }
119+
}).deployed({ timeout: getTimeouts().deployTimeout }); // deploy contract with first funded wallet
120+
console.log('First PrivateVotingContract deployed');
121+
122+
console.log('Deploying second PrivateVotingContract to progress blocks...');
123+
await PrivateVotingContract.deploy(wallet, ownerAccount.address).send({
124+
from: ownerAccount.address,
125+
fee: { paymentMethod: sponsoredPaymentMethod }
126+
}).deployed({ timeout: getTimeouts().deployTimeout }); // deploy contract with first funded wallet
127+
console.log('Second PrivateVotingContract deployed');
152128

153129
// Now deploy random accounts using FeeJuicePaymentMethodWithClaim (which claims and pays in one tx)
154-
// console.log('Starting account deployments with FeeJuicePaymentMethodWithClaim...');
155-
// for (let i = 0; i < randomAccountManagers.length; i++) {
156-
// const paymentMethod = new FeeJuicePaymentMethodWithClaim(randomAddresses[i], claims[i]);
157-
// const deployTx = (await randomAccountManagers[i].getDeployMethod()).send({ from: AztecAddress.ZERO, fee: { paymentMethod } });
158-
// const receipt = await deployTx.wait({ timeout: getTimeouts().deployTimeout });
159-
// }
160-
161-
// balance after deploy should still have full claimed amount (since we used sponsored payment)
162-
// balances = await Promise.all(randomAddresses.map(async a =>
163-
// await feeJuiceContract.methods.balance_of_public(a).simulate({ from: ownerAccount.address })
164-
// ));
165-
// balances.forEach(b => expect(b).toBe(claimAmount));
166-
130+
console.log('Starting account deployments with FeeJuicePaymentMethodWithClaim...');
131+
for (let i = 0; i < randomAccountManagers.length; i++) {
132+
const paymentMethod = new FeeJuicePaymentMethodWithClaim(randomAddresses[i], claims[i]);
133+
const deployTx = (await randomAccountManagers[i].getDeployMethod()).send({ from: AztecAddress.ZERO, fee: { paymentMethod } });
134+
const receipt = await deployTx.wait({ timeout: getTimeouts().deployTimeout });
135+
}
167136
});
168137

169138
it("Deploys first unfunded account from first funded account", async () => {

src/utils/sponsored_fpc.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@ import {
44
type ContractInstanceWithAddress,
55
} from '@aztec/aztec.js/contracts';
66
import type { Wallet } from '@aztec/aztec.js/wallet';
7-
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
87
import type { LogFn } from '@aztec/foundation/log';
98
import { SponsoredFPCContract } from '@aztec/noir-contracts.js/SponsoredFPC';
109

11-
type PxeLike = { getContracts(): Promise<AztecAddress[]> };
12-
1310
const SPONSORED_FPC_SALT = new Fr(0);
1411

1512
export async function getSponsoredFPCInstance(): Promise<ContractInstanceWithAddress> {
@@ -34,12 +31,3 @@ export async function setupSponsoredFPC(deployer: Wallet, log: LogFn) {
3431

3532
log(`SponsoredFPC: ${deployed.address}`);
3633
}
37-
38-
export async function getDeployedSponsoredFPCAddress(pxe: PxeLike) {
39-
const fpc = await getSponsoredFPCAddress();
40-
const contracts = await pxe.getContracts();
41-
if (!contracts.find(c => c.equals(fpc))) {
42-
throw new Error('SponsoredFPC not deployed.');
43-
}
44-
return fpc;
45-
}

0 commit comments

Comments
 (0)