@aztec/end-to-end 0.0.1-commit.6d63667d → 0.0.1-commit.858058eac
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/bench/client_flows/client_flows_benchmark.d.ts +2 -2
- package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -1
- package/dest/bench/client_flows/client_flows_benchmark.js +1 -1
- package/dest/bench/client_flows/config.d.ts +2 -2
- package/dest/bench/client_flows/config.d.ts.map +1 -1
- package/dest/bench/client_flows/config.js +18 -0
- package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +2 -2
- package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts.map +1 -1
- package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +2 -2
- package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts.map +1 -1
- package/dest/e2e_deploy_contract/deploy_test.d.ts +2 -2
- package/dest/e2e_deploy_contract/deploy_test.d.ts.map +1 -1
- package/dest/e2e_epochs/epochs_test.d.ts +1 -1
- package/dest/e2e_epochs/epochs_test.d.ts.map +1 -1
- package/dest/e2e_epochs/epochs_test.js +9 -3
- package/dest/e2e_fees/fees_test.d.ts +2 -2
- package/dest/e2e_fees/fees_test.d.ts.map +1 -1
- package/dest/e2e_p2p/p2p_network.d.ts +2 -2
- package/dest/e2e_p2p/p2p_network.d.ts.map +1 -1
- package/dest/e2e_p2p/shared.d.ts +2 -2
- package/dest/e2e_p2p/shared.d.ts.map +1 -1
- package/dest/e2e_p2p/shared.js +5 -1
- package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.d.ts +2 -0
- package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.d.ts.map +1 -0
- package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.js +184 -0
- package/dest/e2e_storage_proof/fixtures/storage_proof_fixture.d.ts +18 -0
- package/dest/e2e_storage_proof/fixtures/storage_proof_fixture.d.ts.map +1 -0
- package/dest/e2e_storage_proof/fixtures/storage_proof_fixture.js +120 -0
- package/dest/e2e_token_contract/token_contract_test.d.ts +2 -2
- package/dest/e2e_token_contract/token_contract_test.d.ts.map +1 -1
- package/dest/fixtures/e2e_prover_test.d.ts +2 -2
- package/dest/fixtures/e2e_prover_test.d.ts.map +1 -1
- package/dest/fixtures/setup.d.ts +14 -14
- package/dest/fixtures/setup.d.ts.map +1 -1
- package/dest/fixtures/setup.js +12 -76
- package/dest/fixtures/setup_p2p_test.d.ts +10 -5
- package/dest/fixtures/setup_p2p_test.d.ts.map +1 -1
- package/dest/fixtures/setup_p2p_test.js +6 -3
- package/dest/shared/submit-transactions.d.ts +2 -2
- package/dest/shared/submit-transactions.d.ts.map +1 -1
- package/dest/shared/uniswap_l1_l2.d.ts +1 -1
- package/dest/shared/uniswap_l1_l2.d.ts.map +1 -1
- package/dest/shared/uniswap_l1_l2.js +1 -1
- package/dest/spartan/setup_test_wallets.d.ts +2 -2
- package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
- package/dest/spartan/setup_test_wallets.js +3 -1
- package/dest/test-wallet/test_wallet.d.ts +82 -0
- package/dest/test-wallet/test_wallet.d.ts.map +1 -0
- package/dest/test-wallet/test_wallet.js +213 -0
- package/dest/test-wallet/utils.d.ts +41 -0
- package/dest/test-wallet/utils.d.ts.map +1 -0
- package/dest/test-wallet/utils.js +71 -0
- package/package.json +40 -39
- package/src/bench/client_flows/client_flows_benchmark.ts +6 -6
- package/src/bench/client_flows/config.ts +9 -1
- package/src/bench/utils.ts +1 -1
- package/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +2 -2
- package/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +4 -4
- package/src/e2e_deploy_contract/deploy_test.ts +3 -3
- package/src/e2e_epochs/epochs_test.ts +13 -3
- package/src/e2e_fees/bridging_race.notest.ts +1 -1
- package/src/e2e_fees/fees_test.ts +7 -7
- package/src/e2e_nested_contract/nested_contract_test.ts +1 -1
- package/src/e2e_p2p/inactivity_slash_test.ts +4 -4
- package/src/e2e_p2p/p2p_network.ts +5 -5
- package/src/e2e_p2p/reqresp/utils.ts +4 -4
- package/src/e2e_p2p/shared.ts +3 -1
- package/src/e2e_storage_proof/fixtures/storage_proof.json +915 -0
- package/src/e2e_storage_proof/fixtures/storage_proof_fetcher.ts +190 -0
- package/src/e2e_storage_proof/fixtures/storage_proof_fixture.ts +173 -0
- package/src/e2e_token_contract/token_contract_test.ts +2 -2
- package/src/fixtures/e2e_prover_test.ts +4 -4
- package/src/fixtures/setup.ts +22 -106
- package/src/fixtures/setup_p2p_test.ts +16 -7
- package/src/shared/submit-transactions.ts +2 -1
- package/src/shared/uniswap_l1_l2.ts +2 -2
- package/src/spartan/setup_test_wallets.ts +3 -1
- package/src/test-wallet/test_wallet.ts +296 -0
- package/src/test-wallet/utils.ts +112 -0
|
@@ -83,9 +83,17 @@ export async function createNodes(
|
|
|
83
83
|
return nodes;
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
/**
|
|
86
|
+
/** Extended config type for createNode with test-specific overrides. */
|
|
87
|
+
export type CreateNodeConfig = AztecNodeConfig & {
|
|
88
|
+
/** Whether to skip starting the sequencer. */
|
|
89
|
+
dontStartSequencer?: boolean;
|
|
90
|
+
/** Override the private key (instead of deriving from addressIndex). */
|
|
91
|
+
validatorPrivateKey?: `0x${string}`;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
/** Creates a P2P enabled instance of Aztec Node Service with a validator. */
|
|
87
95
|
export async function createNode(
|
|
88
|
-
config:
|
|
96
|
+
config: CreateNodeConfig,
|
|
89
97
|
dateProvider: DateProvider,
|
|
90
98
|
tcpPort: number,
|
|
91
99
|
bootstrapNode: string | undefined,
|
|
@@ -187,20 +195,21 @@ export async function createP2PConfig(
|
|
|
187
195
|
}
|
|
188
196
|
|
|
189
197
|
export async function createValidatorConfig(
|
|
190
|
-
config:
|
|
198
|
+
config: CreateNodeConfig,
|
|
191
199
|
bootstrapNodeEnr?: string,
|
|
192
200
|
port?: number,
|
|
193
201
|
addressIndex: number | number[] = 1,
|
|
194
202
|
dataDirectory?: string,
|
|
195
203
|
) {
|
|
196
204
|
const addressIndices = Array.isArray(addressIndex) ? addressIndex : [addressIndex];
|
|
197
|
-
if (addressIndices.length === 0) {
|
|
205
|
+
if (addressIndices.length === 0 && !config.validatorPrivateKey) {
|
|
198
206
|
throw new Error('At least one address index must be provided to create a validator config');
|
|
199
207
|
}
|
|
200
208
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
209
|
+
// Use override private key if provided, otherwise derive from address indices
|
|
210
|
+
const attesterPrivateKeys = config.validatorPrivateKey
|
|
211
|
+
? [config.validatorPrivateKey]
|
|
212
|
+
: addressIndices.map(index => bufferToHex(getPrivateKeyFromIndex(ATTESTER_PRIVATE_KEYS_START_INDEX + index)!));
|
|
204
213
|
const p2pConfig = await createP2PConfig(config, bootstrapNodeEnr, port, dataDirectory);
|
|
205
214
|
const nodeConfig: AztecNodeConfig = {
|
|
206
215
|
...config,
|
|
@@ -4,7 +4,8 @@ import { Fr, GrumpkinScalar } from '@aztec/aztec.js/fields';
|
|
|
4
4
|
import type { Logger } from '@aztec/aztec.js/log';
|
|
5
5
|
import { TxHash, type TxReceipt, TxStatus } from '@aztec/aztec.js/tx';
|
|
6
6
|
import { times } from '@aztec/foundation/collection';
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
import type { TestWallet } from '../test-wallet/test_wallet.js';
|
|
8
9
|
|
|
9
10
|
// submits a set of transactions to the provided Wallet
|
|
10
11
|
export const submitTxsTo = async (
|
|
@@ -17,12 +17,12 @@ import { InboxAbi, UniswapPortalAbi, UniswapPortalBytecode } from '@aztec/l1-art
|
|
|
17
17
|
import { UniswapContract } from '@aztec/noir-contracts.js/Uniswap';
|
|
18
18
|
import { computeL2ToL1MessageHash } from '@aztec/stdlib/hash';
|
|
19
19
|
import { computeL2ToL1MembershipWitness } from '@aztec/stdlib/messaging';
|
|
20
|
-
import type { TestWallet } from '@aztec/test-wallet/server';
|
|
21
20
|
|
|
22
21
|
import { jest } from '@jest/globals';
|
|
23
22
|
import { type GetContractReturnType, getContract, parseEther, toFunctionSelector } from 'viem';
|
|
24
23
|
|
|
25
24
|
import { type EndToEndContext, ensureAccountContractsPublished } from '../fixtures/utils.js';
|
|
25
|
+
import type { TestWallet } from '../test-wallet/test_wallet.js';
|
|
26
26
|
import { CrossChainTestHarness } from './cross_chain_test_harness.js';
|
|
27
27
|
|
|
28
28
|
// PSA: This tests works on forked mainnet. There is a dump of the data in `dumpedState` such that we
|
|
@@ -84,7 +84,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
84
84
|
|
|
85
85
|
l1Client = deployL1ContractsValues.l1Client;
|
|
86
86
|
|
|
87
|
-
t.watcher
|
|
87
|
+
t.watcher.setIsMarkingAsProven(false);
|
|
88
88
|
|
|
89
89
|
if (Number(await l1Client.getBlockNumber()) < expectedForkBlockNumber) {
|
|
90
90
|
throw new Error('This test must be run on a fork of mainnet with the expected fork block');
|
|
@@ -13,11 +13,13 @@ import type { Logger } from '@aztec/foundation/log';
|
|
|
13
13
|
import { retryUntil } from '@aztec/foundation/retry';
|
|
14
14
|
import { TokenContract } from '@aztec/noir-contracts.js/Token';
|
|
15
15
|
import type { AztecNodeAdmin } from '@aztec/stdlib/interfaces/client';
|
|
16
|
-
import {
|
|
16
|
+
import { registerInitialLocalNetworkAccountsInWallet } from '@aztec/wallets/testing';
|
|
17
17
|
|
|
18
18
|
import { getACVMConfig } from '../fixtures/get_acvm_config.js';
|
|
19
19
|
import { getBBConfig } from '../fixtures/get_bb_config.js';
|
|
20
20
|
import { getSponsoredFPCAddress, registerSponsoredFPC } from '../fixtures/utils.js';
|
|
21
|
+
import { TestWallet } from '../test-wallet/test_wallet.js';
|
|
22
|
+
import { proveInteraction } from '../test-wallet/utils.js';
|
|
21
23
|
|
|
22
24
|
export interface TestAccounts {
|
|
23
25
|
aztecNode: AztecNode;
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import { EcdsaKAccountContract, EcdsaRAccountContract } from '@aztec/accounts/ecdsa';
|
|
2
|
+
import { SchnorrAccountContract } from '@aztec/accounts/schnorr';
|
|
3
|
+
import { StubAccountContractArtifact, createStubAccount } from '@aztec/accounts/stub';
|
|
4
|
+
import { type Account, type AccountContract, SignerlessAccount } from '@aztec/aztec.js/account';
|
|
5
|
+
import {
|
|
6
|
+
type CallIntent,
|
|
7
|
+
type ContractFunctionInteractionCallIntent,
|
|
8
|
+
type IntentInnerHash,
|
|
9
|
+
SetPublicAuthwitContractInteraction,
|
|
10
|
+
computeInnerAuthWitHashFromAction,
|
|
11
|
+
isContractFunctionInteractionCallIntent,
|
|
12
|
+
lookupValidity,
|
|
13
|
+
} from '@aztec/aztec.js/authorization';
|
|
14
|
+
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
15
|
+
import { AccountManager, type SendOptions } from '@aztec/aztec.js/wallet';
|
|
16
|
+
import type { DefaultAccountEntrypointOptions } from '@aztec/entrypoints/account';
|
|
17
|
+
import { Fq, Fr } from '@aztec/foundation/curves/bn254';
|
|
18
|
+
import { GrumpkinScalar } from '@aztec/foundation/curves/grumpkin';
|
|
19
|
+
import { type PXEConfig, getPXEConfig } from '@aztec/pxe/config';
|
|
20
|
+
import { PXE, type PXECreationOptions, createPXE } from '@aztec/pxe/server';
|
|
21
|
+
import { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
22
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
23
|
+
import { getContractInstanceFromInstantiationParams } from '@aztec/stdlib/contract';
|
|
24
|
+
import { deriveSigningKey } from '@aztec/stdlib/keys';
|
|
25
|
+
import type { NoteDao, NotesFilter } from '@aztec/stdlib/note';
|
|
26
|
+
import type { BlockHeader, TxHash, TxReceipt, TxSimulationResult } from '@aztec/stdlib/tx';
|
|
27
|
+
import { ExecutionPayload, mergeExecutionPayloads } from '@aztec/stdlib/tx';
|
|
28
|
+
import { BaseWallet, type FeeOptions } from '@aztec/wallet-sdk/base-wallet';
|
|
29
|
+
|
|
30
|
+
import { AztecNodeProxy, ProvenTx } from './utils.js';
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Data for generating an account.
|
|
34
|
+
*/
|
|
35
|
+
export interface AccountData {
|
|
36
|
+
secret: Fr;
|
|
37
|
+
salt: Fr;
|
|
38
|
+
contract: AccountContract;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Wallet implementation that stores accounts in memory and provides extra debugging
|
|
43
|
+
* utilities
|
|
44
|
+
* It is intended to be used in e2e tests.
|
|
45
|
+
*/
|
|
46
|
+
export class TestWallet extends BaseWallet {
|
|
47
|
+
constructor(
|
|
48
|
+
pxe: PXE,
|
|
49
|
+
private readonly nodeRef: AztecNodeProxy,
|
|
50
|
+
) {
|
|
51
|
+
super(pxe, nodeRef);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
static async create(
|
|
55
|
+
node: AztecNode,
|
|
56
|
+
overridePXEConfig?: Partial<PXEConfig>,
|
|
57
|
+
options: PXECreationOptions = { loggers: {} },
|
|
58
|
+
): Promise<TestWallet> {
|
|
59
|
+
const nodeRef = new AztecNodeProxy(node);
|
|
60
|
+
const pxeConfig = Object.assign(getPXEConfig(), {
|
|
61
|
+
proverEnabled: overridePXEConfig?.proverEnabled ?? false,
|
|
62
|
+
...overridePXEConfig,
|
|
63
|
+
});
|
|
64
|
+
const pxe = await createPXE(nodeRef, pxeConfig, options);
|
|
65
|
+
return new TestWallet(pxe, nodeRef);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Updates the underlying node that this wallet and its PXE communicate with.
|
|
70
|
+
* @param node - The new AztecNode to forward all calls to.
|
|
71
|
+
*/
|
|
72
|
+
updateNode(node: AztecNode): void {
|
|
73
|
+
this.nodeRef.updateTargetNode(node);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
createSchnorrAccount(secret: Fr, salt: Fr, signingKey?: Fq): Promise<AccountManager> {
|
|
77
|
+
signingKey = signingKey ?? deriveSigningKey(secret);
|
|
78
|
+
const accountData = {
|
|
79
|
+
secret,
|
|
80
|
+
salt,
|
|
81
|
+
contract: new SchnorrAccountContract(signingKey),
|
|
82
|
+
};
|
|
83
|
+
return this.createAccount(accountData);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
createECDSARAccount(secret: Fr, salt: Fr, signingKey: Buffer): Promise<AccountManager> {
|
|
87
|
+
const accountData = {
|
|
88
|
+
secret,
|
|
89
|
+
salt,
|
|
90
|
+
contract: new EcdsaRAccountContract(signingKey),
|
|
91
|
+
};
|
|
92
|
+
return this.createAccount(accountData);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
createECDSAKAccount(secret: Fr, salt: Fr, signingKey: Buffer): Promise<AccountManager> {
|
|
96
|
+
const accountData = {
|
|
97
|
+
secret,
|
|
98
|
+
salt,
|
|
99
|
+
contract: new EcdsaKAccountContract(signingKey),
|
|
100
|
+
};
|
|
101
|
+
return this.createAccount(accountData);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async getFakeAccountDataFor(address: AztecAddress) {
|
|
105
|
+
const originalAccount = await this.getAccountFromAddress(address);
|
|
106
|
+
if (originalAccount instanceof SignerlessAccount) {
|
|
107
|
+
throw new Error(`Cannot create fake account data for SignerlessAccount at address: ${address}`);
|
|
108
|
+
}
|
|
109
|
+
const originalAddress = (originalAccount as Account).getCompleteAddress();
|
|
110
|
+
const contractInstance = await this.pxe.getContractInstance(originalAddress.address);
|
|
111
|
+
if (!contractInstance) {
|
|
112
|
+
throw new Error(`No contract instance found for address: ${originalAddress.address}`);
|
|
113
|
+
}
|
|
114
|
+
const stubAccount = createStubAccount(originalAddress);
|
|
115
|
+
const instance = await getContractInstanceFromInstantiationParams(StubAccountContractArtifact, {
|
|
116
|
+
salt: Fr.random(),
|
|
117
|
+
});
|
|
118
|
+
return {
|
|
119
|
+
account: stubAccount,
|
|
120
|
+
instance,
|
|
121
|
+
artifact: StubAccountContractArtifact,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
protected accounts: Map<string, Account> = new Map();
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Toggle for running "simulated simulations" when calling simulateTx.
|
|
128
|
+
*
|
|
129
|
+
* When this flag is true, simulateViaEntrypoint constructs a request using a fake account
|
|
130
|
+
* (and accepts contract overrides on the input) and the PXE emulates kernel effects without
|
|
131
|
+
* generating kernel witnesses. When false, simulateViaEntrypoint defers to the standard
|
|
132
|
+
* simulation path via the real account entrypoint.
|
|
133
|
+
*/
|
|
134
|
+
private simulatedSimulations = false;
|
|
135
|
+
|
|
136
|
+
enableSimulatedSimulations() {
|
|
137
|
+
this.simulatedSimulations = true;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
disableSimulatedSimulations() {
|
|
141
|
+
this.simulatedSimulations = false;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
setMinFeePadding(value?: number) {
|
|
145
|
+
this.minFeePadding = value ?? 0.5;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
protected getAccountFromAddress(address: AztecAddress): Promise<Account> {
|
|
149
|
+
let account: Account | undefined;
|
|
150
|
+
if (address.equals(AztecAddress.ZERO)) {
|
|
151
|
+
account = new SignerlessAccount();
|
|
152
|
+
} else {
|
|
153
|
+
account = this.accounts.get(address?.toString() ?? '');
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (!account) {
|
|
157
|
+
throw new Error(`Account not found in wallet for address: ${address}`);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return Promise.resolve(account);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
getAccounts() {
|
|
164
|
+
return Promise.resolve(Array.from(this.accounts.values()).map(acc => ({ alias: '', item: acc.getAddress() })));
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
async createAccount(accountData?: AccountData): Promise<AccountManager> {
|
|
168
|
+
const secret = accountData?.secret ?? Fr.random();
|
|
169
|
+
const salt = accountData?.salt ?? Fr.random();
|
|
170
|
+
const contract = accountData?.contract ?? new SchnorrAccountContract(GrumpkinScalar.random());
|
|
171
|
+
|
|
172
|
+
const accountManager = await AccountManager.create(this, secret, contract, salt);
|
|
173
|
+
|
|
174
|
+
const instance = accountManager.getInstance();
|
|
175
|
+
const artifact = await contract.getContractArtifact();
|
|
176
|
+
|
|
177
|
+
await this.registerContract(instance, artifact, secret);
|
|
178
|
+
|
|
179
|
+
this.accounts.set(accountManager.address.toString(), await accountManager.getAccount());
|
|
180
|
+
|
|
181
|
+
return accountManager;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
lookupValidity(
|
|
185
|
+
onBehalfOf: AztecAddress,
|
|
186
|
+
intent: IntentInnerHash | CallIntent | ContractFunctionInteractionCallIntent,
|
|
187
|
+
witness: AuthWitness,
|
|
188
|
+
): Promise<{
|
|
189
|
+
isValidInPrivate: boolean;
|
|
190
|
+
isValidInPublic: boolean;
|
|
191
|
+
}> {
|
|
192
|
+
return lookupValidity(this, onBehalfOf, intent, witness);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
public setPublicAuthWit(
|
|
196
|
+
from: AztecAddress,
|
|
197
|
+
messageHashOrIntent: Fr | IntentInnerHash | CallIntent | ContractFunctionInteractionCallIntent,
|
|
198
|
+
authorized: boolean,
|
|
199
|
+
): Promise<SetPublicAuthwitContractInteraction> {
|
|
200
|
+
return SetPublicAuthwitContractInteraction.create(this, from, messageHashOrIntent, authorized);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
public override async createAuthWit(
|
|
204
|
+
from: AztecAddress,
|
|
205
|
+
intent: IntentInnerHash | CallIntent | ContractFunctionInteractionCallIntent,
|
|
206
|
+
): Promise<AuthWitness> {
|
|
207
|
+
const account = await this.getAccountFromAddress(from);
|
|
208
|
+
const chainInfo = await this.getChainInfo();
|
|
209
|
+
let intentInnerHash: IntentInnerHash;
|
|
210
|
+
if ('caller' in intent) {
|
|
211
|
+
const call = isContractFunctionInteractionCallIntent(intent)
|
|
212
|
+
? await intent.action.getFunctionCall()
|
|
213
|
+
: intent.call;
|
|
214
|
+
const innerHash = await computeInnerAuthWitHashFromAction(intent.caller, call);
|
|
215
|
+
intentInnerHash = { innerHash, consumer: call.to };
|
|
216
|
+
} else {
|
|
217
|
+
intentInnerHash = intent;
|
|
218
|
+
}
|
|
219
|
+
return account.createAuthWit(intentInnerHash, chainInfo);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Override simulateViaEntrypoint to use fake accounts for kernelless simulation
|
|
224
|
+
* when simulatedSimulations is enabled. Otherwise falls through to the real entrypoint path.
|
|
225
|
+
*/
|
|
226
|
+
protected override async simulateViaEntrypoint(
|
|
227
|
+
executionPayload: ExecutionPayload,
|
|
228
|
+
from: AztecAddress,
|
|
229
|
+
feeOptions: FeeOptions,
|
|
230
|
+
skipTxValidation?: boolean,
|
|
231
|
+
skipFeeEnforcement?: boolean,
|
|
232
|
+
): Promise<TxSimulationResult> {
|
|
233
|
+
if (!this.simulatedSimulations) {
|
|
234
|
+
return super.simulateViaEntrypoint(executionPayload, from, feeOptions, skipTxValidation, skipFeeEnforcement);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const feeExecutionPayload = await feeOptions.walletFeePaymentMethod?.getExecutionPayload();
|
|
238
|
+
const executionOptions: DefaultAccountEntrypointOptions = {
|
|
239
|
+
txNonce: Fr.random(),
|
|
240
|
+
cancellable: this.cancellableTransactions,
|
|
241
|
+
feePaymentMethodOptions: feeOptions.accountFeePaymentMethodOptions,
|
|
242
|
+
};
|
|
243
|
+
const finalExecutionPayload = feeExecutionPayload
|
|
244
|
+
? mergeExecutionPayloads([feeExecutionPayload, executionPayload])
|
|
245
|
+
: executionPayload;
|
|
246
|
+
const { account: fromAccount, instance, artifact } = await this.getFakeAccountDataFor(from);
|
|
247
|
+
const chainInfo = await this.getChainInfo();
|
|
248
|
+
const txRequest = await fromAccount.createTxExecutionRequest(
|
|
249
|
+
finalExecutionPayload,
|
|
250
|
+
feeOptions.gasSettings,
|
|
251
|
+
chainInfo,
|
|
252
|
+
executionOptions,
|
|
253
|
+
);
|
|
254
|
+
const contractOverrides = {
|
|
255
|
+
[from.toString()]: { instance, artifact },
|
|
256
|
+
};
|
|
257
|
+
return this.pxe.simulateTx(txRequest, {
|
|
258
|
+
simulatePublic: true,
|
|
259
|
+
skipFeeEnforcement: true,
|
|
260
|
+
skipTxValidation: true,
|
|
261
|
+
overrides: { contracts: contractOverrides },
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
async proveTx(exec: ExecutionPayload, opts: Omit<SendOptions, 'wait'>): Promise<ProvenTx> {
|
|
266
|
+
const fee = await this.completeFeeOptions(opts.from, exec.feePayer, opts.fee?.gasSettings);
|
|
267
|
+
const txRequest = await this.createTxExecutionRequestFromPayloadAndFee(exec, opts.from, fee);
|
|
268
|
+
const txProvingResult = await this.pxe.proveTx(txRequest);
|
|
269
|
+
return new ProvenTx(
|
|
270
|
+
this.aztecNode,
|
|
271
|
+
await txProvingResult.toTx(),
|
|
272
|
+
txProvingResult.getOffchainEffects(),
|
|
273
|
+
txProvingResult.stats,
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
getTxReceipt(txHash: TxHash): Promise<TxReceipt> {
|
|
278
|
+
return this.aztecNode.getTxReceipt(txHash);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
getNotes(filter: NotesFilter): Promise<NoteDao[]> {
|
|
282
|
+
return this.pxe.debug.getNotes(filter);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
getSyncedBlockHeader(): Promise<BlockHeader> {
|
|
286
|
+
return this.pxe.getSyncedBlockHeader();
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
sync(): Promise<void> {
|
|
290
|
+
return this.pxe.debug.sync();
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
stop(): Promise<void> {
|
|
294
|
+
return this.pxe.stop();
|
|
295
|
+
}
|
|
296
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ContractFunctionInteraction,
|
|
3
|
+
DeployMethod,
|
|
4
|
+
type DeployOptions,
|
|
5
|
+
NO_WAIT,
|
|
6
|
+
type NoWait,
|
|
7
|
+
type SendInteractionOptions,
|
|
8
|
+
type WaitOpts,
|
|
9
|
+
toSendOptions,
|
|
10
|
+
} from '@aztec/aztec.js/contracts';
|
|
11
|
+
import { type AztecNode, waitForTx } from '@aztec/aztec.js/node';
|
|
12
|
+
import { SimulationError } from '@aztec/stdlib/errors';
|
|
13
|
+
import { type OffchainEffect, type ProvingStats, Tx, TxHash, type TxReceipt } from '@aztec/stdlib/tx';
|
|
14
|
+
|
|
15
|
+
import { inspect } from 'util';
|
|
16
|
+
|
|
17
|
+
import type { TestWallet } from './test_wallet.js';
|
|
18
|
+
|
|
19
|
+
export type ProvenTxSendOpts = {
|
|
20
|
+
wait?: NoWait | WaitOpts;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type ProvenTxSendReturn<T extends NoWait | WaitOpts | undefined> = T extends NoWait ? TxHash : TxReceipt;
|
|
24
|
+
|
|
25
|
+
export class ProvenTx extends Tx {
|
|
26
|
+
constructor(
|
|
27
|
+
private node: AztecNode,
|
|
28
|
+
tx: Tx,
|
|
29
|
+
public offchainEffects: OffchainEffect[],
|
|
30
|
+
public stats?: ProvingStats,
|
|
31
|
+
) {
|
|
32
|
+
super(tx.getTxHash(), tx.data, tx.chonkProof, tx.contractClassLogFields, tx.publicFunctionCalldata);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
send(options?: Omit<ProvenTxSendOpts, 'wait'>): Promise<TxReceipt>;
|
|
36
|
+
send<W extends ProvenTxSendOpts['wait']>(options: ProvenTxSendOpts & { wait: W }): Promise<ProvenTxSendReturn<W>>;
|
|
37
|
+
async send(options?: ProvenTxSendOpts): Promise<TxHash | TxReceipt> {
|
|
38
|
+
const txHash = this.getTxHash();
|
|
39
|
+
await this.node.sendTx(this).catch(err => {
|
|
40
|
+
throw this.contextualizeError(err, inspect(this));
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
if (options?.wait === NO_WAIT) {
|
|
44
|
+
return txHash;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const waitOpts = typeof options?.wait === 'object' ? options.wait : undefined;
|
|
48
|
+
return await waitForTx(this.node, txHash, waitOpts);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
private contextualizeError(err: Error, ...context: string[]): Error {
|
|
52
|
+
let contextStr = '';
|
|
53
|
+
if (context.length > 0) {
|
|
54
|
+
contextStr = `\nContext:\n${context.join('\n')}`;
|
|
55
|
+
}
|
|
56
|
+
if (err instanceof SimulationError) {
|
|
57
|
+
err.setAztecContext(contextStr);
|
|
58
|
+
}
|
|
59
|
+
return err;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export async function proveInteraction(
|
|
64
|
+
wallet: TestWallet,
|
|
65
|
+
interaction: ContractFunctionInteraction | DeployMethod,
|
|
66
|
+
options: SendInteractionOptions | DeployOptions,
|
|
67
|
+
) {
|
|
68
|
+
let execPayload;
|
|
69
|
+
if (interaction instanceof DeployMethod) {
|
|
70
|
+
execPayload = await interaction.request(interaction.convertDeployOptionsToRequestOptions(options));
|
|
71
|
+
} else {
|
|
72
|
+
execPayload = await interaction.request(options);
|
|
73
|
+
}
|
|
74
|
+
return wallet.proveTx(execPayload, toSendOptions(options));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Extends AztecNode via declaration merging so instances can be used wherever AztecNode is expected.
|
|
79
|
+
* The actual method forwarding is handled by a Proxy in the class constructor.
|
|
80
|
+
*/
|
|
81
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
|
|
82
|
+
export interface AztecNodeProxy extends AztecNode {}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Mutable wrapper around an AztecNode that forwards all calls to the current target.
|
|
86
|
+
* Allows swapping the underlying node at runtime via updateTargetNode, which is useful
|
|
87
|
+
* for tests that need to redirect a wallet from one node to another without recreating it.
|
|
88
|
+
*/
|
|
89
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
|
|
90
|
+
export class AztecNodeProxy {
|
|
91
|
+
constructor(private target: AztecNode) {
|
|
92
|
+
return new Proxy(this, {
|
|
93
|
+
get: (obj, prop, receiver) => {
|
|
94
|
+
// Own properties and methods (updateTargetNode, target) are served directly.
|
|
95
|
+
if (Reflect.has(obj, prop)) {
|
|
96
|
+
return Reflect.get(obj, prop, receiver);
|
|
97
|
+
}
|
|
98
|
+
// Everything else is forwarded to the current target node.
|
|
99
|
+
const val = (obj.target as unknown as Record<string | symbol, unknown>)[prop];
|
|
100
|
+
return typeof val === 'function' ? val.bind(obj.target) : val;
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Updates the underlying node that this reference points to.
|
|
107
|
+
* @param node - The new node to forward calls to.
|
|
108
|
+
*/
|
|
109
|
+
updateTargetNode(node: AztecNode): void {
|
|
110
|
+
this.target = node;
|
|
111
|
+
}
|
|
112
|
+
}
|