|
1 | | -import { Contract } from "@aztec/aztec.js/contracts" |
2 | | -import { createAztecNodeClient } from "@aztec/aztec.js/node" |
3 | | -import { SponsoredFeePaymentMethod } from "@aztec/aztec.js/fee" |
4 | | -import type { FieldLike } from "@aztec/aztec.js/abi" |
| 1 | +import { createAztecNodeClient } from "@aztec/aztec.js/node"; |
| 2 | +import { SponsoredFeePaymentMethod } from "@aztec/aztec.js/fee"; |
| 3 | +import type { FieldLike } from "@aztec/aztec.js/abi"; |
5 | 4 | import { getSponsoredFPCInstance } from "./sponsored_fpc.js"; |
6 | 5 | import { SponsoredFPCContract } from "@aztec/noir-contracts.js/SponsoredFPC"; |
7 | | -export const PXE_URL = 'http://localhost:8080' |
8 | | -import { ValueNotEqualContract, ValueNotEqualContractArtifact } from '../contract/artifacts/ValueNotEqual' |
9 | | -import data from '../data.json' |
10 | | -import { getPXEConfig } from "@aztec/pxe/config" |
11 | | -import { TestWallet } from '@aztec/test-wallet/server'; |
12 | | -import { AztecAddress } from "@aztec/aztec.js/addresses" |
| 6 | +export const PXE_URL = "http://localhost:8080"; |
| 7 | +import { ValueNotEqualContract } from "../contract/artifacts/ValueNotEqual"; |
| 8 | +import data from "../data.json"; |
| 9 | +import { getPXEConfig } from "@aztec/pxe/config"; |
| 10 | +import { TestWallet } from "@aztec/test-wallet/server"; |
| 11 | +import { AztecAddress } from "@aztec/aztec.js/addresses"; |
| 12 | +import { rm } from "node:fs/promises"; |
13 | 13 |
|
14 | 14 | const sponsoredFPC = await getSponsoredFPCInstance(); |
15 | | -const sponsoredPaymentMethod = new SponsoredFeePaymentMethod(sponsoredFPC.address); |
| 15 | +const sponsoredPaymentMethod = new SponsoredFeePaymentMethod( |
| 16 | + sponsoredFPC.address |
| 17 | +); |
16 | 18 |
|
17 | 19 | export const setupSandbox = async (): Promise<TestWallet> => { |
18 | | - |
19 | 20 | try { |
20 | | - const nodeUrl = 'http://localhost:8080'; |
| 21 | + const nodeUrl = "http://localhost:8080"; |
21 | 22 | const aztecNode = await createAztecNodeClient(nodeUrl); |
22 | 23 | const config = getPXEConfig(); |
23 | | - config.dataDirectory = 'pxe'; |
| 24 | + await rm("pxe", { recursive: true, force: true }); |
| 25 | + config.dataDirectory = "pxe"; |
24 | 26 | config.proverEnabled = true; |
25 | 27 | let wallet = await TestWallet.create(aztecNode, config); |
26 | | - await wallet.registerContract({ instance: sponsoredFPC, artifact: SponsoredFPCContract.artifact }); |
| 28 | + await wallet.registerContract({ |
| 29 | + instance: sponsoredFPC, |
| 30 | + artifact: SponsoredFPCContract.artifact, |
| 31 | + }); |
27 | 32 |
|
28 | 33 | return wallet; |
29 | 34 | } catch (error) { |
30 | | - console.error('Failed to setup sandbox:', error) |
31 | | - throw error |
| 35 | + console.error("Failed to setup sandbox:", error); |
| 36 | + throw error; |
32 | 37 | } |
33 | | -} |
34 | | - |
| 38 | +}; |
35 | 39 |
|
36 | 40 | async function main() { |
37 | 41 | const testWallet = await setupSandbox(); |
38 | 42 | const account = await testWallet.createAccount(); |
39 | 43 | const manager = await account.getDeployMethod(); |
40 | | - await manager.send({ from: AztecAddress.ZERO, fee: { paymentMethod: sponsoredPaymentMethod } }).deployed() |
| 44 | + await manager |
| 45 | + .send({ |
| 46 | + from: AztecAddress.ZERO, |
| 47 | + fee: { paymentMethod: sponsoredPaymentMethod }, |
| 48 | + }) |
| 49 | + .deployed(); |
41 | 50 | const accounts = await testWallet.getAccounts(); |
42 | 51 |
|
43 | | - const valueNotEqual = await ValueNotEqualContract.deploy(testWallet, 10, accounts[0].item).send({ from: accounts[0].item, fee: { paymentMethod: sponsoredPaymentMethod } }).deployed() |
| 52 | + const valueNotEqual = await ValueNotEqualContract.deploy( |
| 53 | + testWallet, |
| 54 | + 10, |
| 55 | + accounts[0].item |
| 56 | + ) |
| 57 | + .send({ |
| 58 | + from: accounts[0].item, |
| 59 | + fee: { paymentMethod: sponsoredPaymentMethod }, |
| 60 | + }) |
| 61 | + .deployed(); |
44 | 62 |
|
45 | | - const tx = await valueNotEqual.methods.increment(accounts[0].item, data.vkAsFields as unknown as FieldLike[], data.proofAsFields as unknown as FieldLike[], data.publicInputs as unknown as FieldLike[]).send({ from: accounts[0].item, fee: { paymentMethod: sponsoredPaymentMethod } }).wait() |
| 63 | + const tx = await valueNotEqual.methods |
| 64 | + .increment( |
| 65 | + accounts[0].item, |
| 66 | + data.vkAsFields as unknown as FieldLike[], |
| 67 | + data.proofAsFields as unknown as FieldLike[], |
| 68 | + data.publicInputs as unknown as FieldLike[] |
| 69 | + ) |
| 70 | + .send({ |
| 71 | + from: accounts[0].item, |
| 72 | + fee: { paymentMethod: sponsoredPaymentMethod }, |
| 73 | + }) |
| 74 | + .wait(); |
46 | 75 |
|
47 | | - console.log(`Tx hash: ${tx.txHash.toString()}`) |
48 | | - const counterValue = await valueNotEqual.methods.get_counter(accounts[0].item).simulate({ from: accounts[0].item }) |
49 | | - console.log(`Counter value: ${counterValue}`) |
| 76 | + console.log(`Tx hash: ${tx.txHash.toString()}`); |
| 77 | + const counterValue = await valueNotEqual.methods |
| 78 | + .get_counter(accounts[0].item) |
| 79 | + .simulate({ from: accounts[0].item }); |
| 80 | + console.log(`Counter value: ${counterValue}`); |
50 | 81 | } |
51 | 82 |
|
52 | | -main().catch(error => { |
53 | | - console.error(error) |
54 | | - process.exit(1) |
55 | | -}) |
| 83 | +main().catch((error) => { |
| 84 | + console.error(error); |
| 85 | + process.exit(1); |
| 86 | +}); |
0 commit comments