@aztec/test-wallet 0.0.1-commit.0208eb9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/bundle.d.ts +4 -0
- package/dest/bundle.d.ts.map +1 -0
- package/dest/bundle.js +2 -0
- package/dest/lazy.d.ts +4 -0
- package/dest/lazy.d.ts.map +1 -0
- package/dest/lazy.js +2 -0
- package/dest/server.d.ts +4 -0
- package/dest/server.d.ts.map +1 -0
- package/dest/server.js +2 -0
- package/dest/utils.d.ts +64 -0
- package/dest/utils.d.ts.map +1 -0
- package/dest/utils.js +83 -0
- package/dest/wallet/bundle.d.ts +29 -0
- package/dest/wallet/bundle.d.ts.map +1 -0
- package/dest/wallet/bundle.js +78 -0
- package/dest/wallet/lazy.d.ts +29 -0
- package/dest/wallet/lazy.d.ts.map +1 -0
- package/dest/wallet/lazy.js +79 -0
- package/dest/wallet/server.d.ts +29 -0
- package/dest/wallet/server.d.ts.map +1 -0
- package/dest/wallet/server.js +78 -0
- package/dest/wallet/test_wallet.d.ts +163 -0
- package/dest/wallet/test_wallet.d.ts.map +1 -0
- package/dest/wallet/test_wallet.js +202 -0
- package/package.json +97 -0
- package/src/bundle.ts +8 -0
- package/src/lazy.ts +8 -0
- package/src/server.ts +8 -0
- package/src/utils.ts +146 -0
- package/src/wallet/bundle.ts +91 -0
- package/src/wallet/lazy.ts +92 -0
- package/src/wallet/server.ts +91 -0
- package/src/wallet/test_wallet.ts +306 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import type { ContractArtifact } from '@aztec/aztec.js/abi';
|
|
2
|
+
import { type Account, type AccountContract } from '@aztec/aztec.js/account';
|
|
3
|
+
import { type CallIntent, type ContractFunctionInteractionCallIntent, type IntentInnerHash, SetPublicAuthwitContractInteraction } from '@aztec/aztec.js/authorization';
|
|
4
|
+
import { AccountManager, type SendOptions, type SimulateOptions } from '@aztec/aztec.js/wallet';
|
|
5
|
+
import { Fq, Fr } from '@aztec/foundation/curves/bn254';
|
|
6
|
+
import { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
7
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
8
|
+
import type { ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
9
|
+
import type { NoteDao, NotesFilter } from '@aztec/stdlib/note';
|
|
10
|
+
import type { BlockHeader, TxHash, TxReceipt, TxSimulationResult } from '@aztec/stdlib/tx';
|
|
11
|
+
import { ExecutionPayload } from '@aztec/stdlib/tx';
|
|
12
|
+
import { BaseWallet } from '@aztec/wallet-sdk/base-wallet';
|
|
13
|
+
import { ProvenTx } from '../utils.js';
|
|
14
|
+
/**
|
|
15
|
+
* Data for generating an account.
|
|
16
|
+
*/
|
|
17
|
+
export interface AccountData {
|
|
18
|
+
/**
|
|
19
|
+
* Secret to derive the keys for the account.
|
|
20
|
+
*/
|
|
21
|
+
secret: Fr;
|
|
22
|
+
/**
|
|
23
|
+
* Contract address salt.
|
|
24
|
+
*/
|
|
25
|
+
salt: Fr;
|
|
26
|
+
/**
|
|
27
|
+
* Contract that backs the account.
|
|
28
|
+
*/
|
|
29
|
+
contract: AccountContract;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Wallet implementation that stores accounts in memory and allows allows their creation
|
|
33
|
+
* from the outside (which is something actual wallets shouldn't allow!)
|
|
34
|
+
* It is intended to be used in e2e tests.
|
|
35
|
+
*/
|
|
36
|
+
export declare abstract class BaseTestWallet extends BaseWallet {
|
|
37
|
+
protected accounts: Map<string, Account>;
|
|
38
|
+
/**
|
|
39
|
+
* Toggle for running "simulated simulations" when calling simulateTx.
|
|
40
|
+
*
|
|
41
|
+
* Terminology:
|
|
42
|
+
* - "simulation": run private circuits normally and then run the kernel in a simulated (brillig) mode on ACVM.
|
|
43
|
+
* No kernel witnesses are generated, but protocol rules are checked.
|
|
44
|
+
* - "simulated simulation": skip running kernels in ACVM altogether and emulate their behavior in TypeScript
|
|
45
|
+
* (akin to generateSimulatedProvingResult). We mutate public inputs like the kernels would and can swap in
|
|
46
|
+
* fake/private bytecode or accounts for tests. This is much faster but is not usable in situations where we
|
|
47
|
+
* need kernel witnesses.
|
|
48
|
+
*
|
|
49
|
+
* When this flag is true, simulateTx constructs a request using a fake account (and accepts contract overrides
|
|
50
|
+
* on the input) and the PXE emulates kernel effects without generating kernel witnesses. When false, simulateTx
|
|
51
|
+
* defers to the standard simulation path.
|
|
52
|
+
*/
|
|
53
|
+
private simulatedSimulations;
|
|
54
|
+
/** Enable the "simulated simulation" path for simulateTx. */
|
|
55
|
+
enableSimulatedSimulations(): void;
|
|
56
|
+
/** Disable the "simulated simulation" path for simulateTx. */
|
|
57
|
+
disableSimulatedSimulations(): void;
|
|
58
|
+
setMinFeePadding(value?: number): void;
|
|
59
|
+
protected getAccountFromAddress(address: AztecAddress): Promise<Account>;
|
|
60
|
+
getAccounts(): Promise<{
|
|
61
|
+
alias: string;
|
|
62
|
+
item: AztecAddress;
|
|
63
|
+
}[]>;
|
|
64
|
+
/**
|
|
65
|
+
* Creates a new account with the provided account data or generates random values and uses SchnorrAccountContract
|
|
66
|
+
* if not provided.
|
|
67
|
+
*
|
|
68
|
+
* @param accountData - Optional account configuration containing secret, salt and account contract.
|
|
69
|
+
* @returns A new AccountManager instance for the created account
|
|
70
|
+
*/
|
|
71
|
+
createAccount(accountData?: AccountData): Promise<AccountManager>;
|
|
72
|
+
abstract createSchnorrAccount(secret: Fr, salt: Fr, signingKey?: Fq): Promise<AccountManager>;
|
|
73
|
+
abstract createECDSARAccount(secret: Fr, salt: Fr, signingKey: Buffer): Promise<AccountManager>;
|
|
74
|
+
abstract createECDSAKAccount(secret: Fr, salt: Fr, signingKey: Buffer): Promise<AccountManager>;
|
|
75
|
+
/**
|
|
76
|
+
* Lookup the validity of an authwit in private and public contexts.
|
|
77
|
+
*
|
|
78
|
+
* Uses the chain id and version of the wallet.
|
|
79
|
+
*
|
|
80
|
+
* @param wallet - The wallet use to simulate and read the public data
|
|
81
|
+
* @param onBehalfOf - The address of the "approver"
|
|
82
|
+
* @param intent - The consumer and inner hash or the caller and action to lookup
|
|
83
|
+
* @param witness - The computed authentication witness to check
|
|
84
|
+
* @returns - A struct containing the validity of the authwit in private and public contexts.
|
|
85
|
+
*/
|
|
86
|
+
lookupValidity(onBehalfOf: AztecAddress, intent: IntentInnerHash | CallIntent | ContractFunctionInteractionCallIntent, witness: AuthWitness): Promise<{
|
|
87
|
+
/** boolean flag indicating if the authwit is valid in private context */
|
|
88
|
+
isValidInPrivate: boolean;
|
|
89
|
+
/** boolean flag indicating if the authwit is valid in public context */
|
|
90
|
+
isValidInPublic: boolean;
|
|
91
|
+
}>;
|
|
92
|
+
/**
|
|
93
|
+
* Returns an interaction that can be used to set the authorization status
|
|
94
|
+
* of an intent
|
|
95
|
+
* @param from - The address authorizing/revoking the action
|
|
96
|
+
* @param messageHashOrIntent - The action to authorize/revoke
|
|
97
|
+
* @param authorized - Whether the action can be performed or not
|
|
98
|
+
*/
|
|
99
|
+
setPublicAuthWit(from: AztecAddress, messageHashOrIntent: Fr | IntentInnerHash | CallIntent | ContractFunctionInteractionCallIntent, authorized: boolean): Promise<SetPublicAuthwitContractInteraction>;
|
|
100
|
+
/**
|
|
101
|
+
* Creates and returns an authwit according the the rules
|
|
102
|
+
* of the provided account. This authwit can be verified
|
|
103
|
+
* by the account contract
|
|
104
|
+
* @param from - The address authorizing the action
|
|
105
|
+
* @param intent - The action to authorize
|
|
106
|
+
*/
|
|
107
|
+
createAuthWit(from: AztecAddress, intent: IntentInnerHash | CallIntent | ContractFunctionInteractionCallIntent): Promise<AuthWitness>;
|
|
108
|
+
/**
|
|
109
|
+
* Creates a stub account that impersonates the given address, allowing kernelless simulations
|
|
110
|
+
* to bypass the account's authorization mechanisms via contract overrides.
|
|
111
|
+
* @param address - The address of the account to impersonate
|
|
112
|
+
* @returns The stub account, contract instance, and artifact for simulation
|
|
113
|
+
*/
|
|
114
|
+
abstract getFakeAccountDataFor(address: AztecAddress): Promise<{
|
|
115
|
+
account: Account;
|
|
116
|
+
instance: ContractInstanceWithAddress;
|
|
117
|
+
artifact: ContractArtifact;
|
|
118
|
+
}>;
|
|
119
|
+
simulateTx(executionPayload: ExecutionPayload, opts: SimulateOptions): Promise<TxSimulationResult>;
|
|
120
|
+
/**
|
|
121
|
+
* A utility to prove a transaction using this wallet and return it to be sent by a different entity on their own accord
|
|
122
|
+
*
|
|
123
|
+
* Note that this should not be used in production code since a proven transaction could be sent to a malicious
|
|
124
|
+
* node to index and track. It also makes it very difficult for the wallet to keep track of the interaction.
|
|
125
|
+
* @param exec - The execution payload to prove.
|
|
126
|
+
* @param opts - The options to configure the interaction
|
|
127
|
+
* @returns - A proven tx ready to be sent to the network
|
|
128
|
+
*/
|
|
129
|
+
proveTx(exec: ExecutionPayload, opts: Omit<SendOptions, 'wait'>): Promise<ProvenTx>;
|
|
130
|
+
/**
|
|
131
|
+
* Retrieves the transaction receipt for a given transaction hash.
|
|
132
|
+
* This is a passthrough to the underlying node, provided for convenience in testing.
|
|
133
|
+
* @param txHash - The hash of the transaction.
|
|
134
|
+
* @returns The transaction receipt.
|
|
135
|
+
*/
|
|
136
|
+
getTxReceipt(txHash: TxHash): Promise<TxReceipt>;
|
|
137
|
+
/**
|
|
138
|
+
* A debugging utility to get notes based on the provided filter.
|
|
139
|
+
*
|
|
140
|
+
* Note that this should not be used in production code because the structure of notes is considered to be
|
|
141
|
+
* an implementation detail of contracts. This is only meant to be used for debugging purposes. If you need to obtain
|
|
142
|
+
* note-related information in production code, please implement a custom utility function on your contract and call
|
|
143
|
+
* that function instead (e.g. `get_balance(owner: AztecAddress) -> u128` utility function on a Token contract).
|
|
144
|
+
*
|
|
145
|
+
* @param filter - The filter to apply to the notes.
|
|
146
|
+
* @returns The requested notes.
|
|
147
|
+
*/
|
|
148
|
+
getNotes(filter: NotesFilter): Promise<NoteDao[]>;
|
|
149
|
+
/** Returns the block header up to which the wallet has synced. */
|
|
150
|
+
getSyncedBlockHeader(): Promise<BlockHeader>;
|
|
151
|
+
/**
|
|
152
|
+
* Triggers a sync of the wallet with the node to update the latest block header.
|
|
153
|
+
* Blocks until the sync is complete.
|
|
154
|
+
*/
|
|
155
|
+
sync(): Promise<void>;
|
|
156
|
+
/**
|
|
157
|
+
* Stops the internal job queue.
|
|
158
|
+
*
|
|
159
|
+
* This function is typically used when tearing down tests.
|
|
160
|
+
*/
|
|
161
|
+
stop(): Promise<void>;
|
|
162
|
+
}
|
|
163
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdF93YWxsZXQuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy93YWxsZXQvdGVzdF93YWxsZXQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsT0FBTyxLQUFLLEVBQUUsZ0JBQWdCLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQUM1RCxPQUFPLEVBQUUsS0FBSyxPQUFPLEVBQUUsS0FBSyxlQUFlLEVBQXFCLE1BQU0seUJBQXlCLENBQUM7QUFDaEcsT0FBTyxFQUNMLEtBQUssVUFBVSxFQUNmLEtBQUsscUNBQXFDLEVBQzFDLEtBQUssZUFBZSxFQUNwQixtQ0FBbUMsRUFJcEMsTUFBTSwrQkFBK0IsQ0FBQztBQUN2QyxPQUFPLEVBQUUsY0FBYyxFQUFFLEtBQUssV0FBVyxFQUFFLEtBQUssZUFBZSxFQUFFLE1BQU0sd0JBQXdCLENBQUM7QUFFaEcsT0FBTyxFQUFFLEVBQUUsRUFBRSxFQUFFLEVBQUUsTUFBTSxnQ0FBZ0MsQ0FBQztBQUV4RCxPQUFPLEVBQUUsV0FBVyxFQUFFLE1BQU0sNEJBQTRCLENBQUM7QUFDekQsT0FBTyxFQUFFLFlBQVksRUFBRSxNQUFNLDZCQUE2QixDQUFDO0FBQzNELE9BQU8sS0FBSyxFQUFFLDJCQUEyQixFQUFFLE1BQ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SchnorrAccountContract } from '@aztec/accounts/schnorr';
|
|
2
|
+
import { SignerlessAccount } from '@aztec/aztec.js/account';
|
|
3
|
+
import { SetPublicAuthwitContractInteraction, computeInnerAuthWitHashFromAction, isContractFunctionInteractionCallIntent, lookupValidity } from '@aztec/aztec.js/authorization';
|
|
4
|
+
import { AccountManager } from '@aztec/aztec.js/wallet';
|
|
5
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
6
|
+
import { GrumpkinScalar } from '@aztec/foundation/curves/grumpkin';
|
|
7
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
8
|
+
import { mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
9
|
+
import { BaseWallet } from '@aztec/wallet-sdk/base-wallet';
|
|
10
|
+
import { ProvenTx } from '../utils.js';
|
|
11
|
+
/**
|
|
12
|
+
* Wallet implementation that stores accounts in memory and allows allows their creation
|
|
13
|
+
* from the outside (which is something actual wallets shouldn't allow!)
|
|
14
|
+
* It is intended to be used in e2e tests.
|
|
15
|
+
*/ export class BaseTestWallet extends BaseWallet {
|
|
16
|
+
accounts = new Map();
|
|
17
|
+
/**
|
|
18
|
+
* Toggle for running "simulated simulations" when calling simulateTx.
|
|
19
|
+
*
|
|
20
|
+
* Terminology:
|
|
21
|
+
* - "simulation": run private circuits normally and then run the kernel in a simulated (brillig) mode on ACVM.
|
|
22
|
+
* No kernel witnesses are generated, but protocol rules are checked.
|
|
23
|
+
* - "simulated simulation": skip running kernels in ACVM altogether and emulate their behavior in TypeScript
|
|
24
|
+
* (akin to generateSimulatedProvingResult). We mutate public inputs like the kernels would and can swap in
|
|
25
|
+
* fake/private bytecode or accounts for tests. This is much faster but is not usable in situations where we
|
|
26
|
+
* need kernel witnesses.
|
|
27
|
+
*
|
|
28
|
+
* When this flag is true, simulateTx constructs a request using a fake account (and accepts contract overrides
|
|
29
|
+
* on the input) and the PXE emulates kernel effects without generating kernel witnesses. When false, simulateTx
|
|
30
|
+
* defers to the standard simulation path.
|
|
31
|
+
*/ simulatedSimulations = false;
|
|
32
|
+
/** Enable the "simulated simulation" path for simulateTx. */ enableSimulatedSimulations() {
|
|
33
|
+
this.simulatedSimulations = true;
|
|
34
|
+
}
|
|
35
|
+
/** Disable the "simulated simulation" path for simulateTx. */ disableSimulatedSimulations() {
|
|
36
|
+
this.simulatedSimulations = false;
|
|
37
|
+
}
|
|
38
|
+
setMinFeePadding(value) {
|
|
39
|
+
this.minFeePadding = value ?? 0.5;
|
|
40
|
+
}
|
|
41
|
+
getAccountFromAddress(address) {
|
|
42
|
+
let account;
|
|
43
|
+
if (address.equals(AztecAddress.ZERO)) {
|
|
44
|
+
account = new SignerlessAccount();
|
|
45
|
+
} else {
|
|
46
|
+
account = this.accounts.get(address?.toString() ?? '');
|
|
47
|
+
}
|
|
48
|
+
if (!account) {
|
|
49
|
+
throw new Error(`Account not found in wallet for address: ${address}`);
|
|
50
|
+
}
|
|
51
|
+
return Promise.resolve(account);
|
|
52
|
+
}
|
|
53
|
+
getAccounts() {
|
|
54
|
+
return Promise.resolve(Array.from(this.accounts.values()).map((acc)=>({
|
|
55
|
+
alias: '',
|
|
56
|
+
item: acc.getAddress()
|
|
57
|
+
})));
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Creates a new account with the provided account data or generates random values and uses SchnorrAccountContract
|
|
61
|
+
* if not provided.
|
|
62
|
+
*
|
|
63
|
+
* @param accountData - Optional account configuration containing secret, salt and account contract.
|
|
64
|
+
* @returns A new AccountManager instance for the created account
|
|
65
|
+
*/ async createAccount(accountData) {
|
|
66
|
+
// Generate random values if not provided
|
|
67
|
+
const secret = accountData?.secret ?? Fr.random();
|
|
68
|
+
const salt = accountData?.salt ?? Fr.random();
|
|
69
|
+
// Use SchnorrAccountContract if not provided
|
|
70
|
+
const contract = accountData?.contract ?? new SchnorrAccountContract(GrumpkinScalar.random());
|
|
71
|
+
const accountManager = await AccountManager.create(this, secret, contract, salt);
|
|
72
|
+
const instance = accountManager.getInstance();
|
|
73
|
+
const artifact = await contract.getContractArtifact();
|
|
74
|
+
await this.registerContract(instance, artifact, secret);
|
|
75
|
+
this.accounts.set(accountManager.address.toString(), await accountManager.getAccount());
|
|
76
|
+
return accountManager;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Lookup the validity of an authwit in private and public contexts.
|
|
80
|
+
*
|
|
81
|
+
* Uses the chain id and version of the wallet.
|
|
82
|
+
*
|
|
83
|
+
* @param wallet - The wallet use to simulate and read the public data
|
|
84
|
+
* @param onBehalfOf - The address of the "approver"
|
|
85
|
+
* @param intent - The consumer and inner hash or the caller and action to lookup
|
|
86
|
+
* @param witness - The computed authentication witness to check
|
|
87
|
+
* @returns - A struct containing the validity of the authwit in private and public contexts.
|
|
88
|
+
*/ lookupValidity(onBehalfOf, intent, witness) {
|
|
89
|
+
return lookupValidity(this, onBehalfOf, intent, witness);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Returns an interaction that can be used to set the authorization status
|
|
93
|
+
* of an intent
|
|
94
|
+
* @param from - The address authorizing/revoking the action
|
|
95
|
+
* @param messageHashOrIntent - The action to authorize/revoke
|
|
96
|
+
* @param authorized - Whether the action can be performed or not
|
|
97
|
+
*/ setPublicAuthWit(from, messageHashOrIntent, authorized) {
|
|
98
|
+
return SetPublicAuthwitContractInteraction.create(this, from, messageHashOrIntent, authorized);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Creates and returns an authwit according the the rules
|
|
102
|
+
* of the provided account. This authwit can be verified
|
|
103
|
+
* by the account contract
|
|
104
|
+
* @param from - The address authorizing the action
|
|
105
|
+
* @param intent - The action to authorize
|
|
106
|
+
*/ async createAuthWit(from, intent) {
|
|
107
|
+
const account = await this.getAccountFromAddress(from);
|
|
108
|
+
const chainInfo = await this.getChainInfo();
|
|
109
|
+
let intentInnerHash;
|
|
110
|
+
if ('caller' in intent) {
|
|
111
|
+
const call = isContractFunctionInteractionCallIntent(intent) ? await intent.action.getFunctionCall() : intent.call;
|
|
112
|
+
const innerHash = await computeInnerAuthWitHashFromAction(intent.caller, call);
|
|
113
|
+
intentInnerHash = {
|
|
114
|
+
innerHash,
|
|
115
|
+
consumer: call.to
|
|
116
|
+
};
|
|
117
|
+
} else {
|
|
118
|
+
intentInnerHash = intent;
|
|
119
|
+
}
|
|
120
|
+
return account.createAuthWit(intentInnerHash, chainInfo);
|
|
121
|
+
}
|
|
122
|
+
async simulateTx(executionPayload, opts) {
|
|
123
|
+
if (!this.simulatedSimulations) {
|
|
124
|
+
return super.simulateTx(executionPayload, opts);
|
|
125
|
+
} else {
|
|
126
|
+
const feeOptions = opts.fee?.estimateGas ? await this.completeFeeOptionsForEstimation(opts.from, executionPayload.feePayer, opts.fee?.gasSettings) : await this.completeFeeOptions(opts.from, executionPayload.feePayer, opts.fee?.gasSettings);
|
|
127
|
+
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
128
|
+
const executionOptions = {
|
|
129
|
+
txNonce: Fr.random(),
|
|
130
|
+
cancellable: this.cancellableTransactions,
|
|
131
|
+
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions
|
|
132
|
+
};
|
|
133
|
+
const finalExecutionPayload = feeExecutionPayload ? mergeExecutionPayloads([
|
|
134
|
+
feeExecutionPayload,
|
|
135
|
+
executionPayload
|
|
136
|
+
]) : executionPayload;
|
|
137
|
+
const { account: fromAccount, instance, artifact } = await this.getFakeAccountDataFor(opts.from);
|
|
138
|
+
const chainInfo = await this.getChainInfo();
|
|
139
|
+
const txRequest = await fromAccount.createTxExecutionRequest(finalExecutionPayload, feeOptions.gasSettings, chainInfo, executionOptions);
|
|
140
|
+
const contractOverrides = {
|
|
141
|
+
[opts.from.toString()]: {
|
|
142
|
+
instance,
|
|
143
|
+
artifact
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
return this.pxe.simulateTx(txRequest, true, true, true, {
|
|
147
|
+
contracts: contractOverrides
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* A utility to prove a transaction using this wallet and return it to be sent by a different entity on their own accord
|
|
153
|
+
*
|
|
154
|
+
* Note that this should not be used in production code since a proven transaction could be sent to a malicious
|
|
155
|
+
* node to index and track. It also makes it very difficult for the wallet to keep track of the interaction.
|
|
156
|
+
* @param exec - The execution payload to prove.
|
|
157
|
+
* @param opts - The options to configure the interaction
|
|
158
|
+
* @returns - A proven tx ready to be sent to the network
|
|
159
|
+
*/ async proveTx(exec, opts) {
|
|
160
|
+
const fee = await this.completeFeeOptions(opts.from, exec.feePayer, opts.fee?.gasSettings);
|
|
161
|
+
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(exec, opts.from, fee);
|
|
162
|
+
const txProvingResult = await this.pxe.proveTx(txRequest);
|
|
163
|
+
return new ProvenTx(this.aztecNode, await txProvingResult.toTx(), txProvingResult.getOffchainEffects(), txProvingResult.stats);
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Retrieves the transaction receipt for a given transaction hash.
|
|
167
|
+
* This is a passthrough to the underlying node, provided for convenience in testing.
|
|
168
|
+
* @param txHash - The hash of the transaction.
|
|
169
|
+
* @returns The transaction receipt.
|
|
170
|
+
*/ getTxReceipt(txHash) {
|
|
171
|
+
return this.aztecNode.getTxReceipt(txHash);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* A debugging utility to get notes based on the provided filter.
|
|
175
|
+
*
|
|
176
|
+
* Note that this should not be used in production code because the structure of notes is considered to be
|
|
177
|
+
* an implementation detail of contracts. This is only meant to be used for debugging purposes. If you need to obtain
|
|
178
|
+
* note-related information in production code, please implement a custom utility function on your contract and call
|
|
179
|
+
* that function instead (e.g. `get_balance(owner: AztecAddress) -> u128` utility function on a Token contract).
|
|
180
|
+
*
|
|
181
|
+
* @param filter - The filter to apply to the notes.
|
|
182
|
+
* @returns The requested notes.
|
|
183
|
+
*/ getNotes(filter) {
|
|
184
|
+
return this.pxe.debug.getNotes(filter);
|
|
185
|
+
}
|
|
186
|
+
/** Returns the block header up to which the wallet has synced. */ getSyncedBlockHeader() {
|
|
187
|
+
return this.pxe.debug.getSyncedBlockHeader();
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Triggers a sync of the wallet with the node to update the latest block header.
|
|
191
|
+
* Blocks until the sync is complete.
|
|
192
|
+
*/ sync() {
|
|
193
|
+
return this.pxe.debug.sync();
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Stops the internal job queue.
|
|
197
|
+
*
|
|
198
|
+
* This function is typically used when tearing down tests.
|
|
199
|
+
*/ stop() {
|
|
200
|
+
return this.pxe.stop();
|
|
201
|
+
}
|
|
202
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aztec/test-wallet",
|
|
3
|
+
"homepage": "https://github.com/AztecProtocol/aztec-packages/tree/master/yarn-project/test-wallet",
|
|
4
|
+
"version": "0.0.1-commit.0208eb9",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
"./client/bundle": "./dest/bundle.js",
|
|
8
|
+
"./client/lazy": "./dest/lazy.js",
|
|
9
|
+
"./server": "./dest/server.js"
|
|
10
|
+
},
|
|
11
|
+
"typedocOptions": {
|
|
12
|
+
"entryPoints": [
|
|
13
|
+
"./src/index.ts"
|
|
14
|
+
],
|
|
15
|
+
"tsconfig": "./tsconfig.json"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "yarn clean && ../scripts/tsc.sh",
|
|
19
|
+
"build:dev": "../scripts/tsc.sh --watch",
|
|
20
|
+
"build:ts": "../scripts/tsc.sh",
|
|
21
|
+
"clean": "rm -rf ./dest .tsbuildinfo",
|
|
22
|
+
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
|
|
23
|
+
},
|
|
24
|
+
"inherits": [
|
|
25
|
+
"../package.common.json"
|
|
26
|
+
],
|
|
27
|
+
"jest": {
|
|
28
|
+
"moduleNameMapper": {
|
|
29
|
+
"^(\\.{1,2}/.*)\\.[cm]?js$": "$1"
|
|
30
|
+
},
|
|
31
|
+
"testRegex": "./src/.*\\.test\\.(js|mjs|ts)$",
|
|
32
|
+
"rootDir": "./src",
|
|
33
|
+
"transform": {
|
|
34
|
+
"^.+\\.tsx?$": [
|
|
35
|
+
"@swc/jest",
|
|
36
|
+
{
|
|
37
|
+
"jsc": {
|
|
38
|
+
"parser": {
|
|
39
|
+
"syntax": "typescript",
|
|
40
|
+
"decorators": true
|
|
41
|
+
},
|
|
42
|
+
"transform": {
|
|
43
|
+
"decoratorVersion": "2022-03"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
},
|
|
49
|
+
"extensionsToTreatAsEsm": [
|
|
50
|
+
".ts"
|
|
51
|
+
],
|
|
52
|
+
"reporters": [
|
|
53
|
+
"default"
|
|
54
|
+
],
|
|
55
|
+
"testTimeout": 120000,
|
|
56
|
+
"setupFiles": [
|
|
57
|
+
"../../foundation/src/jest/setup.mjs"
|
|
58
|
+
],
|
|
59
|
+
"testEnvironment": "../../foundation/src/jest/env.mjs",
|
|
60
|
+
"setupFilesAfterEnv": [
|
|
61
|
+
"../../foundation/src/jest/setupAfterEnv.mjs"
|
|
62
|
+
]
|
|
63
|
+
},
|
|
64
|
+
"dependencies": {
|
|
65
|
+
"@aztec/accounts": "0.0.1-commit.0208eb9",
|
|
66
|
+
"@aztec/aztec.js": "0.0.1-commit.0208eb9",
|
|
67
|
+
"@aztec/entrypoints": "0.0.1-commit.0208eb9",
|
|
68
|
+
"@aztec/foundation": "0.0.1-commit.0208eb9",
|
|
69
|
+
"@aztec/noir-contracts.js": "0.0.1-commit.0208eb9",
|
|
70
|
+
"@aztec/pxe": "0.0.1-commit.0208eb9",
|
|
71
|
+
"@aztec/stdlib": "0.0.1-commit.0208eb9",
|
|
72
|
+
"@aztec/wallet-sdk": "0.0.1-commit.0208eb9"
|
|
73
|
+
},
|
|
74
|
+
"devDependencies": {
|
|
75
|
+
"@jest/globals": "^30.0.0",
|
|
76
|
+
"@types/jest": "^30.0.0",
|
|
77
|
+
"@types/node": "^22.15.17",
|
|
78
|
+
"@typescript/native-preview": "7.0.0-dev.20260113.1",
|
|
79
|
+
"jest": "^30.0.0",
|
|
80
|
+
"jest-mock-extended": "^4.0.0",
|
|
81
|
+
"resolve-typescript-plugin": "^2.0.1",
|
|
82
|
+
"ts-loader": "^9.5.4",
|
|
83
|
+
"ts-node": "^10.9.1",
|
|
84
|
+
"typescript": "^5.3.3",
|
|
85
|
+
"util": "^0.12.5"
|
|
86
|
+
},
|
|
87
|
+
"files": [
|
|
88
|
+
"dest",
|
|
89
|
+
"src",
|
|
90
|
+
"!*.test.*",
|
|
91
|
+
"artifacts"
|
|
92
|
+
],
|
|
93
|
+
"types": "./dest/index.d.ts",
|
|
94
|
+
"engines": {
|
|
95
|
+
"node": ">=20.10"
|
|
96
|
+
}
|
|
97
|
+
}
|
package/src/bundle.ts
ADDED
package/src/lazy.ts
ADDED
package/src/server.ts
ADDED
package/src/utils.ts
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import type { InitialAccountData } from '@aztec/accounts/testing';
|
|
2
|
+
import { getInitialTestAccountsData } from '@aztec/accounts/testing/lazy';
|
|
3
|
+
import { AztecAddress } from '@aztec/aztec.js/addresses';
|
|
4
|
+
import {
|
|
5
|
+
ContractFunctionInteraction,
|
|
6
|
+
DeployMethod,
|
|
7
|
+
type DeployOptions,
|
|
8
|
+
NO_WAIT,
|
|
9
|
+
type NoWait,
|
|
10
|
+
type SendInteractionOptions,
|
|
11
|
+
type WaitOpts,
|
|
12
|
+
toSendOptions,
|
|
13
|
+
} from '@aztec/aztec.js/contracts';
|
|
14
|
+
import { type AztecNode, waitForTx } from '@aztec/aztec.js/node';
|
|
15
|
+
import { SimulationError } from '@aztec/stdlib/errors';
|
|
16
|
+
import { type OffchainEffect, type ProvingStats, Tx, TxHash, type TxReceipt } from '@aztec/stdlib/tx';
|
|
17
|
+
|
|
18
|
+
import { inspect } from 'util';
|
|
19
|
+
|
|
20
|
+
import type { BaseTestWallet } from './wallet/test_wallet.js';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Options for sending a proven transaction.
|
|
24
|
+
*/
|
|
25
|
+
export type ProvenTxSendOpts = {
|
|
26
|
+
/**
|
|
27
|
+
* Whether to wait for the transaction to be mined.
|
|
28
|
+
* - undefined (default): wait with default options and return TxReceipt
|
|
29
|
+
* - WaitOpts object: wait with custom options and return TxReceipt
|
|
30
|
+
* - NO_WAIT: return txHash immediately without waiting
|
|
31
|
+
*/
|
|
32
|
+
wait?: NoWait | WaitOpts;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Return type for ProvenTx.send based on wait option.
|
|
37
|
+
*/
|
|
38
|
+
export type ProvenTxSendReturn<T extends NoWait | WaitOpts | undefined> = T extends NoWait ? TxHash : TxReceipt;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Deploys the SchnorrAccount contracts backed by prefunded addresses
|
|
42
|
+
* at genesis. This can be directly used to pay for transactions in FeeJuice.
|
|
43
|
+
*/
|
|
44
|
+
export async function deployFundedSchnorrAccounts(
|
|
45
|
+
wallet: BaseTestWallet,
|
|
46
|
+
accountsData: InitialAccountData[],
|
|
47
|
+
waitOptions?: WaitOpts,
|
|
48
|
+
) {
|
|
49
|
+
const accountManagers = [];
|
|
50
|
+
// Serial due to https://github.com/AztecProtocol/aztec-packages/issues/12045
|
|
51
|
+
for (let i = 0; i < accountsData.length; i++) {
|
|
52
|
+
const { secret, salt, signingKey } = accountsData[i];
|
|
53
|
+
const accountManager = await wallet.createSchnorrAccount(secret, salt, signingKey);
|
|
54
|
+
const deployMethod = await accountManager.getDeployMethod();
|
|
55
|
+
await deployMethod.send({
|
|
56
|
+
from: AztecAddress.ZERO,
|
|
57
|
+
skipClassPublication: i !== 0, // Publish the contract class at most once.
|
|
58
|
+
wait: waitOptions,
|
|
59
|
+
});
|
|
60
|
+
accountManagers.push(accountManager);
|
|
61
|
+
}
|
|
62
|
+
return accountManagers;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Registers the initial local network accounts in the wallet.
|
|
67
|
+
* @param wallet - Test wallet to use to register the accounts.
|
|
68
|
+
* @returns Addresses of the registered accounts.
|
|
69
|
+
*/
|
|
70
|
+
export async function registerInitialLocalNetworkAccountsInWallet(wallet: BaseTestWallet): Promise<AztecAddress[]> {
|
|
71
|
+
const testAccounts = await getInitialTestAccountsData();
|
|
72
|
+
return Promise.all(
|
|
73
|
+
testAccounts.map(async account => {
|
|
74
|
+
return (await wallet.createSchnorrAccount(account.secret, account.salt, account.signingKey)).address;
|
|
75
|
+
}),
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* A proven transaction that can be sent to the network. Returned by the `prove` method of the test wallet
|
|
80
|
+
*/
|
|
81
|
+
export class ProvenTx extends Tx {
|
|
82
|
+
constructor(
|
|
83
|
+
private node: AztecNode,
|
|
84
|
+
tx: Tx,
|
|
85
|
+
/** The offchain effects emitted during the execution of the transaction. */
|
|
86
|
+
public offchainEffects: OffchainEffect[],
|
|
87
|
+
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
88
|
+
public stats?: ProvingStats,
|
|
89
|
+
) {
|
|
90
|
+
super(tx.getTxHash(), tx.data, tx.chonkProof, tx.contractClassLogFields, tx.publicFunctionCalldata);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Sends the transaction to the network.
|
|
95
|
+
* @param options - Send options including whether to wait.
|
|
96
|
+
* @returns The transaction receipt if waiting, or the transaction hash if not.
|
|
97
|
+
*/
|
|
98
|
+
send(options?: Omit<ProvenTxSendOpts, 'wait'>): Promise<TxReceipt>;
|
|
99
|
+
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
100
|
+
send<W extends ProvenTxSendOpts['wait']>(options: ProvenTxSendOpts & { wait: W }): Promise<ProvenTxSendReturn<W>>;
|
|
101
|
+
async send(options?: ProvenTxSendOpts): Promise<TxHash | TxReceipt> {
|
|
102
|
+
const txHash = this.getTxHash();
|
|
103
|
+
await this.node.sendTx(this).catch(err => {
|
|
104
|
+
throw this.contextualizeError(err, inspect(this));
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
if (options?.wait === NO_WAIT) {
|
|
108
|
+
return txHash;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const waitOpts = typeof options?.wait === 'object' ? options.wait : undefined;
|
|
112
|
+
return await waitForTx(this.node, txHash, waitOpts);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
private contextualizeError(err: Error, ...context: string[]): Error {
|
|
116
|
+
let contextStr = '';
|
|
117
|
+
if (context.length > 0) {
|
|
118
|
+
contextStr = `\nContext:\n${context.join('\n')}`;
|
|
119
|
+
}
|
|
120
|
+
if (err instanceof SimulationError) {
|
|
121
|
+
err.setAztecContext(contextStr);
|
|
122
|
+
}
|
|
123
|
+
return err;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Helper function to prove an interaction via a TestWallet
|
|
129
|
+
* @param wallet - The TestWallet to use
|
|
130
|
+
* @param interaction - The interaction to prove
|
|
131
|
+
* @param options - Either SendInteractionOptions (for ContractFunctionInteraction) or DeployOptions (for DeployMethod)
|
|
132
|
+
* @returns - A proven transaction ready do be sent to the network
|
|
133
|
+
*/
|
|
134
|
+
export async function proveInteraction(
|
|
135
|
+
wallet: BaseTestWallet,
|
|
136
|
+
interaction: ContractFunctionInteraction | DeployMethod,
|
|
137
|
+
options: SendInteractionOptions | DeployOptions,
|
|
138
|
+
) {
|
|
139
|
+
let execPayload;
|
|
140
|
+
if (interaction instanceof DeployMethod) {
|
|
141
|
+
execPayload = await interaction.request(interaction.convertDeployOptionsToRequestOptions(options));
|
|
142
|
+
} else {
|
|
143
|
+
execPayload = await interaction.request(options);
|
|
144
|
+
}
|
|
145
|
+
return wallet.proveTx(execPayload, toSendOptions(options));
|
|
146
|
+
}
|