@aztec/end-to-end 0.0.1-commit.03f7ef2 → 0.0.1-commit.04d373f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -0
- package/dest/bench/client_flows/benchmark.d.ts +17 -2
- package/dest/bench/client_flows/benchmark.d.ts.map +1 -1
- package/dest/bench/client_flows/benchmark.js +38 -1
- package/dest/bench/client_flows/client_flows_benchmark.d.ts +14 -15
- package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -1
- package/dest/bench/client_flows/client_flows_benchmark.js +132 -150
- package/dest/bench/client_flows/config.d.ts +2 -2
- package/dest/bench/client_flows/config.d.ts.map +1 -1
- package/dest/bench/client_flows/config.js +18 -0
- package/dest/bench/client_flows/data_extractor.js +3 -1
- package/dest/bench/utils.d.ts +9 -8
- package/dest/bench/utils.d.ts.map +1 -1
- package/dest/bench/utils.js +33 -19
- package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +12 -10
- 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 +120 -117
- package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +30 -14
- 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 +122 -70
- package/dest/e2e_deploy_contract/deploy_test.d.ts +6 -5
- package/dest/e2e_deploy_contract/deploy_test.d.ts.map +1 -1
- package/dest/e2e_deploy_contract/deploy_test.js +20 -14
- package/dest/e2e_epochs/epochs_test.d.ts +39 -8
- package/dest/e2e_epochs/epochs_test.d.ts.map +1 -1
- package/dest/e2e_epochs/epochs_test.js +172 -51
- package/dest/e2e_fees/bridging_race.notest.js +3 -5
- package/dest/e2e_fees/fees_test.d.ts +18 -15
- package/dest/e2e_fees/fees_test.d.ts.map +1 -1
- package/dest/e2e_fees/fees_test.js +158 -143
- package/dest/e2e_l1_publisher/write_json.d.ts +4 -3
- package/dest/e2e_l1_publisher/write_json.d.ts.map +1 -1
- package/dest/e2e_l1_publisher/write_json.js +14 -16
- package/dest/e2e_nested_contract/nested_contract_test.d.ts +7 -10
- package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +1 -1
- package/dest/e2e_nested_contract/nested_contract_test.js +32 -41
- package/dest/e2e_p2p/inactivity_slash_test.d.ts +3 -3
- package/dest/e2e_p2p/inactivity_slash_test.d.ts.map +1 -1
- package/dest/e2e_p2p/inactivity_slash_test.js +8 -6
- package/dest/e2e_p2p/p2p_network.d.ts +20 -17
- package/dest/e2e_p2p/p2p_network.d.ts.map +1 -1
- package/dest/e2e_p2p/p2p_network.js +167 -124
- package/dest/e2e_p2p/reqresp/utils.d.ts +22 -0
- package/dest/e2e_p2p/reqresp/utils.d.ts.map +1 -0
- package/dest/e2e_p2p/reqresp/utils.js +206 -0
- package/dest/e2e_p2p/shared.d.ts +30 -12
- package/dest/e2e_p2p/shared.d.ts.map +1 -1
- package/dest/e2e_p2p/shared.js +88 -68
- 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 +20 -11
- package/dest/e2e_token_contract/token_contract_test.d.ts.map +1 -1
- package/dest/e2e_token_contract/token_contract_test.js +103 -93
- package/dest/fixtures/authwit_proxy.d.ts +15 -0
- package/dest/fixtures/authwit_proxy.d.ts.map +1 -0
- package/dest/fixtures/authwit_proxy.js +34 -0
- package/dest/fixtures/e2e_prover_test.d.ts +15 -20
- package/dest/fixtures/e2e_prover_test.d.ts.map +1 -1
- package/dest/fixtures/e2e_prover_test.js +115 -135
- 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 +78 -2
- package/dest/fixtures/fixtures.d.ts.map +1 -1
- package/dest/fixtures/fixtures.js +75 -1
- package/dest/fixtures/get_bb_config.d.ts +1 -1
- package/dest/fixtures/get_bb_config.d.ts.map +1 -1
- package/dest/fixtures/get_bb_config.js +5 -5
- 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/schnorr_hardcoded_account_contract.d.ts +25 -0
- package/dest/fixtures/schnorr_hardcoded_account_contract.d.ts.map +1 -0
- package/dest/fixtures/schnorr_hardcoded_account_contract.js +37 -0
- package/dest/fixtures/setup.d.ts +266 -0
- package/dest/fixtures/setup.d.ts.map +1 -0
- package/dest/fixtures/setup.js +714 -0
- package/dest/fixtures/setup_p2p_test.d.ts +22 -11
- package/dest/fixtures/setup_p2p_test.d.ts.map +1 -1
- package/dest/fixtures/setup_p2p_test.js +43 -32
- package/dest/fixtures/token_utils.d.ts +2 -2
- package/dest/fixtures/token_utils.d.ts.map +1 -1
- package/dest/fixtures/token_utils.js +7 -6
- package/dest/fixtures/utils.d.ts +5 -194
- package/dest/fixtures/utils.d.ts.map +1 -1
- package/dest/fixtures/utils.js +4 -619
- package/dest/forward-compatibility/wallet_rpc_client.d.ts +7 -0
- package/dest/forward-compatibility/wallet_rpc_client.d.ts.map +1 -0
- package/dest/forward-compatibility/wallet_rpc_client.js +15 -0
- package/dest/forward-compatibility/wallet_service.d.ts +3 -0
- package/dest/forward-compatibility/wallet_service.d.ts.map +1 -0
- package/dest/forward-compatibility/wallet_service.js +109 -0
- package/dest/install_legacy_contracts.d.cts +10 -0
- package/dest/install_legacy_contracts.d.cts.map +1 -0
- package/dest/legacy-jest-resolver.d.cts +3 -0
- package/dest/legacy-jest-resolver.d.cts.map +1 -0
- package/dest/quality_of_service/grafana_client.d.ts +41 -0
- package/dest/quality_of_service/grafana_client.d.ts.map +1 -0
- package/dest/quality_of_service/{alert_checker.js → grafana_client.js} +1 -1
- package/dest/quality_of_service/prometheus_client.d.ts +38 -0
- package/dest/quality_of_service/prometheus_client.d.ts.map +1 -0
- package/dest/quality_of_service/prometheus_client.js +67 -0
- package/dest/shared/cross_chain_test_harness.d.ts +18 -6
- package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
- package/dest/shared/cross_chain_test_harness.js +33 -29
- package/dest/shared/gas_portal_test_harness.d.ts +18 -5
- package/dest/shared/gas_portal_test_harness.d.ts.map +1 -1
- package/dest/shared/gas_portal_test_harness.js +20 -11
- 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.js +41 -1
- 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 +4 -4
- package/dest/shared/submit-transactions.d.ts.map +1 -1
- package/dest/shared/submit-transactions.js +9 -11
- package/dest/shared/uniswap_l1_l2.d.ts +3 -28
- package/dest/shared/uniswap_l1_l2.d.ts.map +1 -1
- package/dest/shared/uniswap_l1_l2.js +88 -47
- package/dest/shared/wait_for_l1_to_l2_message.d.ts +13 -0
- package/dest/shared/wait_for_l1_to_l2_message.d.ts.map +1 -0
- package/dest/shared/wait_for_l1_to_l2_message.js +10 -0
- package/dest/simulators/lending_simulator.d.ts +14 -3
- package/dest/simulators/lending_simulator.d.ts.map +1 -1
- package/dest/simulators/lending_simulator.js +28 -16
- package/dest/simulators/token_simulator.d.ts +1 -1
- package/dest/simulators/token_simulator.d.ts.map +1 -1
- package/dest/simulators/token_simulator.js +3 -24
- package/dest/spartan/setup_test_wallets.d.ts +15 -5
- package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
- package/dest/spartan/setup_test_wallets.js +133 -43
- package/dest/spartan/tx_metrics.d.ts +68 -5
- package/dest/spartan/tx_metrics.d.ts.map +1 -1
- package/dest/spartan/tx_metrics.js +399 -19
- package/dest/spartan/utils/bot.d.ts +28 -0
- package/dest/spartan/utils/bot.d.ts.map +1 -0
- package/dest/spartan/utils/bot.js +142 -0
- package/dest/spartan/utils/chaos.d.ts +79 -0
- package/dest/spartan/utils/chaos.d.ts.map +1 -0
- package/dest/spartan/utils/chaos.js +142 -0
- package/dest/spartan/utils/clients.d.ts +39 -0
- package/dest/spartan/utils/clients.d.ts.map +1 -0
- package/dest/spartan/utils/clients.js +90 -0
- package/dest/spartan/utils/config.d.ts +19 -0
- package/dest/spartan/utils/config.d.ts.map +1 -0
- package/dest/spartan/utils/config.js +23 -0
- package/dest/spartan/utils/health.d.ts +63 -0
- package/dest/spartan/utils/health.d.ts.map +1 -0
- package/dest/spartan/utils/health.js +202 -0
- package/dest/spartan/utils/helm.d.ts +15 -0
- package/dest/spartan/utils/helm.d.ts.map +1 -0
- package/dest/spartan/utils/helm.js +47 -0
- package/dest/spartan/utils/index.d.ts +11 -0
- package/dest/spartan/utils/index.d.ts.map +1 -0
- package/dest/spartan/utils/index.js +22 -0
- package/dest/spartan/utils/k8s.d.ts +128 -0
- package/dest/spartan/utils/k8s.d.ts.map +1 -0
- package/dest/spartan/utils/k8s.js +381 -0
- package/dest/spartan/utils/nodes.d.ts +40 -0
- package/dest/spartan/utils/nodes.d.ts.map +1 -0
- package/dest/spartan/utils/nodes.js +461 -0
- package/dest/spartan/utils/pod_logs.d.ts +25 -0
- package/dest/spartan/utils/pod_logs.d.ts.map +1 -0
- package/dest/spartan/utils/pod_logs.js +74 -0
- package/dest/spartan/utils/scripts.d.ts +30 -0
- package/dest/spartan/utils/scripts.d.ts.map +1 -0
- package/dest/spartan/utils/scripts.js +81 -0
- package/dest/spartan/utils.d.ts +2 -231
- package/dest/spartan/utils.d.ts.map +1 -1
- package/dest/spartan/utils.js +1 -853
- package/dest/test-wallet/test_wallet.d.ts +85 -0
- package/dest/test-wallet/test_wallet.d.ts.map +1 -0
- package/dest/test-wallet/test_wallet.js +273 -0
- package/dest/test-wallet/utils.d.ts +41 -0
- package/dest/test-wallet/utils.d.ts.map +1 -0
- package/dest/test-wallet/utils.js +66 -0
- package/dest/test-wallet/wallet_worker_script.d.ts +2 -0
- package/dest/test-wallet/wallet_worker_script.d.ts.map +1 -0
- package/dest/test-wallet/wallet_worker_script.js +48 -0
- package/dest/test-wallet/worker_wallet.d.ts +53 -0
- package/dest/test-wallet/worker_wallet.d.ts.map +1 -0
- package/dest/test-wallet/worker_wallet.js +155 -0
- package/dest/test-wallet/worker_wallet_schema.d.ts +160 -0
- package/dest/test-wallet/worker_wallet_schema.d.ts.map +1 -0
- package/dest/test-wallet/worker_wallet_schema.js +22 -0
- package/package.json +53 -45
- package/src/bench/client_flows/benchmark.ts +43 -2
- package/src/bench/client_flows/client_flows_benchmark.ts +189 -240
- package/src/bench/client_flows/config.ts +9 -1
- package/src/bench/client_flows/data_extractor.ts +1 -1
- package/src/bench/utils.ts +38 -22
- package/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +141 -152
- package/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +166 -118
- package/src/e2e_deploy_contract/deploy_test.ts +24 -16
- package/src/e2e_epochs/epochs_test.ts +218 -94
- package/src/e2e_fees/bridging_race.notest.ts +4 -10
- package/src/e2e_fees/fees_test.ts +207 -230
- package/src/e2e_l1_publisher/write_json.ts +16 -16
- package/src/e2e_nested_contract/nested_contract_test.ts +38 -57
- package/src/e2e_p2p/inactivity_slash_test.ts +8 -6
- package/src/e2e_p2p/p2p_network.ts +239 -191
- package/src/e2e_p2p/reqresp/utils.ts +274 -0
- package/src/e2e_p2p/shared.ts +115 -86
- 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 +129 -117
- package/src/fixtures/authwit_proxy.ts +54 -0
- package/src/fixtures/dumps/epoch_proof_result.json +1 -1
- package/src/fixtures/e2e_prover_test.ts +143 -185
- package/src/fixtures/elu_monitor.ts +126 -0
- package/src/fixtures/fixtures.ts +97 -1
- package/src/fixtures/get_bb_config.ts +7 -6
- package/src/fixtures/ha_setup.ts +188 -0
- package/src/fixtures/index.ts +1 -0
- package/src/fixtures/schnorr_hardcoded_account_contract.ts +49 -0
- package/src/fixtures/setup.ts +1037 -0
- package/src/fixtures/setup_p2p_test.ts +52 -52
- package/src/fixtures/token_utils.ts +7 -6
- package/src/fixtures/utils.ts +29 -907
- package/src/forward-compatibility/wallet_rpc_client.ts +14 -0
- package/src/forward-compatibility/wallet_service.ts +104 -0
- package/src/guides/up_quick_start.sh +3 -5
- package/src/install_legacy_contracts.cjs +75 -0
- package/src/legacy-jest-resolver.cjs +112 -0
- package/src/quality_of_service/{alert_checker.ts → grafana_client.ts} +1 -1
- package/src/quality_of_service/prometheus_client.ts +113 -0
- package/src/shared/cross_chain_test_harness.ts +34 -40
- package/src/shared/gas_portal_test_harness.ts +22 -12
- package/src/shared/index.ts +2 -1
- package/src/shared/jest_setup.ts +51 -1
- package/src/shared/mock_state_view.ts +188 -0
- package/src/shared/submit-transactions.ts +11 -16
- package/src/shared/uniswap_l1_l2.ts +114 -108
- package/src/shared/wait_for_l1_to_l2_message.ts +23 -0
- package/src/simulators/lending_simulator.ts +34 -16
- package/src/simulators/token_simulator.ts +6 -30
- package/src/spartan/setup_test_wallets.ts +191 -29
- package/src/spartan/tx_metrics.ts +329 -25
- 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 -1077
- package/src/test-wallet/test_wallet.ts +376 -0
- package/src/test-wallet/utils.ts +108 -0
- package/src/test-wallet/wallet_worker_script.ts +60 -0
- package/src/test-wallet/worker_wallet.ts +218 -0
- package/src/test-wallet/worker_wallet_schema.ts +13 -0
- package/dest/fixtures/snapshot_manager.d.ts +0 -93
- package/dest/fixtures/snapshot_manager.d.ts.map +0 -1
- package/dest/fixtures/snapshot_manager.js +0 -493
- package/dest/quality_of_service/alert_checker.d.ts +0 -41
- package/dest/quality_of_service/alert_checker.d.ts.map +0 -1
- package/src/fixtures/snapshot_manager.ts +0 -651
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AztecAddress, EthAddress } from '@aztec/aztec.js/addresses';
|
|
2
2
|
import { computeAuthWitMessageHash } from '@aztec/aztec.js/authorization';
|
|
3
|
+
import { waitForProven } from '@aztec/aztec.js/contracts';
|
|
3
4
|
import { generateClaimSecret } from '@aztec/aztec.js/ethereum';
|
|
4
5
|
import { Fr } from '@aztec/aztec.js/fields';
|
|
5
6
|
import type { Logger } from '@aztec/aztec.js/log';
|
|
@@ -10,17 +11,22 @@ import type { DeployAztecL1ContractsReturnType } from '@aztec/ethereum/deploy-az
|
|
|
10
11
|
import { deployL1Contract } from '@aztec/ethereum/deploy-l1-contract';
|
|
11
12
|
import type { ExtendedViemWalletClient } from '@aztec/ethereum/types';
|
|
12
13
|
import { extractEvent } from '@aztec/ethereum/utils';
|
|
14
|
+
import { EpochNumber } from '@aztec/foundation/branded-types';
|
|
13
15
|
import { sha256ToField } from '@aztec/foundation/crypto/sha256';
|
|
14
16
|
import { InboxAbi, UniswapPortalAbi, UniswapPortalBytecode } from '@aztec/l1-artifacts';
|
|
15
17
|
import { UniswapContract } from '@aztec/noir-contracts.js/Uniswap';
|
|
16
18
|
import { computeL2ToL1MessageHash } from '@aztec/stdlib/hash';
|
|
17
19
|
import { computeL2ToL1MembershipWitness } from '@aztec/stdlib/messaging';
|
|
18
|
-
import type { TestWallet } from '@aztec/test-wallet/server';
|
|
19
20
|
|
|
20
21
|
import { jest } from '@jest/globals';
|
|
21
22
|
import { type GetContractReturnType, getContract, parseEther, toFunctionSelector } from 'viem';
|
|
22
23
|
|
|
23
|
-
import {
|
|
24
|
+
import {
|
|
25
|
+
type EndToEndContext,
|
|
26
|
+
ensureAccountContractsPublished,
|
|
27
|
+
ensureAuthRegistryPublished,
|
|
28
|
+
} from '../fixtures/utils.js';
|
|
29
|
+
import type { TestWallet } from '../test-wallet/test_wallet.js';
|
|
24
30
|
import { CrossChainTestHarness } from './cross_chain_test_harness.js';
|
|
25
31
|
|
|
26
32
|
// PSA: This tests works on forked mainnet. There is a dump of the data in `dumpedState` such that we
|
|
@@ -30,30 +36,10 @@ import { CrossChainTestHarness } from './cross_chain_test_harness.js';
|
|
|
30
36
|
// anvil --fork-url https://mainnet.infura.io/v3/9928b52099854248b3a096be07a6b23c --fork-block-number 17514288 --chain-id 31337
|
|
31
37
|
// For CI, this is configured in `run_tests.sh` and `docker-compose-images.yml`
|
|
32
38
|
|
|
33
|
-
const TIMEOUT =
|
|
34
|
-
|
|
35
|
-
/** Objects to be returned by the uniswap setup function */
|
|
36
|
-
export type UniswapSetupContext = {
|
|
37
|
-
/** Aztec Node instance */
|
|
38
|
-
aztecNode: AztecNode;
|
|
39
|
-
/** Logger instance named as the current test. */
|
|
40
|
-
logger: Logger;
|
|
41
|
-
/** The L1 wallet client, extended with public actions. */
|
|
42
|
-
l1Client: ExtendedViemWalletClient;
|
|
43
|
-
/** The wallet. */
|
|
44
|
-
wallet: TestWallet;
|
|
45
|
-
/** The owner address. */
|
|
46
|
-
ownerAddress: AztecAddress;
|
|
47
|
-
/** The sponsor wallet. */
|
|
48
|
-
sponsorAddress: AztecAddress;
|
|
49
|
-
/** */
|
|
50
|
-
deployL1ContractsValues: DeployAztecL1ContractsReturnType;
|
|
51
|
-
/** Cheat codes instance. */
|
|
52
|
-
cheatCodes: CheatCodes;
|
|
53
|
-
};
|
|
39
|
+
const TIMEOUT = 15 * 60 * 1000;
|
|
54
40
|
|
|
55
41
|
export const uniswapL1L2TestSuite = (
|
|
56
|
-
setup: () => Promise<
|
|
42
|
+
setup: () => Promise<EndToEndContext>,
|
|
57
43
|
cleanup: () => Promise<void>,
|
|
58
44
|
expectedForkBlockNumber = 17514288,
|
|
59
45
|
) => {
|
|
@@ -90,8 +76,19 @@ export const uniswapL1L2TestSuite = (
|
|
|
90
76
|
let cheatCodes: CheatCodes;
|
|
91
77
|
let version: number;
|
|
92
78
|
beforeAll(async () => {
|
|
93
|
-
|
|
94
|
-
|
|
79
|
+
const t = await setup();
|
|
80
|
+
({
|
|
81
|
+
aztecNode,
|
|
82
|
+
logger,
|
|
83
|
+
deployL1ContractsValues,
|
|
84
|
+
cheatCodes,
|
|
85
|
+
wallet,
|
|
86
|
+
accounts: [ownerAddress, sponsorAddress],
|
|
87
|
+
} = t);
|
|
88
|
+
|
|
89
|
+
l1Client = deployL1ContractsValues.l1Client;
|
|
90
|
+
|
|
91
|
+
t.watcher.setIsMarkingAsProven(false);
|
|
95
92
|
|
|
96
93
|
if (Number(await l1Client.getBlockNumber()) < expectedForkBlockNumber) {
|
|
97
94
|
throw new Error('This test must be run on a fork of mainnet with the expected fork block');
|
|
@@ -105,6 +102,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
105
102
|
ownerEthAddress = EthAddress.fromString((await l1Client.getAddresses())[0]);
|
|
106
103
|
|
|
107
104
|
await ensureAccountContractsPublished(wallet, [ownerAddress, sponsorAddress]);
|
|
105
|
+
await ensureAuthRegistryPublished(wallet, ownerAddress);
|
|
108
106
|
|
|
109
107
|
logger.info('Deploying DAI Portal, initializing and deploying l2 contract...');
|
|
110
108
|
daiCrossChainHarness = await CrossChainTestHarness.new(
|
|
@@ -137,9 +135,9 @@ export const uniswapL1L2TestSuite = (
|
|
|
137
135
|
client: l1Client,
|
|
138
136
|
});
|
|
139
137
|
// deploy l2 uniswap contract and attach to portal
|
|
140
|
-
uniswapL2Contract = await UniswapContract.deploy(wallet, uniswapPortalAddress)
|
|
141
|
-
|
|
142
|
-
|
|
138
|
+
({ contract: uniswapL2Contract } = await UniswapContract.deploy(wallet, uniswapPortalAddress).send({
|
|
139
|
+
from: ownerAddress,
|
|
140
|
+
}));
|
|
143
141
|
|
|
144
142
|
const registryAddress = (await aztecNode.getNodeInfo()).l1ContractAddresses.registryAddress;
|
|
145
143
|
|
|
@@ -161,7 +159,6 @@ export const uniswapL1L2TestSuite = (
|
|
|
161
159
|
await cleanup();
|
|
162
160
|
});
|
|
163
161
|
|
|
164
|
-
// docs:start:uniswap_private
|
|
165
162
|
it('should uniswap trade on L1 from L2 funds privately (swaps WETH -> DAI)', async () => {
|
|
166
163
|
const wethL1BeforeBalance = await wethCrossChainHarness.getL1BalanceOf(ownerEthAddress);
|
|
167
164
|
|
|
@@ -204,7 +201,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
204
201
|
logger.info('Withdrawing weth to L1 and sending message to swap to dai');
|
|
205
202
|
const [secretForDepositingSwappedDai, secretHashForDepositingSwappedDai] = await generateClaimSecret();
|
|
206
203
|
|
|
207
|
-
const l2UniswapInteractionReceipt = await uniswapL2Contract.methods
|
|
204
|
+
const { receipt: l2UniswapInteractionReceipt } = await uniswapL2Contract.methods
|
|
208
205
|
.swap_private(
|
|
209
206
|
wethCrossChainHarness.l2Token.address,
|
|
210
207
|
wethCrossChainHarness.l2Bridge.address,
|
|
@@ -216,8 +213,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
216
213
|
secretHashForDepositingSwappedDai,
|
|
217
214
|
ownerEthAddress,
|
|
218
215
|
)
|
|
219
|
-
.send({ from: ownerAddress, authWitnesses: [transferToPublicAuhtwit] })
|
|
220
|
-
.wait();
|
|
216
|
+
.send({ from: ownerAddress, authWitnesses: [transferToPublicAuhtwit] });
|
|
221
217
|
|
|
222
218
|
const swapPrivateFunction = 'swap_private(address,uint256,uint24,address,uint256,bytes32,address)';
|
|
223
219
|
const swapPrivateContent = sha256ToField([
|
|
@@ -259,33 +255,35 @@ export const uniswapL1L2TestSuite = (
|
|
|
259
255
|
// ensure that uniswap contract didn't eat the funds.
|
|
260
256
|
await wethCrossChainHarness.expectPublicBalanceOnL2(uniswapL2Contract.address, 0n);
|
|
261
257
|
|
|
262
|
-
// Since the outbox is only consumable when the
|
|
263
|
-
|
|
258
|
+
// Since the outbox is only consumable when the epoch is proven, we need to advance to the next epoch
|
|
259
|
+
// before we can ask the witness helper for a covering root.
|
|
260
|
+
const minedReceipt = await aztecNode.getTxReceipt(l2UniswapInteractionReceipt.txHash);
|
|
261
|
+
if (minedReceipt.epochNumber === undefined) {
|
|
262
|
+
throw new Error('L2 Uniswap interaction tx is not yet in an epoch');
|
|
263
|
+
}
|
|
264
|
+
await cheatCodes.rollup.advanceToEpoch(EpochNumber(minedReceipt.epochNumber + 1));
|
|
265
|
+
await waitForProven(aztecNode, l2UniswapInteractionReceipt, { provenTimeout: 300 });
|
|
264
266
|
|
|
265
267
|
// 5. Consume L2 to L1 message by calling uniswapPortal.swap_private()
|
|
266
268
|
logger.info('Execute withdraw and swap on the uniswapPortal!');
|
|
267
269
|
const daiL1BalanceOfPortalBeforeSwap = await daiCrossChainHarness.getL1BalanceOf(
|
|
268
270
|
daiCrossChainHarness.tokenPortalAddress,
|
|
269
271
|
);
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
)
|
|
275
|
-
const withdrawResult = await computeL2ToL1MembershipWitness(
|
|
276
|
-
aztecNode,
|
|
277
|
-
l2UniswapInteractionReceipt.blockNumber!,
|
|
278
|
-
withdrawLeaf,
|
|
279
|
-
);
|
|
272
|
+
// Fetch the outbox roots once and share them between the two witnesses in this epoch.
|
|
273
|
+
const epochRoots = await wethCrossChainHarness.outboxContract.getRoots(minedReceipt.epochNumber);
|
|
274
|
+
const swapResult = (await computeL2ToL1MembershipWitness(aztecNode, epochRoots, swapPrivateLeaf, minedReceipt))!;
|
|
275
|
+
const { epochNumber: epoch, numCheckpointsInEpoch } = swapResult;
|
|
276
|
+
const withdrawResult = (await computeL2ToL1MembershipWitness(aztecNode, epochRoots, withdrawLeaf, minedReceipt))!;
|
|
280
277
|
|
|
281
|
-
const swapPrivateL2MessageIndex = swapResult
|
|
282
|
-
const swapPrivateSiblingPath = swapResult
|
|
278
|
+
const swapPrivateL2MessageIndex = swapResult.leafIndex;
|
|
279
|
+
const swapPrivateSiblingPath = swapResult.siblingPath;
|
|
283
280
|
|
|
284
|
-
const withdrawL2MessageIndex = withdrawResult
|
|
285
|
-
const withdrawSiblingPath = withdrawResult
|
|
281
|
+
const withdrawL2MessageIndex = withdrawResult.leafIndex;
|
|
282
|
+
const withdrawSiblingPath = withdrawResult.siblingPath;
|
|
286
283
|
|
|
287
284
|
const withdrawMessageMetadata = {
|
|
288
|
-
|
|
285
|
+
_epoch: BigInt(epoch),
|
|
286
|
+
_numCheckpointsInEpoch: BigInt(withdrawResult.numCheckpointsInEpoch),
|
|
289
287
|
_leafIndex: BigInt(withdrawL2MessageIndex),
|
|
290
288
|
_path: withdrawSiblingPath
|
|
291
289
|
.toBufferArray()
|
|
@@ -293,7 +291,8 @@ export const uniswapL1L2TestSuite = (
|
|
|
293
291
|
};
|
|
294
292
|
|
|
295
293
|
const swapPrivateMessageMetadata = {
|
|
296
|
-
|
|
294
|
+
_epoch: BigInt(epoch),
|
|
295
|
+
_numCheckpointsInEpoch: BigInt(numCheckpointsInEpoch),
|
|
297
296
|
_leafIndex: BigInt(swapPrivateL2MessageIndex),
|
|
298
297
|
_path: swapPrivateSiblingPath
|
|
299
298
|
.toBufferArray()
|
|
@@ -351,10 +350,8 @@ export const uniswapL1L2TestSuite = (
|
|
|
351
350
|
logger.info('WETH balance after swap : ', wethL2BalanceAfterSwap.toString());
|
|
352
351
|
logger.info('DAI balance after swap : ', daiL2BalanceAfterSwap.toString());
|
|
353
352
|
});
|
|
354
|
-
// docs:end:uniswap_private
|
|
355
353
|
|
|
356
354
|
// TODO(#7463): reenable look into this failure https://github.com/AztecProtocol/aztec-packages/actions/runs/9912612912/job/27388320150?pr=7462
|
|
357
|
-
// // docs:start:uniswap_public
|
|
358
355
|
// it('should uniswap trade on L1 from L2 funds publicly (swaps WETH -> DAI)', async () => {
|
|
359
356
|
// const wethL1BeforeBalance = await wethCrossChainHarness.getL1BalanceOf(ownerEthAddress);
|
|
360
357
|
|
|
@@ -440,10 +437,10 @@ export const uniswapL1L2TestSuite = (
|
|
|
440
437
|
// ownerEthAddress,
|
|
441
438
|
// nonceForSwap,
|
|
442
439
|
// );
|
|
443
|
-
// await ownerWallet.setPublicAuthWit({ caller: sponsorAddress, action }, true).send()
|
|
440
|
+
// await ownerWallet.setPublicAuthWit({ caller: sponsorAddress, action }, true).send();
|
|
444
441
|
|
|
445
442
|
// // 4.2 Call swap_public from user2 on behalf of owner
|
|
446
|
-
// const uniswapL2Interaction = await action.send()
|
|
443
|
+
// const uniswapL2Interaction = await action.send();
|
|
447
444
|
|
|
448
445
|
// const swapPublicContent = sha256ToField([
|
|
449
446
|
// Buffer.from(
|
|
@@ -504,7 +501,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
504
501
|
// );
|
|
505
502
|
|
|
506
503
|
// const withdrawMessageMetadata = {
|
|
507
|
-
//
|
|
504
|
+
// _epoch: epoch,
|
|
508
505
|
// _leafIndex: BigInt(withdrawL2MessageIndex),
|
|
509
506
|
// _path: withdrawSiblingPath
|
|
510
507
|
// .toBufferArray()
|
|
@@ -512,7 +509,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
512
509
|
// };
|
|
513
510
|
|
|
514
511
|
// const swapPrivateMessageMetadata = {
|
|
515
|
-
//
|
|
512
|
+
// _epoch: epoch,
|
|
516
513
|
// _leafIndex: BigInt(swapPrivateL2MessageIndex),
|
|
517
514
|
// _path: swapPrivateSiblingPath
|
|
518
515
|
// .toBufferArray()
|
|
@@ -587,7 +584,6 @@ export const uniswapL1L2TestSuite = (
|
|
|
587
584
|
// logger.info('WETH balance after swap : ', wethL2BalanceAfterSwap.toString());
|
|
588
585
|
// logger.info('DAI balance after swap : ', daiL2BalanceAfterSwap.toString());
|
|
589
586
|
// });
|
|
590
|
-
// // docs:end:uniswap_public
|
|
591
587
|
|
|
592
588
|
// Edge cases for the private flow:
|
|
593
589
|
// note - tests for uniswapPortal.sol and minting asset on L2 are covered in other tests.
|
|
@@ -661,8 +657,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
661
657
|
Fr.random(),
|
|
662
658
|
ownerEthAddress,
|
|
663
659
|
)
|
|
664
|
-
.send({ from: ownerAddress, authWitnesses: [transferToPublicAuthwith] })
|
|
665
|
-
.wait(),
|
|
660
|
+
.send({ from: ownerAddress, authWitnesses: [transferToPublicAuthwith] }),
|
|
666
661
|
).rejects.toThrow('Assertion failed: input_asset address is not the same as seen in the bridge contract');
|
|
667
662
|
});
|
|
668
663
|
|
|
@@ -687,7 +682,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
687
682
|
},
|
|
688
683
|
true,
|
|
689
684
|
);
|
|
690
|
-
await validateActionInteraction.send()
|
|
685
|
+
await validateActionInteraction.send();
|
|
691
686
|
|
|
692
687
|
// No approval to call `swap` but should work even without it:
|
|
693
688
|
const [_, secretHashForDepositingSwappedDai] = await generateClaimSecret();
|
|
@@ -706,8 +701,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
706
701
|
ownerEthAddress,
|
|
707
702
|
Fr.ZERO, // nonce for swap -> doesn't matter
|
|
708
703
|
)
|
|
709
|
-
.send({ from: ownerAddress })
|
|
710
|
-
.wait();
|
|
704
|
+
.send({ from: ownerAddress });
|
|
711
705
|
// check weth balance of owner on L2 (we first bridged `wethAmountToBridge` into L2 and now withdrew it!)
|
|
712
706
|
await wethCrossChainHarness.expectPublicBalanceOnL2(ownerAddress, 0n);
|
|
713
707
|
});
|
|
@@ -737,7 +731,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
737
731
|
{ caller: approvedUser, action },
|
|
738
732
|
true,
|
|
739
733
|
);
|
|
740
|
-
await validateActionInteraction.send()
|
|
734
|
+
await validateActionInteraction.send();
|
|
741
735
|
|
|
742
736
|
await expect(action.simulate({ from: sponsorAddress })).rejects.toThrow(/unauthorized/);
|
|
743
737
|
});
|
|
@@ -759,7 +753,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
759
753
|
},
|
|
760
754
|
true,
|
|
761
755
|
);
|
|
762
|
-
await validateActionInteraction.send()
|
|
756
|
+
await validateActionInteraction.send();
|
|
763
757
|
|
|
764
758
|
await expect(
|
|
765
759
|
uniswapL2Contract.methods
|
|
@@ -804,7 +798,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
804
798
|
logger.info('Withdrawing weth to L1 and sending message to swap to dai');
|
|
805
799
|
|
|
806
800
|
const [, secretHashForDepositingSwappedDai] = await generateClaimSecret();
|
|
807
|
-
const withdrawReceipt = await uniswapL2Contract.methods
|
|
801
|
+
const { receipt: withdrawReceipt } = await uniswapL2Contract.methods
|
|
808
802
|
.swap_private(
|
|
809
803
|
wethCrossChainHarness.l2Token.address,
|
|
810
804
|
wethCrossChainHarness.l2Bridge.address,
|
|
@@ -816,8 +810,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
816
810
|
secretHashForDepositingSwappedDai,
|
|
817
811
|
ownerEthAddress,
|
|
818
812
|
)
|
|
819
|
-
.send({ from: ownerAddress, authWitnesses: [transferToPublicAuhtwit] })
|
|
820
|
-
.wait();
|
|
813
|
+
.send({ from: ownerAddress, authWitnesses: [transferToPublicAuhtwit] });
|
|
821
814
|
|
|
822
815
|
const swapPrivateContent = sha256ToField([
|
|
823
816
|
Buffer.from(
|
|
@@ -856,21 +849,33 @@ export const uniswapL1L2TestSuite = (
|
|
|
856
849
|
chainId: new Fr(l1Client.chain.id),
|
|
857
850
|
});
|
|
858
851
|
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
);
|
|
852
|
+
// ensure that user's funds were burnt
|
|
853
|
+
await wethCrossChainHarness.expectPrivateBalanceOnL2(ownerAddress, wethL2BalanceBeforeSwap - wethAmountToBridge);
|
|
854
|
+
|
|
855
|
+
// Since the outbox is only consumable when the epoch is proven, we need to advance to the next epoch
|
|
856
|
+
// before we can ask the witness helper for a covering root.
|
|
857
|
+
const minedReceipt = await aztecNode.getTxReceipt(withdrawReceipt.txHash);
|
|
858
|
+
if (minedReceipt.epochNumber === undefined) {
|
|
859
|
+
throw new Error('Withdraw tx is not yet in an epoch');
|
|
860
|
+
}
|
|
861
|
+
await cheatCodes.rollup.advanceToEpoch(EpochNumber(minedReceipt.epochNumber + 1));
|
|
862
|
+
await waitForProven(aztecNode, withdrawReceipt, { provenTimeout: 300 });
|
|
865
863
|
|
|
866
|
-
|
|
867
|
-
const
|
|
864
|
+
// Fetch the outbox roots once and share them between the two witnesses in this epoch.
|
|
865
|
+
const epochRoots = await wethCrossChainHarness.outboxContract.getRoots(minedReceipt.epochNumber);
|
|
866
|
+
const swapResult = (await computeL2ToL1MembershipWitness(aztecNode, epochRoots, swapPrivateLeaf, minedReceipt))!;
|
|
867
|
+
const { epochNumber: epoch, numCheckpointsInEpoch } = swapResult;
|
|
868
|
+
const withdrawResult = (await computeL2ToL1MembershipWitness(aztecNode, epochRoots, withdrawLeaf, minedReceipt))!;
|
|
868
869
|
|
|
869
|
-
const
|
|
870
|
-
const
|
|
870
|
+
const swapPrivateL2MessageIndex = swapResult.leafIndex;
|
|
871
|
+
const swapPrivateSiblingPath = swapResult.siblingPath;
|
|
872
|
+
|
|
873
|
+
const withdrawL2MessageIndex = withdrawResult.leafIndex;
|
|
874
|
+
const withdrawSiblingPath = withdrawResult.siblingPath;
|
|
871
875
|
|
|
872
876
|
const withdrawMessageMetadata = {
|
|
873
|
-
|
|
877
|
+
_epoch: BigInt(epoch),
|
|
878
|
+
_numCheckpointsInEpoch: BigInt(withdrawResult.numCheckpointsInEpoch),
|
|
874
879
|
_leafIndex: BigInt(withdrawL2MessageIndex),
|
|
875
880
|
_path: withdrawSiblingPath
|
|
876
881
|
.toBufferArray()
|
|
@@ -878,19 +883,14 @@ export const uniswapL1L2TestSuite = (
|
|
|
878
883
|
};
|
|
879
884
|
|
|
880
885
|
const swapPrivateMessageMetadata = {
|
|
881
|
-
|
|
886
|
+
_epoch: BigInt(epoch),
|
|
887
|
+
_numCheckpointsInEpoch: BigInt(numCheckpointsInEpoch),
|
|
882
888
|
_leafIndex: BigInt(swapPrivateL2MessageIndex),
|
|
883
889
|
_path: swapPrivateSiblingPath
|
|
884
890
|
.toBufferArray()
|
|
885
891
|
.map((buf: Buffer) => `0x${buf.toString('hex')}`) as readonly `0x${string}`[],
|
|
886
892
|
};
|
|
887
893
|
|
|
888
|
-
// ensure that user's funds were burnt
|
|
889
|
-
await wethCrossChainHarness.expectPrivateBalanceOnL2(ownerAddress, wethL2BalanceBeforeSwap - wethAmountToBridge);
|
|
890
|
-
|
|
891
|
-
// Since the outbox is only consumable when the block is proven, we need to set the block to be proven
|
|
892
|
-
await cheatCodes.rollup.markAsProven(await rollup.getCheckpointNumber());
|
|
893
|
-
|
|
894
894
|
// On L1 call swap_public!
|
|
895
895
|
logger.info('call swap_public on L1');
|
|
896
896
|
const swapArgs = [
|
|
@@ -930,11 +930,11 @@ export const uniswapL1L2TestSuite = (
|
|
|
930
930
|
},
|
|
931
931
|
true,
|
|
932
932
|
);
|
|
933
|
-
await validateActionInteraction.send()
|
|
933
|
+
await validateActionInteraction.send();
|
|
934
934
|
|
|
935
935
|
// Call swap_public on L2
|
|
936
936
|
const secretHashForDepositingSwappedDai = Fr.random();
|
|
937
|
-
const withdrawReceipt = await uniswapL2Contract.methods
|
|
937
|
+
const { receipt: withdrawReceipt } = await uniswapL2Contract.methods
|
|
938
938
|
.swap_public(
|
|
939
939
|
ownerAddress,
|
|
940
940
|
wethCrossChainHarness.l2Bridge.address,
|
|
@@ -948,8 +948,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
948
948
|
ownerEthAddress,
|
|
949
949
|
Fr.ZERO,
|
|
950
950
|
)
|
|
951
|
-
.send({ from: ownerAddress })
|
|
952
|
-
.wait();
|
|
951
|
+
.send({ from: ownerAddress });
|
|
953
952
|
|
|
954
953
|
const swapPublicContent = sha256ToField([
|
|
955
954
|
Buffer.from(
|
|
@@ -991,21 +990,33 @@ export const uniswapL1L2TestSuite = (
|
|
|
991
990
|
chainId: new Fr(l1Client.chain.id),
|
|
992
991
|
});
|
|
993
992
|
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
);
|
|
993
|
+
// check weth balance of owner on L2 (we first bridged `wethAmountToBridge` into L2 and now withdrew it!)
|
|
994
|
+
await wethCrossChainHarness.expectPublicBalanceOnL2(ownerAddress, 0n);
|
|
995
|
+
|
|
996
|
+
// Since the outbox is only consumable when the epoch is proven, we need to advance to the next epoch
|
|
997
|
+
// before we can ask the witness helper for a covering root.
|
|
998
|
+
const minedReceipt = await aztecNode.getTxReceipt(withdrawReceipt.txHash);
|
|
999
|
+
if (minedReceipt.epochNumber === undefined) {
|
|
1000
|
+
throw new Error('Withdraw tx is not yet in an epoch');
|
|
1001
|
+
}
|
|
1002
|
+
await cheatCodes.rollup.advanceToEpoch(EpochNumber(minedReceipt.epochNumber + 1));
|
|
1003
|
+
await waitForProven(aztecNode, withdrawReceipt, { provenTimeout: 300 });
|
|
1004
|
+
|
|
1005
|
+
// Fetch the outbox roots once and share them between the two witnesses in this epoch.
|
|
1006
|
+
const epochRoots = await wethCrossChainHarness.outboxContract.getRoots(minedReceipt.epochNumber);
|
|
1007
|
+
const swapResult = (await computeL2ToL1MembershipWitness(aztecNode, epochRoots, swapPublicLeaf, minedReceipt))!;
|
|
1008
|
+
const { epochNumber: epoch, numCheckpointsInEpoch } = swapResult;
|
|
1009
|
+
const withdrawResult = (await computeL2ToL1MembershipWitness(aztecNode, epochRoots, withdrawLeaf, minedReceipt))!;
|
|
1000
1010
|
|
|
1001
|
-
const swapPublicL2MessageIndex = swapResult
|
|
1002
|
-
const swapPublicSiblingPath = swapResult
|
|
1011
|
+
const swapPublicL2MessageIndex = swapResult.leafIndex;
|
|
1012
|
+
const swapPublicSiblingPath = swapResult.siblingPath;
|
|
1003
1013
|
|
|
1004
|
-
const withdrawL2MessageIndex = withdrawResult
|
|
1005
|
-
const withdrawSiblingPath = withdrawResult
|
|
1014
|
+
const withdrawL2MessageIndex = withdrawResult.leafIndex;
|
|
1015
|
+
const withdrawSiblingPath = withdrawResult.siblingPath;
|
|
1006
1016
|
|
|
1007
1017
|
const withdrawMessageMetadata = {
|
|
1008
|
-
|
|
1018
|
+
_epoch: BigInt(epoch),
|
|
1019
|
+
_numCheckpointsInEpoch: BigInt(withdrawResult.numCheckpointsInEpoch),
|
|
1009
1020
|
_leafIndex: BigInt(withdrawL2MessageIndex),
|
|
1010
1021
|
_path: withdrawSiblingPath
|
|
1011
1022
|
.toBufferArray()
|
|
@@ -1013,19 +1024,14 @@ export const uniswapL1L2TestSuite = (
|
|
|
1013
1024
|
};
|
|
1014
1025
|
|
|
1015
1026
|
const swapPublicMessageMetadata = {
|
|
1016
|
-
|
|
1027
|
+
_epoch: BigInt(epoch),
|
|
1028
|
+
_numCheckpointsInEpoch: BigInt(numCheckpointsInEpoch),
|
|
1017
1029
|
_leafIndex: BigInt(swapPublicL2MessageIndex),
|
|
1018
1030
|
_path: swapPublicSiblingPath
|
|
1019
1031
|
.toBufferArray()
|
|
1020
1032
|
.map((buf: Buffer) => `0x${buf.toString('hex')}`) as readonly `0x${string}`[],
|
|
1021
1033
|
};
|
|
1022
1034
|
|
|
1023
|
-
// check weth balance of owner on L2 (we first bridged `wethAmountToBridge` into L2 and now withdrew it!)
|
|
1024
|
-
await wethCrossChainHarness.expectPublicBalanceOnL2(ownerAddress, 0n);
|
|
1025
|
-
|
|
1026
|
-
// Since the outbox is only consumable when the block is proven, we need to set the block to be proven
|
|
1027
|
-
await cheatCodes.rollup.markAsProven(await rollup.getCheckpointNumber());
|
|
1028
|
-
|
|
1029
1035
|
// Call swap_private on L1
|
|
1030
1036
|
logger.info('Execute withdraw and swap on the uniswapPortal!');
|
|
1031
1037
|
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Fr } from '@aztec/aztec.js/fields';
|
|
2
|
+
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
3
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Waits until the archiver has seen the L1 to L2 message and indexed it. Unlike
|
|
7
|
+
* {@link waitForL1ToL2MessageReady} from `@aztec/aztec.js/messaging`, this does not
|
|
8
|
+
* require the L2 chain to have advanced to the message's checkpoint — it only confirms
|
|
9
|
+
* the message has been picked up from L1. Use this in tests that explicitly produce L2
|
|
10
|
+
* blocks afterwards to make the message consumable.
|
|
11
|
+
*/
|
|
12
|
+
export function waitForL1ToL2MessageSeen(
|
|
13
|
+
node: Pick<AztecNode, 'getL1ToL2MessageCheckpoint'>,
|
|
14
|
+
l1ToL2MessageHash: Fr,
|
|
15
|
+
opts: { timeoutSeconds: number },
|
|
16
|
+
) {
|
|
17
|
+
return retryUntil(
|
|
18
|
+
async () => (await node.getL1ToL2MessageCheckpoint(l1ToL2MessageHash)) !== undefined,
|
|
19
|
+
`L1 to L2 message ${l1ToL2MessageHash.toString()} seen`,
|
|
20
|
+
opts.timeoutSeconds,
|
|
21
|
+
1,
|
|
22
|
+
);
|
|
23
|
+
}
|
|
@@ -4,9 +4,10 @@ import { Fr } from '@aztec/aztec.js/fields';
|
|
|
4
4
|
import { CheatCodes } from '@aztec/aztec/testing';
|
|
5
5
|
import type { RollupContract } from '@aztec/ethereum/contracts';
|
|
6
6
|
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
7
|
-
import {
|
|
7
|
+
import { poseidon2Hash } from '@aztec/foundation/crypto/poseidon';
|
|
8
8
|
import type { TestDateProvider } from '@aztec/foundation/timer';
|
|
9
9
|
import type { LendingContract } from '@aztec/noir-contracts.js/Lending';
|
|
10
|
+
import type { AztecNode, AztecNodeDebug } from '@aztec/stdlib/interfaces/client';
|
|
10
11
|
|
|
11
12
|
import type { TokenSimulator } from './token_simulator.js';
|
|
12
13
|
|
|
@@ -29,7 +30,7 @@ export class LendingAccount {
|
|
|
29
30
|
* @returns Key in public space
|
|
30
31
|
*/
|
|
31
32
|
public key() {
|
|
32
|
-
return
|
|
33
|
+
return poseidon2Hash([this.address, this.secret]);
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
36
|
|
|
@@ -92,30 +93,45 @@ export class LendingSimulator {
|
|
|
92
93
|
public stableCoin: TokenSimulator,
|
|
93
94
|
) {}
|
|
94
95
|
|
|
95
|
-
|
|
96
|
+
prepare() {
|
|
96
97
|
this.accumulator = BASE;
|
|
97
|
-
|
|
98
|
-
this.time = Number(await this.rollup.getTimestampForSlot(slot));
|
|
98
|
+
this.time = 0;
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
|
|
101
|
+
/**
|
|
102
|
+
* Advances the simulator's accumulator and clock to match a block timestamp observed on chain.
|
|
103
|
+
* Call this BEFORE applying any accumulator-sensitive mutation (borrow/repay) so the mutation
|
|
104
|
+
* sees the same accumulator as the contract did during execution.
|
|
105
|
+
*/
|
|
106
|
+
observeBlockTimestamp(ts: number) {
|
|
107
|
+
const diff = ts - this.time;
|
|
108
|
+
if (diff > 0) {
|
|
109
|
+
this.accumulator = muldivDown(this.accumulator, computeMultiplier(this.rate, BigInt(diff)), BASE);
|
|
110
|
+
}
|
|
111
|
+
this.time = ts;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async progressSlots(diff: number, _dateProvider?: TestDateProvider, node?: AztecNode & AztecNodeDebug) {
|
|
102
115
|
if (diff <= 1) {
|
|
103
116
|
return;
|
|
104
117
|
}
|
|
105
118
|
|
|
106
|
-
const slot = await this.rollup.getSlotAt(BigInt(await this.cc.eth.
|
|
119
|
+
const slot = await this.rollup.getSlotAt(BigInt(await this.cc.eth.lastBlockTimestamp()));
|
|
107
120
|
const targetSlot = SlotNumber(slot + diff);
|
|
108
121
|
const ts = Number(await this.rollup.getTimestampForSlot(targetSlot));
|
|
109
|
-
const timeDiff = ts - this.time;
|
|
110
|
-
this.time = ts;
|
|
111
122
|
|
|
112
|
-
//
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
123
|
+
// Queue-aware warp under AutomineSequencer: atomic warp + mineBlock that advances L2 time to the
|
|
124
|
+
// target slot. The cheat code routes through the AutomineSequencer queue when one is installed,
|
|
125
|
+
// and otherwise falls back to a manual warp + mineBlock loop.
|
|
126
|
+
if (node) {
|
|
127
|
+
await this.cc.warpL2TimeAtLeastTo(node, ts);
|
|
128
|
+
} else {
|
|
129
|
+
await this.cc.eth.warp(ts - this.ethereumSlotDuration);
|
|
116
130
|
}
|
|
131
|
+
|
|
132
|
+
// Mark the latest checkpoint as proven so the rollup does not reorg pending checkpoints when
|
|
133
|
+
// time jumps far enough forward to cross an unproven epoch boundary.
|
|
117
134
|
await this.cc.rollup.markAsProven(await this.rollup.getCheckpointNumber());
|
|
118
|
-
this.accumulator = muldivDown(this.accumulator, computeMultiplier(this.rate, BigInt(timeDiff)), BASE);
|
|
119
135
|
}
|
|
120
136
|
|
|
121
137
|
depositPrivate(from: AztecAddress, onBehalfOf: Fr, amount: bigint) {
|
|
@@ -186,14 +202,16 @@ export class LendingSimulator {
|
|
|
186
202
|
|
|
187
203
|
expect(this.borrowed).toEqual(this.stableCoin.totalSupply - this.mintedOutside);
|
|
188
204
|
|
|
189
|
-
const asset = await this.lendingContract.methods.get_asset(0).simulate({ from: this.account.address });
|
|
205
|
+
const { result: asset } = await this.lendingContract.methods.get_asset(0).simulate({ from: this.account.address });
|
|
190
206
|
|
|
191
207
|
const interestAccumulator = asset['interest_accumulator'];
|
|
192
208
|
expect(interestAccumulator).toEqual(this.accumulator);
|
|
193
209
|
expect(asset['last_updated_ts']).toEqual(BigInt(this.time));
|
|
194
210
|
|
|
195
211
|
for (const key of [this.account.address, AztecAddress.fromField(await this.account.key())]) {
|
|
196
|
-
const privatePos = await this.lendingContract.methods
|
|
212
|
+
const { result: privatePos } = await this.lendingContract.methods
|
|
213
|
+
.get_position(key)
|
|
214
|
+
.simulate({ from: this.account.address });
|
|
197
215
|
expect(new Fr(privatePos['collateral'])).toEqual(this.collateral[key.toString()] ?? Fr.ZERO);
|
|
198
216
|
expect(new Fr(privatePos['static_debt'])).toEqual(this.staticDebt[key.toString()] ?? Fr.ZERO);
|
|
199
217
|
expect(privatePos['debt']).toEqual(
|
|
@@ -109,7 +109,9 @@ export class TokenSimulator {
|
|
|
109
109
|
await Promise.all(
|
|
110
110
|
chunk(calls, 5).map(batch => new BatchCall(this.defaultWallet, batch).simulate({ from: this.defaultAddress })),
|
|
111
111
|
)
|
|
112
|
-
)
|
|
112
|
+
)
|
|
113
|
+
.flatMap(r => r.result)
|
|
114
|
+
.map(r => r.result);
|
|
113
115
|
expect(results[0]).toEqual(this.totalSupply);
|
|
114
116
|
|
|
115
117
|
// Check that all our balances match
|
|
@@ -119,39 +121,13 @@ export class TokenSimulator {
|
|
|
119
121
|
}
|
|
120
122
|
|
|
121
123
|
async checkPrivate() {
|
|
122
|
-
// Private calls
|
|
123
|
-
const defaultLookups = [];
|
|
124
|
-
const nonDefaultLookups = [];
|
|
125
|
-
|
|
126
124
|
for (const address of this.accounts) {
|
|
127
|
-
if (this.lookupProvider.has(address.toString())) {
|
|
128
|
-
nonDefaultLookups.push(address);
|
|
129
|
-
} else {
|
|
130
|
-
defaultLookups.push(address);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
const defaultCalls = defaultLookups.map(address => this.token.methods.balance_of_private(address));
|
|
135
|
-
const results = (
|
|
136
|
-
await Promise.all(
|
|
137
|
-
chunk(defaultCalls, 4).map(batch =>
|
|
138
|
-
new BatchCall(this.defaultWallet, batch).simulate({ from: this.defaultAddress }),
|
|
139
|
-
),
|
|
140
|
-
)
|
|
141
|
-
).flat();
|
|
142
|
-
for (let i = 0; i < defaultLookups.length; i++) {
|
|
143
|
-
expect(results[i]).toEqual(this.balanceOfPrivate(defaultLookups[i]));
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// We are just running individual calls for the non-default lookups
|
|
147
|
-
// @todo We should also batch these
|
|
148
|
-
for (const address of nonDefaultLookups) {
|
|
149
125
|
const wallet = this.lookupProvider.get(address.toString());
|
|
150
126
|
const asset = wallet ? this.token.withWallet(wallet) : this.token;
|
|
151
127
|
|
|
152
|
-
const actualPrivateBalance = await asset.methods
|
|
153
|
-
.balance_of_private(
|
|
154
|
-
.simulate({ from:
|
|
128
|
+
const { result: actualPrivateBalance } = await asset.methods
|
|
129
|
+
.balance_of_private(address)
|
|
130
|
+
.simulate({ from: address });
|
|
155
131
|
expect(actualPrivateBalance).toEqual(this.balanceOfPrivate(address));
|
|
156
132
|
}
|
|
157
133
|
}
|