@aztec/end-to-end 0.0.0-test.1 → 0.0.1-commit.1142ef1
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 +80 -0
- package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -0
- package/dest/bench/client_flows/client_flows_benchmark.js +336 -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 +79 -0
- package/dest/bench/utils.d.ts +14 -40
- package/dest/bench/utils.d.ts.map +1 -1
- package/dest/bench/utils.js +37 -70
- package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +21 -13
- 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 +29 -28
- 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 +79 -82
- package/dest/e2e_deploy_contract/deploy_test.d.ts +16 -8
- 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 +65 -22
- package/dest/e2e_epochs/epochs_test.d.ts.map +1 -1
- package/dest/e2e_epochs/epochs_test.js +233 -49
- 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 +27 -12
- package/dest/e2e_fees/fees_test.d.ts.map +1 -1
- package/dest/e2e_fees/fees_test.js +107 -110
- 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 +55 -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 +10 -7
- package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +1 -1
- package/dest/e2e_nested_contract/nested_contract_test.js +24 -20
- 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 +136 -0
- package/dest/e2e_p2p/p2p_network.d.ts +276 -23
- package/dest/e2e_p2p/p2p_network.d.ts.map +1 -1
- package/dest/e2e_p2p/p2p_network.js +188 -133
- package/dest/e2e_p2p/shared.d.ts +43 -7
- package/dest/e2e_p2p/shared.d.ts.map +1 -1
- package/dest/e2e_p2p/shared.js +164 -19
- package/dest/e2e_token_contract/token_contract_test.d.ts +12 -6
- 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/fixtures/e2e_prover_test.d.ts +61 -0
- package/dest/fixtures/e2e_prover_test.d.ts.map +1 -0
- package/dest/{e2e_prover → fixtures}/e2e_prover_test.js +108 -113
- package/dest/fixtures/fixtures.d.ts +6 -8
- package/dest/fixtures/fixtures.d.ts.map +1 -1
- package/dest/fixtures/fixtures.js +5 -5
- package/dest/fixtures/get_acvm_config.d.ts +2 -2
- package/dest/fixtures/get_acvm_config.d.ts.map +1 -1
- package/dest/fixtures/get_acvm_config.js +3 -15
- package/dest/fixtures/get_bb_config.d.ts +2 -2
- package/dest/fixtures/get_bb_config.d.ts.map +1 -1
- package/dest/fixtures/get_bb_config.js +10 -17
- package/dest/fixtures/index.d.ts +1 -1
- package/dest/fixtures/l1_to_l2_messaging.d.ts +11 -7
- package/dest/fixtures/l1_to_l2_messaging.d.ts.map +1 -1
- package/dest/fixtures/l1_to_l2_messaging.js +45 -19
- package/dest/fixtures/logging.d.ts +1 -1
- package/dest/fixtures/setup_p2p_test.d.ts +15 -14
- package/dest/fixtures/setup_p2p_test.d.ts.map +1 -1
- package/dest/fixtures/setup_p2p_test.js +82 -22
- package/dest/fixtures/snapshot_manager.d.ts +20 -14
- package/dest/fixtures/snapshot_manager.d.ts.map +1 -1
- package/dest/fixtures/snapshot_manager.js +147 -138
- package/dest/fixtures/token_utils.d.ts +10 -4
- package/dest/fixtures/token_utils.d.ts.map +1 -1
- package/dest/fixtures/token_utils.js +28 -12
- package/dest/fixtures/utils.d.ts +92 -54
- package/dest/fixtures/utils.d.ts.map +1 -1
- package/dest/fixtures/utils.js +452 -389
- 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/fixtures/with_telemetry_utils.d.ts +2 -2
- package/dest/fixtures/with_telemetry_utils.d.ts.map +1 -1
- package/dest/fixtures/with_telemetry_utils.js +2 -2
- package/dest/index.d.ts +1 -1
- package/dest/quality_of_service/grafana_client.d.ts +41 -0
- package/dest/quality_of_service/grafana_client.d.ts.map +1 -0
- package/dest/quality_of_service/{alert_checker.js → grafana_client.js} +1 -1
- package/dest/shared/cross_chain_test_harness.d.ts +42 -35
- package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
- package/dest/shared/cross_chain_test_harness.js +106 -52
- package/dest/shared/gas_portal_test_harness.d.ts +29 -31
- package/dest/shared/gas_portal_test_harness.d.ts.map +1 -1
- package/dest/shared/gas_portal_test_harness.js +51 -30
- package/dest/shared/index.d.ts +2 -2
- package/dest/shared/index.d.ts.map +1 -1
- package/dest/shared/jest_setup.d.ts +1 -1
- package/dest/shared/jest_setup.js +1 -1
- package/dest/shared/submit-transactions.d.ts +6 -4
- 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 +3 -25
- package/dest/shared/uniswap_l1_l2.d.ts.map +1 -1
- package/dest/shared/uniswap_l1_l2.js +170 -120
- package/dest/simulators/index.d.ts +1 -1
- package/dest/simulators/lending_simulator.d.ts +7 -11
- package/dest/simulators/lending_simulator.d.ts.map +1 -1
- package/dest/simulators/lending_simulator.js +16 -17
- package/dest/simulators/token_simulator.d.ts +6 -3
- 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 +27 -11
- package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
- package/dest/spartan/setup_test_wallets.js +202 -58
- package/dest/spartan/tx_metrics.d.ts +39 -0
- package/dest/spartan/tx_metrics.d.ts.map +1 -0
- package/dest/spartan/tx_metrics.js +95 -0
- package/dest/spartan/utils.d.ts +151 -313
- package/dest/spartan/utils.d.ts.map +1 -1
- package/dest/spartan/utils.js +598 -151
- package/package.json +65 -58
- package/src/bench/client_flows/benchmark.ts +341 -0
- package/src/bench/client_flows/client_flows_benchmark.ts +450 -0
- package/src/bench/client_flows/config.ts +61 -0
- package/src/bench/client_flows/data_extractor.ts +89 -0
- package/src/bench/utils.ts +35 -81
- package/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +80 -77
- package/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +103 -122
- package/src/e2e_deploy_contract/deploy_test.ts +24 -39
- package/src/e2e_epochs/epochs_test.ts +299 -65
- package/src/e2e_fees/bridging_race.notest.ts +80 -0
- package/src/e2e_fees/fees_test.ts +150 -142
- package/src/e2e_l1_publisher/write_json.ts +74 -0
- package/src/e2e_multi_validator/utils.ts +258 -0
- package/src/e2e_nested_contract/nested_contract_test.ts +29 -19
- package/src/e2e_p2p/inactivity_slash_test.ts +179 -0
- package/src/e2e_p2p/p2p_network.ts +274 -171
- package/src/e2e_p2p/shared.ts +252 -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 +112 -160
- package/src/fixtures/fixtures.ts +5 -7
- package/src/fixtures/get_acvm_config.ts +4 -12
- package/src/fixtures/get_bb_config.ts +18 -13
- package/src/fixtures/l1_to_l2_messaging.ts +56 -24
- package/src/fixtures/setup_p2p_test.ts +127 -39
- package/src/fixtures/snapshot_manager.ts +189 -160
- package/src/fixtures/token_utils.ts +32 -15
- package/src/fixtures/utils.ts +556 -475
- package/src/fixtures/web3signer.ts +63 -0
- package/src/fixtures/with_telemetry_utils.ts +2 -2
- package/src/guides/up_quick_start.sh +7 -15
- package/src/quality_of_service/{alert_checker.ts → grafana_client.ts} +2 -2
- package/src/shared/cross_chain_test_harness.ts +113 -87
- package/src/shared/gas_portal_test_harness.ts +59 -50
- package/src/shared/index.ts +1 -1
- package/src/shared/jest_setup.ts +1 -1
- package/src/shared/submit-transactions.ts +12 -8
- package/src/shared/uniswap_l1_l2.ts +194 -211
- package/src/simulators/lending_simulator.ts +15 -16
- package/src/simulators/token_simulator.ts +21 -13
- package/src/spartan/DEVELOP.md +128 -0
- package/src/spartan/setup_test_wallets.ts +258 -93
- package/src/spartan/tx_metrics.ts +130 -0
- package/src/spartan/utils.ts +722 -146
- package/dest/e2e_prover/e2e_prover_test.d.ts +0 -56
- package/dest/e2e_prover/e2e_prover_test.d.ts.map +0 -1
- package/dest/fixtures/setup_l1_contracts.d.ts +0 -6
- package/dest/fixtures/setup_l1_contracts.d.ts.map +0 -1
- package/dest/fixtures/setup_l1_contracts.js +0 -17
- package/dest/quality_of_service/alert_checker.d.ts +0 -41
- package/dest/quality_of_service/alert_checker.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/fixtures/setup_l1_contracts.ts +0 -27
- 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,13 @@
|
|
|
1
1
|
import type { AztecNodeService } from '@aztec/aztec-node';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { BenchmarkingContract } from '@aztec/noir-contracts.js/Benchmarking';
|
|
6
|
-
import
|
|
7
|
-
import type { MetricsType } from '@aztec/telemetry-client';
|
|
2
|
+
import { AztecAddress } from '@aztec/aztec.js/addresses';
|
|
3
|
+
import { BatchCall, type SentTx, type WaitOpts } from '@aztec/aztec.js/contracts';
|
|
4
|
+
import { mean, stdDev, times } from '@aztec/foundation/collection';
|
|
5
|
+
import { BenchmarkingContract } from '@aztec/noir-test-contracts.js/Benchmarking';
|
|
6
|
+
import type { MetricDefinition } from '@aztec/telemetry-client';
|
|
8
7
|
import type { BenchmarkDataPoint, BenchmarkMetricsType, BenchmarkTelemetryClient } from '@aztec/telemetry-client/bench';
|
|
9
8
|
|
|
10
|
-
import { writeFileSync } from 'fs';
|
|
11
|
-
import
|
|
12
|
-
import { globSync } from 'glob';
|
|
13
|
-
import { join } from 'path';
|
|
9
|
+
import { mkdirSync, writeFileSync } from 'fs';
|
|
10
|
+
import path from 'path';
|
|
14
11
|
|
|
15
12
|
import { type EndToEndContext, type SetupOptions, setup } from '../fixtures/utils.js';
|
|
16
13
|
|
|
@@ -19,13 +16,14 @@ import { type EndToEndContext, type SetupOptions, setup } from '../fixtures/util
|
|
|
19
16
|
*/
|
|
20
17
|
export async function benchmarkSetup(
|
|
21
18
|
opts: Partial<SetupOptions> & {
|
|
22
|
-
/** What metrics to export */ metrics: (
|
|
19
|
+
/** What metrics to export */ metrics: (MetricDefinition | MetricFilter)[];
|
|
23
20
|
/** Where to output the benchmark data (defaults to BENCH_OUTPUT or bench.json) */
|
|
24
21
|
benchOutput?: string;
|
|
25
22
|
},
|
|
26
23
|
) {
|
|
27
24
|
const context = await setup(1, { ...opts, telemetryConfig: { benchmark: true } });
|
|
28
|
-
const
|
|
25
|
+
const defaultAccountAddress = context.accounts[0];
|
|
26
|
+
const contract = await BenchmarkingContract.deploy(context.wallet).send({ from: defaultAccountAddress }).deployed();
|
|
29
27
|
context.logger.info(`Deployed benchmarking contract at ${contract.address}`);
|
|
30
28
|
const sequencer = (context.aztecNode as AztecNodeService).getSequencer()!;
|
|
31
29
|
const telemetry = context.telemetryClient! as BenchmarkTelemetryClient;
|
|
@@ -36,7 +34,11 @@ export async function benchmarkSetup(
|
|
|
36
34
|
await telemetry.flush();
|
|
37
35
|
const data = telemetry.getMeters();
|
|
38
36
|
const formatted = formatMetricsForGithubBenchmarkAction(data, opts.metrics);
|
|
37
|
+
if (formatted.length === 0) {
|
|
38
|
+
throw new Error(`No benchmark data generated. Please review your test setup.`);
|
|
39
|
+
}
|
|
39
40
|
const benchOutput = opts.benchOutput ?? process.env.BENCH_OUTPUT ?? 'bench.json';
|
|
41
|
+
mkdirSync(path.dirname(benchOutput), { recursive: true });
|
|
40
42
|
writeFileSync(benchOutput, JSON.stringify(formatted));
|
|
41
43
|
context.logger.info(`Wrote ${data.length} metrics to ${benchOutput}`);
|
|
42
44
|
await origTeardown();
|
|
@@ -45,14 +47,14 @@ export async function benchmarkSetup(
|
|
|
45
47
|
}
|
|
46
48
|
|
|
47
49
|
type MetricFilter = {
|
|
48
|
-
source:
|
|
50
|
+
source: MetricDefinition;
|
|
49
51
|
transform: (value: number) => number;
|
|
50
52
|
name: string;
|
|
51
53
|
unit?: string;
|
|
52
54
|
};
|
|
53
55
|
|
|
54
56
|
// See https://github.com/benchmark-action/github-action-benchmark/blob/e3c661617bc6aa55f26ae4457c737a55545a86a4/src/extract.ts#L659-L670
|
|
55
|
-
type GithubActionBenchmarkResult = {
|
|
57
|
+
export type GithubActionBenchmarkResult = {
|
|
56
58
|
name: string;
|
|
57
59
|
value: number;
|
|
58
60
|
range?: string;
|
|
@@ -60,17 +62,21 @@ type GithubActionBenchmarkResult = {
|
|
|
60
62
|
extra?: string;
|
|
61
63
|
};
|
|
62
64
|
|
|
65
|
+
function isMetricDefinition(f: MetricDefinition | MetricFilter): f is MetricDefinition {
|
|
66
|
+
return 'description' in f;
|
|
67
|
+
}
|
|
68
|
+
|
|
63
69
|
function formatMetricsForGithubBenchmarkAction(
|
|
64
70
|
data: BenchmarkMetricsType,
|
|
65
|
-
filter: (
|
|
71
|
+
filter: (MetricDefinition | MetricFilter)[],
|
|
66
72
|
): GithubActionBenchmarkResult[] {
|
|
67
73
|
const allFilters: MetricFilter[] = filter.map(f =>
|
|
68
|
-
|
|
74
|
+
isMetricDefinition(f) ? { name: f.name, source: f, transform: (x: number) => x, unit: f.unit } : f,
|
|
69
75
|
);
|
|
70
76
|
return data.flatMap(meter => {
|
|
71
77
|
return meter.metrics
|
|
72
|
-
.filter(metric => allFilters.map(f => f.source).includes(metric.name
|
|
73
|
-
.map(metric => [metric, allFilters.find(f => f.source === metric.name)!] as const)
|
|
78
|
+
.filter(metric => allFilters.map(f => f.source.name).includes(metric.name))
|
|
79
|
+
.map(metric => [metric, allFilters.find(f => f.source.name === metric.name)!] as const)
|
|
74
80
|
.map(([metric, filter]) => ({
|
|
75
81
|
name: `${meter.name}/${filter.name}`,
|
|
76
82
|
unit: filter.unit ?? metric.unit ?? 'unknown',
|
|
@@ -91,30 +97,6 @@ function getMetricValues(points: BenchmarkDataPoint[]) {
|
|
|
91
97
|
}
|
|
92
98
|
}
|
|
93
99
|
|
|
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
100
|
/**
|
|
119
101
|
* Returns a call to the benchmark contract. Each call has a private execution (account entrypoint),
|
|
120
102
|
* a nested private call (create_note), a public call (increment_balance), and a nested public
|
|
@@ -126,22 +108,22 @@ export function getFolderSize(path: string): number {
|
|
|
126
108
|
* @param heavyPublicCompute - Whether the transactions include heavy public compute (like a big sha256).
|
|
127
109
|
* @returns A BatchCall instance.
|
|
128
110
|
*/
|
|
129
|
-
|
|
111
|
+
async function makeCall(
|
|
130
112
|
index: number,
|
|
131
113
|
context: EndToEndContext,
|
|
132
114
|
contract: BenchmarkingContract,
|
|
133
115
|
heavyPublicCompute: boolean,
|
|
134
116
|
) {
|
|
135
|
-
const owner = context.wallet.getAddress();
|
|
136
|
-
const sender = owner;
|
|
137
117
|
if (heavyPublicCompute) {
|
|
138
|
-
return new BatchCall(context.wallet, [
|
|
139
|
-
await contract.methods.sha256_hash_2048(randomBytesAsBigInts(2048)).request(),
|
|
140
|
-
]);
|
|
118
|
+
return new BatchCall(context.wallet, [contract.methods.sha256_hash_1024(randomBytesAsBigInts(1024))]);
|
|
141
119
|
} else {
|
|
120
|
+
// We use random address for the new note owner because we can emit at most UNFINALIZED_TAGGING_INDEXES_WINDOW_LEN
|
|
121
|
+
// logs for a given sender-recipient-contract tuple.
|
|
122
|
+
const ownerOfNewNote = await AztecAddress.random();
|
|
123
|
+
const [ownerOfBalance] = context.accounts;
|
|
142
124
|
return new BatchCall(context.wallet, [
|
|
143
|
-
|
|
144
|
-
|
|
125
|
+
contract.methods.create_note(ownerOfNewNote, index + 1),
|
|
126
|
+
contract.methods.increment_balance(ownerOfBalance, index + 1),
|
|
145
127
|
]);
|
|
146
128
|
}
|
|
147
129
|
}
|
|
@@ -161,11 +143,11 @@ export async function sendTxs(
|
|
|
161
143
|
contract: BenchmarkingContract,
|
|
162
144
|
heavyPublicCompute: boolean = false,
|
|
163
145
|
): Promise<SentTx[]> {
|
|
164
|
-
const calls = await
|
|
146
|
+
const calls = await Promise.all(times(txCount, index => makeCall(index, context, contract, heavyPublicCompute)));
|
|
165
147
|
context.logger.info(`Creating ${txCount} txs`);
|
|
166
|
-
const
|
|
148
|
+
const [from] = context.accounts;
|
|
167
149
|
context.logger.info(`Sending ${txCount} txs`);
|
|
168
|
-
return
|
|
150
|
+
return calls.map(call => call.send({ from }));
|
|
169
151
|
}
|
|
170
152
|
|
|
171
153
|
export async function waitTxs(txs: SentTx[], context: EndToEndContext, txWaitOpts?: WaitOpts) {
|
|
@@ -174,34 +156,6 @@ export async function waitTxs(txs: SentTx[], context: EndToEndContext, txWaitOpt
|
|
|
174
156
|
context.logger.info(`All ${txs.length} txs have been mined`);
|
|
175
157
|
}
|
|
176
158
|
|
|
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
159
|
function randomBytesAsBigInts(length: number): bigint[] {
|
|
206
160
|
return [...Array(length)].map(_ => BigInt(Math.floor(Math.random() * 255)));
|
|
207
161
|
}
|
|
@@ -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 =
|
|
133
|
+
this.asset = 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 =
|
|
144
|
+
this.badAccount = 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
|
|