|
1 | | -import { AccountWalletWithSecretKey, Contract, createAztecNodeClient, Fq, Fr, SponsoredFeePaymentMethod, waitForPXE, type FieldLike, type PXE } from "@aztec/aztec.js" |
| 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" |
2 | 5 | import { getSponsoredFPCInstance } from "./sponsored_fpc.js"; |
3 | 6 | import { SponsoredFPCContract } from "@aztec/noir-contracts.js/SponsoredFPC"; |
4 | 7 | export const PXE_URL = 'http://localhost:8080' |
5 | 8 | import { ValueNotEqualContract, ValueNotEqualContractArtifact } from '../contract/artifacts/ValueNotEqual' |
6 | 9 | import data from '../data.json' |
7 | | -import { createPXEService, getPXEServiceConfig } from "@aztec/pxe/server" |
8 | | -import { createStore } from "@aztec/kv-store/lmdb" |
9 | | -import { getSchnorrAccount } from "@aztec/accounts/schnorr" |
| 10 | +import { getPXEConfig } from "@aztec/pxe/config" |
| 11 | +import { TestWallet } from '@aztec/test-wallet/server'; |
| 12 | +import { AztecAddress } from "@aztec/aztec.js/addresses" |
10 | 13 |
|
11 | 14 | const sponsoredFPC = await getSponsoredFPCInstance(); |
12 | 15 | const sponsoredPaymentMethod = new SponsoredFeePaymentMethod(sponsoredFPC.address); |
13 | 16 |
|
14 | | -export const setupSandbox = async (): Promise<PXE> => { |
15 | | - |
| 17 | +export const setupSandbox = async (): Promise<TestWallet> => { |
| 18 | + |
16 | 19 | try { |
17 | 20 | const nodeUrl = 'http://localhost:8080'; |
18 | | - const node = await createAztecNodeClient(nodeUrl); |
19 | | - |
20 | | - try { |
21 | | - await node.getNodeInfo(); |
22 | | - } catch (error) { |
23 | | - throw new Error(`Cannot connect to node at ${nodeUrl}. ${nodeUrl.includes('localhost') ? 'Please run: aztec start --sandbox' : 'Check your connection.'}`); |
24 | | - } |
25 | | - |
26 | | - const l1Contracts = await node.getL1ContractAddresses(); |
27 | | - const config = getPXEServiceConfig(); |
28 | | - const fullConfig = { |
29 | | - ...config, |
30 | | - l1Contracts, |
31 | | - proverEnabled: true |
32 | | - }; |
33 | | - |
34 | | - const store = await createStore('recursive_verification', { |
35 | | - dataDirectory: 'store', |
36 | | - dataStoreMapSizeKB: 1e6, |
37 | | - }); |
38 | | - |
39 | | - const pxe = await createPXEService(node, fullConfig, { store }); |
40 | | - await waitForPXE(pxe); |
41 | | - await pxe.registerContract({ instance: sponsoredFPC, artifact: SponsoredFPCContract.artifact }); |
42 | | - |
43 | | - return pxe; |
| 21 | + const aztecNode = await createAztecNodeClient(nodeUrl); |
| 22 | + const config = getPXEConfig(); |
| 23 | + config.dataDirectory = 'pxe'; |
| 24 | + config.proverEnabled = true; |
| 25 | + let wallet = await TestWallet.create(aztecNode, config); |
| 26 | + await wallet.registerContract({ instance: sponsoredFPC, artifact: SponsoredFPCContract.artifact }); |
| 27 | + |
| 28 | + return wallet; |
44 | 29 | } catch (error) { |
45 | 30 | console.error('Failed to setup sandbox:', error) |
46 | 31 | throw error |
47 | 32 | } |
48 | 33 | } |
49 | 34 |
|
50 | | -export async function deployWallet(pxe: PXE): Promise<AccountWalletWithSecretKey> { |
51 | | - let secretKey = Fr.random(); |
52 | | - let signingKey = Fq.random(); |
53 | | - let salt = Fr.random(); |
54 | | - let schnorrAccount = await getSchnorrAccount(pxe, secretKey, signingKey, salt); |
55 | | - let tx = await schnorrAccount.deploy({ fee: { paymentMethod: sponsoredPaymentMethod } }).wait({ timeout: 120000 }); |
56 | | - let wallet = await schnorrAccount.getWallet(); |
57 | | - return wallet |
58 | | -} |
59 | 35 |
|
60 | 36 | async function main() { |
61 | | - const pxe = await setupSandbox(); |
62 | | - const wallet = await deployWallet(pxe) |
63 | | - |
64 | | - const valueNotEqual = await Contract.deploy(wallet, ValueNotEqualContractArtifact, [ |
65 | | - 10, wallet.getAddress() |
66 | | - ], 'initialize').send({ from: wallet.getAddress(), fee: { paymentMethod: sponsoredPaymentMethod } }).deployed() as ValueNotEqualContract |
| 37 | + const testWallet = await setupSandbox(); |
| 38 | + const account = await testWallet.createAccount(); |
| 39 | + const manager = await account.getDeployMethod(); |
| 40 | + await manager.send({ from: AztecAddress.ZERO, fee: { paymentMethod: sponsoredPaymentMethod } }).deployed() |
| 41 | + const accounts = await testWallet.getAccounts(); |
67 | 42 |
|
68 | | - console.log("Contract Deployed at address", valueNotEqual.address.toString()) |
| 43 | + const valueNotEqual = await Contract.deploy(testWallet, ValueNotEqualContractArtifact, [ |
| 44 | + 10, accounts[0].item |
| 45 | + ], 'initialize').send({ from: accounts[0].item, fee: { paymentMethod: sponsoredPaymentMethod } }).deployed() as ValueNotEqualContract |
69 | 46 |
|
70 | | - const tx = await valueNotEqual.methods.increment(wallet.getAddress(), data.vkAsFields as unknown as FieldLike[], data.proofAsFields as unknown as FieldLike[], data.publicInputs as unknown as FieldLike[]).send({ from: wallet.getAddress(), fee: { paymentMethod: sponsoredPaymentMethod } }).wait() |
| 47 | + 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() |
71 | 48 |
|
72 | 49 | console.log(`Tx hash: ${tx.txHash.toString()}`) |
73 | | - const counterValue = await valueNotEqual.methods.get_counter(wallet.getAddress()).simulate({ from: wallet.getAddress() }) |
| 50 | + const counterValue = await valueNotEqual.methods.get_counter(accounts[0].item).simulate({ from: accounts[0].item }) |
74 | 51 | console.log(`Counter value: ${counterValue}`) |
75 | 52 | } |
76 | 53 |
|
|
0 commit comments