@aztec/end-to-end 0.0.0-test.1 → 0.0.1-commit.1142ef1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/bench/client_flows/benchmark.d.ts +61 -0
- package/dest/bench/client_flows/benchmark.d.ts.map +1 -0
- package/dest/bench/client_flows/benchmark.js +261 -0
- package/dest/bench/client_flows/client_flows_benchmark.d.ts +80 -0
- package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -0
- package/dest/bench/client_flows/client_flows_benchmark.js +336 -0
- package/dest/bench/client_flows/config.d.ts +14 -0
- package/dest/bench/client_flows/config.d.ts.map +1 -0
- package/dest/bench/client_flows/config.js +106 -0
- package/dest/bench/client_flows/data_extractor.d.ts +2 -0
- package/dest/bench/client_flows/data_extractor.d.ts.map +1 -0
- package/dest/bench/client_flows/data_extractor.js +79 -0
- package/dest/bench/utils.d.ts +14 -40
- package/dest/bench/utils.d.ts.map +1 -1
- package/dest/bench/utils.js +37 -70
- package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +21 -13
- package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts.map +1 -1
- package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.js +85 -57
- package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +29 -28
- package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts.map +1 -1
- package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.js +79 -82
- package/dest/e2e_deploy_contract/deploy_test.d.ts +16 -8
- package/dest/e2e_deploy_contract/deploy_test.d.ts.map +1 -1
- package/dest/e2e_deploy_contract/deploy_test.js +13 -19
- package/dest/e2e_epochs/epochs_test.d.ts +65 -22
- package/dest/e2e_epochs/epochs_test.d.ts.map +1 -1
- package/dest/e2e_epochs/epochs_test.js +233 -49
- package/dest/e2e_fees/bridging_race.notest.d.ts +2 -0
- package/dest/e2e_fees/bridging_race.notest.d.ts.map +1 -0
- package/dest/e2e_fees/bridging_race.notest.js +63 -0
- package/dest/e2e_fees/fees_test.d.ts +27 -12
- package/dest/e2e_fees/fees_test.d.ts.map +1 -1
- package/dest/e2e_fees/fees_test.js +107 -110
- package/dest/e2e_l1_publisher/write_json.d.ts +10 -0
- package/dest/e2e_l1_publisher/write_json.d.ts.map +1 -0
- package/dest/e2e_l1_publisher/write_json.js +55 -0
- package/dest/e2e_multi_validator/utils.d.ts +12 -0
- package/dest/e2e_multi_validator/utils.d.ts.map +1 -0
- package/dest/e2e_multi_validator/utils.js +214 -0
- package/dest/e2e_nested_contract/nested_contract_test.d.ts +10 -7
- package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +1 -1
- package/dest/e2e_nested_contract/nested_contract_test.js +24 -20
- package/dest/e2e_p2p/inactivity_slash_test.d.ts +31 -0
- package/dest/e2e_p2p/inactivity_slash_test.d.ts.map +1 -0
- package/dest/e2e_p2p/inactivity_slash_test.js +136 -0
- package/dest/e2e_p2p/p2p_network.d.ts +276 -23
- package/dest/e2e_p2p/p2p_network.d.ts.map +1 -1
- package/dest/e2e_p2p/p2p_network.js +188 -133
- package/dest/e2e_p2p/shared.d.ts +43 -7
- package/dest/e2e_p2p/shared.d.ts.map +1 -1
- package/dest/e2e_p2p/shared.js +164 -19
- package/dest/e2e_token_contract/token_contract_test.d.ts +12 -6
- package/dest/e2e_token_contract/token_contract_test.d.ts.map +1 -1
- package/dest/e2e_token_contract/token_contract_test.js +50 -26
- package/dest/fixtures/e2e_prover_test.d.ts +61 -0
- package/dest/fixtures/e2e_prover_test.d.ts.map +1 -0
- package/dest/{e2e_prover → fixtures}/e2e_prover_test.js +108 -113
- package/dest/fixtures/fixtures.d.ts +6 -8
- package/dest/fixtures/fixtures.d.ts.map +1 -1
- package/dest/fixtures/fixtures.js +5 -5
- package/dest/fixtures/get_acvm_config.d.ts +2 -2
- package/dest/fixtures/get_acvm_config.d.ts.map +1 -1
- package/dest/fixtures/get_acvm_config.js +3 -15
- package/dest/fixtures/get_bb_config.d.ts +2 -2
- package/dest/fixtures/get_bb_config.d.ts.map +1 -1
- package/dest/fixtures/get_bb_config.js +10 -17
- package/dest/fixtures/index.d.ts +1 -1
- package/dest/fixtures/l1_to_l2_messaging.d.ts +11 -7
- package/dest/fixtures/l1_to_l2_messaging.d.ts.map +1 -1
- package/dest/fixtures/l1_to_l2_messaging.js +45 -19
- package/dest/fixtures/logging.d.ts +1 -1
- package/dest/fixtures/setup_p2p_test.d.ts +15 -14
- package/dest/fixtures/setup_p2p_test.d.ts.map +1 -1
- package/dest/fixtures/setup_p2p_test.js +82 -22
- package/dest/fixtures/snapshot_manager.d.ts +20 -14
- package/dest/fixtures/snapshot_manager.d.ts.map +1 -1
- package/dest/fixtures/snapshot_manager.js +147 -138
- package/dest/fixtures/token_utils.d.ts +10 -4
- package/dest/fixtures/token_utils.d.ts.map +1 -1
- package/dest/fixtures/token_utils.js +28 -12
- package/dest/fixtures/utils.d.ts +92 -54
- package/dest/fixtures/utils.d.ts.map +1 -1
- package/dest/fixtures/utils.js +452 -389
- package/dest/fixtures/web3signer.d.ts +5 -0
- package/dest/fixtures/web3signer.d.ts.map +1 -0
- package/dest/fixtures/web3signer.js +53 -0
- package/dest/fixtures/with_telemetry_utils.d.ts +2 -2
- package/dest/fixtures/with_telemetry_utils.d.ts.map +1 -1
- package/dest/fixtures/with_telemetry_utils.js +2 -2
- package/dest/index.d.ts +1 -1
- package/dest/quality_of_service/grafana_client.d.ts +41 -0
- package/dest/quality_of_service/grafana_client.d.ts.map +1 -0
- package/dest/quality_of_service/{alert_checker.js → grafana_client.js} +1 -1
- package/dest/shared/cross_chain_test_harness.d.ts +42 -35
- package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
- package/dest/shared/cross_chain_test_harness.js +106 -52
- package/dest/shared/gas_portal_test_harness.d.ts +29 -31
- package/dest/shared/gas_portal_test_harness.d.ts.map +1 -1
- package/dest/shared/gas_portal_test_harness.js +51 -30
- package/dest/shared/index.d.ts +2 -2
- package/dest/shared/index.d.ts.map +1 -1
- package/dest/shared/jest_setup.d.ts +1 -1
- package/dest/shared/jest_setup.js +1 -1
- package/dest/shared/submit-transactions.d.ts +6 -4
- package/dest/shared/submit-transactions.d.ts.map +1 -1
- package/dest/shared/submit-transactions.js +8 -7
- package/dest/shared/uniswap_l1_l2.d.ts +3 -25
- package/dest/shared/uniswap_l1_l2.d.ts.map +1 -1
- package/dest/shared/uniswap_l1_l2.js +170 -120
- package/dest/simulators/index.d.ts +1 -1
- package/dest/simulators/lending_simulator.d.ts +7 -11
- package/dest/simulators/lending_simulator.d.ts.map +1 -1
- package/dest/simulators/lending_simulator.js +16 -17
- package/dest/simulators/token_simulator.d.ts +6 -3
- package/dest/simulators/token_simulator.d.ts.map +1 -1
- package/dest/simulators/token_simulator.js +16 -13
- package/dest/spartan/setup_test_wallets.d.ts +27 -11
- package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
- package/dest/spartan/setup_test_wallets.js +202 -58
- package/dest/spartan/tx_metrics.d.ts +39 -0
- package/dest/spartan/tx_metrics.d.ts.map +1 -0
- package/dest/spartan/tx_metrics.js +95 -0
- package/dest/spartan/utils.d.ts +151 -313
- package/dest/spartan/utils.d.ts.map +1 -1
- package/dest/spartan/utils.js +598 -151
- package/package.json +65 -58
- package/src/bench/client_flows/benchmark.ts +341 -0
- package/src/bench/client_flows/client_flows_benchmark.ts +450 -0
- package/src/bench/client_flows/config.ts +61 -0
- package/src/bench/client_flows/data_extractor.ts +89 -0
- package/src/bench/utils.ts +35 -81
- package/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +80 -77
- package/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +103 -122
- package/src/e2e_deploy_contract/deploy_test.ts +24 -39
- package/src/e2e_epochs/epochs_test.ts +299 -65
- package/src/e2e_fees/bridging_race.notest.ts +80 -0
- package/src/e2e_fees/fees_test.ts +150 -142
- package/src/e2e_l1_publisher/write_json.ts +74 -0
- package/src/e2e_multi_validator/utils.ts +258 -0
- package/src/e2e_nested_contract/nested_contract_test.ts +29 -19
- package/src/e2e_p2p/inactivity_slash_test.ts +179 -0
- package/src/e2e_p2p/p2p_network.ts +274 -171
- package/src/e2e_p2p/shared.ts +252 -29
- package/src/e2e_token_contract/token_contract_test.ts +43 -39
- package/src/fixtures/dumps/epoch_proof_result.json +1 -1
- package/src/{e2e_prover → fixtures}/e2e_prover_test.ts +112 -160
- package/src/fixtures/fixtures.ts +5 -7
- package/src/fixtures/get_acvm_config.ts +4 -12
- package/src/fixtures/get_bb_config.ts +18 -13
- package/src/fixtures/l1_to_l2_messaging.ts +56 -24
- package/src/fixtures/setup_p2p_test.ts +127 -39
- package/src/fixtures/snapshot_manager.ts +189 -160
- package/src/fixtures/token_utils.ts +32 -15
- package/src/fixtures/utils.ts +556 -475
- package/src/fixtures/web3signer.ts +63 -0
- package/src/fixtures/with_telemetry_utils.ts +2 -2
- package/src/guides/up_quick_start.sh +7 -15
- package/src/quality_of_service/{alert_checker.ts → grafana_client.ts} +2 -2
- package/src/shared/cross_chain_test_harness.ts +113 -87
- package/src/shared/gas_portal_test_harness.ts +59 -50
- package/src/shared/index.ts +1 -1
- package/src/shared/jest_setup.ts +1 -1
- package/src/shared/submit-transactions.ts +12 -8
- package/src/shared/uniswap_l1_l2.ts +194 -211
- package/src/simulators/lending_simulator.ts +15 -16
- package/src/simulators/token_simulator.ts +21 -13
- package/src/spartan/DEVELOP.md +128 -0
- package/src/spartan/setup_test_wallets.ts +258 -93
- package/src/spartan/tx_metrics.ts +130 -0
- package/src/spartan/utils.ts +722 -146
- package/dest/e2e_prover/e2e_prover_test.d.ts +0 -56
- package/dest/e2e_prover/e2e_prover_test.d.ts.map +0 -1
- package/dest/fixtures/setup_l1_contracts.d.ts +0 -6
- package/dest/fixtures/setup_l1_contracts.d.ts.map +0 -1
- package/dest/fixtures/setup_l1_contracts.js +0 -17
- package/dest/quality_of_service/alert_checker.d.ts +0 -41
- package/dest/quality_of_service/alert_checker.d.ts.map +0 -1
- package/dest/sample-dapp/connect.js +0 -12
- package/dest/sample-dapp/contracts.js +0 -10
- package/dest/sample-dapp/deploy.js +0 -35
- package/dest/sample-dapp/index.js +0 -98
- package/src/fixtures/setup_l1_contracts.ts +0 -27
- package/src/sample-dapp/connect.mjs +0 -16
- package/src/sample-dapp/contracts.mjs +0 -14
- package/src/sample-dapp/deploy.mjs +0 -40
- package/src/sample-dapp/index.mjs +0 -128
|
@@ -1,30 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
} from '@aztec/
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
deployL1Contract,
|
|
18
|
-
extractEvent,
|
|
19
|
-
} from '@aztec/ethereum';
|
|
20
|
-
import { sha256ToField } from '@aztec/foundation/crypto';
|
|
21
|
-
import { InboxAbi, RollupAbi, UniswapPortalAbi, UniswapPortalBytecode } from '@aztec/l1-artifacts';
|
|
1
|
+
import { AztecAddress, EthAddress } from '@aztec/aztec.js/addresses';
|
|
2
|
+
import { computeAuthWitMessageHash } from '@aztec/aztec.js/authorization';
|
|
3
|
+
import { waitForProven } from '@aztec/aztec.js/contracts';
|
|
4
|
+
import { generateClaimSecret } from '@aztec/aztec.js/ethereum';
|
|
5
|
+
import { Fr } from '@aztec/aztec.js/fields';
|
|
6
|
+
import type { Logger } from '@aztec/aztec.js/log';
|
|
7
|
+
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
8
|
+
import { CheatCodes } from '@aztec/aztec/testing';
|
|
9
|
+
import { RollupContract } from '@aztec/ethereum/contracts';
|
|
10
|
+
import type { DeployAztecL1ContractsReturnType } from '@aztec/ethereum/deploy-aztec-l1-contracts';
|
|
11
|
+
import { deployL1Contract } from '@aztec/ethereum/deploy-l1-contract';
|
|
12
|
+
import type { ExtendedViemWalletClient } from '@aztec/ethereum/types';
|
|
13
|
+
import { extractEvent } from '@aztec/ethereum/utils';
|
|
14
|
+
import { CheckpointNumber, EpochNumber } from '@aztec/foundation/branded-types';
|
|
15
|
+
import { sha256ToField } from '@aztec/foundation/crypto/sha256';
|
|
16
|
+
import { InboxAbi, UniswapPortalAbi, UniswapPortalBytecode } from '@aztec/l1-artifacts';
|
|
22
17
|
import { UniswapContract } from '@aztec/noir-contracts.js/Uniswap';
|
|
18
|
+
import { computeL2ToL1MessageHash } from '@aztec/stdlib/hash';
|
|
19
|
+
import { computeL2ToL1MembershipWitness } from '@aztec/stdlib/messaging';
|
|
20
|
+
import type { TestWallet } from '@aztec/test-wallet/server';
|
|
23
21
|
|
|
24
22
|
import { jest } from '@jest/globals';
|
|
25
23
|
import { type GetContractReturnType, getContract, parseEther, toFunctionSelector } from 'viem';
|
|
26
24
|
|
|
27
|
-
import {
|
|
25
|
+
import { type EndToEndContext, ensureAccountContractsPublished } from '../fixtures/utils.js';
|
|
28
26
|
import { CrossChainTestHarness } from './cross_chain_test_harness.js';
|
|
29
27
|
|
|
30
28
|
// PSA: This tests works on forked mainnet. There is a dump of the data in `dumpedState` such that we
|
|
@@ -34,38 +32,13 @@ import { CrossChainTestHarness } from './cross_chain_test_harness.js';
|
|
|
34
32
|
// anvil --fork-url https://mainnet.infura.io/v3/9928b52099854248b3a096be07a6b23c --fork-block-number 17514288 --chain-id 31337
|
|
35
33
|
// For CI, this is configured in `run_tests.sh` and `docker-compose-images.yml`
|
|
36
34
|
|
|
37
|
-
// docs:start:uniswap_l1_l2_test_setup_const
|
|
38
35
|
const TIMEOUT = 360_000;
|
|
39
36
|
|
|
40
|
-
/** Objects to be returned by the uniswap setup function */
|
|
41
|
-
export type UniswapSetupContext = {
|
|
42
|
-
/** Aztec Node instance */
|
|
43
|
-
aztecNode: AztecNode;
|
|
44
|
-
/** The Private eXecution Environment (PXE). */
|
|
45
|
-
pxe: PXE;
|
|
46
|
-
/** Logger instance named as the current test. */
|
|
47
|
-
logger: Logger;
|
|
48
|
-
/** Viem Public client instance. */
|
|
49
|
-
publicClient: ViemPublicClient;
|
|
50
|
-
/** Viem Wallet Client instance. */
|
|
51
|
-
walletClient: ViemWalletClient;
|
|
52
|
-
/** The owner wallet. */
|
|
53
|
-
ownerWallet: AccountWallet;
|
|
54
|
-
/** The sponsor wallet. */
|
|
55
|
-
sponsorWallet: AccountWallet;
|
|
56
|
-
/** */
|
|
57
|
-
deployL1ContractsValues: DeployL1ContractsReturnType;
|
|
58
|
-
/** Cheat codes instance. */
|
|
59
|
-
cheatCodes: CheatCodes;
|
|
60
|
-
};
|
|
61
|
-
// docs:end:uniswap_l1_l2_test_setup_const
|
|
62
|
-
|
|
63
37
|
export const uniswapL1L2TestSuite = (
|
|
64
|
-
setup: () => Promise<
|
|
38
|
+
setup: () => Promise<EndToEndContext>,
|
|
65
39
|
cleanup: () => Promise<void>,
|
|
66
40
|
expectedForkBlockNumber = 17514288,
|
|
67
41
|
) => {
|
|
68
|
-
// docs:start:uniswap_l1_l2_test_beforeAll
|
|
69
42
|
describe('uniswap_trade_on_l1_from_l2', () => {
|
|
70
43
|
jest.setTimeout(TIMEOUT);
|
|
71
44
|
|
|
@@ -73,25 +46,22 @@ export const uniswapL1L2TestSuite = (
|
|
|
73
46
|
const DAI_ADDRESS: EthAddress = EthAddress.fromString('0x6B175474E89094C44Da98b954EedeAC495271d0F');
|
|
74
47
|
|
|
75
48
|
let aztecNode: AztecNode;
|
|
76
|
-
let pxe: PXE;
|
|
77
49
|
let logger: Logger;
|
|
78
50
|
|
|
79
|
-
let
|
|
80
|
-
let publicClient: ViemPublicClient;
|
|
51
|
+
let l1Client: ExtendedViemWalletClient;
|
|
81
52
|
|
|
82
|
-
let
|
|
53
|
+
let wallet: TestWallet;
|
|
83
54
|
let ownerAddress: AztecAddress;
|
|
84
55
|
let ownerEthAddress: EthAddress;
|
|
85
56
|
// does transactions on behalf of owner on Aztec:
|
|
86
|
-
let
|
|
87
|
-
// let sponsorAddress: AztecAddress;
|
|
57
|
+
let sponsorAddress: AztecAddress;
|
|
88
58
|
|
|
89
59
|
let daiCrossChainHarness: CrossChainTestHarness;
|
|
90
60
|
let wethCrossChainHarness: CrossChainTestHarness;
|
|
91
61
|
|
|
92
|
-
let deployL1ContractsValues:
|
|
93
|
-
let rollup:
|
|
94
|
-
let uniswapPortal: GetContractReturnType<typeof UniswapPortalAbi,
|
|
62
|
+
let deployL1ContractsValues: DeployAztecL1ContractsReturnType;
|
|
63
|
+
let rollup: RollupContract;
|
|
64
|
+
let uniswapPortal: GetContractReturnType<typeof UniswapPortalAbi, ExtendedViemWalletClient>;
|
|
95
65
|
let uniswapPortalAddress: EthAddress;
|
|
96
66
|
let uniswapL2Contract: UniswapContract;
|
|
97
67
|
|
|
@@ -100,43 +70,41 @@ export const uniswapL1L2TestSuite = (
|
|
|
100
70
|
const minimumOutputAmount = 0n;
|
|
101
71
|
|
|
102
72
|
let cheatCodes: CheatCodes;
|
|
103
|
-
|
|
73
|
+
let version: number;
|
|
104
74
|
beforeAll(async () => {
|
|
75
|
+
const t = await setup();
|
|
105
76
|
({
|
|
106
77
|
aztecNode,
|
|
107
|
-
pxe,
|
|
108
78
|
logger,
|
|
109
|
-
publicClient,
|
|
110
|
-
walletClient,
|
|
111
|
-
ownerWallet,
|
|
112
|
-
sponsorWallet,
|
|
113
79
|
deployL1ContractsValues,
|
|
114
80
|
cheatCodes,
|
|
115
|
-
|
|
81
|
+
wallet,
|
|
82
|
+
accounts: [ownerAddress, sponsorAddress],
|
|
83
|
+
} = t);
|
|
84
|
+
|
|
85
|
+
l1Client = deployL1ContractsValues.l1Client;
|
|
86
|
+
|
|
87
|
+
t.watcher?.setIsMarkingAsProven(false);
|
|
116
88
|
|
|
117
|
-
if (Number(await
|
|
89
|
+
if (Number(await l1Client.getBlockNumber()) < expectedForkBlockNumber) {
|
|
118
90
|
throw new Error('This test must be run on a fork of mainnet with the expected fork block');
|
|
119
91
|
}
|
|
120
92
|
|
|
121
|
-
rollup =
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
ownerAddress = ownerWallet.getAddress();
|
|
128
|
-
// sponsorAddress = sponsorWallet.getAddress();
|
|
129
|
-
ownerEthAddress = EthAddress.fromString((await walletClient.getAddresses())[0]);
|
|
93
|
+
rollup = new RollupContract(
|
|
94
|
+
deployL1ContractsValues.l1Client,
|
|
95
|
+
deployL1ContractsValues.l1ContractAddresses.rollupAddress,
|
|
96
|
+
);
|
|
97
|
+
version = Number(await rollup.getVersion());
|
|
98
|
+
ownerEthAddress = EthAddress.fromString((await l1Client.getAddresses())[0]);
|
|
130
99
|
|
|
131
|
-
await
|
|
100
|
+
await ensureAccountContractsPublished(wallet, [ownerAddress, sponsorAddress]);
|
|
132
101
|
|
|
133
102
|
logger.info('Deploying DAI Portal, initializing and deploying l2 contract...');
|
|
134
103
|
daiCrossChainHarness = await CrossChainTestHarness.new(
|
|
135
104
|
aztecNode,
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
ownerWallet,
|
|
105
|
+
deployL1ContractsValues.l1Client,
|
|
106
|
+
wallet,
|
|
107
|
+
ownerAddress,
|
|
140
108
|
logger,
|
|
141
109
|
DAI_ADDRESS,
|
|
142
110
|
);
|
|
@@ -144,31 +112,29 @@ export const uniswapL1L2TestSuite = (
|
|
|
144
112
|
logger.info('Deploying WETH Portal, initializing and deploying l2 contract...');
|
|
145
113
|
wethCrossChainHarness = await CrossChainTestHarness.new(
|
|
146
114
|
aztecNode,
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
ownerWallet,
|
|
115
|
+
l1Client,
|
|
116
|
+
wallet,
|
|
117
|
+
ownerAddress,
|
|
151
118
|
logger,
|
|
152
119
|
WETH9_ADDRESS,
|
|
153
120
|
);
|
|
154
121
|
|
|
155
122
|
logger.info('Deploy Uniswap portal on L1 and L2...');
|
|
156
|
-
uniswapPortalAddress = await deployL1Contract(
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
UniswapPortalAbi,
|
|
160
|
-
UniswapPortalBytecode,
|
|
161
|
-
).then(({ address }) => address);
|
|
123
|
+
uniswapPortalAddress = await deployL1Contract(l1Client, UniswapPortalAbi, UniswapPortalBytecode).then(
|
|
124
|
+
({ address }) => address,
|
|
125
|
+
);
|
|
162
126
|
|
|
163
127
|
uniswapPortal = getContract({
|
|
164
128
|
address: uniswapPortalAddress.toString(),
|
|
165
129
|
abi: UniswapPortalAbi,
|
|
166
|
-
client:
|
|
130
|
+
client: l1Client,
|
|
167
131
|
});
|
|
168
132
|
// deploy l2 uniswap contract and attach to portal
|
|
169
|
-
uniswapL2Contract = await UniswapContract.deploy(
|
|
133
|
+
uniswapL2Contract = await UniswapContract.deploy(wallet, uniswapPortalAddress)
|
|
134
|
+
.send({ from: ownerAddress })
|
|
135
|
+
.deployed();
|
|
170
136
|
|
|
171
|
-
const registryAddress = (await
|
|
137
|
+
const registryAddress = (await aztecNode.getNodeInfo()).l1ContractAddresses.registryAddress;
|
|
172
138
|
|
|
173
139
|
await uniswapPortal.write.initialize(
|
|
174
140
|
[registryAddress.toString(), uniswapL2Contract.address.toString()],
|
|
@@ -177,13 +143,12 @@ export const uniswapL1L2TestSuite = (
|
|
|
177
143
|
|
|
178
144
|
// Give me some WETH so I can deposit to L2 and do the swap...
|
|
179
145
|
logger.info('Getting some weth');
|
|
180
|
-
const hash = await
|
|
181
|
-
await
|
|
146
|
+
const hash = await l1Client.sendTransaction({ to: WETH9_ADDRESS.toString(), value: parseEther('1000') });
|
|
147
|
+
await l1Client.waitForTransactionReceipt({ hash });
|
|
182
148
|
|
|
183
149
|
const wethBalance = await wethCrossChainHarness.getL1BalanceOf(ownerEthAddress);
|
|
184
150
|
expect(wethBalance).toBe(parseEther('1000'));
|
|
185
151
|
});
|
|
186
|
-
// docs:end:uniswap_l1_l2_test_beforeAll
|
|
187
152
|
|
|
188
153
|
afterAll(async () => {
|
|
189
154
|
await cleanup();
|
|
@@ -218,7 +183,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
218
183
|
// 3. Owner gives uniswap approval to transfer the funds to public to self on its behalf
|
|
219
184
|
logger.info('Approving uniswap to transfer funds to public to self on my behalf');
|
|
220
185
|
const nonceForWETHTransferToPublicApproval = new Fr(1n);
|
|
221
|
-
await
|
|
186
|
+
const transferToPublicAuhtwit = await wallet.createAuthWit(ownerAddress, {
|
|
222
187
|
caller: uniswapL2Contract.address,
|
|
223
188
|
action: wethCrossChainHarness.l2Token.methods.transfer_to_public(
|
|
224
189
|
ownerAddress,
|
|
@@ -244,7 +209,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
244
209
|
secretHashForDepositingSwappedDai,
|
|
245
210
|
ownerEthAddress,
|
|
246
211
|
)
|
|
247
|
-
.send()
|
|
212
|
+
.send({ from: ownerAddress, authWitnesses: [transferToPublicAuhtwit] })
|
|
248
213
|
.wait();
|
|
249
214
|
|
|
250
215
|
const swapPrivateFunction = 'swap_private(address,uint256,uint24,address,uint256,bytes32,address)';
|
|
@@ -259,13 +224,13 @@ export const uniswapL1L2TestSuite = (
|
|
|
259
224
|
ownerEthAddress.toBuffer32(),
|
|
260
225
|
]);
|
|
261
226
|
|
|
262
|
-
const swapPrivateLeaf =
|
|
263
|
-
uniswapL2Contract.address,
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
new Fr(
|
|
267
|
-
|
|
268
|
-
|
|
227
|
+
const swapPrivateLeaf = computeL2ToL1MessageHash({
|
|
228
|
+
l2Sender: uniswapL2Contract.address,
|
|
229
|
+
l1Recipient: EthAddress.fromString(uniswapPortal.address),
|
|
230
|
+
content: swapPrivateContent,
|
|
231
|
+
rollupVersion: new Fr(version),
|
|
232
|
+
chainId: new Fr(l1Client.chain.id),
|
|
233
|
+
});
|
|
269
234
|
|
|
270
235
|
const withdrawContent = sha256ToField([
|
|
271
236
|
Buffer.from(toFunctionSelector('withdraw(address,uint256,address)').substring(2), 'hex'),
|
|
@@ -274,39 +239,41 @@ export const uniswapL1L2TestSuite = (
|
|
|
274
239
|
uniswapPortalAddress.toBuffer32(),
|
|
275
240
|
]);
|
|
276
241
|
|
|
277
|
-
const withdrawLeaf =
|
|
278
|
-
wethCrossChainHarness.l2Bridge.address,
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
new Fr(
|
|
282
|
-
|
|
283
|
-
|
|
242
|
+
const withdrawLeaf = computeL2ToL1MessageHash({
|
|
243
|
+
l2Sender: wethCrossChainHarness.l2Bridge.address,
|
|
244
|
+
l1Recipient: wethCrossChainHarness.tokenPortalAddress,
|
|
245
|
+
content: withdrawContent,
|
|
246
|
+
rollupVersion: new Fr(version),
|
|
247
|
+
chainId: new Fr(l1Client.chain.id),
|
|
248
|
+
});
|
|
284
249
|
|
|
285
250
|
// ensure that user's funds were burnt
|
|
286
251
|
await wethCrossChainHarness.expectPrivateBalanceOnL2(ownerAddress, wethL2BalanceBeforeSwap - wethAmountToBridge);
|
|
287
252
|
// ensure that uniswap contract didn't eat the funds.
|
|
288
253
|
await wethCrossChainHarness.expectPublicBalanceOnL2(uniswapL2Contract.address, 0n);
|
|
289
254
|
|
|
290
|
-
// Since the outbox is only consumable when the
|
|
291
|
-
|
|
255
|
+
// Since the outbox is only consumable when the epoch is proven, we need to advance to the next epoch.
|
|
256
|
+
const checkpointNumber = CheckpointNumber.fromBlockNumber(l2UniswapInteractionReceipt.blockNumber!);
|
|
257
|
+
const epoch = await rollup.getEpochNumberForCheckpoint(checkpointNumber);
|
|
258
|
+
await cheatCodes.rollup.advanceToEpoch(EpochNumber(epoch + 1));
|
|
259
|
+
await waitForProven(aztecNode, l2UniswapInteractionReceipt, { provenTimeout: 300 });
|
|
292
260
|
|
|
293
261
|
// 5. Consume L2 to L1 message by calling uniswapPortal.swap_private()
|
|
294
262
|
logger.info('Execute withdraw and swap on the uniswapPortal!');
|
|
295
263
|
const daiL1BalanceOfPortalBeforeSwap = await daiCrossChainHarness.getL1BalanceOf(
|
|
296
264
|
daiCrossChainHarness.tokenPortalAddress,
|
|
297
265
|
);
|
|
266
|
+
const swapResult = await computeL2ToL1MembershipWitness(aztecNode, epoch, swapPrivateLeaf);
|
|
267
|
+
const withdrawResult = await computeL2ToL1MembershipWitness(aztecNode, epoch, withdrawLeaf);
|
|
298
268
|
|
|
299
|
-
const
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
const
|
|
304
|
-
l2UniswapInteractionReceipt.blockNumber!,
|
|
305
|
-
withdrawLeaf,
|
|
306
|
-
);
|
|
269
|
+
const swapPrivateL2MessageIndex = swapResult!.leafIndex;
|
|
270
|
+
const swapPrivateSiblingPath = swapResult!.siblingPath;
|
|
271
|
+
|
|
272
|
+
const withdrawL2MessageIndex = withdrawResult!.leafIndex;
|
|
273
|
+
const withdrawSiblingPath = withdrawResult!.siblingPath;
|
|
307
274
|
|
|
308
275
|
const withdrawMessageMetadata = {
|
|
309
|
-
|
|
276
|
+
_epoch: BigInt(epoch),
|
|
310
277
|
_leafIndex: BigInt(withdrawL2MessageIndex),
|
|
311
278
|
_path: withdrawSiblingPath
|
|
312
279
|
.toBufferArray()
|
|
@@ -314,7 +281,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
314
281
|
};
|
|
315
282
|
|
|
316
283
|
const swapPrivateMessageMetadata = {
|
|
317
|
-
|
|
284
|
+
_epoch: BigInt(epoch),
|
|
318
285
|
_leafIndex: BigInt(swapPrivateL2MessageIndex),
|
|
319
286
|
_path: swapPrivateSiblingPath
|
|
320
287
|
.toBufferArray()
|
|
@@ -333,7 +300,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
333
300
|
] as const;
|
|
334
301
|
|
|
335
302
|
// this should also insert a message into the inbox.
|
|
336
|
-
const txReceipt = await daiCrossChainHarness.
|
|
303
|
+
const txReceipt = await daiCrossChainHarness.l1Client.waitForTransactionReceipt({
|
|
337
304
|
hash: await uniswapPortal.write.swapPrivate(swapArgs),
|
|
338
305
|
});
|
|
339
306
|
|
|
@@ -525,7 +492,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
525
492
|
// );
|
|
526
493
|
|
|
527
494
|
// const withdrawMessageMetadata = {
|
|
528
|
-
//
|
|
495
|
+
// _epoch: epoch,
|
|
529
496
|
// _leafIndex: BigInt(withdrawL2MessageIndex),
|
|
530
497
|
// _path: withdrawSiblingPath
|
|
531
498
|
// .toBufferArray()
|
|
@@ -533,7 +500,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
533
500
|
// };
|
|
534
501
|
|
|
535
502
|
// const swapPrivateMessageMetadata = {
|
|
536
|
-
//
|
|
503
|
+
// _epoch: epoch,
|
|
537
504
|
// _leafIndex: BigInt(swapPrivateL2MessageIndex),
|
|
538
505
|
// _path: swapPrivateSiblingPath
|
|
539
506
|
// .toBufferArray()
|
|
@@ -620,14 +587,16 @@ export const uniswapL1L2TestSuite = (
|
|
|
620
587
|
const expectedMessageHash = await computeAuthWitMessageHash(
|
|
621
588
|
{
|
|
622
589
|
caller: uniswapL2Contract.address,
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
590
|
+
call: await wethCrossChainHarness.l2Token.methods
|
|
591
|
+
.transfer_to_public(
|
|
592
|
+
ownerAddress,
|
|
593
|
+
uniswapL2Contract.address,
|
|
594
|
+
wethAmountToBridge,
|
|
595
|
+
nonceForWETHTransferToPublicApproval,
|
|
596
|
+
)
|
|
597
|
+
.getFunctionCall(),
|
|
629
598
|
},
|
|
630
|
-
|
|
599
|
+
await wallet.getChainInfo(),
|
|
631
600
|
);
|
|
632
601
|
|
|
633
602
|
await expect(
|
|
@@ -643,7 +612,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
643
612
|
Fr.random(),
|
|
644
613
|
ownerEthAddress,
|
|
645
614
|
)
|
|
646
|
-
.
|
|
615
|
+
.simulate({ from: ownerAddress }),
|
|
647
616
|
).rejects.toThrow(`Unknown auth witness for message hash ${expectedMessageHash.toString()}`);
|
|
648
617
|
});
|
|
649
618
|
|
|
@@ -655,7 +624,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
655
624
|
// 2. owner gives uniswap approval to transfer the funds to public:
|
|
656
625
|
logger.info('Approving uniswap to transfer funds to public to self on my behalf');
|
|
657
626
|
const nonceForWETHTransferToPublicApproval = new Fr(3n);
|
|
658
|
-
await
|
|
627
|
+
const transferToPublicAuthwith = await wallet.createAuthWit(ownerAddress, {
|
|
659
628
|
caller: uniswapL2Contract.address,
|
|
660
629
|
action: wethCrossChainHarness.l2Token.methods.transfer_to_public(
|
|
661
630
|
ownerAddress,
|
|
@@ -680,7 +649,8 @@ export const uniswapL1L2TestSuite = (
|
|
|
680
649
|
Fr.random(),
|
|
681
650
|
ownerEthAddress,
|
|
682
651
|
)
|
|
683
|
-
.
|
|
652
|
+
.send({ from: ownerAddress, authWitnesses: [transferToPublicAuthwith] })
|
|
653
|
+
.wait(),
|
|
684
654
|
).rejects.toThrow('Assertion failed: input_asset address is not the same as seen in the bridge contract');
|
|
685
655
|
});
|
|
686
656
|
|
|
@@ -692,7 +662,8 @@ export const uniswapL1L2TestSuite = (
|
|
|
692
662
|
|
|
693
663
|
// 2. Give approval to uniswap to transfer funds to itself
|
|
694
664
|
const nonceForWETHTransferApproval = new Fr(2n);
|
|
695
|
-
const validateActionInteraction = await
|
|
665
|
+
const validateActionInteraction = await wallet.setPublicAuthWit(
|
|
666
|
+
ownerAddress,
|
|
696
667
|
{
|
|
697
668
|
caller: uniswapL2Contract.address,
|
|
698
669
|
action: wethCrossChainHarness.l2Token.methods.transfer_in_public(
|
|
@@ -723,7 +694,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
723
694
|
ownerEthAddress,
|
|
724
695
|
Fr.ZERO, // nonce for swap -> doesn't matter
|
|
725
696
|
)
|
|
726
|
-
.send()
|
|
697
|
+
.send({ from: ownerAddress })
|
|
727
698
|
.wait();
|
|
728
699
|
// check weth balance of owner on L2 (we first bridged `wethAmountToBridge` into L2 and now withdrew it!)
|
|
729
700
|
await wethCrossChainHarness.expectPublicBalanceOnL2(ownerAddress, 0n);
|
|
@@ -736,32 +707,35 @@ export const uniswapL1L2TestSuite = (
|
|
|
736
707
|
const nonceForWETHTransferApproval = new Fr(3n);
|
|
737
708
|
const nonceForSwap = new Fr(3n);
|
|
738
709
|
const secretHashForDepositingSwappedDai = new Fr(4n);
|
|
739
|
-
const action = uniswapL2Contract
|
|
740
|
-
|
|
741
|
-
.
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
710
|
+
const action = uniswapL2Contract.methods.swap_public(
|
|
711
|
+
ownerAddress,
|
|
712
|
+
wethCrossChainHarness.l2Bridge.address,
|
|
713
|
+
wethAmountToBridge,
|
|
714
|
+
daiCrossChainHarness.l2Bridge.address,
|
|
715
|
+
nonceForWETHTransferApproval,
|
|
716
|
+
uniswapFeeTier,
|
|
717
|
+
minimumOutputAmount,
|
|
718
|
+
ownerAddress,
|
|
719
|
+
secretHashForDepositingSwappedDai,
|
|
720
|
+
ownerEthAddress,
|
|
721
|
+
nonceForSwap,
|
|
722
|
+
);
|
|
723
|
+
const validateActionInteraction = await wallet.setPublicAuthWit(
|
|
724
|
+
ownerAddress,
|
|
725
|
+
{ caller: approvedUser, action },
|
|
726
|
+
true,
|
|
727
|
+
);
|
|
755
728
|
await validateActionInteraction.send().wait();
|
|
756
729
|
|
|
757
|
-
await expect(action.simulate()).rejects.toThrow(/unauthorized/);
|
|
730
|
+
await expect(action.simulate({ from: sponsorAddress })).rejects.toThrow(/unauthorized/);
|
|
758
731
|
});
|
|
759
732
|
|
|
760
733
|
it("uniswap can't pull funds without transfer approval", async () => {
|
|
761
734
|
// swap should fail since no transfer approval to uniswap:
|
|
762
735
|
const nonceForWETHTransferApproval = new Fr(4n);
|
|
763
736
|
|
|
764
|
-
const validateActionInteraction = await
|
|
737
|
+
const validateActionInteraction = await wallet.setPublicAuthWit(
|
|
738
|
+
ownerAddress,
|
|
765
739
|
{
|
|
766
740
|
caller: uniswapL2Contract.address,
|
|
767
741
|
action: wethCrossChainHarness.l2Token.methods.transfer_in_public(
|
|
@@ -790,7 +764,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
790
764
|
ownerEthAddress,
|
|
791
765
|
Fr.ZERO,
|
|
792
766
|
)
|
|
793
|
-
.simulate(),
|
|
767
|
+
.simulate({ from: ownerAddress }),
|
|
794
768
|
).rejects.toThrow(/unauthorized/);
|
|
795
769
|
});
|
|
796
770
|
|
|
@@ -803,7 +777,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
803
777
|
// Owner gives uniswap approval to transfer the funds to public to self on its behalf
|
|
804
778
|
logger.info('Approving uniswap to transfer the funds to public to self on my behalf');
|
|
805
779
|
const nonceForWETHTransferToPublicApproval = new Fr(4n);
|
|
806
|
-
await
|
|
780
|
+
const transferToPublicAuhtwit = await wallet.createAuthWit(ownerAddress, {
|
|
807
781
|
caller: uniswapL2Contract.address,
|
|
808
782
|
action: wethCrossChainHarness.l2Token.methods.transfer_to_public(
|
|
809
783
|
ownerAddress,
|
|
@@ -830,7 +804,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
830
804
|
secretHashForDepositingSwappedDai,
|
|
831
805
|
ownerEthAddress,
|
|
832
806
|
)
|
|
833
|
-
.send()
|
|
807
|
+
.send({ from: ownerAddress, authWitnesses: [transferToPublicAuhtwit] })
|
|
834
808
|
.wait();
|
|
835
809
|
|
|
836
810
|
const swapPrivateContent = sha256ToField([
|
|
@@ -847,13 +821,13 @@ export const uniswapL1L2TestSuite = (
|
|
|
847
821
|
ownerEthAddress.toBuffer32(),
|
|
848
822
|
]);
|
|
849
823
|
|
|
850
|
-
const swapPrivateLeaf =
|
|
851
|
-
uniswapL2Contract.address,
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
new Fr(
|
|
855
|
-
|
|
856
|
-
|
|
824
|
+
const swapPrivateLeaf = computeL2ToL1MessageHash({
|
|
825
|
+
l2Sender: uniswapL2Contract.address,
|
|
826
|
+
l1Recipient: EthAddress.fromString(uniswapPortal.address),
|
|
827
|
+
content: swapPrivateContent,
|
|
828
|
+
rollupVersion: new Fr(version),
|
|
829
|
+
chainId: new Fr(l1Client.chain.id),
|
|
830
|
+
});
|
|
857
831
|
|
|
858
832
|
const withdrawContent = sha256ToField([
|
|
859
833
|
Buffer.from(toFunctionSelector('withdraw(address,uint256,address)').substring(2), 'hex'),
|
|
@@ -862,25 +836,28 @@ export const uniswapL1L2TestSuite = (
|
|
|
862
836
|
uniswapPortalAddress.toBuffer32(),
|
|
863
837
|
]);
|
|
864
838
|
|
|
865
|
-
const withdrawLeaf =
|
|
866
|
-
wethCrossChainHarness.l2Bridge.address,
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
new Fr(
|
|
870
|
-
|
|
871
|
-
|
|
839
|
+
const withdrawLeaf = computeL2ToL1MessageHash({
|
|
840
|
+
l2Sender: wethCrossChainHarness.l2Bridge.address,
|
|
841
|
+
l1Recipient: wethCrossChainHarness.tokenPortalAddress,
|
|
842
|
+
content: withdrawContent,
|
|
843
|
+
rollupVersion: new Fr(version),
|
|
844
|
+
chainId: new Fr(l1Client.chain.id),
|
|
845
|
+
});
|
|
872
846
|
|
|
873
|
-
const
|
|
874
|
-
withdrawReceipt.blockNumber
|
|
875
|
-
swapPrivateLeaf,
|
|
876
|
-
);
|
|
877
|
-
const [withdrawL2MessageIndex, withdrawSiblingPath] = await aztecNode.getL2ToL1MessageMembershipWitness(
|
|
878
|
-
withdrawReceipt.blockNumber!,
|
|
879
|
-
withdrawLeaf,
|
|
847
|
+
const epoch = await rollup.getEpochNumberForCheckpoint(
|
|
848
|
+
CheckpointNumber.fromBlockNumber(withdrawReceipt.blockNumber!),
|
|
880
849
|
);
|
|
850
|
+
const swapResult = await computeL2ToL1MembershipWitness(aztecNode, epoch, swapPrivateLeaf);
|
|
851
|
+
const withdrawResult = await computeL2ToL1MembershipWitness(aztecNode, epoch, withdrawLeaf);
|
|
852
|
+
|
|
853
|
+
const swapPrivateL2MessageIndex = swapResult!.leafIndex;
|
|
854
|
+
const swapPrivateSiblingPath = swapResult!.siblingPath;
|
|
855
|
+
|
|
856
|
+
const withdrawL2MessageIndex = withdrawResult!.leafIndex;
|
|
857
|
+
const withdrawSiblingPath = withdrawResult!.siblingPath;
|
|
881
858
|
|
|
882
859
|
const withdrawMessageMetadata = {
|
|
883
|
-
|
|
860
|
+
_epoch: BigInt(epoch),
|
|
884
861
|
_leafIndex: BigInt(withdrawL2MessageIndex),
|
|
885
862
|
_path: withdrawSiblingPath
|
|
886
863
|
.toBufferArray()
|
|
@@ -888,7 +865,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
888
865
|
};
|
|
889
866
|
|
|
890
867
|
const swapPrivateMessageMetadata = {
|
|
891
|
-
|
|
868
|
+
_epoch: BigInt(epoch),
|
|
892
869
|
_leafIndex: BigInt(swapPrivateL2MessageIndex),
|
|
893
870
|
_path: swapPrivateSiblingPath
|
|
894
871
|
.toBufferArray()
|
|
@@ -898,8 +875,9 @@ export const uniswapL1L2TestSuite = (
|
|
|
898
875
|
// ensure that user's funds were burnt
|
|
899
876
|
await wethCrossChainHarness.expectPrivateBalanceOnL2(ownerAddress, wethL2BalanceBeforeSwap - wethAmountToBridge);
|
|
900
877
|
|
|
901
|
-
// Since the outbox is only consumable when the
|
|
902
|
-
await cheatCodes.rollup.
|
|
878
|
+
// Since the outbox is only consumable when the epoch is proven, we need to advance to the next epoch.
|
|
879
|
+
await cheatCodes.rollup.advanceToEpoch(EpochNumber(epoch + 1));
|
|
880
|
+
await waitForProven(aztecNode, withdrawReceipt, { provenTimeout: 300 });
|
|
903
881
|
|
|
904
882
|
// On L1 call swap_public!
|
|
905
883
|
logger.info('call swap_public on L1');
|
|
@@ -927,7 +905,8 @@ export const uniswapL1L2TestSuite = (
|
|
|
927
905
|
|
|
928
906
|
// Owner gives uniswap approval to transfer funds on its behalf
|
|
929
907
|
const nonceForWETHTransferApproval = new Fr(5n);
|
|
930
|
-
const validateActionInteraction = await
|
|
908
|
+
const validateActionInteraction = await wallet.setPublicAuthWit(
|
|
909
|
+
ownerAddress,
|
|
931
910
|
{
|
|
932
911
|
caller: uniswapL2Contract.address,
|
|
933
912
|
action: wethCrossChainHarness.l2Token.methods.transfer_in_public(
|
|
@@ -957,7 +936,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
957
936
|
ownerEthAddress,
|
|
958
937
|
Fr.ZERO,
|
|
959
938
|
)
|
|
960
|
-
.send()
|
|
939
|
+
.send({ from: ownerAddress })
|
|
961
940
|
.wait();
|
|
962
941
|
|
|
963
942
|
const swapPublicContent = sha256ToField([
|
|
@@ -977,13 +956,13 @@ export const uniswapL1L2TestSuite = (
|
|
|
977
956
|
ownerEthAddress.toBuffer32(),
|
|
978
957
|
]);
|
|
979
958
|
|
|
980
|
-
const swapPublicLeaf =
|
|
981
|
-
uniswapL2Contract.address,
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
new Fr(
|
|
985
|
-
|
|
986
|
-
|
|
959
|
+
const swapPublicLeaf = computeL2ToL1MessageHash({
|
|
960
|
+
l2Sender: uniswapL2Contract.address,
|
|
961
|
+
l1Recipient: EthAddress.fromString(uniswapPortal.address),
|
|
962
|
+
content: swapPublicContent,
|
|
963
|
+
rollupVersion: new Fr(version),
|
|
964
|
+
chainId: new Fr(l1Client.chain.id),
|
|
965
|
+
});
|
|
987
966
|
|
|
988
967
|
const withdrawContent = sha256ToField([
|
|
989
968
|
Buffer.from(toFunctionSelector('withdraw(address,uint256,address)').substring(2), 'hex'),
|
|
@@ -992,25 +971,28 @@ export const uniswapL1L2TestSuite = (
|
|
|
992
971
|
uniswapPortalAddress.toBuffer32(),
|
|
993
972
|
]);
|
|
994
973
|
|
|
995
|
-
const withdrawLeaf =
|
|
996
|
-
wethCrossChainHarness.l2Bridge.address,
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
new Fr(
|
|
1000
|
-
|
|
1001
|
-
|
|
974
|
+
const withdrawLeaf = computeL2ToL1MessageHash({
|
|
975
|
+
l2Sender: wethCrossChainHarness.l2Bridge.address,
|
|
976
|
+
l1Recipient: wethCrossChainHarness.tokenPortalAddress,
|
|
977
|
+
content: withdrawContent,
|
|
978
|
+
rollupVersion: new Fr(version),
|
|
979
|
+
chainId: new Fr(l1Client.chain.id),
|
|
980
|
+
});
|
|
1002
981
|
|
|
1003
|
-
const
|
|
1004
|
-
withdrawReceipt.blockNumber
|
|
1005
|
-
swapPublicLeaf,
|
|
1006
|
-
);
|
|
1007
|
-
const [withdrawL2MessageIndex, withdrawSiblingPath] = await aztecNode.getL2ToL1MessageMembershipWitness(
|
|
1008
|
-
withdrawReceipt.blockNumber!,
|
|
1009
|
-
withdrawLeaf,
|
|
982
|
+
const epoch = await rollup.getEpochNumberForCheckpoint(
|
|
983
|
+
CheckpointNumber.fromBlockNumber(withdrawReceipt.blockNumber!),
|
|
1010
984
|
);
|
|
985
|
+
const swapResult = await computeL2ToL1MembershipWitness(aztecNode, epoch, swapPublicLeaf);
|
|
986
|
+
const withdrawResult = await computeL2ToL1MembershipWitness(aztecNode, epoch, withdrawLeaf);
|
|
987
|
+
|
|
988
|
+
const swapPublicL2MessageIndex = swapResult!.leafIndex;
|
|
989
|
+
const swapPublicSiblingPath = swapResult!.siblingPath;
|
|
990
|
+
|
|
991
|
+
const withdrawL2MessageIndex = withdrawResult!.leafIndex;
|
|
992
|
+
const withdrawSiblingPath = withdrawResult!.siblingPath;
|
|
1011
993
|
|
|
1012
994
|
const withdrawMessageMetadata = {
|
|
1013
|
-
|
|
995
|
+
_epoch: BigInt(epoch),
|
|
1014
996
|
_leafIndex: BigInt(withdrawL2MessageIndex),
|
|
1015
997
|
_path: withdrawSiblingPath
|
|
1016
998
|
.toBufferArray()
|
|
@@ -1018,7 +1000,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
1018
1000
|
};
|
|
1019
1001
|
|
|
1020
1002
|
const swapPublicMessageMetadata = {
|
|
1021
|
-
|
|
1003
|
+
_epoch: BigInt(epoch),
|
|
1022
1004
|
_leafIndex: BigInt(swapPublicL2MessageIndex),
|
|
1023
1005
|
_path: swapPublicSiblingPath
|
|
1024
1006
|
.toBufferArray()
|
|
@@ -1028,8 +1010,9 @@ export const uniswapL1L2TestSuite = (
|
|
|
1028
1010
|
// check weth balance of owner on L2 (we first bridged `wethAmountToBridge` into L2 and now withdrew it!)
|
|
1029
1011
|
await wethCrossChainHarness.expectPublicBalanceOnL2(ownerAddress, 0n);
|
|
1030
1012
|
|
|
1031
|
-
// Since the outbox is only consumable when the
|
|
1032
|
-
await cheatCodes.rollup.
|
|
1013
|
+
// Since the outbox is only consumable when the epoch is proven, we need to advance to the next epoch.
|
|
1014
|
+
await cheatCodes.rollup.advanceToEpoch(EpochNumber(epoch + 1));
|
|
1015
|
+
await waitForProven(aztecNode, withdrawReceipt, { provenTimeout: 300 });
|
|
1033
1016
|
|
|
1034
1017
|
// Call swap_private on L1
|
|
1035
1018
|
logger.info('Execute withdraw and swap on the uniswapPortal!');
|