@aztec/end-to-end 0.0.0-test.1 → 0.0.1-commit.017a351
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/README.md +27 -0
- package/dest/bench/client_flows/benchmark.d.ts +76 -0
- package/dest/bench/client_flows/benchmark.d.ts.map +1 -0
- package/dest/bench/client_flows/benchmark.js +298 -0
- package/dest/bench/client_flows/client_flows_benchmark.d.ts +79 -0
- package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -0
- package/dest/bench/client_flows/client_flows_benchmark.js +318 -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 +124 -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 +16 -41
- package/dest/bench/utils.d.ts.map +1 -1
- package/dest/bench/utils.js +46 -72
- package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +30 -20
- 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 +137 -106
- package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +44 -33
- 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 +136 -103
- package/dest/e2e_deploy_contract/deploy_test.d.ts +20 -11
- package/dest/e2e_deploy_contract/deploy_test.d.ts.map +1 -1
- package/dest/e2e_deploy_contract/deploy_test.js +28 -28
- package/dest/e2e_epochs/epochs_test.d.ts +98 -24
- package/dest/e2e_epochs/epochs_test.d.ts.map +1 -1
- package/dest/e2e_epochs/epochs_test.js +366 -61
- 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 +61 -0
- package/dest/e2e_fees/fees_test.d.ts +42 -24
- package/dest/e2e_fees/fees_test.d.ts.map +1 -1
- package/dest/e2e_fees/fees_test.js +194 -182
- package/dest/e2e_l1_publisher/write_json.d.ts +11 -0
- package/dest/e2e_l1_publisher/write_json.d.ts.map +1 -0
- package/dest/e2e_l1_publisher/write_json.js +56 -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 +16 -16
- package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +1 -1
- package/dest/e2e_nested_contract/nested_contract_test.js +38 -43
- 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 +137 -0
- package/dest/e2e_p2p/p2p_network.d.ts +287 -31
- package/dest/e2e_p2p/p2p_network.d.ts.map +1 -1
- package/dest/e2e_p2p/p2p_network.js +281 -183
- package/dest/e2e_p2p/reqresp/utils.d.ts +22 -0
- package/dest/e2e_p2p/reqresp/utils.d.ts.map +1 -0
- package/dest/e2e_p2p/reqresp/utils.js +206 -0
- package/dest/e2e_p2p/shared.d.ts +73 -8
- package/dest/e2e_p2p/shared.d.ts.map +1 -1
- package/dest/e2e_p2p/shared.js +205 -27
- package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.d.ts +2 -0
- package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.d.ts.map +1 -0
- package/dest/e2e_storage_proof/fixtures/storage_proof_fetcher.js +184 -0
- package/dest/e2e_storage_proof/fixtures/storage_proof_fixture.d.ts +18 -0
- package/dest/e2e_storage_proof/fixtures/storage_proof_fixture.d.ts.map +1 -0
- package/dest/e2e_storage_proof/fixtures/storage_proof_fixture.js +120 -0
- package/dest/e2e_token_contract/token_contract_test.d.ts +30 -15
- package/dest/e2e_token_contract/token_contract_test.d.ts.map +1 -1
- package/dest/e2e_token_contract/token_contract_test.js +110 -76
- package/dest/fixtures/authwit_proxy.d.ts +15 -0
- package/dest/fixtures/authwit_proxy.d.ts.map +1 -0
- package/dest/fixtures/authwit_proxy.js +34 -0
- package/dest/fixtures/e2e_prover_test.d.ts +56 -0
- package/dest/fixtures/e2e_prover_test.d.ts.map +1 -0
- package/dest/fixtures/e2e_prover_test.js +267 -0
- package/dest/fixtures/elu_monitor.d.ts +21 -0
- package/dest/fixtures/elu_monitor.d.ts.map +1 -0
- package/dest/fixtures/elu_monitor.js +102 -0
- package/dest/fixtures/fixtures.d.ts +79 -8
- package/dest/fixtures/fixtures.d.ts.map +1 -1
- package/dest/fixtures/fixtures.js +76 -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/ha_setup.d.ts +71 -0
- package/dest/fixtures/ha_setup.d.ts.map +1 -0
- package/dest/fixtures/ha_setup.js +116 -0
- package/dest/fixtures/index.d.ts +2 -1
- package/dest/fixtures/index.d.ts.map +1 -1
- package/dest/fixtures/index.js +1 -0
- 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/schnorr_hardcoded_account_contract.d.ts +25 -0
- package/dest/fixtures/schnorr_hardcoded_account_contract.d.ts.map +1 -0
- package/dest/fixtures/schnorr_hardcoded_account_contract.js +37 -0
- package/dest/fixtures/setup.d.ts +272 -0
- package/dest/fixtures/setup.d.ts.map +1 -0
- package/dest/fixtures/setup.js +735 -0
- package/dest/fixtures/setup_p2p_test.d.ts +28 -16
- package/dest/fixtures/setup_p2p_test.d.ts.map +1 -1
- package/dest/fixtures/setup_p2p_test.js +103 -32
- 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 +30 -13
- package/dest/fixtures/utils.d.ts +5 -153
- package/dest/fixtures/utils.d.ts.map +1 -1
- package/dest/fixtures/utils.js +4 -552
- 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/forward-compatibility/wallet_rpc_client.d.ts +7 -0
- package/dest/forward-compatibility/wallet_rpc_client.d.ts.map +1 -0
- package/dest/forward-compatibility/wallet_rpc_client.js +15 -0
- package/dest/forward-compatibility/wallet_service.d.ts +3 -0
- package/dest/forward-compatibility/wallet_service.d.ts.map +1 -0
- package/dest/forward-compatibility/wallet_service.js +109 -0
- package/dest/index.d.ts +1 -1
- package/dest/install_legacy_contracts.d.cts +10 -0
- package/dest/install_legacy_contracts.d.cts.map +1 -0
- package/dest/legacy-jest-resolver.d.cts +3 -0
- package/dest/legacy-jest-resolver.d.cts.map +1 -0
- 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/quality_of_service/prometheus_client.d.ts +38 -0
- package/dest/quality_of_service/prometheus_client.d.ts.map +1 -0
- package/dest/quality_of_service/prometheus_client.js +67 -0
- package/dest/shared/cross_chain_test_harness.d.ts +46 -27
- package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
- package/dest/shared/cross_chain_test_harness.js +113 -55
- package/dest/shared/gas_portal_test_harness.d.ts +39 -28
- package/dest/shared/gas_portal_test_harness.d.ts.map +1 -1
- package/dest/shared/gas_portal_test_harness.js +64 -34
- package/dest/shared/index.d.ts +3 -2
- package/dest/shared/index.d.ts.map +1 -1
- package/dest/shared/index.js +1 -0
- package/dest/shared/jest_setup.d.ts +1 -1
- package/dest/shared/jest_setup.js +42 -2
- package/dest/shared/mock_state_view.d.ts +86 -0
- package/dest/shared/mock_state_view.d.ts.map +1 -0
- package/dest/shared/mock_state_view.js +186 -0
- 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 +15 -16
- 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 +202 -135
- package/dest/shared/wait_for_l1_to_l2_message.d.ts +13 -0
- package/dest/shared/wait_for_l1_to_l2_message.d.ts.map +1 -0
- package/dest/shared/wait_for_l1_to_l2_message.js +10 -0
- package/dest/simulators/index.d.ts +1 -1
- package/dest/simulators/lending_simulator.d.ts +16 -9
- package/dest/simulators/lending_simulator.d.ts.map +1 -1
- package/dest/simulators/lending_simulator.js +38 -27
- 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 +12 -30
- package/dest/spartan/setup_test_wallets.d.ts +36 -11
- package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
- package/dest/spartan/setup_test_wallets.js +301 -63
- package/dest/spartan/tx_metrics.d.ts +102 -0
- package/dest/spartan/tx_metrics.d.ts.map +1 -0
- package/dest/spartan/tx_metrics.js +475 -0
- package/dest/spartan/utils/bot.d.ts +28 -0
- package/dest/spartan/utils/bot.d.ts.map +1 -0
- package/dest/spartan/utils/bot.js +142 -0
- package/dest/spartan/utils/chaos.d.ts +79 -0
- package/dest/spartan/utils/chaos.d.ts.map +1 -0
- package/dest/spartan/utils/chaos.js +142 -0
- package/dest/spartan/utils/clients.d.ts +39 -0
- package/dest/spartan/utils/clients.d.ts.map +1 -0
- package/dest/spartan/utils/clients.js +90 -0
- package/dest/spartan/utils/config.d.ts +19 -0
- package/dest/spartan/utils/config.d.ts.map +1 -0
- package/dest/spartan/utils/config.js +23 -0
- package/dest/spartan/utils/health.d.ts +63 -0
- package/dest/spartan/utils/health.d.ts.map +1 -0
- package/dest/spartan/utils/health.js +202 -0
- package/dest/spartan/utils/helm.d.ts +15 -0
- package/dest/spartan/utils/helm.d.ts.map +1 -0
- package/dest/spartan/utils/helm.js +47 -0
- package/dest/spartan/utils/index.d.ts +11 -0
- package/dest/spartan/utils/index.d.ts.map +1 -0
- package/dest/spartan/utils/index.js +22 -0
- package/dest/spartan/utils/k8s.d.ts +128 -0
- package/dest/spartan/utils/k8s.d.ts.map +1 -0
- package/dest/spartan/utils/k8s.js +381 -0
- package/dest/spartan/utils/nodes.d.ts +40 -0
- package/dest/spartan/utils/nodes.d.ts.map +1 -0
- package/dest/spartan/utils/nodes.js +461 -0
- package/dest/spartan/utils/pod_logs.d.ts +25 -0
- package/dest/spartan/utils/pod_logs.d.ts.map +1 -0
- package/dest/spartan/utils/pod_logs.js +74 -0
- package/dest/spartan/utils/scripts.d.ts +30 -0
- package/dest/spartan/utils/scripts.d.ts.map +1 -0
- package/dest/spartan/utils/scripts.js +81 -0
- package/dest/spartan/utils.d.ts +2 -415
- package/dest/spartan/utils.d.ts.map +1 -1
- package/dest/spartan/utils.js +1 -445
- package/dest/test-wallet/test_wallet.d.ts +85 -0
- package/dest/test-wallet/test_wallet.d.ts.map +1 -0
- package/dest/test-wallet/test_wallet.js +273 -0
- package/dest/test-wallet/utils.d.ts +41 -0
- package/dest/test-wallet/utils.d.ts.map +1 -0
- package/dest/test-wallet/utils.js +66 -0
- package/dest/test-wallet/wallet_worker_script.d.ts +2 -0
- package/dest/test-wallet/wallet_worker_script.d.ts.map +1 -0
- package/dest/test-wallet/wallet_worker_script.js +53 -0
- package/dest/test-wallet/worker_wallet.d.ts +53 -0
- package/dest/test-wallet/worker_wallet.d.ts.map +1 -0
- package/dest/test-wallet/worker_wallet.js +155 -0
- package/dest/test-wallet/worker_wallet_schema.d.ts +160 -0
- package/dest/test-wallet/worker_wallet_schema.d.ts.map +1 -0
- package/dest/test-wallet/worker_wallet_schema.js +22 -0
- package/package.json +79 -64
- package/src/bench/client_flows/benchmark.ts +382 -0
- package/src/bench/client_flows/client_flows_benchmark.ts +399 -0
- package/src/bench/client_flows/config.ts +69 -0
- package/src/bench/client_flows/data_extractor.ts +89 -0
- package/src/bench/utils.ts +49 -87
- package/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +164 -172
- package/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +194 -183
- package/src/e2e_deploy_contract/deploy_test.ts +42 -49
- package/src/e2e_epochs/epochs_test.ts +451 -93
- package/src/e2e_fees/bridging_race.notest.ts +74 -0
- package/src/e2e_fees/fees_test.ts +249 -262
- package/src/e2e_l1_publisher/write_json.ts +77 -0
- package/src/e2e_multi_validator/utils.ts +258 -0
- package/src/e2e_nested_contract/nested_contract_test.ts +51 -60
- package/src/e2e_p2p/inactivity_slash_test.ts +180 -0
- package/src/e2e_p2p/p2p_network.ts +391 -240
- package/src/e2e_p2p/reqresp/utils.ts +274 -0
- package/src/e2e_p2p/shared.ts +304 -39
- package/src/e2e_storage_proof/fixtures/storage_proof.json +915 -0
- package/src/e2e_storage_proof/fixtures/storage_proof_fetcher.ts +190 -0
- package/src/e2e_storage_proof/fixtures/storage_proof_fixture.ts +173 -0
- package/src/e2e_token_contract/token_contract_test.ts +140 -124
- package/src/fixtures/authwit_proxy.ts +54 -0
- package/src/fixtures/dumps/epoch_proof_result.json +1 -1
- package/src/fixtures/e2e_prover_test.ts +329 -0
- package/src/fixtures/elu_monitor.ts +126 -0
- package/src/fixtures/fixtures.ts +98 -7
- package/src/fixtures/get_acvm_config.ts +4 -12
- package/src/fixtures/get_bb_config.ts +19 -13
- package/src/fixtures/ha_setup.ts +188 -0
- package/src/fixtures/index.ts +1 -0
- package/src/fixtures/l1_to_l2_messaging.ts +56 -24
- package/src/fixtures/schnorr_hardcoded_account_contract.ts +49 -0
- package/src/fixtures/setup.ts +1056 -0
- package/src/fixtures/setup_p2p_test.ts +142 -54
- package/src/fixtures/token_utils.ts +34 -16
- package/src/fixtures/utils.ts +29 -820
- package/src/fixtures/web3signer.ts +63 -0
- package/src/fixtures/with_telemetry_utils.ts +2 -2
- package/src/forward-compatibility/wallet_rpc_client.ts +14 -0
- package/src/forward-compatibility/wallet_service.ts +104 -0
- package/src/guides/up_quick_start.sh +9 -19
- package/src/install_legacy_contracts.cjs +75 -0
- package/src/legacy-jest-resolver.cjs +112 -0
- package/src/quality_of_service/{alert_checker.ts → grafana_client.ts} +2 -2
- package/src/quality_of_service/prometheus_client.ts +113 -0
- package/src/shared/cross_chain_test_harness.ts +116 -90
- package/src/shared/gas_portal_test_harness.ts +75 -56
- package/src/shared/index.ts +2 -1
- package/src/shared/jest_setup.ts +52 -2
- package/src/shared/mock_state_view.ts +188 -0
- package/src/shared/submit-transactions.ts +19 -20
- package/src/shared/uniswap_l1_l2.ts +259 -234
- package/src/shared/wait_for_l1_to_l2_message.ts +23 -0
- package/src/simulators/lending_simulator.ts +43 -26
- package/src/simulators/token_simulator.ts +18 -34
- package/src/spartan/DEVELOP.md +128 -0
- package/src/spartan/setup_test_wallets.ts +420 -96
- package/src/spartan/tx_metrics.ts +434 -0
- package/src/spartan/utils/bot.ts +188 -0
- package/src/spartan/utils/chaos.ts +253 -0
- package/src/spartan/utils/clients.ts +100 -0
- package/src/spartan/utils/config.ts +29 -0
- package/src/spartan/utils/health.ts +255 -0
- package/src/spartan/utils/helm.ts +84 -0
- package/src/spartan/utils/index.ts +71 -0
- package/src/spartan/utils/k8s.ts +535 -0
- package/src/spartan/utils/nodes.ts +543 -0
- package/src/spartan/utils/pod_logs.ts +99 -0
- package/src/spartan/utils/scripts.ts +99 -0
- package/src/spartan/utils.ts +1 -582
- package/src/test-wallet/test_wallet.ts +376 -0
- package/src/test-wallet/utils.ts +108 -0
- package/src/test-wallet/wallet_worker_script.ts +63 -0
- package/src/test-wallet/worker_wallet.ts +218 -0
- package/src/test-wallet/worker_wallet_schema.ts +13 -0
- 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/e2e_prover/e2e_prover_test.js +0 -291
- 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/fixtures/snapshot_manager.d.ts +0 -87
- package/dest/fixtures/snapshot_manager.d.ts.map +0 -1
- package/dest/fixtures/snapshot_manager.js +0 -479
- 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/e2e_prover/e2e_prover_test.ts +0 -418
- package/src/fixtures/setup_l1_contracts.ts +0 -27
- package/src/fixtures/snapshot_manager.ts +0 -617
- 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
|
@@ -1,30 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
} from '@aztec/
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
extractEvent,
|
|
19
|
-
} from '@aztec/ethereum';
|
|
20
|
-
import { sha256ToField } from '@aztec/foundation/crypto';
|
|
21
|
-
import { InboxAbi, RollupAbi, UniswapPortalAbi, UniswapPortalBytecode } from '@aztec/l1-artifacts';
|
|
1
|
+
import { AztecAddress, EthAddress } from '@aztec/aztec.js/addresses';
|
|
2
|
+
import { computeAuthWitMessageHash } from '@aztec/aztec.js/authorization';
|
|
3
|
+
import { waitForProven } from '@aztec/aztec.js/contracts';
|
|
4
|
+
import { generateClaimSecret } from '@aztec/aztec.js/ethereum';
|
|
5
|
+
import { Fr } from '@aztec/aztec.js/fields';
|
|
6
|
+
import type { Logger } from '@aztec/aztec.js/log';
|
|
7
|
+
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
8
|
+
import { CheatCodes } from '@aztec/aztec/testing';
|
|
9
|
+
import { RollupContract } from '@aztec/ethereum/contracts';
|
|
10
|
+
import type { DeployAztecL1ContractsReturnType } from '@aztec/ethereum/deploy-aztec-l1-contracts';
|
|
11
|
+
import { deployL1Contract } from '@aztec/ethereum/deploy-l1-contract';
|
|
12
|
+
import type { ExtendedViemWalletClient } from '@aztec/ethereum/types';
|
|
13
|
+
import { extractEvent } from '@aztec/ethereum/utils';
|
|
14
|
+
import { EpochNumber } from '@aztec/foundation/branded-types';
|
|
15
|
+
import { sha256ToField } from '@aztec/foundation/crypto/sha256';
|
|
16
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
17
|
+
import { InboxAbi, UniswapPortalAbi, UniswapPortalBytecode } from '@aztec/l1-artifacts';
|
|
22
18
|
import { UniswapContract } from '@aztec/noir-contracts.js/Uniswap';
|
|
19
|
+
import { computeL2ToL1MessageHash } from '@aztec/stdlib/hash';
|
|
23
20
|
|
|
24
21
|
import { jest } from '@jest/globals';
|
|
25
22
|
import { type GetContractReturnType, getContract, parseEther, toFunctionSelector } from 'viem';
|
|
26
23
|
|
|
27
|
-
import {
|
|
24
|
+
import {
|
|
25
|
+
type EndToEndContext,
|
|
26
|
+
ensureAccountContractsPublished,
|
|
27
|
+
ensureAuthRegistryPublished,
|
|
28
|
+
} from '../fixtures/utils.js';
|
|
29
|
+
import type { TestWallet } from '../test-wallet/test_wallet.js';
|
|
28
30
|
import { CrossChainTestHarness } from './cross_chain_test_harness.js';
|
|
29
31
|
|
|
30
32
|
// PSA: This tests works on forked mainnet. There is a dump of the data in `dumpedState` such that we
|
|
@@ -34,38 +36,13 @@ import { CrossChainTestHarness } from './cross_chain_test_harness.js';
|
|
|
34
36
|
// anvil --fork-url https://mainnet.infura.io/v3/9928b52099854248b3a096be07a6b23c --fork-block-number 17514288 --chain-id 31337
|
|
35
37
|
// For CI, this is configured in `run_tests.sh` and `docker-compose-images.yml`
|
|
36
38
|
|
|
37
|
-
|
|
38
|
-
const TIMEOUT = 360_000;
|
|
39
|
-
|
|
40
|
-
/** Objects to be returned by the uniswap setup function */
|
|
41
|
-
export type UniswapSetupContext = {
|
|
42
|
-
/** Aztec Node instance */
|
|
43
|
-
aztecNode: AztecNode;
|
|
44
|
-
/** The Private eXecution Environment (PXE). */
|
|
45
|
-
pxe: PXE;
|
|
46
|
-
/** Logger instance named as the current test. */
|
|
47
|
-
logger: Logger;
|
|
48
|
-
/** Viem Public client instance. */
|
|
49
|
-
publicClient: ViemPublicClient;
|
|
50
|
-
/** Viem Wallet Client instance. */
|
|
51
|
-
walletClient: ViemWalletClient;
|
|
52
|
-
/** The owner wallet. */
|
|
53
|
-
ownerWallet: AccountWallet;
|
|
54
|
-
/** The sponsor wallet. */
|
|
55
|
-
sponsorWallet: AccountWallet;
|
|
56
|
-
/** */
|
|
57
|
-
deployL1ContractsValues: DeployL1ContractsReturnType;
|
|
58
|
-
/** Cheat codes instance. */
|
|
59
|
-
cheatCodes: CheatCodes;
|
|
60
|
-
};
|
|
61
|
-
// docs:end:uniswap_l1_l2_test_setup_const
|
|
39
|
+
const TIMEOUT = 15 * 60 * 1000;
|
|
62
40
|
|
|
63
41
|
export const uniswapL1L2TestSuite = (
|
|
64
|
-
setup: () => Promise<
|
|
42
|
+
setup: () => Promise<EndToEndContext>,
|
|
65
43
|
cleanup: () => Promise<void>,
|
|
66
44
|
expectedForkBlockNumber = 17514288,
|
|
67
45
|
) => {
|
|
68
|
-
// docs:start:uniswap_l1_l2_test_beforeAll
|
|
69
46
|
describe('uniswap_trade_on_l1_from_l2', () => {
|
|
70
47
|
jest.setTimeout(TIMEOUT);
|
|
71
48
|
|
|
@@ -73,25 +50,22 @@ export const uniswapL1L2TestSuite = (
|
|
|
73
50
|
const DAI_ADDRESS: EthAddress = EthAddress.fromString('0x6B175474E89094C44Da98b954EedeAC495271d0F');
|
|
74
51
|
|
|
75
52
|
let aztecNode: AztecNode;
|
|
76
|
-
let pxe: PXE;
|
|
77
53
|
let logger: Logger;
|
|
78
54
|
|
|
79
|
-
let
|
|
80
|
-
let publicClient: ViemPublicClient;
|
|
55
|
+
let l1Client: ExtendedViemWalletClient;
|
|
81
56
|
|
|
82
|
-
let
|
|
57
|
+
let wallet: TestWallet;
|
|
83
58
|
let ownerAddress: AztecAddress;
|
|
84
59
|
let ownerEthAddress: EthAddress;
|
|
85
60
|
// does transactions on behalf of owner on Aztec:
|
|
86
|
-
let
|
|
87
|
-
// let sponsorAddress: AztecAddress;
|
|
61
|
+
let sponsorAddress: AztecAddress;
|
|
88
62
|
|
|
89
63
|
let daiCrossChainHarness: CrossChainTestHarness;
|
|
90
64
|
let wethCrossChainHarness: CrossChainTestHarness;
|
|
91
65
|
|
|
92
|
-
let deployL1ContractsValues:
|
|
93
|
-
let rollup:
|
|
94
|
-
let uniswapPortal: GetContractReturnType<typeof UniswapPortalAbi,
|
|
66
|
+
let deployL1ContractsValues: DeployAztecL1ContractsReturnType;
|
|
67
|
+
let rollup: RollupContract;
|
|
68
|
+
let uniswapPortal: GetContractReturnType<typeof UniswapPortalAbi, ExtendedViemWalletClient>;
|
|
95
69
|
let uniswapPortalAddress: EthAddress;
|
|
96
70
|
let uniswapL2Contract: UniswapContract;
|
|
97
71
|
|
|
@@ -100,43 +74,42 @@ export const uniswapL1L2TestSuite = (
|
|
|
100
74
|
const minimumOutputAmount = 0n;
|
|
101
75
|
|
|
102
76
|
let cheatCodes: CheatCodes;
|
|
103
|
-
|
|
77
|
+
let version: number;
|
|
104
78
|
beforeAll(async () => {
|
|
79
|
+
const t = await setup();
|
|
105
80
|
({
|
|
106
81
|
aztecNode,
|
|
107
|
-
pxe,
|
|
108
82
|
logger,
|
|
109
|
-
publicClient,
|
|
110
|
-
walletClient,
|
|
111
|
-
ownerWallet,
|
|
112
|
-
sponsorWallet,
|
|
113
83
|
deployL1ContractsValues,
|
|
114
84
|
cheatCodes,
|
|
115
|
-
|
|
85
|
+
wallet,
|
|
86
|
+
accounts: [ownerAddress, sponsorAddress],
|
|
87
|
+
} = t);
|
|
88
|
+
|
|
89
|
+
l1Client = deployL1ContractsValues.l1Client;
|
|
116
90
|
|
|
117
|
-
|
|
91
|
+
t.watcher.setIsMarkingAsProven(false);
|
|
92
|
+
|
|
93
|
+
if (Number(await l1Client.getBlockNumber()) < expectedForkBlockNumber) {
|
|
118
94
|
throw new Error('This test must be run on a fork of mainnet with the expected fork block');
|
|
119
95
|
}
|
|
120
96
|
|
|
121
|
-
rollup =
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
ownerAddress = ownerWallet.getAddress();
|
|
128
|
-
// sponsorAddress = sponsorWallet.getAddress();
|
|
129
|
-
ownerEthAddress = EthAddress.fromString((await walletClient.getAddresses())[0]);
|
|
97
|
+
rollup = new RollupContract(
|
|
98
|
+
deployL1ContractsValues.l1Client,
|
|
99
|
+
deployL1ContractsValues.l1ContractAddresses.rollupAddress,
|
|
100
|
+
);
|
|
101
|
+
version = Number(await rollup.getVersion());
|
|
102
|
+
ownerEthAddress = EthAddress.fromString((await l1Client.getAddresses())[0]);
|
|
130
103
|
|
|
131
|
-
await
|
|
104
|
+
await ensureAccountContractsPublished(wallet, [ownerAddress, sponsorAddress]);
|
|
105
|
+
await ensureAuthRegistryPublished(wallet, ownerAddress);
|
|
132
106
|
|
|
133
107
|
logger.info('Deploying DAI Portal, initializing and deploying l2 contract...');
|
|
134
108
|
daiCrossChainHarness = await CrossChainTestHarness.new(
|
|
135
109
|
aztecNode,
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
ownerWallet,
|
|
110
|
+
deployL1ContractsValues.l1Client,
|
|
111
|
+
wallet,
|
|
112
|
+
ownerAddress,
|
|
140
113
|
logger,
|
|
141
114
|
DAI_ADDRESS,
|
|
142
115
|
);
|
|
@@ -144,31 +117,29 @@ export const uniswapL1L2TestSuite = (
|
|
|
144
117
|
logger.info('Deploying WETH Portal, initializing and deploying l2 contract...');
|
|
145
118
|
wethCrossChainHarness = await CrossChainTestHarness.new(
|
|
146
119
|
aztecNode,
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
ownerWallet,
|
|
120
|
+
l1Client,
|
|
121
|
+
wallet,
|
|
122
|
+
ownerAddress,
|
|
151
123
|
logger,
|
|
152
124
|
WETH9_ADDRESS,
|
|
153
125
|
);
|
|
154
126
|
|
|
155
127
|
logger.info('Deploy Uniswap portal on L1 and L2...');
|
|
156
|
-
uniswapPortalAddress = await deployL1Contract(
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
UniswapPortalAbi,
|
|
160
|
-
UniswapPortalBytecode,
|
|
161
|
-
).then(({ address }) => address);
|
|
128
|
+
uniswapPortalAddress = await deployL1Contract(l1Client, UniswapPortalAbi, UniswapPortalBytecode).then(
|
|
129
|
+
({ address }) => address,
|
|
130
|
+
);
|
|
162
131
|
|
|
163
132
|
uniswapPortal = getContract({
|
|
164
133
|
address: uniswapPortalAddress.toString(),
|
|
165
134
|
abi: UniswapPortalAbi,
|
|
166
|
-
client:
|
|
135
|
+
client: l1Client,
|
|
167
136
|
});
|
|
168
137
|
// deploy l2 uniswap contract and attach to portal
|
|
169
|
-
uniswapL2Contract = await UniswapContract.deploy(
|
|
138
|
+
({ contract: uniswapL2Contract } = await UniswapContract.deploy(wallet, uniswapPortalAddress).send({
|
|
139
|
+
from: ownerAddress,
|
|
140
|
+
}));
|
|
170
141
|
|
|
171
|
-
const registryAddress = (await
|
|
142
|
+
const registryAddress = (await aztecNode.getNodeInfo()).l1ContractAddresses.registryAddress;
|
|
172
143
|
|
|
173
144
|
await uniswapPortal.write.initialize(
|
|
174
145
|
[registryAddress.toString(), uniswapL2Contract.address.toString()],
|
|
@@ -177,19 +148,17 @@ export const uniswapL1L2TestSuite = (
|
|
|
177
148
|
|
|
178
149
|
// Give me some WETH so I can deposit to L2 and do the swap...
|
|
179
150
|
logger.info('Getting some weth');
|
|
180
|
-
const hash = await
|
|
181
|
-
await
|
|
151
|
+
const hash = await l1Client.sendTransaction({ to: WETH9_ADDRESS.toString(), value: parseEther('1000') });
|
|
152
|
+
await l1Client.waitForTransactionReceipt({ hash });
|
|
182
153
|
|
|
183
154
|
const wethBalance = await wethCrossChainHarness.getL1BalanceOf(ownerEthAddress);
|
|
184
155
|
expect(wethBalance).toBe(parseEther('1000'));
|
|
185
156
|
});
|
|
186
|
-
// docs:end:uniswap_l1_l2_test_beforeAll
|
|
187
157
|
|
|
188
158
|
afterAll(async () => {
|
|
189
159
|
await cleanup();
|
|
190
160
|
});
|
|
191
161
|
|
|
192
|
-
// docs:start:uniswap_private
|
|
193
162
|
it('should uniswap trade on L1 from L2 funds privately (swaps WETH -> DAI)', async () => {
|
|
194
163
|
const wethL1BeforeBalance = await wethCrossChainHarness.getL1BalanceOf(ownerEthAddress);
|
|
195
164
|
|
|
@@ -218,7 +187,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
218
187
|
// 3. Owner gives uniswap approval to transfer the funds to public to self on its behalf
|
|
219
188
|
logger.info('Approving uniswap to transfer funds to public to self on my behalf');
|
|
220
189
|
const nonceForWETHTransferToPublicApproval = new Fr(1n);
|
|
221
|
-
await
|
|
190
|
+
const transferToPublicAuhtwit = await wallet.createAuthWit(ownerAddress, {
|
|
222
191
|
caller: uniswapL2Contract.address,
|
|
223
192
|
action: wethCrossChainHarness.l2Token.methods.transfer_to_public(
|
|
224
193
|
ownerAddress,
|
|
@@ -232,7 +201,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
232
201
|
logger.info('Withdrawing weth to L1 and sending message to swap to dai');
|
|
233
202
|
const [secretForDepositingSwappedDai, secretHashForDepositingSwappedDai] = await generateClaimSecret();
|
|
234
203
|
|
|
235
|
-
const l2UniswapInteractionReceipt = await uniswapL2Contract.methods
|
|
204
|
+
const { receipt: l2UniswapInteractionReceipt } = await uniswapL2Contract.methods
|
|
236
205
|
.swap_private(
|
|
237
206
|
wethCrossChainHarness.l2Token.address,
|
|
238
207
|
wethCrossChainHarness.l2Bridge.address,
|
|
@@ -244,8 +213,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
244
213
|
secretHashForDepositingSwappedDai,
|
|
245
214
|
ownerEthAddress,
|
|
246
215
|
)
|
|
247
|
-
.send()
|
|
248
|
-
.wait();
|
|
216
|
+
.send({ from: ownerAddress, authWitnesses: [transferToPublicAuhtwit] });
|
|
249
217
|
|
|
250
218
|
const swapPrivateFunction = 'swap_private(address,uint256,uint24,address,uint256,bytes32,address)';
|
|
251
219
|
const swapPrivateContent = sha256ToField([
|
|
@@ -259,13 +227,13 @@ export const uniswapL1L2TestSuite = (
|
|
|
259
227
|
ownerEthAddress.toBuffer32(),
|
|
260
228
|
]);
|
|
261
229
|
|
|
262
|
-
const swapPrivateLeaf =
|
|
263
|
-
uniswapL2Contract.address,
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
new Fr(
|
|
267
|
-
|
|
268
|
-
|
|
230
|
+
const swapPrivateLeaf = computeL2ToL1MessageHash({
|
|
231
|
+
l2Sender: uniswapL2Contract.address,
|
|
232
|
+
l1Recipient: EthAddress.fromString(uniswapPortal.address),
|
|
233
|
+
content: swapPrivateContent,
|
|
234
|
+
rollupVersion: new Fr(version),
|
|
235
|
+
chainId: new Fr(l1Client.chain.id),
|
|
236
|
+
});
|
|
269
237
|
|
|
270
238
|
const withdrawContent = sha256ToField([
|
|
271
239
|
Buffer.from(toFunctionSelector('withdraw(address,uint256,address)').substring(2), 'hex'),
|
|
@@ -274,39 +242,56 @@ export const uniswapL1L2TestSuite = (
|
|
|
274
242
|
uniswapPortalAddress.toBuffer32(),
|
|
275
243
|
]);
|
|
276
244
|
|
|
277
|
-
const withdrawLeaf =
|
|
278
|
-
wethCrossChainHarness.l2Bridge.address,
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
new Fr(
|
|
282
|
-
|
|
283
|
-
|
|
245
|
+
const withdrawLeaf = computeL2ToL1MessageHash({
|
|
246
|
+
l2Sender: wethCrossChainHarness.l2Bridge.address,
|
|
247
|
+
l1Recipient: wethCrossChainHarness.tokenPortalAddress,
|
|
248
|
+
content: withdrawContent,
|
|
249
|
+
rollupVersion: new Fr(version),
|
|
250
|
+
chainId: new Fr(l1Client.chain.id),
|
|
251
|
+
});
|
|
284
252
|
|
|
285
253
|
// ensure that user's funds were burnt
|
|
286
254
|
await wethCrossChainHarness.expectPrivateBalanceOnL2(ownerAddress, wethL2BalanceBeforeSwap - wethAmountToBridge);
|
|
287
255
|
// ensure that uniswap contract didn't eat the funds.
|
|
288
256
|
await wethCrossChainHarness.expectPublicBalanceOnL2(uniswapL2Contract.address, 0n);
|
|
289
257
|
|
|
290
|
-
// Since the outbox is only consumable when the
|
|
291
|
-
|
|
258
|
+
// Since the outbox is only consumable when the epoch is proven, we need to advance to the next epoch
|
|
259
|
+
// before we can ask the witness helper for a covering root.
|
|
260
|
+
const minedReceipt = await aztecNode.getTxReceipt(l2UniswapInteractionReceipt.txHash);
|
|
261
|
+
if (minedReceipt.epochNumber === undefined) {
|
|
262
|
+
throw new Error('L2 Uniswap interaction tx is not yet in an epoch');
|
|
263
|
+
}
|
|
264
|
+
await cheatCodes.rollup.advanceToEpoch(EpochNumber(minedReceipt.epochNumber + 1));
|
|
265
|
+
await waitForProven(aztecNode, l2UniswapInteractionReceipt, { provenTimeout: 300 });
|
|
292
266
|
|
|
293
267
|
// 5. Consume L2 to L1 message by calling uniswapPortal.swap_private()
|
|
294
268
|
logger.info('Execute withdraw and swap on the uniswapPortal!');
|
|
295
269
|
const daiL1BalanceOfPortalBeforeSwap = await daiCrossChainHarness.getL1BalanceOf(
|
|
296
270
|
daiCrossChainHarness.tokenPortalAddress,
|
|
297
271
|
);
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
272
|
+
const swapResult = await retryUntil(
|
|
273
|
+
() => aztecNode.getL2ToL1MembershipWitness(minedReceipt.txHash, swapPrivateLeaf),
|
|
274
|
+
'swap private l2 to l1 witness',
|
|
275
|
+
60,
|
|
276
|
+
1,
|
|
302
277
|
);
|
|
303
|
-
const
|
|
304
|
-
|
|
305
|
-
withdrawLeaf,
|
|
278
|
+
const { epochNumber: epoch, numCheckpointsInEpoch } = swapResult;
|
|
279
|
+
const withdrawResult = await retryUntil(
|
|
280
|
+
() => aztecNode.getL2ToL1MembershipWitness(minedReceipt.txHash, withdrawLeaf),
|
|
281
|
+
'withdraw l2 to l1 witness',
|
|
282
|
+
60,
|
|
283
|
+
1,
|
|
306
284
|
);
|
|
307
285
|
|
|
286
|
+
const swapPrivateL2MessageIndex = swapResult.leafIndex;
|
|
287
|
+
const swapPrivateSiblingPath = swapResult.siblingPath;
|
|
288
|
+
|
|
289
|
+
const withdrawL2MessageIndex = withdrawResult.leafIndex;
|
|
290
|
+
const withdrawSiblingPath = withdrawResult.siblingPath;
|
|
291
|
+
|
|
308
292
|
const withdrawMessageMetadata = {
|
|
309
|
-
|
|
293
|
+
_epoch: BigInt(epoch),
|
|
294
|
+
_numCheckpointsInEpoch: BigInt(withdrawResult.numCheckpointsInEpoch),
|
|
310
295
|
_leafIndex: BigInt(withdrawL2MessageIndex),
|
|
311
296
|
_path: withdrawSiblingPath
|
|
312
297
|
.toBufferArray()
|
|
@@ -314,7 +299,8 @@ export const uniswapL1L2TestSuite = (
|
|
|
314
299
|
};
|
|
315
300
|
|
|
316
301
|
const swapPrivateMessageMetadata = {
|
|
317
|
-
|
|
302
|
+
_epoch: BigInt(epoch),
|
|
303
|
+
_numCheckpointsInEpoch: BigInt(numCheckpointsInEpoch),
|
|
318
304
|
_leafIndex: BigInt(swapPrivateL2MessageIndex),
|
|
319
305
|
_path: swapPrivateSiblingPath
|
|
320
306
|
.toBufferArray()
|
|
@@ -333,7 +319,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
333
319
|
] as const;
|
|
334
320
|
|
|
335
321
|
// this should also insert a message into the inbox.
|
|
336
|
-
const txReceipt = await daiCrossChainHarness.
|
|
322
|
+
const txReceipt = await daiCrossChainHarness.l1Client.waitForTransactionReceipt({
|
|
337
323
|
hash: await uniswapPortal.write.swapPrivate(swapArgs),
|
|
338
324
|
});
|
|
339
325
|
|
|
@@ -372,10 +358,8 @@ export const uniswapL1L2TestSuite = (
|
|
|
372
358
|
logger.info('WETH balance after swap : ', wethL2BalanceAfterSwap.toString());
|
|
373
359
|
logger.info('DAI balance after swap : ', daiL2BalanceAfterSwap.toString());
|
|
374
360
|
});
|
|
375
|
-
// docs:end:uniswap_private
|
|
376
361
|
|
|
377
362
|
// TODO(#7463): reenable look into this failure https://github.com/AztecProtocol/aztec-packages/actions/runs/9912612912/job/27388320150?pr=7462
|
|
378
|
-
// // docs:start:uniswap_public
|
|
379
363
|
// it('should uniswap trade on L1 from L2 funds publicly (swaps WETH -> DAI)', async () => {
|
|
380
364
|
// const wethL1BeforeBalance = await wethCrossChainHarness.getL1BalanceOf(ownerEthAddress);
|
|
381
365
|
|
|
@@ -461,10 +445,10 @@ export const uniswapL1L2TestSuite = (
|
|
|
461
445
|
// ownerEthAddress,
|
|
462
446
|
// nonceForSwap,
|
|
463
447
|
// );
|
|
464
|
-
// await ownerWallet.setPublicAuthWit({ caller: sponsorAddress, action }, true).send()
|
|
448
|
+
// await ownerWallet.setPublicAuthWit({ caller: sponsorAddress, action }, true).send();
|
|
465
449
|
|
|
466
450
|
// // 4.2 Call swap_public from user2 on behalf of owner
|
|
467
|
-
// const uniswapL2Interaction = await action.send()
|
|
451
|
+
// const uniswapL2Interaction = await action.send();
|
|
468
452
|
|
|
469
453
|
// const swapPublicContent = sha256ToField([
|
|
470
454
|
// Buffer.from(
|
|
@@ -525,7 +509,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
525
509
|
// );
|
|
526
510
|
|
|
527
511
|
// const withdrawMessageMetadata = {
|
|
528
|
-
//
|
|
512
|
+
// _epoch: epoch,
|
|
529
513
|
// _leafIndex: BigInt(withdrawL2MessageIndex),
|
|
530
514
|
// _path: withdrawSiblingPath
|
|
531
515
|
// .toBufferArray()
|
|
@@ -533,7 +517,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
533
517
|
// };
|
|
534
518
|
|
|
535
519
|
// const swapPrivateMessageMetadata = {
|
|
536
|
-
//
|
|
520
|
+
// _epoch: epoch,
|
|
537
521
|
// _leafIndex: BigInt(swapPrivateL2MessageIndex),
|
|
538
522
|
// _path: swapPrivateSiblingPath
|
|
539
523
|
// .toBufferArray()
|
|
@@ -608,7 +592,6 @@ export const uniswapL1L2TestSuite = (
|
|
|
608
592
|
// logger.info('WETH balance after swap : ', wethL2BalanceAfterSwap.toString());
|
|
609
593
|
// logger.info('DAI balance after swap : ', daiL2BalanceAfterSwap.toString());
|
|
610
594
|
// });
|
|
611
|
-
// // docs:end:uniswap_public
|
|
612
595
|
|
|
613
596
|
// Edge cases for the private flow:
|
|
614
597
|
// note - tests for uniswapPortal.sol and minting asset on L2 are covered in other tests.
|
|
@@ -620,14 +603,16 @@ export const uniswapL1L2TestSuite = (
|
|
|
620
603
|
const expectedMessageHash = await computeAuthWitMessageHash(
|
|
621
604
|
{
|
|
622
605
|
caller: uniswapL2Contract.address,
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
606
|
+
call: await wethCrossChainHarness.l2Token.methods
|
|
607
|
+
.transfer_to_public(
|
|
608
|
+
ownerAddress,
|
|
609
|
+
uniswapL2Contract.address,
|
|
610
|
+
wethAmountToBridge,
|
|
611
|
+
nonceForWETHTransferToPublicApproval,
|
|
612
|
+
)
|
|
613
|
+
.getFunctionCall(),
|
|
629
614
|
},
|
|
630
|
-
|
|
615
|
+
await wallet.getChainInfo(),
|
|
631
616
|
);
|
|
632
617
|
|
|
633
618
|
await expect(
|
|
@@ -643,7 +628,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
643
628
|
Fr.random(),
|
|
644
629
|
ownerEthAddress,
|
|
645
630
|
)
|
|
646
|
-
.
|
|
631
|
+
.simulate({ from: ownerAddress }),
|
|
647
632
|
).rejects.toThrow(`Unknown auth witness for message hash ${expectedMessageHash.toString()}`);
|
|
648
633
|
});
|
|
649
634
|
|
|
@@ -655,7 +640,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
655
640
|
// 2. owner gives uniswap approval to transfer the funds to public:
|
|
656
641
|
logger.info('Approving uniswap to transfer funds to public to self on my behalf');
|
|
657
642
|
const nonceForWETHTransferToPublicApproval = new Fr(3n);
|
|
658
|
-
await
|
|
643
|
+
const transferToPublicAuthwith = await wallet.createAuthWit(ownerAddress, {
|
|
659
644
|
caller: uniswapL2Contract.address,
|
|
660
645
|
action: wethCrossChainHarness.l2Token.methods.transfer_to_public(
|
|
661
646
|
ownerAddress,
|
|
@@ -680,7 +665,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
680
665
|
Fr.random(),
|
|
681
666
|
ownerEthAddress,
|
|
682
667
|
)
|
|
683
|
-
.
|
|
668
|
+
.send({ from: ownerAddress, authWitnesses: [transferToPublicAuthwith] }),
|
|
684
669
|
).rejects.toThrow('Assertion failed: input_asset address is not the same as seen in the bridge contract');
|
|
685
670
|
});
|
|
686
671
|
|
|
@@ -692,7 +677,8 @@ export const uniswapL1L2TestSuite = (
|
|
|
692
677
|
|
|
693
678
|
// 2. Give approval to uniswap to transfer funds to itself
|
|
694
679
|
const nonceForWETHTransferApproval = new Fr(2n);
|
|
695
|
-
const validateActionInteraction = await
|
|
680
|
+
const validateActionInteraction = await wallet.setPublicAuthWit(
|
|
681
|
+
ownerAddress,
|
|
696
682
|
{
|
|
697
683
|
caller: uniswapL2Contract.address,
|
|
698
684
|
action: wethCrossChainHarness.l2Token.methods.transfer_in_public(
|
|
@@ -704,7 +690,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
704
690
|
},
|
|
705
691
|
true,
|
|
706
692
|
);
|
|
707
|
-
await validateActionInteraction.send()
|
|
693
|
+
await validateActionInteraction.send();
|
|
708
694
|
|
|
709
695
|
// No approval to call `swap` but should work even without it:
|
|
710
696
|
const [_, secretHashForDepositingSwappedDai] = await generateClaimSecret();
|
|
@@ -723,8 +709,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
723
709
|
ownerEthAddress,
|
|
724
710
|
Fr.ZERO, // nonce for swap -> doesn't matter
|
|
725
711
|
)
|
|
726
|
-
.send()
|
|
727
|
-
.wait();
|
|
712
|
+
.send({ from: ownerAddress });
|
|
728
713
|
// check weth balance of owner on L2 (we first bridged `wethAmountToBridge` into L2 and now withdrew it!)
|
|
729
714
|
await wethCrossChainHarness.expectPublicBalanceOnL2(ownerAddress, 0n);
|
|
730
715
|
});
|
|
@@ -736,32 +721,35 @@ export const uniswapL1L2TestSuite = (
|
|
|
736
721
|
const nonceForWETHTransferApproval = new Fr(3n);
|
|
737
722
|
const nonceForSwap = new Fr(3n);
|
|
738
723
|
const secretHashForDepositingSwappedDai = new Fr(4n);
|
|
739
|
-
const action = uniswapL2Contract
|
|
740
|
-
|
|
741
|
-
.
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
724
|
+
const action = uniswapL2Contract.methods.swap_public(
|
|
725
|
+
ownerAddress,
|
|
726
|
+
wethCrossChainHarness.l2Bridge.address,
|
|
727
|
+
wethAmountToBridge,
|
|
728
|
+
daiCrossChainHarness.l2Bridge.address,
|
|
729
|
+
nonceForWETHTransferApproval,
|
|
730
|
+
uniswapFeeTier,
|
|
731
|
+
minimumOutputAmount,
|
|
732
|
+
ownerAddress,
|
|
733
|
+
secretHashForDepositingSwappedDai,
|
|
734
|
+
ownerEthAddress,
|
|
735
|
+
nonceForSwap,
|
|
736
|
+
);
|
|
737
|
+
const validateActionInteraction = await wallet.setPublicAuthWit(
|
|
738
|
+
ownerAddress,
|
|
739
|
+
{ caller: approvedUser, action },
|
|
740
|
+
true,
|
|
741
|
+
);
|
|
742
|
+
await validateActionInteraction.send();
|
|
756
743
|
|
|
757
|
-
await expect(action.simulate()).rejects.toThrow(/unauthorized/);
|
|
744
|
+
await expect(action.simulate({ from: sponsorAddress })).rejects.toThrow(/unauthorized/);
|
|
758
745
|
});
|
|
759
746
|
|
|
760
747
|
it("uniswap can't pull funds without transfer approval", async () => {
|
|
761
748
|
// swap should fail since no transfer approval to uniswap:
|
|
762
749
|
const nonceForWETHTransferApproval = new Fr(4n);
|
|
763
750
|
|
|
764
|
-
const validateActionInteraction = await
|
|
751
|
+
const validateActionInteraction = await wallet.setPublicAuthWit(
|
|
752
|
+
ownerAddress,
|
|
765
753
|
{
|
|
766
754
|
caller: uniswapL2Contract.address,
|
|
767
755
|
action: wethCrossChainHarness.l2Token.methods.transfer_in_public(
|
|
@@ -773,7 +761,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
773
761
|
},
|
|
774
762
|
true,
|
|
775
763
|
);
|
|
776
|
-
await validateActionInteraction.send()
|
|
764
|
+
await validateActionInteraction.send();
|
|
777
765
|
|
|
778
766
|
await expect(
|
|
779
767
|
uniswapL2Contract.methods
|
|
@@ -790,7 +778,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
790
778
|
ownerEthAddress,
|
|
791
779
|
Fr.ZERO,
|
|
792
780
|
)
|
|
793
|
-
.simulate(),
|
|
781
|
+
.simulate({ from: ownerAddress }),
|
|
794
782
|
).rejects.toThrow(/unauthorized/);
|
|
795
783
|
});
|
|
796
784
|
|
|
@@ -803,7 +791,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
803
791
|
// Owner gives uniswap approval to transfer the funds to public to self on its behalf
|
|
804
792
|
logger.info('Approving uniswap to transfer the funds to public to self on my behalf');
|
|
805
793
|
const nonceForWETHTransferToPublicApproval = new Fr(4n);
|
|
806
|
-
await
|
|
794
|
+
const transferToPublicAuhtwit = await wallet.createAuthWit(ownerAddress, {
|
|
807
795
|
caller: uniswapL2Contract.address,
|
|
808
796
|
action: wethCrossChainHarness.l2Token.methods.transfer_to_public(
|
|
809
797
|
ownerAddress,
|
|
@@ -818,7 +806,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
818
806
|
logger.info('Withdrawing weth to L1 and sending message to swap to dai');
|
|
819
807
|
|
|
820
808
|
const [, secretHashForDepositingSwappedDai] = await generateClaimSecret();
|
|
821
|
-
const withdrawReceipt = await uniswapL2Contract.methods
|
|
809
|
+
const { receipt: withdrawReceipt } = await uniswapL2Contract.methods
|
|
822
810
|
.swap_private(
|
|
823
811
|
wethCrossChainHarness.l2Token.address,
|
|
824
812
|
wethCrossChainHarness.l2Bridge.address,
|
|
@@ -830,8 +818,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
830
818
|
secretHashForDepositingSwappedDai,
|
|
831
819
|
ownerEthAddress,
|
|
832
820
|
)
|
|
833
|
-
.send()
|
|
834
|
-
.wait();
|
|
821
|
+
.send({ from: ownerAddress, authWitnesses: [transferToPublicAuhtwit] });
|
|
835
822
|
|
|
836
823
|
const swapPrivateContent = sha256ToField([
|
|
837
824
|
Buffer.from(
|
|
@@ -847,13 +834,13 @@ export const uniswapL1L2TestSuite = (
|
|
|
847
834
|
ownerEthAddress.toBuffer32(),
|
|
848
835
|
]);
|
|
849
836
|
|
|
850
|
-
const swapPrivateLeaf =
|
|
851
|
-
uniswapL2Contract.address,
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
new Fr(
|
|
855
|
-
|
|
856
|
-
|
|
837
|
+
const swapPrivateLeaf = computeL2ToL1MessageHash({
|
|
838
|
+
l2Sender: uniswapL2Contract.address,
|
|
839
|
+
l1Recipient: EthAddress.fromString(uniswapPortal.address),
|
|
840
|
+
content: swapPrivateContent,
|
|
841
|
+
rollupVersion: new Fr(version),
|
|
842
|
+
chainId: new Fr(l1Client.chain.id),
|
|
843
|
+
});
|
|
857
844
|
|
|
858
845
|
const withdrawContent = sha256ToField([
|
|
859
846
|
Buffer.from(toFunctionSelector('withdraw(address,uint256,address)').substring(2), 'hex'),
|
|
@@ -862,25 +849,49 @@ export const uniswapL1L2TestSuite = (
|
|
|
862
849
|
uniswapPortalAddress.toBuffer32(),
|
|
863
850
|
]);
|
|
864
851
|
|
|
865
|
-
const withdrawLeaf =
|
|
866
|
-
wethCrossChainHarness.l2Bridge.address,
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
new Fr(
|
|
870
|
-
|
|
871
|
-
|
|
852
|
+
const withdrawLeaf = computeL2ToL1MessageHash({
|
|
853
|
+
l2Sender: wethCrossChainHarness.l2Bridge.address,
|
|
854
|
+
l1Recipient: wethCrossChainHarness.tokenPortalAddress,
|
|
855
|
+
content: withdrawContent,
|
|
856
|
+
rollupVersion: new Fr(version),
|
|
857
|
+
chainId: new Fr(l1Client.chain.id),
|
|
858
|
+
});
|
|
859
|
+
|
|
860
|
+
// ensure that user's funds were burnt
|
|
861
|
+
await wethCrossChainHarness.expectPrivateBalanceOnL2(ownerAddress, wethL2BalanceBeforeSwap - wethAmountToBridge);
|
|
872
862
|
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
863
|
+
// Since the outbox is only consumable when the epoch is proven, we need to advance to the next epoch
|
|
864
|
+
// before we can ask the witness helper for a covering root.
|
|
865
|
+
const minedReceipt = await aztecNode.getTxReceipt(withdrawReceipt.txHash);
|
|
866
|
+
if (minedReceipt.epochNumber === undefined) {
|
|
867
|
+
throw new Error('Withdraw tx is not yet in an epoch');
|
|
868
|
+
}
|
|
869
|
+
await cheatCodes.rollup.advanceToEpoch(EpochNumber(minedReceipt.epochNumber + 1));
|
|
870
|
+
await waitForProven(aztecNode, withdrawReceipt, { provenTimeout: 300 });
|
|
871
|
+
|
|
872
|
+
const swapResult = await retryUntil(
|
|
873
|
+
() => aztecNode.getL2ToL1MembershipWitness(minedReceipt.txHash, swapPrivateLeaf),
|
|
874
|
+
'swap private l2 to l1 witness',
|
|
875
|
+
60,
|
|
876
|
+
1,
|
|
876
877
|
);
|
|
877
|
-
const
|
|
878
|
-
|
|
879
|
-
withdrawLeaf,
|
|
878
|
+
const { epochNumber: epoch, numCheckpointsInEpoch } = swapResult;
|
|
879
|
+
const withdrawResult = await retryUntil(
|
|
880
|
+
() => aztecNode.getL2ToL1MembershipWitness(minedReceipt.txHash, withdrawLeaf),
|
|
881
|
+
'withdraw l2 to l1 witness',
|
|
882
|
+
60,
|
|
883
|
+
1,
|
|
880
884
|
);
|
|
881
885
|
|
|
886
|
+
const swapPrivateL2MessageIndex = swapResult.leafIndex;
|
|
887
|
+
const swapPrivateSiblingPath = swapResult.siblingPath;
|
|
888
|
+
|
|
889
|
+
const withdrawL2MessageIndex = withdrawResult.leafIndex;
|
|
890
|
+
const withdrawSiblingPath = withdrawResult.siblingPath;
|
|
891
|
+
|
|
882
892
|
const withdrawMessageMetadata = {
|
|
883
|
-
|
|
893
|
+
_epoch: BigInt(epoch),
|
|
894
|
+
_numCheckpointsInEpoch: BigInt(withdrawResult.numCheckpointsInEpoch),
|
|
884
895
|
_leafIndex: BigInt(withdrawL2MessageIndex),
|
|
885
896
|
_path: withdrawSiblingPath
|
|
886
897
|
.toBufferArray()
|
|
@@ -888,19 +899,14 @@ export const uniswapL1L2TestSuite = (
|
|
|
888
899
|
};
|
|
889
900
|
|
|
890
901
|
const swapPrivateMessageMetadata = {
|
|
891
|
-
|
|
902
|
+
_epoch: BigInt(epoch),
|
|
903
|
+
_numCheckpointsInEpoch: BigInt(numCheckpointsInEpoch),
|
|
892
904
|
_leafIndex: BigInt(swapPrivateL2MessageIndex),
|
|
893
905
|
_path: swapPrivateSiblingPath
|
|
894
906
|
.toBufferArray()
|
|
895
907
|
.map((buf: Buffer) => `0x${buf.toString('hex')}`) as readonly `0x${string}`[],
|
|
896
908
|
};
|
|
897
909
|
|
|
898
|
-
// ensure that user's funds were burnt
|
|
899
|
-
await wethCrossChainHarness.expectPrivateBalanceOnL2(ownerAddress, wethL2BalanceBeforeSwap - wethAmountToBridge);
|
|
900
|
-
|
|
901
|
-
// Since the outbox is only consumable when the block is proven, we need to set the block to be proven
|
|
902
|
-
await cheatCodes.rollup.markAsProven(await rollup.read.getPendingBlockNumber());
|
|
903
|
-
|
|
904
910
|
// On L1 call swap_public!
|
|
905
911
|
logger.info('call swap_public on L1');
|
|
906
912
|
const swapArgs = [
|
|
@@ -927,7 +933,8 @@ export const uniswapL1L2TestSuite = (
|
|
|
927
933
|
|
|
928
934
|
// Owner gives uniswap approval to transfer funds on its behalf
|
|
929
935
|
const nonceForWETHTransferApproval = new Fr(5n);
|
|
930
|
-
const validateActionInteraction = await
|
|
936
|
+
const validateActionInteraction = await wallet.setPublicAuthWit(
|
|
937
|
+
ownerAddress,
|
|
931
938
|
{
|
|
932
939
|
caller: uniswapL2Contract.address,
|
|
933
940
|
action: wethCrossChainHarness.l2Token.methods.transfer_in_public(
|
|
@@ -939,11 +946,11 @@ export const uniswapL1L2TestSuite = (
|
|
|
939
946
|
},
|
|
940
947
|
true,
|
|
941
948
|
);
|
|
942
|
-
await validateActionInteraction.send()
|
|
949
|
+
await validateActionInteraction.send();
|
|
943
950
|
|
|
944
951
|
// Call swap_public on L2
|
|
945
952
|
const secretHashForDepositingSwappedDai = Fr.random();
|
|
946
|
-
const withdrawReceipt = await uniswapL2Contract.methods
|
|
953
|
+
const { receipt: withdrawReceipt } = await uniswapL2Contract.methods
|
|
947
954
|
.swap_public(
|
|
948
955
|
ownerAddress,
|
|
949
956
|
wethCrossChainHarness.l2Bridge.address,
|
|
@@ -957,8 +964,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
957
964
|
ownerEthAddress,
|
|
958
965
|
Fr.ZERO,
|
|
959
966
|
)
|
|
960
|
-
.send()
|
|
961
|
-
.wait();
|
|
967
|
+
.send({ from: ownerAddress });
|
|
962
968
|
|
|
963
969
|
const swapPublicContent = sha256ToField([
|
|
964
970
|
Buffer.from(
|
|
@@ -977,13 +983,13 @@ export const uniswapL1L2TestSuite = (
|
|
|
977
983
|
ownerEthAddress.toBuffer32(),
|
|
978
984
|
]);
|
|
979
985
|
|
|
980
|
-
const swapPublicLeaf =
|
|
981
|
-
uniswapL2Contract.address,
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
new Fr(
|
|
985
|
-
|
|
986
|
-
|
|
986
|
+
const swapPublicLeaf = computeL2ToL1MessageHash({
|
|
987
|
+
l2Sender: uniswapL2Contract.address,
|
|
988
|
+
l1Recipient: EthAddress.fromString(uniswapPortal.address),
|
|
989
|
+
content: swapPublicContent,
|
|
990
|
+
rollupVersion: new Fr(version),
|
|
991
|
+
chainId: new Fr(l1Client.chain.id),
|
|
992
|
+
});
|
|
987
993
|
|
|
988
994
|
const withdrawContent = sha256ToField([
|
|
989
995
|
Buffer.from(toFunctionSelector('withdraw(address,uint256,address)').substring(2), 'hex'),
|
|
@@ -992,25 +998,49 @@ export const uniswapL1L2TestSuite = (
|
|
|
992
998
|
uniswapPortalAddress.toBuffer32(),
|
|
993
999
|
]);
|
|
994
1000
|
|
|
995
|
-
const withdrawLeaf =
|
|
996
|
-
wethCrossChainHarness.l2Bridge.address,
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
new Fr(
|
|
1000
|
-
|
|
1001
|
-
|
|
1001
|
+
const withdrawLeaf = computeL2ToL1MessageHash({
|
|
1002
|
+
l2Sender: wethCrossChainHarness.l2Bridge.address,
|
|
1003
|
+
l1Recipient: wethCrossChainHarness.tokenPortalAddress,
|
|
1004
|
+
content: withdrawContent,
|
|
1005
|
+
rollupVersion: new Fr(version),
|
|
1006
|
+
chainId: new Fr(l1Client.chain.id),
|
|
1007
|
+
});
|
|
1002
1008
|
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1009
|
+
// check weth balance of owner on L2 (we first bridged `wethAmountToBridge` into L2 and now withdrew it!)
|
|
1010
|
+
await wethCrossChainHarness.expectPublicBalanceOnL2(ownerAddress, 0n);
|
|
1011
|
+
|
|
1012
|
+
// Since the outbox is only consumable when the epoch is proven, we need to advance to the next epoch
|
|
1013
|
+
// before we can ask the witness helper for a covering root.
|
|
1014
|
+
const minedReceipt = await aztecNode.getTxReceipt(withdrawReceipt.txHash);
|
|
1015
|
+
if (minedReceipt.epochNumber === undefined) {
|
|
1016
|
+
throw new Error('Withdraw tx is not yet in an epoch');
|
|
1017
|
+
}
|
|
1018
|
+
await cheatCodes.rollup.advanceToEpoch(EpochNumber(minedReceipt.epochNumber + 1));
|
|
1019
|
+
await waitForProven(aztecNode, withdrawReceipt, { provenTimeout: 300 });
|
|
1020
|
+
|
|
1021
|
+
const swapResult = await retryUntil(
|
|
1022
|
+
() => aztecNode.getL2ToL1MembershipWitness(minedReceipt.txHash, swapPublicLeaf),
|
|
1023
|
+
'swap public l2 to l1 witness',
|
|
1024
|
+
60,
|
|
1025
|
+
1,
|
|
1006
1026
|
);
|
|
1007
|
-
const
|
|
1008
|
-
|
|
1009
|
-
withdrawLeaf,
|
|
1027
|
+
const { epochNumber: epoch, numCheckpointsInEpoch } = swapResult;
|
|
1028
|
+
const withdrawResult = await retryUntil(
|
|
1029
|
+
() => aztecNode.getL2ToL1MembershipWitness(minedReceipt.txHash, withdrawLeaf),
|
|
1030
|
+
'withdraw l2 to l1 witness',
|
|
1031
|
+
60,
|
|
1032
|
+
1,
|
|
1010
1033
|
);
|
|
1011
1034
|
|
|
1035
|
+
const swapPublicL2MessageIndex = swapResult.leafIndex;
|
|
1036
|
+
const swapPublicSiblingPath = swapResult.siblingPath;
|
|
1037
|
+
|
|
1038
|
+
const withdrawL2MessageIndex = withdrawResult.leafIndex;
|
|
1039
|
+
const withdrawSiblingPath = withdrawResult.siblingPath;
|
|
1040
|
+
|
|
1012
1041
|
const withdrawMessageMetadata = {
|
|
1013
|
-
|
|
1042
|
+
_epoch: BigInt(epoch),
|
|
1043
|
+
_numCheckpointsInEpoch: BigInt(withdrawResult.numCheckpointsInEpoch),
|
|
1014
1044
|
_leafIndex: BigInt(withdrawL2MessageIndex),
|
|
1015
1045
|
_path: withdrawSiblingPath
|
|
1016
1046
|
.toBufferArray()
|
|
@@ -1018,19 +1048,14 @@ export const uniswapL1L2TestSuite = (
|
|
|
1018
1048
|
};
|
|
1019
1049
|
|
|
1020
1050
|
const swapPublicMessageMetadata = {
|
|
1021
|
-
|
|
1051
|
+
_epoch: BigInt(epoch),
|
|
1052
|
+
_numCheckpointsInEpoch: BigInt(numCheckpointsInEpoch),
|
|
1022
1053
|
_leafIndex: BigInt(swapPublicL2MessageIndex),
|
|
1023
1054
|
_path: swapPublicSiblingPath
|
|
1024
1055
|
.toBufferArray()
|
|
1025
1056
|
.map((buf: Buffer) => `0x${buf.toString('hex')}`) as readonly `0x${string}`[],
|
|
1026
1057
|
};
|
|
1027
1058
|
|
|
1028
|
-
// check weth balance of owner on L2 (we first bridged `wethAmountToBridge` into L2 and now withdrew it!)
|
|
1029
|
-
await wethCrossChainHarness.expectPublicBalanceOnL2(ownerAddress, 0n);
|
|
1030
|
-
|
|
1031
|
-
// Since the outbox is only consumable when the block is proven, we need to set the block to be proven
|
|
1032
|
-
await cheatCodes.rollup.markAsProven(await rollup.read.getPendingBlockNumber());
|
|
1033
|
-
|
|
1034
1059
|
// Call swap_private on L1
|
|
1035
1060
|
logger.info('Execute withdraw and swap on the uniswapPortal!');
|
|
1036
1061
|
|