@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,23 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Fr, GrumpkinScalar
|
|
1
|
+
import { NO_WAIT } from '@aztec/aztec.js/contracts';
|
|
2
|
+
import { Fr, GrumpkinScalar } from '@aztec/aztec.js/fields';
|
|
3
|
+
import { TxStatus } from '@aztec/aztec.js/tx';
|
|
3
4
|
import { times } from '@aztec/foundation/collection';
|
|
4
|
-
// submits a set of transactions to the provided
|
|
5
|
-
export const submitTxsTo = async (
|
|
6
|
-
const
|
|
5
|
+
// submits a set of transactions to the provided Wallet
|
|
6
|
+
export const submitTxsTo = async (wallet, submitter, numTxs, logger)=>{
|
|
7
|
+
const txHashes = [];
|
|
7
8
|
await Promise.all(times(numTxs, async ()=>{
|
|
8
|
-
const accountManager = await
|
|
9
|
-
const
|
|
10
|
-
|
|
9
|
+
const accountManager = await wallet.createSchnorrAccount(Fr.random(), Fr.random(), GrumpkinScalar.random());
|
|
10
|
+
const deployMethod = await accountManager.getDeployMethod();
|
|
11
|
+
const { txHash } = await deployMethod.send({
|
|
12
|
+
from: submitter,
|
|
13
|
+
wait: NO_WAIT
|
|
11
14
|
});
|
|
12
|
-
const txHash = await tx.getTxHash();
|
|
13
15
|
logger.info(`Tx sent with hash ${txHash}`);
|
|
14
|
-
const receipt = await
|
|
15
|
-
expect(receipt).
|
|
16
|
-
status: TxStatus.PENDING,
|
|
17
|
-
error: ''
|
|
18
|
-
}));
|
|
16
|
+
const receipt = await wallet.getTxReceipt(txHash);
|
|
17
|
+
expect(receipt.status).toBe(TxStatus.PENDING);
|
|
19
18
|
logger.info(`Receipt received for ${txHash}`);
|
|
20
|
-
|
|
19
|
+
txHashes.push(txHash);
|
|
21
20
|
}));
|
|
22
|
-
return
|
|
21
|
+
return txHashes;
|
|
23
22
|
};
|
|
@@ -1,25 +1,3 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export type UniswapSetupContext = {
|
|
5
|
-
/** Aztec Node instance */
|
|
6
|
-
aztecNode: AztecNode;
|
|
7
|
-
/** The Private eXecution Environment (PXE). */
|
|
8
|
-
pxe: PXE;
|
|
9
|
-
/** Logger instance named as the current test. */
|
|
10
|
-
logger: Logger;
|
|
11
|
-
/** Viem Public client instance. */
|
|
12
|
-
publicClient: ViemPublicClient;
|
|
13
|
-
/** Viem Wallet Client instance. */
|
|
14
|
-
walletClient: ViemWalletClient;
|
|
15
|
-
/** The owner wallet. */
|
|
16
|
-
ownerWallet: AccountWallet;
|
|
17
|
-
/** The sponsor wallet. */
|
|
18
|
-
sponsorWallet: AccountWallet;
|
|
19
|
-
/** */
|
|
20
|
-
deployL1ContractsValues: DeployL1ContractsReturnType;
|
|
21
|
-
/** Cheat codes instance. */
|
|
22
|
-
cheatCodes: CheatCodes;
|
|
23
|
-
};
|
|
24
|
-
export declare const uniswapL1L2TestSuite: (setup: () => Promise<UniswapSetupContext>, cleanup: () => Promise<void>, expectedForkBlockNumber?: number) => void;
|
|
25
|
-
//# sourceMappingURL=uniswap_l1_l2.d.ts.map
|
|
1
|
+
import { type EndToEndContext } from '../fixtures/utils.js';
|
|
2
|
+
export declare const uniswapL1L2TestSuite: (setup: () => Promise<EndToEndContext>, cleanup: () => Promise<void>, expectedForkBlockNumber?: number) => void;
|
|
3
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidW5pc3dhcF9sMV9sMi5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3NoYXJlZC91bmlzd2FwX2wxX2wyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQXVCQSxPQUFPLEVBQUUsS0FBSyxlQUFlLEVBQW1DLE1BQU0sc0JBQXNCLENBQUM7QUFhN0YsZUFBTyxNQUFNLG9CQUFvQixpSEF1K0JoQyxDQUFDIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uniswap_l1_l2.d.ts","sourceRoot":"","sources":["../../src/shared/uniswap_l1_l2.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"uniswap_l1_l2.d.ts","sourceRoot":"","sources":["../../src/shared/uniswap_l1_l2.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,KAAK,eAAe,EAAmC,MAAM,sBAAsB,CAAC;AAa7F,eAAO,MAAM,oBAAoB,iHAu+BhC,CAAC"}
|
|
@@ -1,11 +1,20 @@
|
|
|
1
|
-
import { AztecAddress, EthAddress
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
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 { RollupContract } from '@aztec/ethereum/contracts';
|
|
7
|
+
import { deployL1Contract } from '@aztec/ethereum/deploy-l1-contract';
|
|
8
|
+
import { extractEvent } from '@aztec/ethereum/utils';
|
|
9
|
+
import { EpochNumber } from '@aztec/foundation/branded-types';
|
|
10
|
+
import { sha256ToField } from '@aztec/foundation/crypto/sha256';
|
|
11
|
+
import { InboxAbi, UniswapPortalAbi, UniswapPortalBytecode } from '@aztec/l1-artifacts';
|
|
5
12
|
import { UniswapContract } from '@aztec/noir-contracts.js/Uniswap';
|
|
13
|
+
import { computeL2ToL1MessageHash } from '@aztec/stdlib/hash';
|
|
14
|
+
import { computeL2ToL1MembershipWitness } from '@aztec/stdlib/messaging';
|
|
6
15
|
import { jest } from '@jest/globals';
|
|
7
16
|
import { getContract, parseEther, toFunctionSelector } from 'viem';
|
|
8
|
-
import {
|
|
17
|
+
import { ensureAccountContractsPublished } from '../fixtures/utils.js';
|
|
9
18
|
import { CrossChainTestHarness } from './cross_chain_test_harness.js';
|
|
10
19
|
// PSA: This tests works on forked mainnet. There is a dump of the data in `dumpedState` such that we
|
|
11
20
|
// don't need to burn through RPC requests.
|
|
@@ -13,26 +22,20 @@ import { CrossChainTestHarness } from './cross_chain_test_harness.js';
|
|
|
13
22
|
// To start an actual fork, use the command:
|
|
14
23
|
// anvil --fork-url https://mainnet.infura.io/v3/9928b52099854248b3a096be07a6b23c --fork-block-number 17514288 --chain-id 31337
|
|
15
24
|
// For CI, this is configured in `run_tests.sh` and `docker-compose-images.yml`
|
|
16
|
-
// docs:start:uniswap_l1_l2_test_setup_const
|
|
17
25
|
const TIMEOUT = 360_000;
|
|
18
|
-
// docs:end:uniswap_l1_l2_test_setup_const
|
|
19
26
|
export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 17514288)=>{
|
|
20
|
-
// docs:start:uniswap_l1_l2_test_beforeAll
|
|
21
27
|
describe('uniswap_trade_on_l1_from_l2', ()=>{
|
|
22
28
|
jest.setTimeout(TIMEOUT);
|
|
23
29
|
const WETH9_ADDRESS = EthAddress.fromString('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2');
|
|
24
30
|
const DAI_ADDRESS = EthAddress.fromString('0x6B175474E89094C44Da98b954EedeAC495271d0F');
|
|
25
31
|
let aztecNode;
|
|
26
|
-
let pxe;
|
|
27
32
|
let logger;
|
|
28
|
-
let
|
|
29
|
-
let
|
|
30
|
-
let ownerWallet;
|
|
33
|
+
let l1Client;
|
|
34
|
+
let wallet;
|
|
31
35
|
let ownerAddress;
|
|
32
36
|
let ownerEthAddress;
|
|
33
37
|
// does transactions on behalf of owner on Aztec:
|
|
34
|
-
let
|
|
35
|
-
// let sponsorAddress: AztecAddress;
|
|
38
|
+
let sponsorAddress;
|
|
36
39
|
let daiCrossChainHarness;
|
|
37
40
|
let wethCrossChainHarness;
|
|
38
41
|
let deployL1ContractsValues;
|
|
@@ -44,54 +47,54 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
44
47
|
const uniswapFeeTier = 3000n;
|
|
45
48
|
const minimumOutputAmount = 0n;
|
|
46
49
|
let cheatCodes;
|
|
50
|
+
let version;
|
|
47
51
|
beforeAll(async ()=>{
|
|
48
|
-
|
|
49
|
-
|
|
52
|
+
const t = await setup();
|
|
53
|
+
({ aztecNode, logger, deployL1ContractsValues, cheatCodes, wallet, accounts: [ownerAddress, sponsorAddress] } = t);
|
|
54
|
+
l1Client = deployL1ContractsValues.l1Client;
|
|
55
|
+
t.watcher.setIsMarkingAsProven(false);
|
|
56
|
+
if (Number(await l1Client.getBlockNumber()) < expectedForkBlockNumber) {
|
|
50
57
|
throw new Error('This test must be run on a fork of mainnet with the expected fork block');
|
|
51
58
|
}
|
|
52
|
-
rollup =
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
// sponsorAddress = sponsorWallet.getAddress();
|
|
59
|
-
ownerEthAddress = EthAddress.fromString((await walletClient.getAddresses())[0]);
|
|
60
|
-
await ensureAccountsPubliclyDeployed(ownerWallet, [
|
|
61
|
-
ownerWallet,
|
|
62
|
-
sponsorWallet
|
|
59
|
+
rollup = new RollupContract(deployL1ContractsValues.l1Client, deployL1ContractsValues.l1ContractAddresses.rollupAddress);
|
|
60
|
+
version = Number(await rollup.getVersion());
|
|
61
|
+
ownerEthAddress = EthAddress.fromString((await l1Client.getAddresses())[0]);
|
|
62
|
+
await ensureAccountContractsPublished(wallet, [
|
|
63
|
+
ownerAddress,
|
|
64
|
+
sponsorAddress
|
|
63
65
|
]);
|
|
64
66
|
logger.info('Deploying DAI Portal, initializing and deploying l2 contract...');
|
|
65
|
-
daiCrossChainHarness = await CrossChainTestHarness.new(aztecNode,
|
|
67
|
+
daiCrossChainHarness = await CrossChainTestHarness.new(aztecNode, deployL1ContractsValues.l1Client, wallet, ownerAddress, logger, DAI_ADDRESS);
|
|
66
68
|
logger.info('Deploying WETH Portal, initializing and deploying l2 contract...');
|
|
67
|
-
wethCrossChainHarness = await CrossChainTestHarness.new(aztecNode,
|
|
69
|
+
wethCrossChainHarness = await CrossChainTestHarness.new(aztecNode, l1Client, wallet, ownerAddress, logger, WETH9_ADDRESS);
|
|
68
70
|
logger.info('Deploy Uniswap portal on L1 and L2...');
|
|
69
|
-
uniswapPortalAddress = await deployL1Contract(
|
|
71
|
+
uniswapPortalAddress = await deployL1Contract(l1Client, UniswapPortalAbi, UniswapPortalBytecode).then(({ address })=>address);
|
|
70
72
|
uniswapPortal = getContract({
|
|
71
73
|
address: uniswapPortalAddress.toString(),
|
|
72
74
|
abi: UniswapPortalAbi,
|
|
73
|
-
client:
|
|
75
|
+
client: l1Client
|
|
74
76
|
});
|
|
75
77
|
// deploy l2 uniswap contract and attach to portal
|
|
76
|
-
uniswapL2Contract = await UniswapContract.deploy(
|
|
77
|
-
|
|
78
|
+
({ contract: uniswapL2Contract } = await UniswapContract.deploy(wallet, uniswapPortalAddress).send({
|
|
79
|
+
from: ownerAddress
|
|
80
|
+
}));
|
|
81
|
+
const registryAddress = (await aztecNode.getNodeInfo()).l1ContractAddresses.registryAddress;
|
|
78
82
|
await uniswapPortal.write.initialize([
|
|
79
83
|
registryAddress.toString(),
|
|
80
84
|
uniswapL2Contract.address.toString()
|
|
81
85
|
], {});
|
|
82
86
|
// Give me some WETH so I can deposit to L2 and do the swap...
|
|
83
87
|
logger.info('Getting some weth');
|
|
84
|
-
const hash = await
|
|
88
|
+
const hash = await l1Client.sendTransaction({
|
|
85
89
|
to: WETH9_ADDRESS.toString(),
|
|
86
90
|
value: parseEther('1000')
|
|
87
91
|
});
|
|
88
|
-
await
|
|
92
|
+
await l1Client.waitForTransactionReceipt({
|
|
89
93
|
hash
|
|
90
94
|
});
|
|
91
95
|
const wethBalance = await wethCrossChainHarness.getL1BalanceOf(ownerEthAddress);
|
|
92
96
|
expect(wethBalance).toBe(parseEther('1000'));
|
|
93
97
|
});
|
|
94
|
-
// docs:end:uniswap_l1_l2_test_beforeAll
|
|
95
98
|
afterAll(async ()=>{
|
|
96
99
|
await cleanup();
|
|
97
100
|
});
|
|
@@ -114,14 +117,19 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
114
117
|
// 3. Owner gives uniswap approval to transfer the funds to public to self on its behalf
|
|
115
118
|
logger.info('Approving uniswap to transfer funds to public to self on my behalf');
|
|
116
119
|
const nonceForWETHTransferToPublicApproval = new Fr(1n);
|
|
117
|
-
await
|
|
120
|
+
const transferToPublicAuhtwit = await wallet.createAuthWit(ownerAddress, {
|
|
118
121
|
caller: uniswapL2Contract.address,
|
|
119
122
|
action: wethCrossChainHarness.l2Token.methods.transfer_to_public(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHTransferToPublicApproval)
|
|
120
123
|
});
|
|
121
124
|
// 4. Swap on L1 - sends L2 to L1 message to withdraw WETH to L1 and another message to swap assets.
|
|
122
125
|
logger.info('Withdrawing weth to L1 and sending message to swap to dai');
|
|
123
126
|
const [secretForDepositingSwappedDai, secretHashForDepositingSwappedDai] = await generateClaimSecret();
|
|
124
|
-
const l2UniswapInteractionReceipt = await uniswapL2Contract.methods.swap_private(wethCrossChainHarness.l2Token.address, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferToPublicApproval, uniswapFeeTier, minimumOutputAmount, secretHashForDepositingSwappedDai, ownerEthAddress).send(
|
|
127
|
+
const { receipt: l2UniswapInteractionReceipt } = await uniswapL2Contract.methods.swap_private(wethCrossChainHarness.l2Token.address, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferToPublicApproval, uniswapFeeTier, minimumOutputAmount, secretHashForDepositingSwappedDai, ownerEthAddress).send({
|
|
128
|
+
from: ownerAddress,
|
|
129
|
+
authWitnesses: [
|
|
130
|
+
transferToPublicAuhtwit
|
|
131
|
+
]
|
|
132
|
+
});
|
|
125
133
|
const swapPrivateFunction = 'swap_private(address,uint256,uint24,address,uint256,bytes32,address)';
|
|
126
134
|
const swapPrivateContent = sha256ToField([
|
|
127
135
|
Buffer.from(toFunctionSelector(swapPrivateFunction).substring(2), 'hex'),
|
|
@@ -133,44 +141,52 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
133
141
|
secretHashForDepositingSwappedDai,
|
|
134
142
|
ownerEthAddress.toBuffer32()
|
|
135
143
|
]);
|
|
136
|
-
const swapPrivateLeaf =
|
|
137
|
-
uniswapL2Contract.address,
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
new Fr(
|
|
141
|
-
|
|
142
|
-
|
|
144
|
+
const swapPrivateLeaf = computeL2ToL1MessageHash({
|
|
145
|
+
l2Sender: uniswapL2Contract.address,
|
|
146
|
+
l1Recipient: EthAddress.fromString(uniswapPortal.address),
|
|
147
|
+
content: swapPrivateContent,
|
|
148
|
+
rollupVersion: new Fr(version),
|
|
149
|
+
chainId: new Fr(l1Client.chain.id)
|
|
150
|
+
});
|
|
143
151
|
const withdrawContent = sha256ToField([
|
|
144
152
|
Buffer.from(toFunctionSelector('withdraw(address,uint256,address)').substring(2), 'hex'),
|
|
145
153
|
uniswapPortalAddress.toBuffer32(),
|
|
146
154
|
new Fr(wethAmountToBridge),
|
|
147
155
|
uniswapPortalAddress.toBuffer32()
|
|
148
156
|
]);
|
|
149
|
-
const withdrawLeaf =
|
|
150
|
-
wethCrossChainHarness.l2Bridge.address,
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
new Fr(
|
|
154
|
-
|
|
155
|
-
|
|
157
|
+
const withdrawLeaf = computeL2ToL1MessageHash({
|
|
158
|
+
l2Sender: wethCrossChainHarness.l2Bridge.address,
|
|
159
|
+
l1Recipient: wethCrossChainHarness.tokenPortalAddress,
|
|
160
|
+
content: withdrawContent,
|
|
161
|
+
rollupVersion: new Fr(version),
|
|
162
|
+
chainId: new Fr(l1Client.chain.id)
|
|
163
|
+
});
|
|
156
164
|
// ensure that user's funds were burnt
|
|
157
165
|
await wethCrossChainHarness.expectPrivateBalanceOnL2(ownerAddress, wethL2BalanceBeforeSwap - wethAmountToBridge);
|
|
158
166
|
// ensure that uniswap contract didn't eat the funds.
|
|
159
167
|
await wethCrossChainHarness.expectPublicBalanceOnL2(uniswapL2Contract.address, 0n);
|
|
160
|
-
// Since the outbox is only consumable when the
|
|
161
|
-
await
|
|
168
|
+
// Since the outbox is only consumable when the epoch is proven, we need to advance to the next epoch.
|
|
169
|
+
const swapResult = await computeL2ToL1MembershipWitness(aztecNode, swapPrivateLeaf, l2UniswapInteractionReceipt.txHash);
|
|
170
|
+
const { epochNumber: epoch } = swapResult;
|
|
171
|
+
await cheatCodes.rollup.advanceToEpoch(EpochNumber(epoch + 1));
|
|
172
|
+
await waitForProven(aztecNode, l2UniswapInteractionReceipt, {
|
|
173
|
+
provenTimeout: 300
|
|
174
|
+
});
|
|
162
175
|
// 5. Consume L2 to L1 message by calling uniswapPortal.swap_private()
|
|
163
176
|
logger.info('Execute withdraw and swap on the uniswapPortal!');
|
|
164
177
|
const daiL1BalanceOfPortalBeforeSwap = await daiCrossChainHarness.getL1BalanceOf(daiCrossChainHarness.tokenPortalAddress);
|
|
165
|
-
const
|
|
166
|
-
const
|
|
178
|
+
const withdrawResult = await computeL2ToL1MembershipWitness(aztecNode, withdrawLeaf, l2UniswapInteractionReceipt.txHash);
|
|
179
|
+
const swapPrivateL2MessageIndex = swapResult.leafIndex;
|
|
180
|
+
const swapPrivateSiblingPath = swapResult.siblingPath;
|
|
181
|
+
const withdrawL2MessageIndex = withdrawResult.leafIndex;
|
|
182
|
+
const withdrawSiblingPath = withdrawResult.siblingPath;
|
|
167
183
|
const withdrawMessageMetadata = {
|
|
168
|
-
|
|
184
|
+
_epoch: BigInt(epoch),
|
|
169
185
|
_leafIndex: BigInt(withdrawL2MessageIndex),
|
|
170
186
|
_path: withdrawSiblingPath.toBufferArray().map((buf)=>`0x${buf.toString('hex')}`)
|
|
171
187
|
};
|
|
172
188
|
const swapPrivateMessageMetadata = {
|
|
173
|
-
|
|
189
|
+
_epoch: BigInt(epoch),
|
|
174
190
|
_leafIndex: BigInt(swapPrivateL2MessageIndex),
|
|
175
191
|
_path: swapPrivateSiblingPath.toBufferArray().map((buf)=>`0x${buf.toString('hex')}`)
|
|
176
192
|
};
|
|
@@ -188,7 +204,7 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
188
204
|
]
|
|
189
205
|
];
|
|
190
206
|
// this should also insert a message into the inbox.
|
|
191
|
-
const txReceipt = await daiCrossChainHarness.
|
|
207
|
+
const txReceipt = await daiCrossChainHarness.l1Client.waitForTransactionReceipt({
|
|
192
208
|
hash: await uniswapPortal.write.swapPrivate(swapArgs)
|
|
193
209
|
});
|
|
194
210
|
// We get the msg leaf from event so that we can later wait for it to be available for consumption
|
|
@@ -297,9 +313,9 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
297
313
|
// ownerEthAddress,
|
|
298
314
|
// nonceForSwap,
|
|
299
315
|
// );
|
|
300
|
-
// await ownerWallet.setPublicAuthWit({ caller: sponsorAddress, action }, true).send()
|
|
316
|
+
// await ownerWallet.setPublicAuthWit({ caller: sponsorAddress, action }, true).send();
|
|
301
317
|
// // 4.2 Call swap_public from user2 on behalf of owner
|
|
302
|
-
// const uniswapL2Interaction = await action.send()
|
|
318
|
+
// const uniswapL2Interaction = await action.send();
|
|
303
319
|
// const swapPublicContent = sha256ToField([
|
|
304
320
|
// Buffer.from(
|
|
305
321
|
// toFunctionSelector('swap_public(address,uint256,uint24,address,uint256,bytes32,bytes32,address)').substring(
|
|
@@ -352,14 +368,14 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
352
368
|
// withdrawLeaf,
|
|
353
369
|
// );
|
|
354
370
|
// const withdrawMessageMetadata = {
|
|
355
|
-
//
|
|
371
|
+
// _epoch: epoch,
|
|
356
372
|
// _leafIndex: BigInt(withdrawL2MessageIndex),
|
|
357
373
|
// _path: withdrawSiblingPath
|
|
358
374
|
// .toBufferArray()
|
|
359
375
|
// .map((buf: Buffer) => `0x${buf.toString('hex')}`) as readonly `0x${string}`[],
|
|
360
376
|
// };
|
|
361
377
|
// const swapPrivateMessageMetadata = {
|
|
362
|
-
//
|
|
378
|
+
// _epoch: epoch,
|
|
363
379
|
// _leafIndex: BigInt(swapPrivateL2MessageIndex),
|
|
364
380
|
// _path: swapPrivateSiblingPath
|
|
365
381
|
// .toBufferArray()
|
|
@@ -432,12 +448,11 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
432
448
|
const nonceForWETHTransferToPublicApproval = new Fr(2n);
|
|
433
449
|
const expectedMessageHash = await computeAuthWitMessageHash({
|
|
434
450
|
caller: uniswapL2Contract.address,
|
|
435
|
-
|
|
436
|
-
},
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
});
|
|
440
|
-
await expect(uniswapL2Contract.methods.swap_private(wethCrossChainHarness.l2Token.address, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferToPublicApproval, uniswapFeeTier, minimumOutputAmount, Fr.random(), ownerEthAddress).prove()).rejects.toThrow(`Unknown auth witness for message hash ${expectedMessageHash.toString()}`);
|
|
451
|
+
call: await wethCrossChainHarness.l2Token.methods.transfer_to_public(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHTransferToPublicApproval).getFunctionCall()
|
|
452
|
+
}, await wallet.getChainInfo());
|
|
453
|
+
await expect(uniswapL2Contract.methods.swap_private(wethCrossChainHarness.l2Token.address, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferToPublicApproval, uniswapFeeTier, minimumOutputAmount, Fr.random(), ownerEthAddress).simulate({
|
|
454
|
+
from: ownerAddress
|
|
455
|
+
})).rejects.toThrow(`Unknown auth witness for message hash ${expectedMessageHash.toString()}`);
|
|
441
456
|
});
|
|
442
457
|
it("can't swap if user passes a token different to what the bridge tracks", async ()=>{
|
|
443
458
|
// 1. give user private funds on L2:
|
|
@@ -446,13 +461,18 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
446
461
|
// 2. owner gives uniswap approval to transfer the funds to public:
|
|
447
462
|
logger.info('Approving uniswap to transfer funds to public to self on my behalf');
|
|
448
463
|
const nonceForWETHTransferToPublicApproval = new Fr(3n);
|
|
449
|
-
await
|
|
464
|
+
const transferToPublicAuthwith = await wallet.createAuthWit(ownerAddress, {
|
|
450
465
|
caller: uniswapL2Contract.address,
|
|
451
466
|
action: wethCrossChainHarness.l2Token.methods.transfer_to_public(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHTransferToPublicApproval)
|
|
452
467
|
});
|
|
453
468
|
// 3. Swap but send the wrong token address
|
|
454
469
|
logger.info('Swap but send the wrong token address');
|
|
455
|
-
await expect(uniswapL2Contract.methods.swap_private(wethCrossChainHarness.l2Token.address, daiCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferToPublicApproval, uniswapFeeTier, minimumOutputAmount, Fr.random(), ownerEthAddress).
|
|
470
|
+
await expect(uniswapL2Contract.methods.swap_private(wethCrossChainHarness.l2Token.address, daiCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferToPublicApproval, uniswapFeeTier, minimumOutputAmount, Fr.random(), ownerEthAddress).send({
|
|
471
|
+
from: ownerAddress,
|
|
472
|
+
authWitnesses: [
|
|
473
|
+
transferToPublicAuthwith
|
|
474
|
+
]
|
|
475
|
+
})).rejects.toThrow('Assertion failed: input_asset address is not the same as seen in the bridge contract');
|
|
456
476
|
});
|
|
457
477
|
// edge cases for public flow:
|
|
458
478
|
it("I don't need approval to call swap_public if I'm swapping on my own behalf", async ()=>{
|
|
@@ -460,14 +480,16 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
460
480
|
await wethCrossChainHarness.mintTokensPublicOnL2(wethAmountToBridge);
|
|
461
481
|
// 2. Give approval to uniswap to transfer funds to itself
|
|
462
482
|
const nonceForWETHTransferApproval = new Fr(2n);
|
|
463
|
-
const validateActionInteraction = await
|
|
483
|
+
const validateActionInteraction = await wallet.setPublicAuthWit(ownerAddress, {
|
|
464
484
|
caller: uniswapL2Contract.address,
|
|
465
485
|
action: wethCrossChainHarness.l2Token.methods.transfer_in_public(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHTransferApproval)
|
|
466
486
|
}, true);
|
|
467
|
-
await validateActionInteraction.send()
|
|
487
|
+
await validateActionInteraction.send();
|
|
468
488
|
// No approval to call `swap` but should work even without it:
|
|
469
489
|
const [_, secretHashForDepositingSwappedDai] = await generateClaimSecret();
|
|
470
|
-
await uniswapL2Contract.methods.swap_public(ownerAddress, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferApproval, uniswapFeeTier, minimumOutputAmount, ownerAddress, secretHashForDepositingSwappedDai, ownerEthAddress, Fr.ZERO).send(
|
|
490
|
+
await uniswapL2Contract.methods.swap_public(ownerAddress, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferApproval, uniswapFeeTier, minimumOutputAmount, ownerAddress, secretHashForDepositingSwappedDai, ownerEthAddress, Fr.ZERO).send({
|
|
491
|
+
from: ownerAddress
|
|
492
|
+
});
|
|
471
493
|
// check weth balance of owner on L2 (we first bridged `wethAmountToBridge` into L2 and now withdrew it!)
|
|
472
494
|
await wethCrossChainHarness.expectPublicBalanceOnL2(ownerAddress, 0n);
|
|
473
495
|
});
|
|
@@ -477,23 +499,27 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
477
499
|
const nonceForWETHTransferApproval = new Fr(3n);
|
|
478
500
|
const nonceForSwap = new Fr(3n);
|
|
479
501
|
const secretHashForDepositingSwappedDai = new Fr(4n);
|
|
480
|
-
const action = uniswapL2Contract.
|
|
481
|
-
const validateActionInteraction = await
|
|
502
|
+
const action = uniswapL2Contract.methods.swap_public(ownerAddress, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferApproval, uniswapFeeTier, minimumOutputAmount, ownerAddress, secretHashForDepositingSwappedDai, ownerEthAddress, nonceForSwap);
|
|
503
|
+
const validateActionInteraction = await wallet.setPublicAuthWit(ownerAddress, {
|
|
482
504
|
caller: approvedUser,
|
|
483
505
|
action
|
|
484
506
|
}, true);
|
|
485
|
-
await validateActionInteraction.send()
|
|
486
|
-
await expect(action.simulate(
|
|
507
|
+
await validateActionInteraction.send();
|
|
508
|
+
await expect(action.simulate({
|
|
509
|
+
from: sponsorAddress
|
|
510
|
+
})).rejects.toThrow(/unauthorized/);
|
|
487
511
|
});
|
|
488
512
|
it("uniswap can't pull funds without transfer approval", async ()=>{
|
|
489
513
|
// swap should fail since no transfer approval to uniswap:
|
|
490
514
|
const nonceForWETHTransferApproval = new Fr(4n);
|
|
491
|
-
const validateActionInteraction = await
|
|
515
|
+
const validateActionInteraction = await wallet.setPublicAuthWit(ownerAddress, {
|
|
492
516
|
caller: uniswapL2Contract.address,
|
|
493
517
|
action: wethCrossChainHarness.l2Token.methods.transfer_in_public(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHTransferApproval)
|
|
494
518
|
}, true);
|
|
495
|
-
await validateActionInteraction.send()
|
|
496
|
-
await expect(uniswapL2Contract.methods.swap_public(ownerAddress, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, new Fr(420), uniswapFeeTier, minimumOutputAmount, ownerAddress, Fr.random(), ownerEthAddress, Fr.ZERO).simulate(
|
|
519
|
+
await validateActionInteraction.send();
|
|
520
|
+
await expect(uniswapL2Contract.methods.swap_public(ownerAddress, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, new Fr(420), uniswapFeeTier, minimumOutputAmount, ownerAddress, Fr.random(), ownerEthAddress, Fr.ZERO).simulate({
|
|
521
|
+
from: ownerAddress
|
|
522
|
+
})).rejects.toThrow(/unauthorized/);
|
|
497
523
|
});
|
|
498
524
|
// tests when trying to mix private and public flows:
|
|
499
525
|
it("can't call swap_public on L1 if called swap_private on L2", async ()=>{
|
|
@@ -503,7 +529,7 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
503
529
|
// Owner gives uniswap approval to transfer the funds to public to self on its behalf
|
|
504
530
|
logger.info('Approving uniswap to transfer the funds to public to self on my behalf');
|
|
505
531
|
const nonceForWETHTransferToPublicApproval = new Fr(4n);
|
|
506
|
-
await
|
|
532
|
+
const transferToPublicAuhtwit = await wallet.createAuthWit(ownerAddress, {
|
|
507
533
|
caller: uniswapL2Contract.address,
|
|
508
534
|
action: wethCrossChainHarness.l2Token.methods.transfer_to_public(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHTransferToPublicApproval)
|
|
509
535
|
});
|
|
@@ -511,7 +537,12 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
511
537
|
// Swap
|
|
512
538
|
logger.info('Withdrawing weth to L1 and sending message to swap to dai');
|
|
513
539
|
const [, secretHashForDepositingSwappedDai] = await generateClaimSecret();
|
|
514
|
-
const withdrawReceipt = await uniswapL2Contract.methods.swap_private(wethCrossChainHarness.l2Token.address, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferToPublicApproval, uniswapFeeTier, minimumOutputAmount, secretHashForDepositingSwappedDai, ownerEthAddress).send(
|
|
540
|
+
const { receipt: withdrawReceipt } = await uniswapL2Contract.methods.swap_private(wethCrossChainHarness.l2Token.address, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferToPublicApproval, uniswapFeeTier, minimumOutputAmount, secretHashForDepositingSwappedDai, ownerEthAddress).send({
|
|
541
|
+
from: ownerAddress,
|
|
542
|
+
authWitnesses: [
|
|
543
|
+
transferToPublicAuhtwit
|
|
544
|
+
]
|
|
545
|
+
});
|
|
515
546
|
const swapPrivateContent = sha256ToField([
|
|
516
547
|
Buffer.from(toFunctionSelector('swap_private(address,uint256,uint24,address,uint256,bytes32,address)').substring(2), 'hex'),
|
|
517
548
|
wethCrossChainHarness.tokenPortalAddress.toBuffer32(),
|
|
@@ -522,42 +553,50 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
522
553
|
secretHashForDepositingSwappedDai,
|
|
523
554
|
ownerEthAddress.toBuffer32()
|
|
524
555
|
]);
|
|
525
|
-
const swapPrivateLeaf =
|
|
526
|
-
uniswapL2Contract.address,
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
new Fr(
|
|
530
|
-
|
|
531
|
-
|
|
556
|
+
const swapPrivateLeaf = computeL2ToL1MessageHash({
|
|
557
|
+
l2Sender: uniswapL2Contract.address,
|
|
558
|
+
l1Recipient: EthAddress.fromString(uniswapPortal.address),
|
|
559
|
+
content: swapPrivateContent,
|
|
560
|
+
rollupVersion: new Fr(version),
|
|
561
|
+
chainId: new Fr(l1Client.chain.id)
|
|
562
|
+
});
|
|
532
563
|
const withdrawContent = sha256ToField([
|
|
533
564
|
Buffer.from(toFunctionSelector('withdraw(address,uint256,address)').substring(2), 'hex'),
|
|
534
565
|
uniswapPortalAddress.toBuffer32(),
|
|
535
566
|
new Fr(wethAmountToBridge),
|
|
536
567
|
uniswapPortalAddress.toBuffer32()
|
|
537
568
|
]);
|
|
538
|
-
const withdrawLeaf =
|
|
539
|
-
wethCrossChainHarness.l2Bridge.address,
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
new Fr(
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
const
|
|
546
|
-
const
|
|
569
|
+
const withdrawLeaf = computeL2ToL1MessageHash({
|
|
570
|
+
l2Sender: wethCrossChainHarness.l2Bridge.address,
|
|
571
|
+
l1Recipient: wethCrossChainHarness.tokenPortalAddress,
|
|
572
|
+
content: withdrawContent,
|
|
573
|
+
rollupVersion: new Fr(version),
|
|
574
|
+
chainId: new Fr(l1Client.chain.id)
|
|
575
|
+
});
|
|
576
|
+
const swapResult = await computeL2ToL1MembershipWitness(aztecNode, swapPrivateLeaf, withdrawReceipt.txHash);
|
|
577
|
+
const { epochNumber: epoch } = swapResult;
|
|
578
|
+
const withdrawResult = await computeL2ToL1MembershipWitness(aztecNode, withdrawLeaf, withdrawReceipt.txHash);
|
|
579
|
+
const swapPrivateL2MessageIndex = swapResult.leafIndex;
|
|
580
|
+
const swapPrivateSiblingPath = swapResult.siblingPath;
|
|
581
|
+
const withdrawL2MessageIndex = withdrawResult.leafIndex;
|
|
582
|
+
const withdrawSiblingPath = withdrawResult.siblingPath;
|
|
547
583
|
const withdrawMessageMetadata = {
|
|
548
|
-
|
|
584
|
+
_epoch: BigInt(epoch),
|
|
549
585
|
_leafIndex: BigInt(withdrawL2MessageIndex),
|
|
550
586
|
_path: withdrawSiblingPath.toBufferArray().map((buf)=>`0x${buf.toString('hex')}`)
|
|
551
587
|
};
|
|
552
588
|
const swapPrivateMessageMetadata = {
|
|
553
|
-
|
|
589
|
+
_epoch: BigInt(epoch),
|
|
554
590
|
_leafIndex: BigInt(swapPrivateL2MessageIndex),
|
|
555
591
|
_path: swapPrivateSiblingPath.toBufferArray().map((buf)=>`0x${buf.toString('hex')}`)
|
|
556
592
|
};
|
|
557
593
|
// ensure that user's funds were burnt
|
|
558
594
|
await wethCrossChainHarness.expectPrivateBalanceOnL2(ownerAddress, wethL2BalanceBeforeSwap - wethAmountToBridge);
|
|
559
|
-
// Since the outbox is only consumable when the
|
|
560
|
-
await cheatCodes.rollup.
|
|
595
|
+
// Since the outbox is only consumable when the epoch is proven, we need to advance to the next epoch.
|
|
596
|
+
await cheatCodes.rollup.advanceToEpoch(EpochNumber(epoch + 1));
|
|
597
|
+
await waitForProven(aztecNode, withdrawReceipt, {
|
|
598
|
+
provenTimeout: 300
|
|
599
|
+
});
|
|
561
600
|
// On L1 call swap_public!
|
|
562
601
|
logger.info('call swap_public on L1');
|
|
563
602
|
const swapArgs = [
|
|
@@ -583,14 +622,16 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
583
622
|
await wethCrossChainHarness.mintTokensPublicOnL2(wethAmountToBridge);
|
|
584
623
|
// Owner gives uniswap approval to transfer funds on its behalf
|
|
585
624
|
const nonceForWETHTransferApproval = new Fr(5n);
|
|
586
|
-
const validateActionInteraction = await
|
|
625
|
+
const validateActionInteraction = await wallet.setPublicAuthWit(ownerAddress, {
|
|
587
626
|
caller: uniswapL2Contract.address,
|
|
588
627
|
action: wethCrossChainHarness.l2Token.methods.transfer_in_public(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHTransferApproval)
|
|
589
628
|
}, true);
|
|
590
|
-
await validateActionInteraction.send()
|
|
629
|
+
await validateActionInteraction.send();
|
|
591
630
|
// Call swap_public on L2
|
|
592
631
|
const secretHashForDepositingSwappedDai = Fr.random();
|
|
593
|
-
const withdrawReceipt = await uniswapL2Contract.methods.swap_public(ownerAddress, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferApproval, uniswapFeeTier, minimumOutputAmount, ownerAddress, secretHashForDepositingSwappedDai, ownerEthAddress, Fr.ZERO).send(
|
|
632
|
+
const { receipt: withdrawReceipt } = await uniswapL2Contract.methods.swap_public(ownerAddress, wethCrossChainHarness.l2Bridge.address, wethAmountToBridge, daiCrossChainHarness.l2Bridge.address, nonceForWETHTransferApproval, uniswapFeeTier, minimumOutputAmount, ownerAddress, secretHashForDepositingSwappedDai, ownerEthAddress, Fr.ZERO).send({
|
|
633
|
+
from: ownerAddress
|
|
634
|
+
});
|
|
594
635
|
const swapPublicContent = sha256ToField([
|
|
595
636
|
Buffer.from(toFunctionSelector('swap_public(address,uint256,uint24,address,uint256,bytes32,bytes32,address)').substring(2), 'hex'),
|
|
596
637
|
wethCrossChainHarness.tokenPortalAddress.toBuffer32(),
|
|
@@ -602,42 +643,50 @@ export const uniswapL1L2TestSuite = (setup, cleanup, expectedForkBlockNumber = 1
|
|
|
602
643
|
secretHashForDepositingSwappedDai,
|
|
603
644
|
ownerEthAddress.toBuffer32()
|
|
604
645
|
]);
|
|
605
|
-
const swapPublicLeaf =
|
|
606
|
-
uniswapL2Contract.address,
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
new Fr(
|
|
610
|
-
|
|
611
|
-
|
|
646
|
+
const swapPublicLeaf = computeL2ToL1MessageHash({
|
|
647
|
+
l2Sender: uniswapL2Contract.address,
|
|
648
|
+
l1Recipient: EthAddress.fromString(uniswapPortal.address),
|
|
649
|
+
content: swapPublicContent,
|
|
650
|
+
rollupVersion: new Fr(version),
|
|
651
|
+
chainId: new Fr(l1Client.chain.id)
|
|
652
|
+
});
|
|
612
653
|
const withdrawContent = sha256ToField([
|
|
613
654
|
Buffer.from(toFunctionSelector('withdraw(address,uint256,address)').substring(2), 'hex'),
|
|
614
655
|
uniswapPortalAddress.toBuffer32(),
|
|
615
656
|
new Fr(wethAmountToBridge),
|
|
616
657
|
uniswapPortalAddress.toBuffer32()
|
|
617
658
|
]);
|
|
618
|
-
const withdrawLeaf =
|
|
619
|
-
wethCrossChainHarness.l2Bridge.address,
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
new Fr(
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
const
|
|
626
|
-
const
|
|
659
|
+
const withdrawLeaf = computeL2ToL1MessageHash({
|
|
660
|
+
l2Sender: wethCrossChainHarness.l2Bridge.address,
|
|
661
|
+
l1Recipient: wethCrossChainHarness.tokenPortalAddress,
|
|
662
|
+
content: withdrawContent,
|
|
663
|
+
rollupVersion: new Fr(version),
|
|
664
|
+
chainId: new Fr(l1Client.chain.id)
|
|
665
|
+
});
|
|
666
|
+
const swapResult = await computeL2ToL1MembershipWitness(aztecNode, swapPublicLeaf, withdrawReceipt.txHash);
|
|
667
|
+
const { epochNumber: epoch } = swapResult;
|
|
668
|
+
const withdrawResult = await computeL2ToL1MembershipWitness(aztecNode, withdrawLeaf, withdrawReceipt.txHash);
|
|
669
|
+
const swapPublicL2MessageIndex = swapResult.leafIndex;
|
|
670
|
+
const swapPublicSiblingPath = swapResult.siblingPath;
|
|
671
|
+
const withdrawL2MessageIndex = withdrawResult.leafIndex;
|
|
672
|
+
const withdrawSiblingPath = withdrawResult.siblingPath;
|
|
627
673
|
const withdrawMessageMetadata = {
|
|
628
|
-
|
|
674
|
+
_epoch: BigInt(epoch),
|
|
629
675
|
_leafIndex: BigInt(withdrawL2MessageIndex),
|
|
630
676
|
_path: withdrawSiblingPath.toBufferArray().map((buf)=>`0x${buf.toString('hex')}`)
|
|
631
677
|
};
|
|
632
678
|
const swapPublicMessageMetadata = {
|
|
633
|
-
|
|
679
|
+
_epoch: BigInt(epoch),
|
|
634
680
|
_leafIndex: BigInt(swapPublicL2MessageIndex),
|
|
635
681
|
_path: swapPublicSiblingPath.toBufferArray().map((buf)=>`0x${buf.toString('hex')}`)
|
|
636
682
|
};
|
|
637
683
|
// check weth balance of owner on L2 (we first bridged `wethAmountToBridge` into L2 and now withdrew it!)
|
|
638
684
|
await wethCrossChainHarness.expectPublicBalanceOnL2(ownerAddress, 0n);
|
|
639
|
-
// Since the outbox is only consumable when the
|
|
640
|
-
await cheatCodes.rollup.
|
|
685
|
+
// Since the outbox is only consumable when the epoch is proven, we need to advance to the next epoch.
|
|
686
|
+
await cheatCodes.rollup.advanceToEpoch(EpochNumber(epoch + 1));
|
|
687
|
+
await waitForProven(aztecNode, withdrawReceipt, {
|
|
688
|
+
provenTimeout: 300
|
|
689
|
+
});
|
|
641
690
|
// Call swap_private on L1
|
|
642
691
|
logger.info('Execute withdraw and swap on the uniswapPortal!');
|
|
643
692
|
const swapArgs = [
|