-
Notifications
You must be signed in to change notification settings - Fork 333
/
Copy pathshared.ts
89 lines (80 loc) · 3.05 KB
/
shared.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { getSchnorrAccount } from '@aztec/accounts/schnorr';
import { type AztecNodeService } from '@aztec/aztec-node';
import { type DebugLogger, type SentTx } from '@aztec/aztec.js';
import { CompleteAddress, TxStatus } from '@aztec/aztec.js';
import { Fr, GrumpkinScalar } from '@aztec/foundation/fields';
import { type SpamContract } from '@aztec/noir-contracts.js';
import { type PXEService, createPXEService, getPXEServiceConfig as getRpcConfig } from '@aztec/pxe';
import { type NodeContext } from '../fixtures/setup_p2p_test.js';
// submits a set of transactions to the provided Private eXecution Environment (PXE)
export const submitComplexTxsTo = async (logger: DebugLogger, spamContract: SpamContract, numTxs: number) => {
const txs: SentTx[] = [];
const seed = 1234n;
const spamCount = 15;
for (let i = 0; i < numTxs; i++) {
const tx = spamContract.methods.spam(seed + BigInt(i * spamCount), spamCount, false).send();
const txHash = await tx.getTxHash();
logger.info(`Tx sent with hash ${txHash}`);
const receipt = await tx.getReceipt();
expect(receipt).toEqual(
expect.objectContaining({
status: TxStatus.PENDING,
error: '',
}),
);
logger.info(`Receipt received for ${txHash}`);
txs.push(tx);
}
return txs;
};
// creates an instance of the PXE and submit a given number of transactions to it.
export const createPXEServiceAndSubmitTransactions = async (
logger: DebugLogger,
node: AztecNodeService,
numTxs: number,
): Promise<NodeContext> => {
const rpcConfig = getRpcConfig();
const pxeService = await createPXEService(node, rpcConfig, true);
const secretKey = Fr.random();
const completeAddress = CompleteAddress.fromSecretKeyAndPartialAddress(secretKey, Fr.random());
await pxeService.registerAccount(secretKey, completeAddress.partialAddress);
const txs = await submitTxsTo(logger, pxeService, numTxs);
return {
txs,
account: completeAddress.address,
pxeService,
node,
};
};
// submits a set of transactions to the provided Private eXecution Environment (PXE)
const submitTxsTo = async (logger: DebugLogger, pxe: PXEService, numTxs: number) => {
const provenTxs = [];
for (let i = 0; i < numTxs; i++) {
const accountManager = getSchnorrAccount(pxe, Fr.random(), GrumpkinScalar.random(), Fr.random());
const deployMethod = await accountManager.getDeployMethod();
const tx = await deployMethod.prove({
contractAddressSalt: accountManager.salt,
skipClassRegistration: true,
skipPublicDeployment: true,
universalDeploy: true,
});
provenTxs.push(tx);
}
const sentTxs = await Promise.all(
provenTxs.map(async provenTx => {
const tx = provenTx.send();
const txHash = await tx.getTxHash();
logger.info(`Tx sent with hash ${txHash}`);
const receipt = await tx.getReceipt();
expect(receipt).toEqual(
expect.objectContaining({
status: TxStatus.PENDING,
error: '',
}),
);
logger.info(`Receipt received for ${txHash}`);
return tx;
}),
);
return sentTxs;
};