@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
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { randomBytes } from '@aztec/foundation/crypto/random';
|
|
2
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
3
|
+
import { sleep } from '@aztec/foundation/sleep';
|
|
4
|
+
import { RemoteSigner } from '@aztec/node-keystore';
|
|
5
|
+
|
|
6
|
+
import { mkdirSync } from 'node:fs';
|
|
7
|
+
import { writeFile } from 'node:fs/promises';
|
|
8
|
+
import { join } from 'node:path';
|
|
9
|
+
|
|
10
|
+
export async function createWeb3SignerKeystore(dir: string, ...privateKeys: string[]) {
|
|
11
|
+
const yaml = privateKeys
|
|
12
|
+
.map(
|
|
13
|
+
pk => `\
|
|
14
|
+
type: file-raw
|
|
15
|
+
keyType: SECP256K1
|
|
16
|
+
privateKey: ${pk}`,
|
|
17
|
+
)
|
|
18
|
+
.join('\n---\n');
|
|
19
|
+
|
|
20
|
+
// NOTE: nodejs stdlib can only create temp directories, not temp files!
|
|
21
|
+
// this write uses wx (write-exclusive) so it'll throw if the file already exists
|
|
22
|
+
const path = join(dir, `keystore-${randomBytes(4).toString('hex')}.yaml`);
|
|
23
|
+
await writeFile(path, yaml, { flag: 'wx' });
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export async function refreshWeb3Signer(url: string, ...expectedAddresses: string[]) {
|
|
27
|
+
await fetch(new URL('reload', url), { method: 'POST' });
|
|
28
|
+
|
|
29
|
+
if (expectedAddresses.length > 0) {
|
|
30
|
+
await retryUntil(
|
|
31
|
+
async () => {
|
|
32
|
+
try {
|
|
33
|
+
await RemoteSigner.validateAccess(url, expectedAddresses);
|
|
34
|
+
return true;
|
|
35
|
+
} catch {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
'web3signer refresh',
|
|
40
|
+
10,
|
|
41
|
+
0.5,
|
|
42
|
+
);
|
|
43
|
+
} else {
|
|
44
|
+
await sleep(1000);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function getWeb3SignerTestKeystoreDir(): string {
|
|
49
|
+
if (process.env.WEB3_SIGNER_TEST_KEYSTORE_DIR) {
|
|
50
|
+
mkdirSync(process.env.WEB3_SIGNER_TEST_KEYSTORE_DIR, { recursive: true });
|
|
51
|
+
return process.env.WEB3_SIGNER_TEST_KEYSTORE_DIR;
|
|
52
|
+
} else {
|
|
53
|
+
throw new Error('Web3signer not running');
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function getWeb3SignerUrl(): string {
|
|
58
|
+
if (process.env.WEB3_SIGNER_URL) {
|
|
59
|
+
return process.env.WEB3_SIGNER_URL;
|
|
60
|
+
} else {
|
|
61
|
+
throw new Error('Web3signer not running');
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -7,12 +7,12 @@ import {
|
|
|
7
7
|
} from '@aztec/telemetry-client';
|
|
8
8
|
import { OTelPinoStream } from '@aztec/telemetry-client/otel-pino-stream';
|
|
9
9
|
|
|
10
|
-
export function getEndToEndTestTelemetryClient(metricsPort?: number): TelemetryClient {
|
|
10
|
+
export async function getEndToEndTestTelemetryClient(metricsPort?: number): Promise<TelemetryClient> {
|
|
11
11
|
if (metricsPort) {
|
|
12
12
|
const otelStream = new OTelPinoStream({ levels });
|
|
13
13
|
registerLoggingStream(otelStream);
|
|
14
14
|
}
|
|
15
|
-
return initTelemetryClient(getEndToEndTestTelemetryConfig(metricsPort));
|
|
15
|
+
return await initTelemetryClient(getEndToEndTestTelemetryConfig(metricsPort));
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
/**
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
# Run locally from end-to-end folder while running anvil and
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Run locally from end-to-end folder while running anvil and local network with:
|
|
3
3
|
# PATH=$PATH:../node_modules/.bin ./src/guides/up_quick_start.sh
|
|
4
4
|
set -eux
|
|
5
5
|
|
|
6
6
|
export WALLET_DATA_DIRECTORY=$(mktemp -d)/up_quick_start
|
|
7
|
+
export PXE_PROVER="none"
|
|
7
8
|
|
|
8
9
|
function on_exit {
|
|
9
10
|
echo "Cleaning up $WALLET_DATA_DIRECTORY..."
|
|
@@ -18,37 +19,28 @@ aztec-wallet() {
|
|
|
18
19
|
aztec-wallet import-test-accounts
|
|
19
20
|
|
|
20
21
|
# docs:start:declare-accounts
|
|
21
|
-
aztec-wallet create-account -a alice
|
|
22
|
-
aztec-wallet create-account -a bob
|
|
22
|
+
aztec-wallet create-account -a alice -f test0
|
|
23
|
+
aztec-wallet create-account -a bob -f test0
|
|
23
24
|
# docs:end:declare-accounts
|
|
24
25
|
|
|
25
|
-
# docs:start:deploy
|
|
26
26
|
DEPLOY_OUTPUT=$(aztec-wallet deploy ../noir-contracts.js/artifacts/token_contract-Token.json --args accounts:test0 Test TST 18 -f test0)
|
|
27
27
|
TOKEN_ADDRESS=$(echo "$DEPLOY_OUTPUT" | grep -oE 'Contract deployed at 0x[0-9a-fA-F]+' | cut -d ' ' -f4)
|
|
28
28
|
echo "Deployed contract at $TOKEN_ADDRESS"
|
|
29
|
-
# docs:end:deploy
|
|
30
29
|
|
|
31
|
-
# docs:start:mint-private
|
|
32
30
|
MINT_AMOUNT=69
|
|
33
|
-
aztec-wallet send mint_to_private -ca last --args accounts:
|
|
34
|
-
# docs:end:mint-private
|
|
31
|
+
aztec-wallet send mint_to_private -ca last --args accounts:alice $MINT_AMOUNT -f test0
|
|
35
32
|
|
|
36
|
-
# docs:start:get-balance
|
|
37
33
|
ALICE_BALANCE=$(aztec-wallet simulate balance_of_private -ca last --args accounts:alice -f alice)
|
|
38
34
|
if ! echo $ALICE_BALANCE | grep -q $MINT_AMOUNT; then
|
|
39
35
|
echo "Incorrect Alice balance after transaction (expected $MINT_AMOUNT but got $ALICE_BALANCE)"
|
|
40
36
|
exit 1
|
|
41
37
|
fi
|
|
42
|
-
# docs:end:get-balance
|
|
43
38
|
|
|
44
|
-
# docs:start:transfer
|
|
45
39
|
TRANSFER_AMOUNT=42
|
|
46
40
|
|
|
47
41
|
aztec-wallet create-authwit transfer_in_private accounts:test0 -ca last --args accounts:alice accounts:bob $TRANSFER_AMOUNT 1 -f alice
|
|
48
|
-
aztec-wallet add-authwit authwits:last alice -f test0
|
|
49
42
|
|
|
50
|
-
aztec-wallet send transfer_in_private -ca last --args accounts:alice accounts:bob $TRANSFER_AMOUNT 1 -f test0
|
|
51
|
-
# docs:end:transfer
|
|
43
|
+
aztec-wallet send transfer_in_private -ca last --args accounts:alice accounts:bob $TRANSFER_AMOUNT 1 -aw authwits:last -f test0
|
|
52
44
|
|
|
53
45
|
# Test end result
|
|
54
46
|
ALICE_BALANCE=$(aztec-wallet simulate balance_of_private -ca last --args accounts:alice -f alice)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Logger } from '@aztec/aztec.js';
|
|
1
|
+
import type { Logger } from '@aztec/aztec.js/log';
|
|
2
2
|
|
|
3
3
|
import * as fs from 'fs';
|
|
4
4
|
import * as yaml from 'js-yaml';
|
|
@@ -25,7 +25,7 @@ const DEFAULT_CONFIG: AlertCheckerConfig = {
|
|
|
25
25
|
grafanaCredentials: 'admin:admin',
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
-
export class
|
|
28
|
+
export class GrafanaClient {
|
|
29
29
|
private config: AlertCheckerConfig;
|
|
30
30
|
private logger: Logger;
|
|
31
31
|
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
|
|
1
|
+
import type { AztecAddress } from '@aztec/aztec.js/addresses';
|
|
2
|
+
import { EthAddress } from '@aztec/aztec.js/addresses';
|
|
3
|
+
import { AuthWitness } from '@aztec/aztec.js/authorization';
|
|
2
4
|
import {
|
|
3
|
-
type AccountWallet,
|
|
4
|
-
type AztecAddress,
|
|
5
|
-
type AztecNode,
|
|
6
|
-
EthAddress,
|
|
7
|
-
type FieldsOf,
|
|
8
|
-
Fr,
|
|
9
5
|
type L1TokenManager,
|
|
10
6
|
L1TokenPortalManager,
|
|
11
7
|
type L2AmountClaim,
|
|
12
8
|
type L2AmountClaimWithRecipient,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
} from '@aztec/
|
|
21
|
-
import type { L1ContractAddresses
|
|
9
|
+
} from '@aztec/aztec.js/ethereum';
|
|
10
|
+
import { Fr } from '@aztec/aztec.js/fields';
|
|
11
|
+
import type { Logger } from '@aztec/aztec.js/log';
|
|
12
|
+
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
13
|
+
import type { SiblingPath } from '@aztec/aztec.js/trees';
|
|
14
|
+
import type { TxReceipt } from '@aztec/aztec.js/tx';
|
|
15
|
+
import type { Wallet } from '@aztec/aztec.js/wallet';
|
|
16
|
+
import { deployL1Contract } from '@aztec/ethereum/deploy-l1-contract';
|
|
17
|
+
import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
|
|
18
|
+
import type { ExtendedViemWalletClient } from '@aztec/ethereum/types';
|
|
19
|
+
import { EpochNumber } from '@aztec/foundation/branded-types';
|
|
20
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
21
|
+
import type { FieldsOf } from '@aztec/foundation/types';
|
|
22
22
|
import { TestERC20Abi, TokenPortalAbi, TokenPortalBytecode } from '@aztec/l1-artifacts';
|
|
23
23
|
import { TokenContract } from '@aztec/noir-contracts.js/Token';
|
|
24
24
|
import { TokenBridgeContract } from '@aztec/noir-contracts.js/TokenBridge';
|
|
@@ -27,7 +27,6 @@ import { type Hex, getContract } from 'viem';
|
|
|
27
27
|
|
|
28
28
|
import { mintTokensToPrivate } from '../fixtures/token_utils.js';
|
|
29
29
|
|
|
30
|
-
// docs:start:deployAndInitializeTokenAndBridgeContracts
|
|
31
30
|
/**
|
|
32
31
|
* Deploy L1 token and portal, initialize portal, deploy a non native l2 token contract, its L2 bridge contract and attach is to the portal.
|
|
33
32
|
* @param wallet - the wallet instance
|
|
@@ -40,8 +39,7 @@ import { mintTokensToPrivate } from '../fixtures/token_utils.js';
|
|
|
40
39
|
*/
|
|
41
40
|
export async function deployAndInitializeTokenAndBridgeContracts(
|
|
42
41
|
wallet: Wallet,
|
|
43
|
-
|
|
44
|
-
publicClient: ViemPublicClient,
|
|
42
|
+
l1Client: ExtendedViemWalletClient,
|
|
45
43
|
rollupRegistryAddress: EthAddress,
|
|
46
44
|
owner: AztecAddress,
|
|
47
45
|
underlyingERC20Address: EthAddress,
|
|
@@ -68,35 +66,34 @@ export async function deployAndInitializeTokenAndBridgeContracts(
|
|
|
68
66
|
underlyingERC20: any;
|
|
69
67
|
}> {
|
|
70
68
|
// deploy the token portal
|
|
71
|
-
const { address: tokenPortalAddress } = await deployL1Contract(
|
|
72
|
-
walletClient,
|
|
73
|
-
publicClient,
|
|
74
|
-
TokenPortalAbi,
|
|
75
|
-
TokenPortalBytecode,
|
|
76
|
-
);
|
|
69
|
+
const { address: tokenPortalAddress } = await deployL1Contract(l1Client, TokenPortalAbi, TokenPortalBytecode);
|
|
77
70
|
const tokenPortal = getContract({
|
|
78
71
|
address: tokenPortalAddress.toString(),
|
|
79
72
|
abi: TokenPortalAbi,
|
|
80
|
-
client:
|
|
73
|
+
client: l1Client,
|
|
81
74
|
});
|
|
82
75
|
|
|
83
76
|
// deploy l2 token
|
|
84
|
-
const token = await TokenContract.deploy(wallet, owner, 'TokenName', 'TokenSymbol', 18)
|
|
77
|
+
const token = await TokenContract.deploy(wallet, owner, 'TokenName', 'TokenSymbol', 18)
|
|
78
|
+
.send({ from: owner })
|
|
79
|
+
.deployed();
|
|
85
80
|
|
|
86
81
|
// deploy l2 token bridge and attach to the portal
|
|
87
|
-
const bridge = await TokenBridgeContract.deploy(wallet, token.address, tokenPortalAddress)
|
|
82
|
+
const bridge = await TokenBridgeContract.deploy(wallet, token.address, tokenPortalAddress)
|
|
83
|
+
.send({ from: owner })
|
|
84
|
+
.deployed();
|
|
88
85
|
|
|
89
|
-
if ((await token.methods.get_admin().simulate()) !== owner.toBigInt()) {
|
|
86
|
+
if ((await token.methods.get_admin().simulate({ from: owner })) !== owner.toBigInt()) {
|
|
90
87
|
throw new Error(`Token admin is not ${owner}`);
|
|
91
88
|
}
|
|
92
89
|
|
|
93
|
-
if (!(await bridge.methods.get_config().simulate()).token.equals(token.address)) {
|
|
90
|
+
if (!(await bridge.methods.get_config().simulate({ from: owner })).token.equals(token.address)) {
|
|
94
91
|
throw new Error(`Bridge token is not ${token.address}`);
|
|
95
92
|
}
|
|
96
93
|
|
|
97
94
|
// make the bridge a minter on the token:
|
|
98
|
-
await token.methods.set_minter(bridge.address, true).send().wait();
|
|
99
|
-
if ((await token.methods.is_minter(bridge.address).simulate()) === 1n) {
|
|
95
|
+
await token.methods.set_minter(bridge.address, true).send({ from: owner }).wait();
|
|
96
|
+
if ((await token.methods.is_minter(bridge.address).simulate({ from: owner })) === 1n) {
|
|
100
97
|
throw new Error(`Bridge is not a minter`);
|
|
101
98
|
}
|
|
102
99
|
|
|
@@ -109,12 +106,22 @@ export async function deployAndInitializeTokenAndBridgeContracts(
|
|
|
109
106
|
const underlyingERC20 = getContract({
|
|
110
107
|
address: underlyingERC20Address.toString(),
|
|
111
108
|
abi: TestERC20Abi,
|
|
112
|
-
client:
|
|
109
|
+
client: l1Client,
|
|
113
110
|
});
|
|
114
111
|
|
|
115
112
|
return { token, bridge, tokenPortalAddress, tokenPortal, underlyingERC20 };
|
|
116
113
|
}
|
|
117
|
-
|
|
114
|
+
|
|
115
|
+
export type CrossChainContext = {
|
|
116
|
+
l2Token: AztecAddress;
|
|
117
|
+
l2Bridge: AztecAddress;
|
|
118
|
+
tokenPortal: EthAddress;
|
|
119
|
+
underlying: EthAddress;
|
|
120
|
+
ethAccount: EthAddress;
|
|
121
|
+
ownerAddress: AztecAddress;
|
|
122
|
+
inbox: EthAddress;
|
|
123
|
+
outbox: EthAddress;
|
|
124
|
+
};
|
|
118
125
|
|
|
119
126
|
/**
|
|
120
127
|
* A Class for testing cross chain interactions, contains common interactions
|
|
@@ -123,54 +130,47 @@ export async function deployAndInitializeTokenAndBridgeContracts(
|
|
|
123
130
|
export class CrossChainTestHarness {
|
|
124
131
|
static async new(
|
|
125
132
|
aztecNode: AztecNode,
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
wallet: AccountWallet,
|
|
133
|
+
l1Client: ExtendedViemWalletClient,
|
|
134
|
+
wallet: Wallet,
|
|
135
|
+
ownerAddress: AztecAddress,
|
|
130
136
|
logger: Logger,
|
|
131
137
|
underlyingERC20Address: EthAddress,
|
|
132
138
|
): Promise<CrossChainTestHarness> {
|
|
133
|
-
const ethAccount = EthAddress.fromString((await
|
|
134
|
-
const l1ContractAddresses = (await
|
|
139
|
+
const ethAccount = EthAddress.fromString((await l1Client.getAddresses())[0]);
|
|
140
|
+
const l1ContractAddresses = (await aztecNode.getNodeInfo()).l1ContractAddresses;
|
|
135
141
|
|
|
136
142
|
// Deploy and initialize all required contracts
|
|
137
143
|
logger.info('Deploying and initializing token, portal and its bridge...');
|
|
138
144
|
const { token, bridge, tokenPortalAddress, underlyingERC20 } = await deployAndInitializeTokenAndBridgeContracts(
|
|
139
145
|
wallet,
|
|
140
|
-
|
|
141
|
-
publicClient,
|
|
146
|
+
l1Client,
|
|
142
147
|
l1ContractAddresses.registryAddress,
|
|
143
|
-
|
|
148
|
+
ownerAddress,
|
|
144
149
|
underlyingERC20Address,
|
|
145
150
|
);
|
|
146
151
|
logger.info('Deployed and initialized token, portal and its bridge.');
|
|
147
152
|
|
|
148
153
|
return new CrossChainTestHarness(
|
|
149
154
|
aztecNode,
|
|
150
|
-
pxeService,
|
|
151
155
|
logger,
|
|
152
156
|
token,
|
|
153
157
|
bridge,
|
|
154
158
|
ethAccount,
|
|
155
159
|
tokenPortalAddress,
|
|
156
160
|
underlyingERC20.address,
|
|
157
|
-
|
|
158
|
-
walletClient,
|
|
161
|
+
l1Client,
|
|
159
162
|
l1ContractAddresses,
|
|
160
163
|
wallet,
|
|
164
|
+
ownerAddress,
|
|
161
165
|
);
|
|
162
166
|
}
|
|
163
167
|
|
|
164
168
|
private readonly l1TokenManager: L1TokenManager;
|
|
165
169
|
private readonly l1TokenPortalManager: L1TokenPortalManager;
|
|
166
170
|
|
|
167
|
-
public readonly ownerAddress: AztecAddress;
|
|
168
|
-
|
|
169
171
|
constructor(
|
|
170
172
|
/** Aztec node instance. */
|
|
171
173
|
public aztecNode: AztecNode,
|
|
172
|
-
/** Private eXecution Environment (PXE). */
|
|
173
|
-
public pxeService: PXE,
|
|
174
174
|
/** Logger. */
|
|
175
175
|
public logger: Logger,
|
|
176
176
|
|
|
@@ -186,32 +186,39 @@ export class CrossChainTestHarness {
|
|
|
186
186
|
public tokenPortalAddress: EthAddress,
|
|
187
187
|
/** Underlying token for portal tests. */
|
|
188
188
|
public underlyingERC20Address: EthAddress,
|
|
189
|
-
/** Viem
|
|
190
|
-
public
|
|
191
|
-
/** Viem Wallet Client instance. */
|
|
192
|
-
public walletClient: ViemWalletClient,
|
|
189
|
+
/** Viem Extended client instance. */
|
|
190
|
+
public l1Client: ExtendedViemWalletClient,
|
|
193
191
|
|
|
194
192
|
/** Deployment addresses for all L1 contracts */
|
|
195
193
|
public readonly l1ContractAddresses: L1ContractAddresses,
|
|
196
194
|
|
|
197
|
-
/** Wallet
|
|
198
|
-
public readonly
|
|
195
|
+
/** Wallet to simulate and send txs from. */
|
|
196
|
+
public readonly wallet: Wallet,
|
|
197
|
+
|
|
198
|
+
/** Owner of the l2 token and bridge */
|
|
199
|
+
public readonly ownerAddress: AztecAddress,
|
|
199
200
|
) {
|
|
200
201
|
this.l1TokenPortalManager = new L1TokenPortalManager(
|
|
201
202
|
this.tokenPortalAddress,
|
|
202
203
|
this.underlyingERC20Address,
|
|
204
|
+
this.l1ContractAddresses.feeAssetHandlerAddress,
|
|
203
205
|
this.l1ContractAddresses.outboxAddress,
|
|
204
|
-
this.
|
|
205
|
-
this.walletClient,
|
|
206
|
+
this.l1Client,
|
|
206
207
|
this.logger,
|
|
207
208
|
);
|
|
208
209
|
this.l1TokenManager = this.l1TokenPortalManager.getTokenManager();
|
|
209
|
-
this.ownerAddress = this.ownerWallet.getAddress();
|
|
210
210
|
}
|
|
211
211
|
|
|
212
212
|
async mintTokensOnL1(amount: bigint) {
|
|
213
|
-
|
|
214
|
-
|
|
213
|
+
const contract = getContract({
|
|
214
|
+
abi: TestERC20Abi,
|
|
215
|
+
address: this.l1TokenManager.tokenAddress.toString(),
|
|
216
|
+
client: this.l1Client,
|
|
217
|
+
});
|
|
218
|
+
const balanceBefore = await this.l1TokenManager.getL1TokenBalance(this.ethAccount.toString());
|
|
219
|
+
const hash = await contract.write.mint([this.ethAccount.toString(), amount]);
|
|
220
|
+
await this.l1Client.waitForTransactionReceipt({ hash });
|
|
221
|
+
expect(await this.l1TokenManager.getL1TokenBalance(this.ethAccount.toString())).toEqual(balanceBefore + amount);
|
|
215
222
|
}
|
|
216
223
|
|
|
217
224
|
getL1BalanceOf(address: EthAddress) {
|
|
@@ -228,16 +235,19 @@ export class CrossChainTestHarness {
|
|
|
228
235
|
|
|
229
236
|
async mintTokensPublicOnL2(amount: bigint) {
|
|
230
237
|
this.logger.info('Minting tokens on L2 publicly');
|
|
231
|
-
await this.l2Token.methods.mint_to_public(this.ownerAddress, amount).send().wait();
|
|
238
|
+
await this.l2Token.methods.mint_to_public(this.ownerAddress, amount).send({ from: this.ownerAddress }).wait();
|
|
232
239
|
}
|
|
233
240
|
|
|
234
241
|
async mintTokensPrivateOnL2(amount: bigint) {
|
|
235
|
-
await mintTokensToPrivate(this.l2Token, this.
|
|
242
|
+
await mintTokensToPrivate(this.l2Token, this.ownerAddress, this.ownerAddress, amount);
|
|
236
243
|
}
|
|
237
244
|
|
|
238
245
|
async sendL2PublicTransfer(transferAmount: bigint, receiverAddress: AztecAddress) {
|
|
239
246
|
// send a transfer tx to force through rollup with the message included
|
|
240
|
-
await this.l2Token.methods
|
|
247
|
+
await this.l2Token.methods
|
|
248
|
+
.transfer_in_public(this.ownerAddress, receiverAddress, transferAmount, 0)
|
|
249
|
+
.send({ from: this.ownerAddress })
|
|
250
|
+
.wait();
|
|
241
251
|
}
|
|
242
252
|
|
|
243
253
|
async consumeMessageOnAztecAndMintPrivately(
|
|
@@ -247,7 +257,7 @@ export class CrossChainTestHarness {
|
|
|
247
257
|
const { recipient, claimAmount, claimSecret: secretForL2MessageConsumption, messageLeafIndex } = claim;
|
|
248
258
|
await this.l2Bridge.methods
|
|
249
259
|
.claim_private(recipient, claimAmount, secretForL2MessageConsumption, messageLeafIndex)
|
|
250
|
-
.send()
|
|
260
|
+
.send({ from: this.ownerAddress })
|
|
251
261
|
.wait();
|
|
252
262
|
}
|
|
253
263
|
|
|
@@ -258,23 +268,27 @@ export class CrossChainTestHarness {
|
|
|
258
268
|
const { claimAmount, claimSecret, messageLeafIndex } = claim;
|
|
259
269
|
await this.l2Bridge.methods
|
|
260
270
|
.claim_public(this.ownerAddress, claimAmount, claimSecret, messageLeafIndex)
|
|
261
|
-
.send()
|
|
271
|
+
.send({ from: this.ownerAddress })
|
|
262
272
|
.wait();
|
|
263
273
|
}
|
|
264
274
|
|
|
265
|
-
async withdrawPrivateFromAztecToL1(
|
|
275
|
+
async withdrawPrivateFromAztecToL1(
|
|
276
|
+
withdrawAmount: bigint,
|
|
277
|
+
authwitNonce: Fr = Fr.ZERO,
|
|
278
|
+
authWitness: AuthWitness,
|
|
279
|
+
): Promise<FieldsOf<TxReceipt>> {
|
|
266
280
|
const withdrawReceipt = await this.l2Bridge.methods
|
|
267
|
-
.exit_to_l1_private(this.l2Token.address, this.ethAccount, withdrawAmount, EthAddress.ZERO,
|
|
268
|
-
.send()
|
|
281
|
+
.exit_to_l1_private(this.l2Token.address, this.ethAccount, withdrawAmount, EthAddress.ZERO, authwitNonce)
|
|
282
|
+
.send({ authWitnesses: [authWitness], from: this.ownerAddress })
|
|
269
283
|
.wait();
|
|
270
284
|
|
|
271
285
|
return withdrawReceipt;
|
|
272
286
|
}
|
|
273
287
|
|
|
274
|
-
async withdrawPublicFromAztecToL1(withdrawAmount: bigint,
|
|
288
|
+
async withdrawPublicFromAztecToL1(withdrawAmount: bigint, authwitNonce: Fr = Fr.ZERO): Promise<FieldsOf<TxReceipt>> {
|
|
275
289
|
const withdrawReceipt = await this.l2Bridge.methods
|
|
276
|
-
.exit_to_l1_public(this.ethAccount, withdrawAmount, EthAddress.ZERO,
|
|
277
|
-
.send()
|
|
290
|
+
.exit_to_l1_public(this.ethAccount, withdrawAmount, EthAddress.ZERO, authwitNonce)
|
|
291
|
+
.send({ from: this.ownerAddress })
|
|
278
292
|
.wait();
|
|
279
293
|
|
|
280
294
|
return withdrawReceipt;
|
|
@@ -291,7 +305,7 @@ export class CrossChainTestHarness {
|
|
|
291
305
|
}
|
|
292
306
|
|
|
293
307
|
async getL2PublicBalanceOf(owner: AztecAddress) {
|
|
294
|
-
return await this.l2Token.methods.balance_of_public(owner).simulate();
|
|
308
|
+
return await this.l2Token.methods.balance_of_public(owner).simulate({ from: this.ownerAddress });
|
|
295
309
|
}
|
|
296
310
|
|
|
297
311
|
async expectPublicBalanceOnL2(owner: AztecAddress, expectedBalance: bigint) {
|
|
@@ -299,8 +313,8 @@ export class CrossChainTestHarness {
|
|
|
299
313
|
expect(balance).toBe(expectedBalance);
|
|
300
314
|
}
|
|
301
315
|
|
|
302
|
-
getL2ToL1MessageLeaf(withdrawAmount: bigint, callerOnL1: EthAddress = EthAddress.ZERO): Fr {
|
|
303
|
-
return this.l1TokenPortalManager.getL2ToL1MessageLeaf(
|
|
316
|
+
async getL2ToL1MessageLeaf(withdrawAmount: bigint, callerOnL1: EthAddress = EthAddress.ZERO): Promise<Fr> {
|
|
317
|
+
return await this.l1TokenPortalManager.getL2ToL1MessageLeaf(
|
|
304
318
|
withdrawAmount,
|
|
305
319
|
this.ethAccount,
|
|
306
320
|
this.l2Bridge.address,
|
|
@@ -310,27 +324,27 @@ export class CrossChainTestHarness {
|
|
|
310
324
|
|
|
311
325
|
withdrawFundsFromBridgeOnL1(
|
|
312
326
|
amount: bigint,
|
|
313
|
-
|
|
327
|
+
epochNumber: EpochNumber,
|
|
314
328
|
messageIndex: bigint,
|
|
315
329
|
siblingPath: SiblingPath<number>,
|
|
316
330
|
) {
|
|
317
|
-
return this.l1TokenPortalManager.withdrawFunds(
|
|
318
|
-
amount,
|
|
319
|
-
this.ethAccount,
|
|
320
|
-
BigInt(blockNumber),
|
|
321
|
-
messageIndex,
|
|
322
|
-
siblingPath,
|
|
323
|
-
);
|
|
331
|
+
return this.l1TokenPortalManager.withdrawFunds(amount, this.ethAccount, epochNumber, messageIndex, siblingPath);
|
|
324
332
|
}
|
|
325
333
|
|
|
326
334
|
async transferToPrivateOnL2(shieldAmount: bigint) {
|
|
327
335
|
this.logger.info('Transferring to private on L2');
|
|
328
|
-
await this.l2Token.methods
|
|
336
|
+
await this.l2Token.methods
|
|
337
|
+
.transfer_to_private(this.ownerAddress, shieldAmount)
|
|
338
|
+
.send({ from: this.ownerAddress })
|
|
339
|
+
.wait();
|
|
329
340
|
}
|
|
330
341
|
|
|
331
|
-
async transferToPublicOnL2(amount: bigint,
|
|
342
|
+
async transferToPublicOnL2(amount: bigint, authwitNonce = Fr.ZERO) {
|
|
332
343
|
this.logger.info('Transferring tokens to public');
|
|
333
|
-
await this.l2Token.methods
|
|
344
|
+
await this.l2Token.methods
|
|
345
|
+
.transfer_to_public(this.ownerAddress, this.ownerAddress, amount, authwitNonce)
|
|
346
|
+
.send({ from: this.ownerAddress })
|
|
347
|
+
.wait();
|
|
334
348
|
}
|
|
335
349
|
|
|
336
350
|
/**
|
|
@@ -348,5 +362,17 @@ export class CrossChainTestHarness {
|
|
|
348
362
|
await this.mintTokensPublicOnL2(0n);
|
|
349
363
|
await this.mintTokensPublicOnL2(0n);
|
|
350
364
|
}
|
|
365
|
+
|
|
366
|
+
toCrossChainContext(): CrossChainContext {
|
|
367
|
+
return {
|
|
368
|
+
l2Token: this.l2Token.address,
|
|
369
|
+
l2Bridge: this.l2Bridge.address,
|
|
370
|
+
tokenPortal: this.tokenPortalAddress,
|
|
371
|
+
underlying: this.underlyingERC20Address,
|
|
372
|
+
ethAccount: this.ethAccount,
|
|
373
|
+
ownerAddress: this.ownerAddress,
|
|
374
|
+
inbox: this.l1ContractAddresses.inboxAddress,
|
|
375
|
+
outbox: this.l1ContractAddresses.outboxAddress,
|
|
376
|
+
};
|
|
377
|
+
}
|
|
351
378
|
}
|
|
352
|
-
// docs:end:cross_chain_test_harness
|