@aztec/end-to-end 0.0.0-test.1 → 0.0.1-commit.b655e406
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/benchmark.d.ts +61 -0
- package/dest/bench/client_flows/benchmark.d.ts.map +1 -0
- package/dest/bench/client_flows/benchmark.js +261 -0
- package/dest/bench/client_flows/client_flows_benchmark.d.ts +73 -0
- package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -0
- package/dest/bench/client_flows/client_flows_benchmark.js +311 -0
- package/dest/bench/client_flows/config.d.ts +14 -0
- package/dest/bench/client_flows/config.d.ts.map +1 -0
- package/dest/bench/client_flows/config.js +106 -0
- package/dest/bench/client_flows/data_extractor.d.ts +2 -0
- package/dest/bench/client_flows/data_extractor.d.ts.map +1 -0
- package/dest/bench/client_flows/data_extractor.js +99 -0
- package/dest/bench/utils.d.ts +10 -36
- package/dest/bench/utils.d.ts.map +1 -1
- package/dest/bench/utils.js +26 -66
- package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +20 -12
- package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts.map +1 -1
- package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.js +85 -57
- package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +18 -24
- package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts.map +1 -1
- package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.js +48 -69
- package/dest/e2e_deploy_contract/deploy_test.d.ts +14 -6
- package/dest/e2e_deploy_contract/deploy_test.d.ts.map +1 -1
- package/dest/e2e_deploy_contract/deploy_test.js +13 -19
- package/dest/e2e_epochs/epochs_test.d.ts +58 -17
- package/dest/e2e_epochs/epochs_test.d.ts.map +1 -1
- package/dest/e2e_epochs/epochs_test.js +224 -43
- package/dest/e2e_fees/bridging_race.notest.d.ts +2 -0
- package/dest/e2e_fees/bridging_race.notest.d.ts.map +1 -0
- package/dest/e2e_fees/bridging_race.notest.js +63 -0
- package/dest/e2e_fees/fees_test.d.ts +20 -9
- package/dest/e2e_fees/fees_test.d.ts.map +1 -1
- package/dest/e2e_fees/fees_test.js +98 -107
- package/dest/e2e_l1_publisher/write_json.d.ts +10 -0
- package/dest/e2e_l1_publisher/write_json.d.ts.map +1 -0
- package/dest/e2e_l1_publisher/write_json.js +57 -0
- package/dest/e2e_multi_validator/utils.d.ts +12 -0
- package/dest/e2e_multi_validator/utils.d.ts.map +1 -0
- package/dest/e2e_multi_validator/utils.js +214 -0
- package/dest/e2e_nested_contract/nested_contract_test.d.ts +9 -6
- package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +1 -1
- package/dest/e2e_nested_contract/nested_contract_test.js +22 -19
- package/dest/e2e_p2p/inactivity_slash_test.d.ts +31 -0
- package/dest/e2e_p2p/inactivity_slash_test.d.ts.map +1 -0
- package/dest/e2e_p2p/inactivity_slash_test.js +135 -0
- package/dest/e2e_p2p/p2p_network.d.ts +69 -22
- package/dest/e2e_p2p/p2p_network.d.ts.map +1 -1
- package/dest/e2e_p2p/p2p_network.js +180 -129
- package/dest/e2e_p2p/shared.d.ts +41 -5
- package/dest/e2e_p2p/shared.d.ts.map +1 -1
- package/dest/e2e_p2p/shared.js +163 -19
- package/dest/e2e_token_contract/token_contract_test.d.ts +11 -5
- package/dest/e2e_token_contract/token_contract_test.d.ts.map +1 -1
- package/dest/e2e_token_contract/token_contract_test.js +50 -26
- package/dest/{e2e_prover → fixtures}/e2e_prover_test.d.ts +14 -9
- package/dest/fixtures/e2e_prover_test.d.ts.map +1 -0
- package/dest/{e2e_prover → fixtures}/e2e_prover_test.js +95 -100
- package/dest/fixtures/fixtures.d.ts +5 -6
- package/dest/fixtures/fixtures.d.ts.map +1 -1
- package/dest/fixtures/fixtures.js +4 -3
- package/dest/fixtures/get_acvm_config.d.ts +1 -1
- package/dest/fixtures/get_acvm_config.d.ts.map +1 -1
- package/dest/fixtures/get_acvm_config.js +2 -14
- package/dest/fixtures/get_bb_config.d.ts +1 -1
- package/dest/fixtures/get_bb_config.d.ts.map +1 -1
- package/dest/fixtures/get_bb_config.js +10 -17
- package/dest/fixtures/l1_to_l2_messaging.d.ts +8 -5
- package/dest/fixtures/l1_to_l2_messaging.d.ts.map +1 -1
- package/dest/fixtures/l1_to_l2_messaging.js +44 -18
- package/dest/fixtures/setup_l1_contracts.d.ts +3 -3
- package/dest/fixtures/setup_l1_contracts.d.ts.map +1 -1
- package/dest/fixtures/setup_l1_contracts.js +4 -4
- package/dest/fixtures/setup_p2p_test.d.ts +14 -13
- package/dest/fixtures/setup_p2p_test.d.ts.map +1 -1
- package/dest/fixtures/setup_p2p_test.js +73 -21
- package/dest/fixtures/snapshot_manager.d.ts +15 -7
- package/dest/fixtures/snapshot_manager.d.ts.map +1 -1
- package/dest/fixtures/snapshot_manager.js +147 -121
- package/dest/fixtures/token_utils.d.ts +6 -3
- package/dest/fixtures/token_utils.d.ts.map +1 -1
- package/dest/fixtures/token_utils.js +23 -10
- package/dest/fixtures/utils.d.ts +76 -37
- package/dest/fixtures/utils.d.ts.map +1 -1
- package/dest/fixtures/utils.js +464 -368
- package/dest/fixtures/web3signer.d.ts +5 -0
- package/dest/fixtures/web3signer.d.ts.map +1 -0
- package/dest/fixtures/web3signer.js +53 -0
- package/dest/quality_of_service/alert_checker.d.ts +1 -1
- package/dest/quality_of_service/alert_checker.d.ts.map +1 -1
- package/dest/shared/cross_chain_test_harness.d.ts +41 -25
- package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
- package/dest/shared/cross_chain_test_harness.js +104 -50
- package/dest/shared/gas_portal_test_harness.d.ts +32 -24
- package/dest/shared/gas_portal_test_harness.d.ts.map +1 -1
- package/dest/shared/gas_portal_test_harness.js +50 -29
- package/dest/shared/jest_setup.js +1 -1
- package/dest/shared/submit-transactions.d.ts +5 -3
- package/dest/shared/submit-transactions.d.ts.map +1 -1
- package/dest/shared/submit-transactions.js +8 -7
- package/dest/shared/uniswap_l1_l2.d.ts +13 -11
- package/dest/shared/uniswap_l1_l2.d.ts.map +1 -1
- package/dest/shared/uniswap_l1_l2.js +138 -108
- package/dest/simulators/lending_simulator.d.ts +6 -6
- package/dest/simulators/lending_simulator.d.ts.map +1 -1
- package/dest/simulators/lending_simulator.js +13 -16
- package/dest/simulators/token_simulator.d.ts +5 -2
- package/dest/simulators/token_simulator.d.ts.map +1 -1
- package/dest/simulators/token_simulator.js +16 -13
- package/dest/spartan/setup_test_wallets.d.ts +23 -10
- package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
- package/dest/spartan/setup_test_wallets.js +167 -58
- package/dest/spartan/utils.d.ts +106 -303
- package/dest/spartan/utils.d.ts.map +1 -1
- package/dest/spartan/utils.js +434 -130
- package/package.json +61 -56
- package/src/bench/client_flows/benchmark.ts +341 -0
- package/src/bench/client_flows/client_flows_benchmark.ts +402 -0
- package/src/bench/client_flows/config.ts +61 -0
- package/src/bench/client_flows/data_extractor.ts +111 -0
- package/src/bench/utils.ts +22 -76
- package/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +80 -77
- package/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +63 -105
- package/src/e2e_deploy_contract/deploy_test.ts +23 -38
- package/src/e2e_epochs/epochs_test.ts +274 -54
- package/src/e2e_fees/bridging_race.notest.ts +80 -0
- package/src/e2e_fees/fees_test.ts +137 -136
- package/src/e2e_l1_publisher/write_json.ts +76 -0
- package/src/e2e_multi_validator/utils.ts +258 -0
- package/src/e2e_nested_contract/nested_contract_test.ts +27 -18
- package/src/e2e_p2p/inactivity_slash_test.ts +178 -0
- package/src/e2e_p2p/p2p_network.ts +272 -166
- package/src/e2e_p2p/shared.ts +244 -29
- package/src/e2e_token_contract/token_contract_test.ts +43 -39
- package/src/fixtures/dumps/epoch_proof_result.json +1 -1
- package/src/{e2e_prover → fixtures}/e2e_prover_test.ts +101 -145
- package/src/fixtures/fixtures.ts +4 -3
- package/src/fixtures/get_acvm_config.ts +3 -11
- package/src/fixtures/get_bb_config.ts +18 -13
- package/src/fixtures/l1_to_l2_messaging.ts +53 -23
- package/src/fixtures/setup_l1_contracts.ts +6 -7
- package/src/fixtures/setup_p2p_test.ts +112 -38
- package/src/fixtures/snapshot_manager.ts +187 -139
- package/src/fixtures/token_utils.ts +29 -12
- package/src/fixtures/utils.ts +552 -425
- package/src/fixtures/web3signer.ts +63 -0
- package/src/guides/up_quick_start.sh +6 -14
- package/src/quality_of_service/alert_checker.ts +1 -1
- package/src/shared/cross_chain_test_harness.ts +108 -79
- package/src/shared/gas_portal_test_harness.ts +58 -49
- package/src/shared/jest_setup.ts +1 -1
- package/src/shared/submit-transactions.ts +12 -8
- package/src/shared/uniswap_l1_l2.ts +173 -176
- package/src/simulators/lending_simulator.ts +12 -15
- package/src/simulators/token_simulator.ts +21 -13
- package/src/spartan/DEVELOP.md +121 -0
- package/src/spartan/setup_test_wallets.ts +215 -93
- package/src/spartan/utils.ts +490 -130
- package/dest/e2e_prover/e2e_prover_test.d.ts.map +0 -1
- package/dest/sample-dapp/connect.js +0 -12
- package/dest/sample-dapp/contracts.js +0 -10
- package/dest/sample-dapp/deploy.js +0 -35
- package/dest/sample-dapp/index.js +0 -98
- package/src/sample-dapp/connect.mjs +0 -16
- package/src/sample-dapp/contracts.mjs +0 -14
- package/src/sample-dapp/deploy.mjs +0 -40
- package/src/sample-dapp/index.mjs +0 -128
package/src/bench/utils.ts
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
import type { AztecNodeService } from '@aztec/aztec-node';
|
|
2
|
-
import {
|
|
3
|
-
import { mean, stdDev,
|
|
4
|
-
import {
|
|
5
|
-
import { BenchmarkingContract } from '@aztec/noir-contracts.js/Benchmarking';
|
|
6
|
-
import { type PXEService, type PXEServiceConfig, createPXEService } from '@aztec/pxe/server';
|
|
2
|
+
import { BatchCall, type SentTx, type WaitOpts } from '@aztec/aztec.js/contracts';
|
|
3
|
+
import { mean, stdDev, times } from '@aztec/foundation/collection';
|
|
4
|
+
import { BenchmarkingContract } from '@aztec/noir-test-contracts.js/Benchmarking';
|
|
7
5
|
import type { MetricsType } from '@aztec/telemetry-client';
|
|
8
6
|
import type { BenchmarkDataPoint, BenchmarkMetricsType, BenchmarkTelemetryClient } from '@aztec/telemetry-client/bench';
|
|
9
7
|
|
|
10
|
-
import { writeFileSync } from 'fs';
|
|
11
|
-
import
|
|
12
|
-
import { globSync } from 'glob';
|
|
13
|
-
import { join } from 'path';
|
|
8
|
+
import { mkdirSync, writeFileSync } from 'fs';
|
|
9
|
+
import path from 'path';
|
|
14
10
|
|
|
15
11
|
import { type EndToEndContext, type SetupOptions, setup } from '../fixtures/utils.js';
|
|
16
12
|
|
|
@@ -25,7 +21,8 @@ export async function benchmarkSetup(
|
|
|
25
21
|
},
|
|
26
22
|
) {
|
|
27
23
|
const context = await setup(1, { ...opts, telemetryConfig: { benchmark: true } });
|
|
28
|
-
const
|
|
24
|
+
const defaultAccountAddress = context.accounts[0];
|
|
25
|
+
const contract = await BenchmarkingContract.deploy(context.wallet).send({ from: defaultAccountAddress }).deployed();
|
|
29
26
|
context.logger.info(`Deployed benchmarking contract at ${contract.address}`);
|
|
30
27
|
const sequencer = (context.aztecNode as AztecNodeService).getSequencer()!;
|
|
31
28
|
const telemetry = context.telemetryClient! as BenchmarkTelemetryClient;
|
|
@@ -36,7 +33,11 @@ export async function benchmarkSetup(
|
|
|
36
33
|
await telemetry.flush();
|
|
37
34
|
const data = telemetry.getMeters();
|
|
38
35
|
const formatted = formatMetricsForGithubBenchmarkAction(data, opts.metrics);
|
|
36
|
+
if (formatted.length === 0) {
|
|
37
|
+
throw new Error(`No benchmark data generated. Please review your test setup.`);
|
|
38
|
+
}
|
|
39
39
|
const benchOutput = opts.benchOutput ?? process.env.BENCH_OUTPUT ?? 'bench.json';
|
|
40
|
+
mkdirSync(path.dirname(benchOutput), { recursive: true });
|
|
40
41
|
writeFileSync(benchOutput, JSON.stringify(formatted));
|
|
41
42
|
context.logger.info(`Wrote ${data.length} metrics to ${benchOutput}`);
|
|
42
43
|
await origTeardown();
|
|
@@ -52,7 +53,7 @@ type MetricFilter = {
|
|
|
52
53
|
};
|
|
53
54
|
|
|
54
55
|
// See https://github.com/benchmark-action/github-action-benchmark/blob/e3c661617bc6aa55f26ae4457c737a55545a86a4/src/extract.ts#L659-L670
|
|
55
|
-
type GithubActionBenchmarkResult = {
|
|
56
|
+
export type GithubActionBenchmarkResult = {
|
|
56
57
|
name: string;
|
|
57
58
|
value: number;
|
|
58
59
|
range?: string;
|
|
@@ -91,30 +92,6 @@ function getMetricValues(points: BenchmarkDataPoint[]) {
|
|
|
91
92
|
}
|
|
92
93
|
}
|
|
93
94
|
|
|
94
|
-
/**
|
|
95
|
-
* Creates and returns a directory with the current job name and a random number.
|
|
96
|
-
* @param index - Index to merge into the dir path.
|
|
97
|
-
* @returns A path to a created dir.
|
|
98
|
-
*/
|
|
99
|
-
export function makeDataDirectory(index: number) {
|
|
100
|
-
const testName = expect.getState().currentTestName!.split(' ')[0].replaceAll('/', '_');
|
|
101
|
-
const db = join('data', testName, index.toString(), `${randomInt(99)}`);
|
|
102
|
-
mkdirpSync(db);
|
|
103
|
-
return db;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Returns the size in disk of a folder.
|
|
108
|
-
* @param path - Path to the folder.
|
|
109
|
-
* @returns Size in bytes.
|
|
110
|
-
*/
|
|
111
|
-
export function getFolderSize(path: string): number {
|
|
112
|
-
return globSync('**', { stat: true, cwd: path, nodir: true, withFileTypes: true }).reduce(
|
|
113
|
-
(accum, file) => accum + (file as any as { /** Size */ size: number }).size,
|
|
114
|
-
0,
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
95
|
/**
|
|
119
96
|
* Returns a call to the benchmark contract. Each call has a private execution (account entrypoint),
|
|
120
97
|
* a nested private call (create_note), a public call (increment_balance), and a nested public
|
|
@@ -126,22 +103,19 @@ export function getFolderSize(path: string): number {
|
|
|
126
103
|
* @param heavyPublicCompute - Whether the transactions include heavy public compute (like a big sha256).
|
|
127
104
|
* @returns A BatchCall instance.
|
|
128
105
|
*/
|
|
129
|
-
|
|
106
|
+
function makeCall(
|
|
130
107
|
index: number,
|
|
131
108
|
context: EndToEndContext,
|
|
132
109
|
contract: BenchmarkingContract,
|
|
133
110
|
heavyPublicCompute: boolean,
|
|
134
111
|
) {
|
|
135
|
-
const owner = context.
|
|
136
|
-
const sender = owner;
|
|
112
|
+
const [owner] = context.accounts;
|
|
137
113
|
if (heavyPublicCompute) {
|
|
138
|
-
return new BatchCall(context.wallet, [
|
|
139
|
-
await contract.methods.sha256_hash_2048(randomBytesAsBigInts(2048)).request(),
|
|
140
|
-
]);
|
|
114
|
+
return new BatchCall(context.wallet, [contract.methods.sha256_hash_1024(randomBytesAsBigInts(1024))]);
|
|
141
115
|
} else {
|
|
142
116
|
return new BatchCall(context.wallet, [
|
|
143
|
-
|
|
144
|
-
|
|
117
|
+
contract.methods.create_note(owner, index + 1),
|
|
118
|
+
contract.methods.increment_balance(owner, index + 1),
|
|
145
119
|
]);
|
|
146
120
|
}
|
|
147
121
|
}
|
|
@@ -155,17 +129,17 @@ export async function makeCall(
|
|
|
155
129
|
* @param heavyPublicCompute - Whether the transactions include heavy public compute (like a big sha256).
|
|
156
130
|
* @returns Array of sent txs.
|
|
157
131
|
*/
|
|
158
|
-
export
|
|
132
|
+
export function sendTxs(
|
|
159
133
|
txCount: number,
|
|
160
134
|
context: EndToEndContext,
|
|
161
135
|
contract: BenchmarkingContract,
|
|
162
136
|
heavyPublicCompute: boolean = false,
|
|
163
|
-
):
|
|
164
|
-
const calls =
|
|
137
|
+
): SentTx[] {
|
|
138
|
+
const calls = times(txCount, index => makeCall(index, context, contract, heavyPublicCompute));
|
|
165
139
|
context.logger.info(`Creating ${txCount} txs`);
|
|
166
|
-
const
|
|
140
|
+
const [from] = context.accounts;
|
|
167
141
|
context.logger.info(`Sending ${txCount} txs`);
|
|
168
|
-
return
|
|
142
|
+
return calls.map(call => call.send({ from }));
|
|
169
143
|
}
|
|
170
144
|
|
|
171
145
|
export async function waitTxs(txs: SentTx[], context: EndToEndContext, txWaitOpts?: WaitOpts) {
|
|
@@ -174,34 +148,6 @@ export async function waitTxs(txs: SentTx[], context: EndToEndContext, txWaitOpt
|
|
|
174
148
|
context.logger.info(`All ${txs.length} txs have been mined`);
|
|
175
149
|
}
|
|
176
150
|
|
|
177
|
-
/**
|
|
178
|
-
* Creates a new PXE
|
|
179
|
-
* @param node - Node to connect the pxe to.
|
|
180
|
-
* @param contract - Benchmark contract to add to the pxe.
|
|
181
|
-
* @param startingBlock - First l2 block to process.
|
|
182
|
-
* @returns The new PXE.
|
|
183
|
-
*/
|
|
184
|
-
export async function createNewPXE(
|
|
185
|
-
node: AztecNode,
|
|
186
|
-
contract: BenchmarkingContract,
|
|
187
|
-
startingBlock: number = INITIAL_L2_BLOCK_NUM,
|
|
188
|
-
): Promise<PXEService> {
|
|
189
|
-
const l1Contracts = await node.getL1ContractAddresses();
|
|
190
|
-
const { l1ChainId, protocolVersion } = await node.getNodeInfo();
|
|
191
|
-
const pxeConfig = {
|
|
192
|
-
l2StartingBlock: startingBlock,
|
|
193
|
-
l2BlockPollingIntervalMS: 100,
|
|
194
|
-
dataDirectory: undefined,
|
|
195
|
-
dataStoreMapSizeKB: 1024 * 1024,
|
|
196
|
-
l1Contracts,
|
|
197
|
-
l1ChainId,
|
|
198
|
-
version: protocolVersion,
|
|
199
|
-
} as PXEServiceConfig;
|
|
200
|
-
const pxe = await createPXEService(node, pxeConfig);
|
|
201
|
-
await pxe.registerContract(contract);
|
|
202
|
-
return pxe;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
151
|
function randomBytesAsBigInts(length: number): bigint[] {
|
|
206
152
|
return [...Array(length)].map(_ => BigInt(Math.floor(Math.random() * 255)));
|
|
207
153
|
}
|
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
computeSecretHash,
|
|
9
|
-
createLogger,
|
|
10
|
-
} from '@aztec/aztec.js';
|
|
11
|
-
import { MAX_NOTE_HASHES_PER_TX } from '@aztec/constants';
|
|
12
|
-
import { DocsExampleContract } from '@aztec/noir-contracts.js/DocsExample';
|
|
1
|
+
import { AztecAddress } from '@aztec/aztec.js/addresses';
|
|
2
|
+
import { computeSecretHash } from '@aztec/aztec.js/crypto';
|
|
3
|
+
import { Fr } from '@aztec/aztec.js/fields';
|
|
4
|
+
import { type Logger, createLogger } from '@aztec/aztec.js/log';
|
|
5
|
+
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
6
|
+
import type { TxHash } from '@aztec/aztec.js/tx';
|
|
7
|
+
import type { CheatCodes } from '@aztec/aztec/testing';
|
|
13
8
|
import type { TokenContract } from '@aztec/noir-contracts.js/Token';
|
|
14
9
|
import { TokenBlacklistContract } from '@aztec/noir-contracts.js/TokenBlacklist';
|
|
10
|
+
import { InvalidAccountContract } from '@aztec/noir-test-contracts.js/InvalidAccount';
|
|
11
|
+
import type { SequencerClient } from '@aztec/sequencer-client';
|
|
12
|
+
import type { TestWallet } from '@aztec/test-wallet/server';
|
|
15
13
|
|
|
16
14
|
import { jest } from '@jest/globals';
|
|
17
15
|
|
|
@@ -54,31 +52,34 @@ export class Role {
|
|
|
54
52
|
}
|
|
55
53
|
|
|
56
54
|
export class BlacklistTokenContractTest {
|
|
57
|
-
// A low delay is really poor ux, but we need to keep it low for the tests to run "quickly".
|
|
58
55
|
// This value MUST match the same value that we have in the contract
|
|
59
|
-
static
|
|
56
|
+
static CHANGE_ROLES_DELAY = 86400;
|
|
60
57
|
|
|
61
58
|
private snapshotManager: ISnapshotManager;
|
|
62
59
|
logger: Logger;
|
|
63
|
-
|
|
64
|
-
accounts: CompleteAddress[] = [];
|
|
60
|
+
wallet!: TestWallet;
|
|
65
61
|
asset!: TokenBlacklistContract;
|
|
66
62
|
tokenSim!: TokenSimulator;
|
|
67
|
-
badAccount!:
|
|
63
|
+
badAccount!: InvalidAccountContract;
|
|
64
|
+
cheatCodes!: CheatCodes;
|
|
65
|
+
sequencer!: SequencerClient;
|
|
66
|
+
aztecNode!: AztecNode;
|
|
68
67
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
68
|
+
adminAddress!: AztecAddress;
|
|
69
|
+
otherAddress!: AztecAddress;
|
|
70
|
+
blacklistedAddress!: AztecAddress;
|
|
72
71
|
|
|
73
72
|
constructor(testName: string) {
|
|
74
73
|
this.logger = createLogger(`e2e:e2e_blacklist_token_contract:${testName}`);
|
|
75
74
|
this.snapshotManager = createSnapshotManager(`e2e_blacklist_token_contract/${testName}`, dataPath);
|
|
76
75
|
}
|
|
77
76
|
|
|
78
|
-
async
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
77
|
+
async crossTimestampOfChange() {
|
|
78
|
+
await this.cheatCodes.warpL2TimeAtLeastBy(
|
|
79
|
+
this.sequencer,
|
|
80
|
+
this.aztecNode,
|
|
81
|
+
BlacklistTokenContractTest.CHANGE_ROLES_DELAY,
|
|
82
|
+
);
|
|
82
83
|
}
|
|
83
84
|
|
|
84
85
|
/**
|
|
@@ -93,12 +94,15 @@ export class BlacklistTokenContractTest {
|
|
|
93
94
|
await this.snapshotManager.snapshot(
|
|
94
95
|
'3_accounts',
|
|
95
96
|
deployAccounts(3, this.logger),
|
|
96
|
-
|
|
97
|
-
this.
|
|
98
|
-
this.
|
|
99
|
-
this.
|
|
100
|
-
this.
|
|
101
|
-
this.
|
|
97
|
+
({ deployedAccounts }, { cheatCodes, aztecNode, sequencer, wallet }) => {
|
|
98
|
+
this.cheatCodes = cheatCodes;
|
|
99
|
+
this.aztecNode = aztecNode;
|
|
100
|
+
this.sequencer = sequencer;
|
|
101
|
+
this.wallet = wallet;
|
|
102
|
+
this.adminAddress = deployedAccounts[0].address;
|
|
103
|
+
this.otherAddress = deployedAccounts[1].address;
|
|
104
|
+
this.blacklistedAddress = deployedAccounts[2].address;
|
|
105
|
+
return Promise.resolve();
|
|
102
106
|
},
|
|
103
107
|
);
|
|
104
108
|
|
|
@@ -108,36 +112,39 @@ export class BlacklistTokenContractTest {
|
|
|
108
112
|
// Create the token contract state.
|
|
109
113
|
// Move this account thing to addAccounts above?
|
|
110
114
|
this.logger.verbose(`Public deploy accounts...`);
|
|
111
|
-
await publicDeployAccounts(this.
|
|
115
|
+
await publicDeployAccounts(this.wallet, [this.adminAddress, this.otherAddress, this.blacklistedAddress]);
|
|
112
116
|
|
|
113
117
|
this.logger.verbose(`Deploying TokenContract...`);
|
|
114
|
-
this.asset = await TokenBlacklistContract.deploy(this.
|
|
118
|
+
this.asset = await TokenBlacklistContract.deploy(this.wallet, this.adminAddress)
|
|
119
|
+
.send({ from: this.adminAddress })
|
|
120
|
+
.deployed();
|
|
115
121
|
this.logger.verbose(`Token deployed to ${this.asset.address}`);
|
|
116
122
|
|
|
117
123
|
this.logger.verbose(`Deploying bad account...`);
|
|
118
|
-
this.badAccount = await
|
|
124
|
+
this.badAccount = await InvalidAccountContract.deploy(this.wallet).send({ from: this.adminAddress }).deployed();
|
|
119
125
|
this.logger.verbose(`Deployed to ${this.badAccount.address}.`);
|
|
120
126
|
|
|
121
|
-
await this.
|
|
127
|
+
await this.crossTimestampOfChange();
|
|
122
128
|
|
|
123
129
|
return { tokenContractAddress: this.asset.address, badAccountAddress: this.badAccount.address };
|
|
124
130
|
},
|
|
125
131
|
async ({ tokenContractAddress, badAccountAddress }) => {
|
|
126
132
|
// Restore the token contract state.
|
|
127
|
-
this.asset = await TokenBlacklistContract.at(tokenContractAddress, this.
|
|
133
|
+
this.asset = await TokenBlacklistContract.at(tokenContractAddress, this.wallet);
|
|
128
134
|
this.logger.verbose(`Token contract address: ${this.asset.address}`);
|
|
129
135
|
|
|
130
136
|
this.tokenSim = new TokenSimulator(
|
|
131
137
|
this.asset as unknown as TokenContract,
|
|
132
|
-
this.
|
|
138
|
+
this.wallet,
|
|
139
|
+
this.adminAddress,
|
|
133
140
|
this.logger,
|
|
134
|
-
this.
|
|
141
|
+
[this.adminAddress, this.otherAddress, this.blacklistedAddress],
|
|
135
142
|
);
|
|
136
143
|
|
|
137
|
-
this.badAccount = await
|
|
144
|
+
this.badAccount = await InvalidAccountContract.at(badAccountAddress, this.wallet);
|
|
138
145
|
this.logger.verbose(`Bad account address: ${this.badAccount.address}`);
|
|
139
146
|
|
|
140
|
-
expect(await this.asset.methods.get_roles(this.
|
|
147
|
+
expect(await this.asset.methods.get_roles(this.adminAddress).simulate({ from: this.adminAddress })).toEqual(
|
|
141
148
|
new Role().withAdmin().toNoirStruct(),
|
|
142
149
|
);
|
|
143
150
|
},
|
|
@@ -158,91 +165,87 @@ export class BlacklistTokenContractTest {
|
|
|
158
165
|
await this.snapshotManager.teardown();
|
|
159
166
|
}
|
|
160
167
|
|
|
161
|
-
#toBoundedVec(arr: Fr[], maxLen: number) {
|
|
162
|
-
return { len: arr.length, storage: arr.concat(new Array(maxLen - arr.length).fill(new Fr(0))) };
|
|
163
|
-
}
|
|
164
|
-
|
|
165
168
|
async addPendingShieldNoteToPXE(
|
|
166
169
|
contract: TokenBlacklistContract,
|
|
167
|
-
|
|
170
|
+
recipient: AztecAddress,
|
|
168
171
|
amount: bigint,
|
|
169
172
|
secretHash: Fr,
|
|
170
173
|
txHash: TxHash,
|
|
171
174
|
) {
|
|
172
|
-
const txEffects = await
|
|
175
|
+
const txEffects = await this.aztecNode.getTxEffect(txHash);
|
|
173
176
|
await contract.methods
|
|
174
177
|
.deliver_transparent_note(
|
|
175
178
|
contract.address,
|
|
176
179
|
amount,
|
|
177
180
|
secretHash,
|
|
178
181
|
txHash.hash,
|
|
179
|
-
|
|
182
|
+
txEffects!.data.noteHashes,
|
|
180
183
|
txEffects!.data.nullifiers[0],
|
|
181
|
-
|
|
184
|
+
recipient,
|
|
182
185
|
)
|
|
183
|
-
.simulate();
|
|
186
|
+
.simulate({ from: recipient });
|
|
184
187
|
}
|
|
185
188
|
|
|
186
189
|
async applyMintSnapshot() {
|
|
187
190
|
await this.snapshotManager.snapshot(
|
|
188
191
|
'mint',
|
|
189
192
|
async () => {
|
|
190
|
-
const { asset
|
|
193
|
+
const { asset } = this;
|
|
191
194
|
const amount = 10000n;
|
|
192
195
|
|
|
193
196
|
const adminMinterRole = new Role().withAdmin().withMinter();
|
|
194
|
-
await this.asset
|
|
195
|
-
.
|
|
196
|
-
.
|
|
197
|
-
.send()
|
|
197
|
+
await this.asset.methods
|
|
198
|
+
.update_roles(this.adminAddress, adminMinterRole.toNoirStruct())
|
|
199
|
+
.send({ from: this.adminAddress })
|
|
198
200
|
.wait();
|
|
199
201
|
|
|
200
202
|
const blacklistRole = new Role().withBlacklisted();
|
|
201
|
-
await this.asset
|
|
202
|
-
.
|
|
203
|
-
.
|
|
204
|
-
.send()
|
|
203
|
+
await this.asset.methods
|
|
204
|
+
.update_roles(this.blacklistedAddress, blacklistRole.toNoirStruct())
|
|
205
|
+
.send({ from: this.adminAddress })
|
|
205
206
|
.wait();
|
|
206
207
|
|
|
207
|
-
await this.
|
|
208
|
+
await this.crossTimestampOfChange();
|
|
208
209
|
|
|
209
|
-
expect(await this.asset.methods.get_roles(this.
|
|
210
|
+
expect(await this.asset.methods.get_roles(this.adminAddress).simulate({ from: this.adminAddress })).toEqual(
|
|
210
211
|
adminMinterRole.toNoirStruct(),
|
|
211
212
|
);
|
|
212
213
|
|
|
213
214
|
this.logger.verbose(`Minting ${amount} publicly...`);
|
|
214
|
-
await asset.methods.mint_public(
|
|
215
|
+
await asset.methods.mint_public(this.adminAddress, amount).send({ from: this.adminAddress }).wait();
|
|
215
216
|
|
|
216
217
|
this.logger.verbose(`Minting ${amount} privately...`);
|
|
217
218
|
const secret = Fr.random();
|
|
218
219
|
const secretHash = await computeSecretHash(secret);
|
|
219
|
-
const receipt = await asset.methods.mint_private(amount, secretHash).send().wait();
|
|
220
|
+
const receipt = await asset.methods.mint_private(amount, secretHash).send({ from: this.adminAddress }).wait();
|
|
220
221
|
|
|
221
|
-
await this.addPendingShieldNoteToPXE(asset,
|
|
222
|
-
const txClaim = asset.methods
|
|
223
|
-
|
|
222
|
+
await this.addPendingShieldNoteToPXE(asset, this.adminAddress, amount, secretHash, receipt.txHash);
|
|
223
|
+
const txClaim = asset.methods
|
|
224
|
+
.redeem_shield(this.adminAddress, amount, secret)
|
|
225
|
+
.send({ from: this.adminAddress });
|
|
226
|
+
await txClaim.wait();
|
|
224
227
|
this.logger.verbose(`Minting complete.`);
|
|
225
228
|
|
|
226
229
|
return { amount };
|
|
227
230
|
},
|
|
228
231
|
async ({ amount }) => {
|
|
229
|
-
const {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
const publicBalance = await asset.methods.balance_of_public(address).simulate();
|
|
232
|
+
const { asset, tokenSim } = this;
|
|
233
|
+
tokenSim.mintPublic(this.adminAddress, amount);
|
|
234
|
+
|
|
235
|
+
const publicBalance = await asset.methods
|
|
236
|
+
.balance_of_public(this.adminAddress)
|
|
237
|
+
.simulate({ from: this.adminAddress });
|
|
237
238
|
this.logger.verbose(`Public balance of wallet 0: ${publicBalance}`);
|
|
238
|
-
expect(publicBalance).toEqual(this.tokenSim.balanceOfPublic(
|
|
239
|
+
expect(publicBalance).toEqual(this.tokenSim.balanceOfPublic(this.adminAddress));
|
|
239
240
|
|
|
240
|
-
tokenSim.mintPrivate(
|
|
241
|
-
const privateBalance = await asset.methods
|
|
241
|
+
tokenSim.mintPrivate(this.adminAddress, amount);
|
|
242
|
+
const privateBalance = await asset.methods
|
|
243
|
+
.balance_of_private(this.adminAddress)
|
|
244
|
+
.simulate({ from: this.adminAddress });
|
|
242
245
|
this.logger.verbose(`Private balance of wallet 0: ${privateBalance}`);
|
|
243
|
-
expect(privateBalance).toEqual(tokenSim.balanceOfPrivate(
|
|
246
|
+
expect(privateBalance).toEqual(tokenSim.balanceOfPrivate(this.adminAddress));
|
|
244
247
|
|
|
245
|
-
const totalSupply = await asset.methods.total_supply().simulate();
|
|
248
|
+
const totalSupply = await asset.methods.total_supply().simulate({ from: this.adminAddress });
|
|
246
249
|
this.logger.verbose(`Total supply: ${totalSupply}`);
|
|
247
250
|
expect(totalSupply).toEqual(tokenSim.totalSupply);
|
|
248
251
|
|