@aztec/end-to-end 0.0.0-test.0 → 0.0.1-commit.001888fc
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 +62 -0
- package/dest/bench/client_flows/benchmark.d.ts.map +1 -0
- package/dest/bench/client_flows/benchmark.js +281 -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 +329 -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 +44 -72
- package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +28 -19
- 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 +125 -103
- package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +32 -32
- 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 +105 -104
- package/dest/e2e_deploy_contract/deploy_test.d.ts +19 -10
- package/dest/e2e_deploy_contract/deploy_test.d.ts.map +1 -1
- package/dest/e2e_deploy_contract/deploy_test.js +26 -27
- package/dest/e2e_epochs/epochs_test.d.ts +75 -24
- package/dest/e2e_epochs/epochs_test.d.ts.map +1 -1
- package/dest/e2e_epochs/epochs_test.js +290 -58
- 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 +38 -23
- package/dest/e2e_fees/fees_test.d.ts.map +1 -1
- package/dest/e2e_fees/fees_test.js +169 -183
- 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 +15 -15
- package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +1 -1
- package/dest/e2e_nested_contract/nested_contract_test.js +36 -42
- 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 +282 -27
- package/dest/e2e_p2p/p2p_network.d.ts.map +1 -1
- package/dest/e2e_p2p/p2p_network.js +255 -176
- 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 +190 -0
- package/dest/e2e_p2p/shared.d.ts +64 -8
- package/dest/e2e_p2p/shared.d.ts.map +1 -1
- package/dest/e2e_p2p/shared.js +200 -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 +29 -14
- package/dest/e2e_token_contract/token_contract_test.d.ts.map +1 -1
- package/dest/e2e_token_contract/token_contract_test.js +107 -75
- 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 +30 -0
- package/dest/fixtures/e2e_prover_test.d.ts +55 -0
- package/dest/fixtures/e2e_prover_test.d.ts.map +1 -0
- package/dest/fixtures/e2e_prover_test.js +271 -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 +10 -8
- package/dest/fixtures/fixtures.d.ts.map +1 -1
- package/dest/fixtures/fixtures.js +11 -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/setup.d.ts +239 -0
- package/dest/fixtures/setup.d.ts.map +1 -0
- package/dest/fixtures/setup.js +606 -0
- package/dest/fixtures/setup_p2p_test.d.ts +23 -15
- package/dest/fixtures/setup_p2p_test.d.ts.map +1 -1
- package/dest/fixtures/setup_p2p_test.js +102 -31
- 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 +33 -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/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/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 +44 -27
- package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
- package/dest/shared/cross_chain_test_harness.js +107 -53
- package/dest/shared/gas_portal_test_harness.d.ts +33 -25
- 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 +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 +175 -126
- package/dest/simulators/index.d.ts +1 -1
- package/dest/simulators/lending_simulator.d.ts +7 -7
- package/dest/simulators/lending_simulator.d.ts.map +1 -1
- package/dest/simulators/lending_simulator.js +17 -18
- 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 +276 -62
- package/dest/spartan/tx_metrics.d.ts +88 -0
- package/dest/spartan/tx_metrics.d.ts.map +1 -0
- package/dest/spartan/tx_metrics.js +422 -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 +45 -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 +83 -0
- package/dest/test-wallet/test_wallet.d.ts.map +1 -0
- package/dest/test-wallet/test_wallet.js +214 -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 +71 -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 +48 -0
- package/dest/test-wallet/worker_wallet.d.ts +52 -0
- package/dest/test-wallet/worker_wallet.d.ts.map +1 -0
- package/dest/test-wallet/worker_wallet.js +151 -0
- package/dest/test-wallet/worker_wallet_schema.d.ts +274 -0
- package/dest/test-wallet/worker_wallet_schema.d.ts.map +1 -0
- package/dest/test-wallet/worker_wallet_schema.js +10 -0
- package/package.json +72 -62
- package/src/bench/client_flows/benchmark.ts +363 -0
- package/src/bench/client_flows/client_flows_benchmark.ts +388 -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 +47 -86
- package/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +149 -171
- package/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +155 -182
- package/src/e2e_deploy_contract/deploy_test.ts +40 -48
- package/src/e2e_epochs/epochs_test.ts +364 -93
- package/src/e2e_fees/bridging_race.notest.ts +74 -0
- package/src/e2e_fees/fees_test.ts +213 -259
- 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 +48 -59
- package/src/e2e_p2p/inactivity_slash_test.ts +179 -0
- package/src/e2e_p2p/p2p_network.ts +367 -234
- package/src/e2e_p2p/reqresp/utils.ts +256 -0
- package/src/e2e_p2p/shared.ts +315 -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 +132 -126
- package/src/fixtures/authwit_proxy.ts +50 -0
- package/src/fixtures/dumps/epoch_proof_result.json +1 -1
- package/src/fixtures/e2e_prover_test.ts +332 -0
- package/src/fixtures/elu_monitor.ts +126 -0
- package/src/fixtures/fixtures.ts +15 -7
- package/src/fixtures/get_acvm_config.ts +4 -12
- package/src/fixtures/get_bb_config.ts +18 -13
- package/src/fixtures/ha_setup.ts +186 -0
- package/src/fixtures/index.ts +1 -0
- package/src/fixtures/l1_to_l2_messaging.ts +56 -24
- package/src/fixtures/setup.ts +903 -0
- package/src/fixtures/setup_p2p_test.ts +134 -50
- package/src/fixtures/token_utils.ts +37 -16
- package/src/fixtures/utils.ts +27 -820
- package/src/fixtures/web3signer.ts +63 -0
- package/src/fixtures/with_telemetry_utils.ts +2 -2
- package/src/guides/up_quick_start.sh +9 -17
- 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 +110 -94
- package/src/shared/gas_portal_test_harness.ts +59 -50
- 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 +207 -226
- package/src/simulators/lending_simulator.ts +18 -17
- package/src/simulators/token_simulator.ts +18 -34
- package/src/spartan/DEVELOP.md +128 -0
- package/src/spartan/setup_test_wallets.ts +393 -95
- package/src/spartan/tx_metrics.ts +376 -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 +306 -0
- package/src/test-wallet/utils.ts +112 -0
- package/src/test-wallet/wallet_worker_script.ts +60 -0
- package/src/test-wallet/worker_wallet.ts +213 -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,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
} from '@aztec/
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
deployL1Contract,
|
|
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 { InboxAbi, UniswapPortalAbi, UniswapPortalBytecode } from '@aztec/l1-artifacts';
|
|
22
17
|
import { UniswapContract } from '@aztec/noir-contracts.js/Uniswap';
|
|
18
|
+
import { computeL2ToL1MessageHash } from '@aztec/stdlib/hash';
|
|
19
|
+
import { computeL2ToL1MembershipWitness } from '@aztec/stdlib/messaging';
|
|
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 { type EndToEndContext, ensureAccountContractsPublished } from '../fixtures/utils.js';
|
|
25
|
+
import type { TestWallet } from '../test-wallet/test_wallet.js';
|
|
28
26
|
import { CrossChainTestHarness } from './cross_chain_test_harness.js';
|
|
29
27
|
|
|
30
28
|
// PSA: This tests works on forked mainnet. There is a dump of the data in `dumpedState` such that we
|
|
@@ -34,38 +32,13 @@ import { CrossChainTestHarness } from './cross_chain_test_harness.js';
|
|
|
34
32
|
// anvil --fork-url https://mainnet.infura.io/v3/9928b52099854248b3a096be07a6b23c --fork-block-number 17514288 --chain-id 31337
|
|
35
33
|
// For CI, this is configured in `run_tests.sh` and `docker-compose-images.yml`
|
|
36
34
|
|
|
37
|
-
// docs:start:uniswap_l1_l2_test_setup_const
|
|
38
35
|
const TIMEOUT = 360_000;
|
|
39
36
|
|
|
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
|
|
62
|
-
|
|
63
37
|
export const uniswapL1L2TestSuite = (
|
|
64
|
-
setup: () => Promise<
|
|
38
|
+
setup: () => Promise<EndToEndContext>,
|
|
65
39
|
cleanup: () => Promise<void>,
|
|
66
40
|
expectedForkBlockNumber = 17514288,
|
|
67
41
|
) => {
|
|
68
|
-
// docs:start:uniswap_l1_l2_test_beforeAll
|
|
69
42
|
describe('uniswap_trade_on_l1_from_l2', () => {
|
|
70
43
|
jest.setTimeout(TIMEOUT);
|
|
71
44
|
|
|
@@ -73,25 +46,22 @@ export const uniswapL1L2TestSuite = (
|
|
|
73
46
|
const DAI_ADDRESS: EthAddress = EthAddress.fromString('0x6B175474E89094C44Da98b954EedeAC495271d0F');
|
|
74
47
|
|
|
75
48
|
let aztecNode: AztecNode;
|
|
76
|
-
let pxe: PXE;
|
|
77
49
|
let logger: Logger;
|
|
78
50
|
|
|
79
|
-
let
|
|
80
|
-
let publicClient: ViemPublicClient;
|
|
51
|
+
let l1Client: ExtendedViemWalletClient;
|
|
81
52
|
|
|
82
|
-
let
|
|
53
|
+
let wallet: TestWallet;
|
|
83
54
|
let ownerAddress: AztecAddress;
|
|
84
55
|
let ownerEthAddress: EthAddress;
|
|
85
56
|
// does transactions on behalf of owner on Aztec:
|
|
86
|
-
let
|
|
87
|
-
// let sponsorAddress: AztecAddress;
|
|
57
|
+
let sponsorAddress: AztecAddress;
|
|
88
58
|
|
|
89
59
|
let daiCrossChainHarness: CrossChainTestHarness;
|
|
90
60
|
let wethCrossChainHarness: CrossChainTestHarness;
|
|
91
61
|
|
|
92
|
-
let deployL1ContractsValues:
|
|
93
|
-
let rollup:
|
|
94
|
-
let uniswapPortal: GetContractReturnType<typeof UniswapPortalAbi,
|
|
62
|
+
let deployL1ContractsValues: DeployAztecL1ContractsReturnType;
|
|
63
|
+
let rollup: RollupContract;
|
|
64
|
+
let uniswapPortal: GetContractReturnType<typeof UniswapPortalAbi, ExtendedViemWalletClient>;
|
|
95
65
|
let uniswapPortalAddress: EthAddress;
|
|
96
66
|
let uniswapL2Contract: UniswapContract;
|
|
97
67
|
|
|
@@ -100,43 +70,41 @@ export const uniswapL1L2TestSuite = (
|
|
|
100
70
|
const minimumOutputAmount = 0n;
|
|
101
71
|
|
|
102
72
|
let cheatCodes: CheatCodes;
|
|
103
|
-
|
|
73
|
+
let version: number;
|
|
104
74
|
beforeAll(async () => {
|
|
75
|
+
const t = await setup();
|
|
105
76
|
({
|
|
106
77
|
aztecNode,
|
|
107
|
-
pxe,
|
|
108
78
|
logger,
|
|
109
|
-
publicClient,
|
|
110
|
-
walletClient,
|
|
111
|
-
ownerWallet,
|
|
112
|
-
sponsorWallet,
|
|
113
79
|
deployL1ContractsValues,
|
|
114
80
|
cheatCodes,
|
|
115
|
-
|
|
81
|
+
wallet,
|
|
82
|
+
accounts: [ownerAddress, sponsorAddress],
|
|
83
|
+
} = t);
|
|
84
|
+
|
|
85
|
+
l1Client = deployL1ContractsValues.l1Client;
|
|
86
|
+
|
|
87
|
+
t.watcher.setIsMarkingAsProven(false);
|
|
116
88
|
|
|
117
|
-
if (Number(await
|
|
89
|
+
if (Number(await l1Client.getBlockNumber()) < expectedForkBlockNumber) {
|
|
118
90
|
throw new Error('This test must be run on a fork of mainnet with the expected fork block');
|
|
119
91
|
}
|
|
120
92
|
|
|
121
|
-
rollup =
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
ownerAddress = ownerWallet.getAddress();
|
|
128
|
-
// sponsorAddress = sponsorWallet.getAddress();
|
|
129
|
-
ownerEthAddress = EthAddress.fromString((await walletClient.getAddresses())[0]);
|
|
93
|
+
rollup = new RollupContract(
|
|
94
|
+
deployL1ContractsValues.l1Client,
|
|
95
|
+
deployL1ContractsValues.l1ContractAddresses.rollupAddress,
|
|
96
|
+
);
|
|
97
|
+
version = Number(await rollup.getVersion());
|
|
98
|
+
ownerEthAddress = EthAddress.fromString((await l1Client.getAddresses())[0]);
|
|
130
99
|
|
|
131
|
-
await
|
|
100
|
+
await ensureAccountContractsPublished(wallet, [ownerAddress, sponsorAddress]);
|
|
132
101
|
|
|
133
102
|
logger.info('Deploying DAI Portal, initializing and deploying l2 contract...');
|
|
134
103
|
daiCrossChainHarness = await CrossChainTestHarness.new(
|
|
135
104
|
aztecNode,
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
ownerWallet,
|
|
105
|
+
deployL1ContractsValues.l1Client,
|
|
106
|
+
wallet,
|
|
107
|
+
ownerAddress,
|
|
140
108
|
logger,
|
|
141
109
|
DAI_ADDRESS,
|
|
142
110
|
);
|
|
@@ -144,31 +112,29 @@ export const uniswapL1L2TestSuite = (
|
|
|
144
112
|
logger.info('Deploying WETH Portal, initializing and deploying l2 contract...');
|
|
145
113
|
wethCrossChainHarness = await CrossChainTestHarness.new(
|
|
146
114
|
aztecNode,
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
ownerWallet,
|
|
115
|
+
l1Client,
|
|
116
|
+
wallet,
|
|
117
|
+
ownerAddress,
|
|
151
118
|
logger,
|
|
152
119
|
WETH9_ADDRESS,
|
|
153
120
|
);
|
|
154
121
|
|
|
155
122
|
logger.info('Deploy Uniswap portal on L1 and L2...');
|
|
156
|
-
uniswapPortalAddress = await deployL1Contract(
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
UniswapPortalAbi,
|
|
160
|
-
UniswapPortalBytecode,
|
|
161
|
-
).then(({ address }) => address);
|
|
123
|
+
uniswapPortalAddress = await deployL1Contract(l1Client, UniswapPortalAbi, UniswapPortalBytecode).then(
|
|
124
|
+
({ address }) => address,
|
|
125
|
+
);
|
|
162
126
|
|
|
163
127
|
uniswapPortal = getContract({
|
|
164
128
|
address: uniswapPortalAddress.toString(),
|
|
165
129
|
abi: UniswapPortalAbi,
|
|
166
|
-
client:
|
|
130
|
+
client: l1Client,
|
|
167
131
|
});
|
|
168
132
|
// deploy l2 uniswap contract and attach to portal
|
|
169
|
-
uniswapL2Contract = await UniswapContract.deploy(
|
|
133
|
+
({ contract: uniswapL2Contract } = await UniswapContract.deploy(wallet, uniswapPortalAddress).send({
|
|
134
|
+
from: ownerAddress,
|
|
135
|
+
}));
|
|
170
136
|
|
|
171
|
-
const registryAddress = (await
|
|
137
|
+
const registryAddress = (await aztecNode.getNodeInfo()).l1ContractAddresses.registryAddress;
|
|
172
138
|
|
|
173
139
|
await uniswapPortal.write.initialize(
|
|
174
140
|
[registryAddress.toString(), uniswapL2Contract.address.toString()],
|
|
@@ -177,13 +143,12 @@ export const uniswapL1L2TestSuite = (
|
|
|
177
143
|
|
|
178
144
|
// Give me some WETH so I can deposit to L2 and do the swap...
|
|
179
145
|
logger.info('Getting some weth');
|
|
180
|
-
const hash = await
|
|
181
|
-
await
|
|
146
|
+
const hash = await l1Client.sendTransaction({ to: WETH9_ADDRESS.toString(), value: parseEther('1000') });
|
|
147
|
+
await l1Client.waitForTransactionReceipt({ hash });
|
|
182
148
|
|
|
183
149
|
const wethBalance = await wethCrossChainHarness.getL1BalanceOf(ownerEthAddress);
|
|
184
150
|
expect(wethBalance).toBe(parseEther('1000'));
|
|
185
151
|
});
|
|
186
|
-
// docs:end:uniswap_l1_l2_test_beforeAll
|
|
187
152
|
|
|
188
153
|
afterAll(async () => {
|
|
189
154
|
await cleanup();
|
|
@@ -218,7 +183,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
218
183
|
// 3. Owner gives uniswap approval to transfer the funds to public to self on its behalf
|
|
219
184
|
logger.info('Approving uniswap to transfer funds to public to self on my behalf');
|
|
220
185
|
const nonceForWETHTransferToPublicApproval = new Fr(1n);
|
|
221
|
-
await
|
|
186
|
+
const transferToPublicAuhtwit = await wallet.createAuthWit(ownerAddress, {
|
|
222
187
|
caller: uniswapL2Contract.address,
|
|
223
188
|
action: wethCrossChainHarness.l2Token.methods.transfer_to_public(
|
|
224
189
|
ownerAddress,
|
|
@@ -232,7 +197,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
232
197
|
logger.info('Withdrawing weth to L1 and sending message to swap to dai');
|
|
233
198
|
const [secretForDepositingSwappedDai, secretHashForDepositingSwappedDai] = await generateClaimSecret();
|
|
234
199
|
|
|
235
|
-
const l2UniswapInteractionReceipt = await uniswapL2Contract.methods
|
|
200
|
+
const { receipt: l2UniswapInteractionReceipt } = await uniswapL2Contract.methods
|
|
236
201
|
.swap_private(
|
|
237
202
|
wethCrossChainHarness.l2Token.address,
|
|
238
203
|
wethCrossChainHarness.l2Bridge.address,
|
|
@@ -244,8 +209,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
244
209
|
secretHashForDepositingSwappedDai,
|
|
245
210
|
ownerEthAddress,
|
|
246
211
|
)
|
|
247
|
-
.send()
|
|
248
|
-
.wait();
|
|
212
|
+
.send({ from: ownerAddress, authWitnesses: [transferToPublicAuhtwit] });
|
|
249
213
|
|
|
250
214
|
const swapPrivateFunction = 'swap_private(address,uint256,uint24,address,uint256,bytes32,address)';
|
|
251
215
|
const swapPrivateContent = sha256ToField([
|
|
@@ -259,13 +223,13 @@ export const uniswapL1L2TestSuite = (
|
|
|
259
223
|
ownerEthAddress.toBuffer32(),
|
|
260
224
|
]);
|
|
261
225
|
|
|
262
|
-
const swapPrivateLeaf =
|
|
263
|
-
uniswapL2Contract.address,
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
new Fr(
|
|
267
|
-
|
|
268
|
-
|
|
226
|
+
const swapPrivateLeaf = computeL2ToL1MessageHash({
|
|
227
|
+
l2Sender: uniswapL2Contract.address,
|
|
228
|
+
l1Recipient: EthAddress.fromString(uniswapPortal.address),
|
|
229
|
+
content: swapPrivateContent,
|
|
230
|
+
rollupVersion: new Fr(version),
|
|
231
|
+
chainId: new Fr(l1Client.chain.id),
|
|
232
|
+
});
|
|
269
233
|
|
|
270
234
|
const withdrawContent = sha256ToField([
|
|
271
235
|
Buffer.from(toFunctionSelector('withdraw(address,uint256,address)').substring(2), 'hex'),
|
|
@@ -274,39 +238,48 @@ export const uniswapL1L2TestSuite = (
|
|
|
274
238
|
uniswapPortalAddress.toBuffer32(),
|
|
275
239
|
]);
|
|
276
240
|
|
|
277
|
-
const withdrawLeaf =
|
|
278
|
-
wethCrossChainHarness.l2Bridge.address,
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
new Fr(
|
|
282
|
-
|
|
283
|
-
|
|
241
|
+
const withdrawLeaf = computeL2ToL1MessageHash({
|
|
242
|
+
l2Sender: wethCrossChainHarness.l2Bridge.address,
|
|
243
|
+
l1Recipient: wethCrossChainHarness.tokenPortalAddress,
|
|
244
|
+
content: withdrawContent,
|
|
245
|
+
rollupVersion: new Fr(version),
|
|
246
|
+
chainId: new Fr(l1Client.chain.id),
|
|
247
|
+
});
|
|
284
248
|
|
|
285
249
|
// ensure that user's funds were burnt
|
|
286
250
|
await wethCrossChainHarness.expectPrivateBalanceOnL2(ownerAddress, wethL2BalanceBeforeSwap - wethAmountToBridge);
|
|
287
251
|
// ensure that uniswap contract didn't eat the funds.
|
|
288
252
|
await wethCrossChainHarness.expectPublicBalanceOnL2(uniswapL2Contract.address, 0n);
|
|
289
253
|
|
|
290
|
-
// Since the outbox is only consumable when the
|
|
291
|
-
|
|
254
|
+
// Since the outbox is only consumable when the epoch is proven, we need to advance to the next epoch.
|
|
255
|
+
const swapResult = (await computeL2ToL1MembershipWitness(
|
|
256
|
+
aztecNode,
|
|
257
|
+
swapPrivateLeaf,
|
|
258
|
+
l2UniswapInteractionReceipt.txHash,
|
|
259
|
+
))!;
|
|
260
|
+
const { epochNumber: epoch } = swapResult;
|
|
261
|
+
await cheatCodes.rollup.advanceToEpoch(EpochNumber(epoch + 1));
|
|
262
|
+
await waitForProven(aztecNode, l2UniswapInteractionReceipt, { provenTimeout: 300 });
|
|
292
263
|
|
|
293
264
|
// 5. Consume L2 to L1 message by calling uniswapPortal.swap_private()
|
|
294
265
|
logger.info('Execute withdraw and swap on the uniswapPortal!');
|
|
295
266
|
const daiL1BalanceOfPortalBeforeSwap = await daiCrossChainHarness.getL1BalanceOf(
|
|
296
267
|
daiCrossChainHarness.tokenPortalAddress,
|
|
297
268
|
);
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
l2UniswapInteractionReceipt.blockNumber!,
|
|
301
|
-
swapPrivateLeaf,
|
|
302
|
-
);
|
|
303
|
-
const [withdrawL2MessageIndex, withdrawSiblingPath] = await aztecNode.getL2ToL1MessageMembershipWitness(
|
|
304
|
-
l2UniswapInteractionReceipt.blockNumber!,
|
|
269
|
+
const withdrawResult = (await computeL2ToL1MembershipWitness(
|
|
270
|
+
aztecNode,
|
|
305
271
|
withdrawLeaf,
|
|
306
|
-
|
|
272
|
+
l2UniswapInteractionReceipt.txHash,
|
|
273
|
+
))!;
|
|
274
|
+
|
|
275
|
+
const swapPrivateL2MessageIndex = swapResult.leafIndex;
|
|
276
|
+
const swapPrivateSiblingPath = swapResult.siblingPath;
|
|
277
|
+
|
|
278
|
+
const withdrawL2MessageIndex = withdrawResult.leafIndex;
|
|
279
|
+
const withdrawSiblingPath = withdrawResult.siblingPath;
|
|
307
280
|
|
|
308
281
|
const withdrawMessageMetadata = {
|
|
309
|
-
|
|
282
|
+
_epoch: BigInt(epoch),
|
|
310
283
|
_leafIndex: BigInt(withdrawL2MessageIndex),
|
|
311
284
|
_path: withdrawSiblingPath
|
|
312
285
|
.toBufferArray()
|
|
@@ -314,7 +287,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
314
287
|
};
|
|
315
288
|
|
|
316
289
|
const swapPrivateMessageMetadata = {
|
|
317
|
-
|
|
290
|
+
_epoch: BigInt(epoch),
|
|
318
291
|
_leafIndex: BigInt(swapPrivateL2MessageIndex),
|
|
319
292
|
_path: swapPrivateSiblingPath
|
|
320
293
|
.toBufferArray()
|
|
@@ -333,7 +306,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
333
306
|
] as const;
|
|
334
307
|
|
|
335
308
|
// this should also insert a message into the inbox.
|
|
336
|
-
const txReceipt = await daiCrossChainHarness.
|
|
309
|
+
const txReceipt = await daiCrossChainHarness.l1Client.waitForTransactionReceipt({
|
|
337
310
|
hash: await uniswapPortal.write.swapPrivate(swapArgs),
|
|
338
311
|
});
|
|
339
312
|
|
|
@@ -461,10 +434,10 @@ export const uniswapL1L2TestSuite = (
|
|
|
461
434
|
// ownerEthAddress,
|
|
462
435
|
// nonceForSwap,
|
|
463
436
|
// );
|
|
464
|
-
// await ownerWallet.setPublicAuthWit({ caller: sponsorAddress, action }, true).send()
|
|
437
|
+
// await ownerWallet.setPublicAuthWit({ caller: sponsorAddress, action }, true).send();
|
|
465
438
|
|
|
466
439
|
// // 4.2 Call swap_public from user2 on behalf of owner
|
|
467
|
-
// const uniswapL2Interaction = await action.send()
|
|
440
|
+
// const uniswapL2Interaction = await action.send();
|
|
468
441
|
|
|
469
442
|
// const swapPublicContent = sha256ToField([
|
|
470
443
|
// Buffer.from(
|
|
@@ -525,7 +498,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
525
498
|
// );
|
|
526
499
|
|
|
527
500
|
// const withdrawMessageMetadata = {
|
|
528
|
-
//
|
|
501
|
+
// _epoch: epoch,
|
|
529
502
|
// _leafIndex: BigInt(withdrawL2MessageIndex),
|
|
530
503
|
// _path: withdrawSiblingPath
|
|
531
504
|
// .toBufferArray()
|
|
@@ -533,7 +506,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
533
506
|
// };
|
|
534
507
|
|
|
535
508
|
// const swapPrivateMessageMetadata = {
|
|
536
|
-
//
|
|
509
|
+
// _epoch: epoch,
|
|
537
510
|
// _leafIndex: BigInt(swapPrivateL2MessageIndex),
|
|
538
511
|
// _path: swapPrivateSiblingPath
|
|
539
512
|
// .toBufferArray()
|
|
@@ -620,14 +593,16 @@ export const uniswapL1L2TestSuite = (
|
|
|
620
593
|
const expectedMessageHash = await computeAuthWitMessageHash(
|
|
621
594
|
{
|
|
622
595
|
caller: uniswapL2Contract.address,
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
596
|
+
call: await wethCrossChainHarness.l2Token.methods
|
|
597
|
+
.transfer_to_public(
|
|
598
|
+
ownerAddress,
|
|
599
|
+
uniswapL2Contract.address,
|
|
600
|
+
wethAmountToBridge,
|
|
601
|
+
nonceForWETHTransferToPublicApproval,
|
|
602
|
+
)
|
|
603
|
+
.getFunctionCall(),
|
|
629
604
|
},
|
|
630
|
-
|
|
605
|
+
await wallet.getChainInfo(),
|
|
631
606
|
);
|
|
632
607
|
|
|
633
608
|
await expect(
|
|
@@ -643,7 +618,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
643
618
|
Fr.random(),
|
|
644
619
|
ownerEthAddress,
|
|
645
620
|
)
|
|
646
|
-
.
|
|
621
|
+
.simulate({ from: ownerAddress }),
|
|
647
622
|
).rejects.toThrow(`Unknown auth witness for message hash ${expectedMessageHash.toString()}`);
|
|
648
623
|
});
|
|
649
624
|
|
|
@@ -655,7 +630,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
655
630
|
// 2. owner gives uniswap approval to transfer the funds to public:
|
|
656
631
|
logger.info('Approving uniswap to transfer funds to public to self on my behalf');
|
|
657
632
|
const nonceForWETHTransferToPublicApproval = new Fr(3n);
|
|
658
|
-
await
|
|
633
|
+
const transferToPublicAuthwith = await wallet.createAuthWit(ownerAddress, {
|
|
659
634
|
caller: uniswapL2Contract.address,
|
|
660
635
|
action: wethCrossChainHarness.l2Token.methods.transfer_to_public(
|
|
661
636
|
ownerAddress,
|
|
@@ -680,7 +655,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
680
655
|
Fr.random(),
|
|
681
656
|
ownerEthAddress,
|
|
682
657
|
)
|
|
683
|
-
.
|
|
658
|
+
.send({ from: ownerAddress, authWitnesses: [transferToPublicAuthwith] }),
|
|
684
659
|
).rejects.toThrow('Assertion failed: input_asset address is not the same as seen in the bridge contract');
|
|
685
660
|
});
|
|
686
661
|
|
|
@@ -692,7 +667,8 @@ export const uniswapL1L2TestSuite = (
|
|
|
692
667
|
|
|
693
668
|
// 2. Give approval to uniswap to transfer funds to itself
|
|
694
669
|
const nonceForWETHTransferApproval = new Fr(2n);
|
|
695
|
-
const validateActionInteraction = await
|
|
670
|
+
const validateActionInteraction = await wallet.setPublicAuthWit(
|
|
671
|
+
ownerAddress,
|
|
696
672
|
{
|
|
697
673
|
caller: uniswapL2Contract.address,
|
|
698
674
|
action: wethCrossChainHarness.l2Token.methods.transfer_in_public(
|
|
@@ -704,7 +680,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
704
680
|
},
|
|
705
681
|
true,
|
|
706
682
|
);
|
|
707
|
-
await validateActionInteraction.send()
|
|
683
|
+
await validateActionInteraction.send();
|
|
708
684
|
|
|
709
685
|
// No approval to call `swap` but should work even without it:
|
|
710
686
|
const [_, secretHashForDepositingSwappedDai] = await generateClaimSecret();
|
|
@@ -723,8 +699,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
723
699
|
ownerEthAddress,
|
|
724
700
|
Fr.ZERO, // nonce for swap -> doesn't matter
|
|
725
701
|
)
|
|
726
|
-
.send()
|
|
727
|
-
.wait();
|
|
702
|
+
.send({ from: ownerAddress });
|
|
728
703
|
// check weth balance of owner on L2 (we first bridged `wethAmountToBridge` into L2 and now withdrew it!)
|
|
729
704
|
await wethCrossChainHarness.expectPublicBalanceOnL2(ownerAddress, 0n);
|
|
730
705
|
});
|
|
@@ -736,32 +711,35 @@ export const uniswapL1L2TestSuite = (
|
|
|
736
711
|
const nonceForWETHTransferApproval = new Fr(3n);
|
|
737
712
|
const nonceForSwap = new Fr(3n);
|
|
738
713
|
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
|
-
|
|
714
|
+
const action = uniswapL2Contract.methods.swap_public(
|
|
715
|
+
ownerAddress,
|
|
716
|
+
wethCrossChainHarness.l2Bridge.address,
|
|
717
|
+
wethAmountToBridge,
|
|
718
|
+
daiCrossChainHarness.l2Bridge.address,
|
|
719
|
+
nonceForWETHTransferApproval,
|
|
720
|
+
uniswapFeeTier,
|
|
721
|
+
minimumOutputAmount,
|
|
722
|
+
ownerAddress,
|
|
723
|
+
secretHashForDepositingSwappedDai,
|
|
724
|
+
ownerEthAddress,
|
|
725
|
+
nonceForSwap,
|
|
726
|
+
);
|
|
727
|
+
const validateActionInteraction = await wallet.setPublicAuthWit(
|
|
728
|
+
ownerAddress,
|
|
729
|
+
{ caller: approvedUser, action },
|
|
730
|
+
true,
|
|
731
|
+
);
|
|
732
|
+
await validateActionInteraction.send();
|
|
756
733
|
|
|
757
|
-
await expect(action.simulate()).rejects.toThrow(/unauthorized/);
|
|
734
|
+
await expect(action.simulate({ from: sponsorAddress })).rejects.toThrow(/unauthorized/);
|
|
758
735
|
});
|
|
759
736
|
|
|
760
737
|
it("uniswap can't pull funds without transfer approval", async () => {
|
|
761
738
|
// swap should fail since no transfer approval to uniswap:
|
|
762
739
|
const nonceForWETHTransferApproval = new Fr(4n);
|
|
763
740
|
|
|
764
|
-
const validateActionInteraction = await
|
|
741
|
+
const validateActionInteraction = await wallet.setPublicAuthWit(
|
|
742
|
+
ownerAddress,
|
|
765
743
|
{
|
|
766
744
|
caller: uniswapL2Contract.address,
|
|
767
745
|
action: wethCrossChainHarness.l2Token.methods.transfer_in_public(
|
|
@@ -773,7 +751,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
773
751
|
},
|
|
774
752
|
true,
|
|
775
753
|
);
|
|
776
|
-
await validateActionInteraction.send()
|
|
754
|
+
await validateActionInteraction.send();
|
|
777
755
|
|
|
778
756
|
await expect(
|
|
779
757
|
uniswapL2Contract.methods
|
|
@@ -790,7 +768,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
790
768
|
ownerEthAddress,
|
|
791
769
|
Fr.ZERO,
|
|
792
770
|
)
|
|
793
|
-
.simulate(),
|
|
771
|
+
.simulate({ from: ownerAddress }),
|
|
794
772
|
).rejects.toThrow(/unauthorized/);
|
|
795
773
|
});
|
|
796
774
|
|
|
@@ -803,7 +781,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
803
781
|
// Owner gives uniswap approval to transfer the funds to public to self on its behalf
|
|
804
782
|
logger.info('Approving uniswap to transfer the funds to public to self on my behalf');
|
|
805
783
|
const nonceForWETHTransferToPublicApproval = new Fr(4n);
|
|
806
|
-
await
|
|
784
|
+
const transferToPublicAuhtwit = await wallet.createAuthWit(ownerAddress, {
|
|
807
785
|
caller: uniswapL2Contract.address,
|
|
808
786
|
action: wethCrossChainHarness.l2Token.methods.transfer_to_public(
|
|
809
787
|
ownerAddress,
|
|
@@ -818,7 +796,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
818
796
|
logger.info('Withdrawing weth to L1 and sending message to swap to dai');
|
|
819
797
|
|
|
820
798
|
const [, secretHashForDepositingSwappedDai] = await generateClaimSecret();
|
|
821
|
-
const withdrawReceipt = await uniswapL2Contract.methods
|
|
799
|
+
const { receipt: withdrawReceipt } = await uniswapL2Contract.methods
|
|
822
800
|
.swap_private(
|
|
823
801
|
wethCrossChainHarness.l2Token.address,
|
|
824
802
|
wethCrossChainHarness.l2Bridge.address,
|
|
@@ -830,8 +808,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
830
808
|
secretHashForDepositingSwappedDai,
|
|
831
809
|
ownerEthAddress,
|
|
832
810
|
)
|
|
833
|
-
.send()
|
|
834
|
-
.wait();
|
|
811
|
+
.send({ from: ownerAddress, authWitnesses: [transferToPublicAuhtwit] });
|
|
835
812
|
|
|
836
813
|
const swapPrivateContent = sha256ToField([
|
|
837
814
|
Buffer.from(
|
|
@@ -847,13 +824,13 @@ export const uniswapL1L2TestSuite = (
|
|
|
847
824
|
ownerEthAddress.toBuffer32(),
|
|
848
825
|
]);
|
|
849
826
|
|
|
850
|
-
const swapPrivateLeaf =
|
|
851
|
-
uniswapL2Contract.address,
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
new Fr(
|
|
855
|
-
|
|
856
|
-
|
|
827
|
+
const swapPrivateLeaf = computeL2ToL1MessageHash({
|
|
828
|
+
l2Sender: uniswapL2Contract.address,
|
|
829
|
+
l1Recipient: EthAddress.fromString(uniswapPortal.address),
|
|
830
|
+
content: swapPrivateContent,
|
|
831
|
+
rollupVersion: new Fr(version),
|
|
832
|
+
chainId: new Fr(l1Client.chain.id),
|
|
833
|
+
});
|
|
857
834
|
|
|
858
835
|
const withdrawContent = sha256ToField([
|
|
859
836
|
Buffer.from(toFunctionSelector('withdraw(address,uint256,address)').substring(2), 'hex'),
|
|
@@ -862,25 +839,26 @@ export const uniswapL1L2TestSuite = (
|
|
|
862
839
|
uniswapPortalAddress.toBuffer32(),
|
|
863
840
|
]);
|
|
864
841
|
|
|
865
|
-
const withdrawLeaf =
|
|
866
|
-
wethCrossChainHarness.l2Bridge.address,
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
new Fr(
|
|
870
|
-
|
|
871
|
-
|
|
842
|
+
const withdrawLeaf = computeL2ToL1MessageHash({
|
|
843
|
+
l2Sender: wethCrossChainHarness.l2Bridge.address,
|
|
844
|
+
l1Recipient: wethCrossChainHarness.tokenPortalAddress,
|
|
845
|
+
content: withdrawContent,
|
|
846
|
+
rollupVersion: new Fr(version),
|
|
847
|
+
chainId: new Fr(l1Client.chain.id),
|
|
848
|
+
});
|
|
872
849
|
|
|
873
|
-
const
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
const
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
850
|
+
const swapResult = (await computeL2ToL1MembershipWitness(aztecNode, swapPrivateLeaf, withdrawReceipt.txHash))!;
|
|
851
|
+
const { epochNumber: epoch } = swapResult;
|
|
852
|
+
const withdrawResult = (await computeL2ToL1MembershipWitness(aztecNode, withdrawLeaf, withdrawReceipt.txHash))!;
|
|
853
|
+
|
|
854
|
+
const swapPrivateL2MessageIndex = swapResult.leafIndex;
|
|
855
|
+
const swapPrivateSiblingPath = swapResult.siblingPath;
|
|
856
|
+
|
|
857
|
+
const withdrawL2MessageIndex = withdrawResult.leafIndex;
|
|
858
|
+
const withdrawSiblingPath = withdrawResult.siblingPath;
|
|
881
859
|
|
|
882
860
|
const withdrawMessageMetadata = {
|
|
883
|
-
|
|
861
|
+
_epoch: BigInt(epoch),
|
|
884
862
|
_leafIndex: BigInt(withdrawL2MessageIndex),
|
|
885
863
|
_path: withdrawSiblingPath
|
|
886
864
|
.toBufferArray()
|
|
@@ -888,7 +866,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
888
866
|
};
|
|
889
867
|
|
|
890
868
|
const swapPrivateMessageMetadata = {
|
|
891
|
-
|
|
869
|
+
_epoch: BigInt(epoch),
|
|
892
870
|
_leafIndex: BigInt(swapPrivateL2MessageIndex),
|
|
893
871
|
_path: swapPrivateSiblingPath
|
|
894
872
|
.toBufferArray()
|
|
@@ -898,8 +876,9 @@ export const uniswapL1L2TestSuite = (
|
|
|
898
876
|
// ensure that user's funds were burnt
|
|
899
877
|
await wethCrossChainHarness.expectPrivateBalanceOnL2(ownerAddress, wethL2BalanceBeforeSwap - wethAmountToBridge);
|
|
900
878
|
|
|
901
|
-
// Since the outbox is only consumable when the
|
|
902
|
-
await cheatCodes.rollup.
|
|
879
|
+
// Since the outbox is only consumable when the epoch is proven, we need to advance to the next epoch.
|
|
880
|
+
await cheatCodes.rollup.advanceToEpoch(EpochNumber(epoch + 1));
|
|
881
|
+
await waitForProven(aztecNode, withdrawReceipt, { provenTimeout: 300 });
|
|
903
882
|
|
|
904
883
|
// On L1 call swap_public!
|
|
905
884
|
logger.info('call swap_public on L1');
|
|
@@ -927,7 +906,8 @@ export const uniswapL1L2TestSuite = (
|
|
|
927
906
|
|
|
928
907
|
// Owner gives uniswap approval to transfer funds on its behalf
|
|
929
908
|
const nonceForWETHTransferApproval = new Fr(5n);
|
|
930
|
-
const validateActionInteraction = await
|
|
909
|
+
const validateActionInteraction = await wallet.setPublicAuthWit(
|
|
910
|
+
ownerAddress,
|
|
931
911
|
{
|
|
932
912
|
caller: uniswapL2Contract.address,
|
|
933
913
|
action: wethCrossChainHarness.l2Token.methods.transfer_in_public(
|
|
@@ -939,11 +919,11 @@ export const uniswapL1L2TestSuite = (
|
|
|
939
919
|
},
|
|
940
920
|
true,
|
|
941
921
|
);
|
|
942
|
-
await validateActionInteraction.send()
|
|
922
|
+
await validateActionInteraction.send();
|
|
943
923
|
|
|
944
924
|
// Call swap_public on L2
|
|
945
925
|
const secretHashForDepositingSwappedDai = Fr.random();
|
|
946
|
-
const withdrawReceipt = await uniswapL2Contract.methods
|
|
926
|
+
const { receipt: withdrawReceipt } = await uniswapL2Contract.methods
|
|
947
927
|
.swap_public(
|
|
948
928
|
ownerAddress,
|
|
949
929
|
wethCrossChainHarness.l2Bridge.address,
|
|
@@ -957,8 +937,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
957
937
|
ownerEthAddress,
|
|
958
938
|
Fr.ZERO,
|
|
959
939
|
)
|
|
960
|
-
.send()
|
|
961
|
-
.wait();
|
|
940
|
+
.send({ from: ownerAddress });
|
|
962
941
|
|
|
963
942
|
const swapPublicContent = sha256ToField([
|
|
964
943
|
Buffer.from(
|
|
@@ -977,13 +956,13 @@ export const uniswapL1L2TestSuite = (
|
|
|
977
956
|
ownerEthAddress.toBuffer32(),
|
|
978
957
|
]);
|
|
979
958
|
|
|
980
|
-
const swapPublicLeaf =
|
|
981
|
-
uniswapL2Contract.address,
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
new Fr(
|
|
985
|
-
|
|
986
|
-
|
|
959
|
+
const swapPublicLeaf = computeL2ToL1MessageHash({
|
|
960
|
+
l2Sender: uniswapL2Contract.address,
|
|
961
|
+
l1Recipient: EthAddress.fromString(uniswapPortal.address),
|
|
962
|
+
content: swapPublicContent,
|
|
963
|
+
rollupVersion: new Fr(version),
|
|
964
|
+
chainId: new Fr(l1Client.chain.id),
|
|
965
|
+
});
|
|
987
966
|
|
|
988
967
|
const withdrawContent = sha256ToField([
|
|
989
968
|
Buffer.from(toFunctionSelector('withdraw(address,uint256,address)').substring(2), 'hex'),
|
|
@@ -992,25 +971,26 @@ export const uniswapL1L2TestSuite = (
|
|
|
992
971
|
uniswapPortalAddress.toBuffer32(),
|
|
993
972
|
]);
|
|
994
973
|
|
|
995
|
-
const withdrawLeaf =
|
|
996
|
-
wethCrossChainHarness.l2Bridge.address,
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
new Fr(
|
|
1000
|
-
|
|
1001
|
-
|
|
974
|
+
const withdrawLeaf = computeL2ToL1MessageHash({
|
|
975
|
+
l2Sender: wethCrossChainHarness.l2Bridge.address,
|
|
976
|
+
l1Recipient: wethCrossChainHarness.tokenPortalAddress,
|
|
977
|
+
content: withdrawContent,
|
|
978
|
+
rollupVersion: new Fr(version),
|
|
979
|
+
chainId: new Fr(l1Client.chain.id),
|
|
980
|
+
});
|
|
1002
981
|
|
|
1003
|
-
const
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
const
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
982
|
+
const swapResult = (await computeL2ToL1MembershipWitness(aztecNode, swapPublicLeaf, withdrawReceipt.txHash))!;
|
|
983
|
+
const { epochNumber: epoch } = swapResult;
|
|
984
|
+
const withdrawResult = (await computeL2ToL1MembershipWitness(aztecNode, withdrawLeaf, withdrawReceipt.txHash))!;
|
|
985
|
+
|
|
986
|
+
const swapPublicL2MessageIndex = swapResult.leafIndex;
|
|
987
|
+
const swapPublicSiblingPath = swapResult.siblingPath;
|
|
988
|
+
|
|
989
|
+
const withdrawL2MessageIndex = withdrawResult.leafIndex;
|
|
990
|
+
const withdrawSiblingPath = withdrawResult.siblingPath;
|
|
1011
991
|
|
|
1012
992
|
const withdrawMessageMetadata = {
|
|
1013
|
-
|
|
993
|
+
_epoch: BigInt(epoch),
|
|
1014
994
|
_leafIndex: BigInt(withdrawL2MessageIndex),
|
|
1015
995
|
_path: withdrawSiblingPath
|
|
1016
996
|
.toBufferArray()
|
|
@@ -1018,7 +998,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
1018
998
|
};
|
|
1019
999
|
|
|
1020
1000
|
const swapPublicMessageMetadata = {
|
|
1021
|
-
|
|
1001
|
+
_epoch: BigInt(epoch),
|
|
1022
1002
|
_leafIndex: BigInt(swapPublicL2MessageIndex),
|
|
1023
1003
|
_path: swapPublicSiblingPath
|
|
1024
1004
|
.toBufferArray()
|
|
@@ -1028,8 +1008,9 @@ export const uniswapL1L2TestSuite = (
|
|
|
1028
1008
|
// check weth balance of owner on L2 (we first bridged `wethAmountToBridge` into L2 and now withdrew it!)
|
|
1029
1009
|
await wethCrossChainHarness.expectPublicBalanceOnL2(ownerAddress, 0n);
|
|
1030
1010
|
|
|
1031
|
-
// Since the outbox is only consumable when the
|
|
1032
|
-
await cheatCodes.rollup.
|
|
1011
|
+
// Since the outbox is only consumable when the epoch is proven, we need to advance to the next epoch.
|
|
1012
|
+
await cheatCodes.rollup.advanceToEpoch(EpochNumber(epoch + 1));
|
|
1013
|
+
await waitForProven(aztecNode, withdrawReceipt, { provenTimeout: 300 });
|
|
1033
1014
|
|
|
1034
1015
|
// Call swap_private on L1
|
|
1035
1016
|
logger.info('Execute withdraw and swap on the uniswapPortal!');
|