Skip to content

Commit e5c6fc2

Browse files
authored
Merge pull request #60 from AztecProtocol/jz/test-sponsored-fpc
Jz/test sponsored fpc
2 parents b86945f + f22ea0e commit e5c6fc2

File tree

8 files changed

+192
-92
lines changed

8 files changed

+192
-92
lines changed

.github/workflows/tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828

2929
- name: Set Aztec version and start sandbox
3030
run: |
31-
VERSION=0.77.1 aztec-up
31+
VERSION=0.78.1 aztec-up
3232
aztec start --sandbox &
3333
3434
- name: Install project dependencies

Nargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ authors = [ "" ]
55
compiler_version = ">=0.18.0"
66

77
[dependencies]
8-
aztec = { git = "https://github.com/AztecProtocol/aztec-packages/", tag = "v0.77.1", directory = "noir-projects/aztec-nr/aztec" }
8+
aztec = { git = "https://github.com/AztecProtocol/aztec-packages/", tag = "v0.78.1", directory = "noir-projects/aztec-nr/aztec" }

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ bash -i <(curl -s https://install.aztec.network)
4040
Install the correct version of the toolkit with:
4141

4242
```bash
43-
aztec-up 0.77.1
43+
aztec-up 0.78.1
4444
```
4545

4646
Start the sandbox with:

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
"update-readme-version": "node ./.github/scripts/update-readme-version.js"
2121
},
2222
"dependencies": {
23-
"@aztec/accounts": "0.77.1",
24-
"@aztec/aztec.js": "0.77.1",
25-
"@aztec/noir-contracts.js": "0.77.1",
26-
"@aztec/stdlib": "0.77.1",
23+
"@aztec/accounts": "0.78.1",
24+
"@aztec/aztec.js": "0.78.1",
25+
"@aztec/noir-contracts.js": "0.78.1",
26+
"@aztec/stdlib": "0.78.1",
2727
"@types/node": "^22.5.1"
2828
},
2929
"devDependencies": {

src/test/index.test.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { EasyPrivateVotingContractArtifact, EasyPrivateVotingContract } from "../artifacts/EasyPrivateVoting.js"
2-
import { AccountWallet, CompleteAddress, ContractDeployer, createLogger, Fr, PXE, waitForPXE, TxStatus, createPXEClient, getContractInstanceFromDeployParams, Logger } from "@aztec/aztec.js";
3-
import { getInitialTestAccountsWallets } from "@aztec/accounts/testing"
2+
import { AccountManager, AccountWallet, CompleteAddress, ContractDeployer, createLogger, Fr, PXE, waitForPXE, TxStatus, createPXEClient, getContractInstanceFromDeployParams, Logger } from "@aztec/aztec.js";
3+
import { getInitialTestAccountsWallets, generateSchnorrAccounts } from "@aztec/accounts/testing"
4+
import { getSchnorrAccount } from '@aztec/accounts/schnorr';
45
import { spawn } from 'child_process';
6+
import { SponsoredFeePaymentMethod } from './sponsored_fee_payment_method.js';
57

68
const setupSandbox = async () => {
79
const { PXE_URL = 'http://localhost:8080' } = process.env;
@@ -17,6 +19,7 @@ describe("Voting", () => {
1719
let accounts: CompleteAddress[] = [];
1820
let logger: Logger;
1921
let sandboxInstance;
22+
let sponsoredPaymentMethod: SponsoredFeePaymentMethod;
2023

2124
beforeAll(async () => {
2225
sandboxInstance = spawn("aztec", ["start", "--sandbox"], {
@@ -31,6 +34,7 @@ describe("Voting", () => {
3134

3235
wallets = await getInitialTestAccountsWallets(pxe);
3336
accounts = wallets.map(w => w.getCompleteAddress())
37+
sponsoredPaymentMethod = await SponsoredFeePaymentMethod.new(pxe);
3438
})
3539

3640
afterAll(async () => {
@@ -40,8 +44,17 @@ describe("Voting", () => {
4044
it("Deploys the contract", async () => {
4145
const salt = Fr.random();
4246
const VotingContractArtifact = EasyPrivateVotingContractArtifact
43-
const [deployerWallet, adminWallet] = wallets; // using first account as deployer and second as contract admin
44-
const adminAddress = adminWallet.getCompleteAddress().address;
47+
// const [deployerWallet, adminWallet] = wallets; // using first account as deployer and second as contract admin
48+
const accounts = await Promise.all(
49+
(await generateSchnorrAccounts(2)).map(
50+
async a => await getSchnorrAccount(pxe, a.secret, a.signingKey, a.salt)
51+
)
52+
);
53+
await Promise.all(accounts.map(a => a.deploy({ fee: { paymentMethod: sponsoredPaymentMethod } })));
54+
const daWallets = await Promise.all(accounts.map(a => a.getWallet()));
55+
const [deployerWallet, adminWallet] = daWallets;
56+
const [deployerAddress, adminAddress] = daWallets.map(w => w.getAddress());
57+
// const adminAddress = adminWallet.getCompleteAddress().address;
4558

4659
const deploymentData = await getContractInstanceFromDeployParams(VotingContractArtifact,
4760
{
@@ -50,7 +63,10 @@ describe("Voting", () => {
5063
deployer: deployerWallet.getAddress()
5164
});
5265
const deployer = new ContractDeployer(VotingContractArtifact, deployerWallet);
53-
const tx = deployer.deploy(adminAddress).send({ contractAddressSalt: salt })
66+
const tx = deployer.deploy(adminAddress).send({
67+
contractAddressSalt: salt,
68+
fee: { paymentMethod: sponsoredPaymentMethod } // without the sponsoredFPC the deployment fails, thus confirming it works
69+
})
5470
const receipt = await tx.getReceipt();
5571

5672
expect(receipt).toEqual(
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import type { FeePaymentMethod } from '@aztec/aztec.js';
2+
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
3+
import { type FunctionCall, FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
4+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
5+
import type { PXE } from '@aztec/stdlib/interfaces/client';
6+
7+
import { getDeployedSponsoredFPCAddress } from './sponsored_fpc.js';
8+
9+
/**
10+
* A payment method that uses the SponsoredFPCContract to pay the fee unconditionally.
11+
*/
12+
export class SponsoredFeePaymentMethod implements FeePaymentMethod {
13+
constructor(
14+
/**
15+
* Contract which will pay the fee.
16+
*/
17+
private paymentContract: AztecAddress,
18+
) {}
19+
20+
static async new(pxe: PXE) {
21+
const sponsoredFPC = await getDeployedSponsoredFPCAddress(pxe);
22+
return new SponsoredFeePaymentMethod(sponsoredFPC);
23+
}
24+
25+
getAsset(): Promise<AztecAddress> {
26+
return Promise.resolve(ProtocolContractAddress.FeeJuice);
27+
}
28+
29+
getFeePayer(): Promise<AztecAddress> {
30+
return Promise.resolve(this.paymentContract);
31+
}
32+
33+
async getFunctionCalls(): Promise<FunctionCall[]> {
34+
return [
35+
{
36+
name: 'sponsor_unconditionally',
37+
to: this.paymentContract,
38+
selector: await FunctionSelector.fromSignature('sponsor_unconditionally()'),
39+
type: FunctionType.PRIVATE,
40+
isStatic: false,
41+
args: [],
42+
returnTypes: [],
43+
},
44+
];
45+
}
46+
}

src/test/sponsored_fpc.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import {
2+
type ContractInstanceWithAddress,
3+
Fr,
4+
type PXE,
5+
type Wallet,
6+
getContractInstanceFromDeployParams,
7+
} from '@aztec/aztec.js';
8+
import type { LogFn } from '@aztec/foundation/log';
9+
import { SponsoredFPCContract } from '@aztec/noir-contracts.js/SponsoredFPC';
10+
11+
const SPONSORED_FPC_SALT = new Fr(0);
12+
13+
async function getSponsoredFPCInstance(): Promise<ContractInstanceWithAddress> {
14+
return await getContractInstanceFromDeployParams(SponsoredFPCContract.artifact, {
15+
salt: SPONSORED_FPC_SALT,
16+
});
17+
}
18+
19+
export async function getSponsoredFPCAddress() {
20+
return (await getSponsoredFPCInstance()).address;
21+
}
22+
23+
export async function setupSponsoredFPC(deployer: Wallet, log: LogFn) {
24+
const deployed = await SponsoredFPCContract.deploy(deployer)
25+
.send({ contractAddressSalt: SPONSORED_FPC_SALT, universalDeploy: true })
26+
.deployed();
27+
28+
log(`SponsoredFPC: ${deployed.address}`);
29+
}
30+
31+
export async function getDeployedSponsoredFPCAddress(pxe: PXE) {
32+
const fpc = await getSponsoredFPCAddress();
33+
const contracts = await pxe.getContracts();
34+
if (!contracts.find(c => c.equals(fpc))) {
35+
throw new Error('SponsoredFPC not deployed.');
36+
}
37+
return fpc;
38+
}

0 commit comments

Comments
 (0)