@aztec/end-to-end 0.0.0-test.1 → 0.0.1-fake-ceab37513c
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 +60 -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 +69 -0
- package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -0
- package/dest/bench/client_flows/client_flows_benchmark.js +315 -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 +99 -0
- package/dest/bench/utils.d.ts +10 -27
- package/dest/bench/utils.d.ts.map +1 -1
- package/dest/bench/utils.js +27 -43
- package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +15 -7
- 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 +66 -38
- package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +10 -18
- 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 +34 -53
- package/dest/e2e_deploy_contract/deploy_test.d.ts +4 -2
- package/dest/e2e_deploy_contract/deploy_test.d.ts.map +1 -1
- package/dest/e2e_deploy_contract/deploy_test.js +9 -6
- package/dest/e2e_epochs/epochs_test.d.ts +56 -17
- package/dest/e2e_epochs/epochs_test.d.ts.map +1 -1
- package/dest/e2e_epochs/epochs_test.js +222 -42
- 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 +60 -0
- package/dest/e2e_fees/fees_test.d.ts +16 -5
- package/dest/e2e_fees/fees_test.d.ts.map +1 -1
- package/dest/e2e_fees/fees_test.js +87 -88
- package/dest/e2e_l1_publisher/write_json.d.ts +8 -0
- package/dest/e2e_l1_publisher/write_json.d.ts.map +1 -0
- package/dest/e2e_l1_publisher/write_json.js +57 -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 +5 -5
- package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +1 -1
- package/dest/e2e_nested_contract/nested_contract_test.js +19 -14
- 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 +132 -0
- package/dest/e2e_p2p/p2p_network.d.ts +56 -21
- package/dest/e2e_p2p/p2p_network.d.ts.map +1 -1
- package/dest/e2e_p2p/p2p_network.js +154 -125
- package/dest/e2e_p2p/shared.d.ts +41 -3
- package/dest/e2e_p2p/shared.d.ts.map +1 -1
- package/dest/e2e_p2p/shared.js +146 -6
- package/dest/e2e_token_contract/token_contract_test.d.ts +10 -5
- package/dest/e2e_token_contract/token_contract_test.d.ts.map +1 -1
- package/dest/e2e_token_contract/token_contract_test.js +51 -24
- package/dest/{e2e_prover → fixtures}/e2e_prover_test.d.ts +7 -4
- package/dest/fixtures/e2e_prover_test.d.ts.map +1 -0
- package/dest/{e2e_prover → fixtures}/e2e_prover_test.js +67 -62
- package/dest/fixtures/fixtures.d.ts +5 -6
- package/dest/fixtures/fixtures.d.ts.map +1 -1
- package/dest/fixtures/fixtures.js +4 -3
- package/dest/fixtures/get_acvm_config.d.ts.map +1 -1
- package/dest/fixtures/get_acvm_config.js +2 -14
- package/dest/fixtures/get_bb_config.d.ts.map +1 -1
- package/dest/fixtures/get_bb_config.js +8 -15
- package/dest/fixtures/l1_to_l2_messaging.d.ts +8 -5
- package/dest/fixtures/l1_to_l2_messaging.d.ts.map +1 -1
- package/dest/fixtures/l1_to_l2_messaging.js +44 -18
- package/dest/fixtures/setup_l1_contracts.d.ts +3 -3
- package/dest/fixtures/setup_l1_contracts.d.ts.map +1 -1
- package/dest/fixtures/setup_l1_contracts.js +3 -3
- package/dest/fixtures/setup_p2p_test.d.ts +14 -6
- package/dest/fixtures/setup_p2p_test.d.ts.map +1 -1
- package/dest/fixtures/setup_p2p_test.js +73 -21
- package/dest/fixtures/snapshot_manager.d.ts +8 -3
- package/dest/fixtures/snapshot_manager.d.ts.map +1 -1
- package/dest/fixtures/snapshot_manager.js +120 -104
- package/dest/fixtures/token_utils.d.ts +4 -3
- package/dest/fixtures/token_utils.d.ts.map +1 -1
- package/dest/fixtures/token_utils.js +24 -7
- package/dest/fixtures/utils.d.ts +65 -22
- package/dest/fixtures/utils.d.ts.map +1 -1
- package/dest/fixtures/utils.js +439 -318
- package/dest/fixtures/web3signer.d.ts +5 -0
- package/dest/fixtures/web3signer.d.ts.map +1 -0
- package/dest/fixtures/web3signer.js +42 -0
- package/dest/shared/cross_chain_test_harness.d.ts +28 -18
- package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
- package/dest/shared/cross_chain_test_harness.js +97 -41
- package/dest/shared/gas_portal_test_harness.d.ts +23 -18
- package/dest/shared/gas_portal_test_harness.d.ts.map +1 -1
- package/dest/shared/gas_portal_test_harness.js +43 -25
- package/dest/shared/submit-transactions.d.ts.map +1 -1
- package/dest/shared/uniswap_l1_l2.d.ts +5 -6
- package/dest/shared/uniswap_l1_l2.d.ts.map +1 -1
- package/dest/shared/uniswap_l1_l2.js +136 -90
- package/dest/simulators/lending_simulator.d.ts +5 -6
- package/dest/simulators/lending_simulator.d.ts.map +1 -1
- package/dest/simulators/lending_simulator.js +11 -15
- package/dest/simulators/token_simulator.d.ts +2 -1
- 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 +8 -1
- package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
- package/dest/spartan/setup_test_wallets.js +108 -22
- package/dest/spartan/utils.d.ts +60 -307
- package/dest/spartan/utils.d.ts.map +1 -1
- package/dest/spartan/utils.js +200 -115
- package/package.json +60 -56
- package/src/bench/client_flows/benchmark.ts +341 -0
- package/src/bench/client_flows/client_flows_benchmark.ts +422 -0
- package/src/bench/client_flows/config.ts +61 -0
- package/src/bench/client_flows/data_extractor.ts +111 -0
- package/src/bench/utils.ts +26 -52
- package/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +60 -40
- package/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +47 -75
- package/src/e2e_deploy_contract/deploy_test.ts +11 -8
- package/src/e2e_epochs/epochs_test.ts +276 -54
- package/src/e2e_fees/bridging_race.notest.ts +75 -0
- package/src/e2e_fees/fees_test.ts +121 -108
- 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 +22 -14
- package/src/e2e_p2p/inactivity_slash_test.ts +174 -0
- package/src/e2e_p2p/p2p_network.ts +212 -144
- package/src/e2e_p2p/shared.ts +234 -14
- package/src/e2e_token_contract/token_contract_test.ts +42 -38
- package/src/fixtures/dumps/epoch_proof_result.json +1 -1
- package/src/{e2e_prover → fixtures}/e2e_prover_test.ts +62 -69
- package/src/fixtures/fixtures.ts +4 -3
- package/src/fixtures/get_acvm_config.ts +2 -10
- package/src/fixtures/get_bb_config.ts +15 -11
- package/src/fixtures/l1_to_l2_messaging.ts +53 -23
- package/src/fixtures/setup_l1_contracts.ts +5 -6
- package/src/fixtures/setup_p2p_test.ts +112 -30
- package/src/fixtures/snapshot_manager.ts +150 -102
- package/src/fixtures/token_utils.ts +33 -8
- package/src/fixtures/utils.ts +530 -352
- package/src/fixtures/web3signer.ts +46 -0
- package/src/guides/up_quick_start.sh +4 -4
- package/src/shared/cross_chain_test_harness.ts +92 -52
- package/src/shared/gas_portal_test_harness.ts +47 -31
- package/src/shared/uniswap_l1_l2.ts +127 -124
- package/src/simulators/lending_simulator.ts +11 -15
- package/src/simulators/token_simulator.ts +17 -12
- package/src/spartan/DEVELOP.md +116 -0
- package/src/spartan/setup_test_wallets.ts +144 -29
- package/src/spartan/utils.ts +194 -116
- package/dest/e2e_prover/e2e_prover_test.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/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
|
@@ -2,7 +2,6 @@ import {
|
|
|
2
2
|
type AccountWallet,
|
|
3
3
|
AztecAddress,
|
|
4
4
|
type AztecNode,
|
|
5
|
-
type CheatCodes,
|
|
6
5
|
EthAddress,
|
|
7
6
|
Fr,
|
|
8
7
|
type Logger,
|
|
@@ -10,21 +9,24 @@ import {
|
|
|
10
9
|
computeAuthWitMessageHash,
|
|
11
10
|
generateClaimSecret,
|
|
12
11
|
} from '@aztec/aztec.js';
|
|
12
|
+
import { CheatCodes } from '@aztec/aztec/testing';
|
|
13
13
|
import {
|
|
14
14
|
type DeployL1ContractsReturnType,
|
|
15
|
-
type
|
|
16
|
-
|
|
15
|
+
type ExtendedViemWalletClient,
|
|
16
|
+
RollupContract,
|
|
17
17
|
deployL1Contract,
|
|
18
18
|
extractEvent,
|
|
19
19
|
} from '@aztec/ethereum';
|
|
20
20
|
import { sha256ToField } from '@aztec/foundation/crypto';
|
|
21
|
-
import { InboxAbi,
|
|
21
|
+
import { InboxAbi, UniswapPortalAbi, UniswapPortalBytecode } from '@aztec/l1-artifacts';
|
|
22
22
|
import { UniswapContract } from '@aztec/noir-contracts.js/Uniswap';
|
|
23
|
+
import { computeL2ToL1MessageHash } from '@aztec/stdlib/hash';
|
|
24
|
+
import { computeL2ToL1MembershipWitness } from '@aztec/stdlib/messaging';
|
|
23
25
|
|
|
24
26
|
import { jest } from '@jest/globals';
|
|
25
27
|
import { type GetContractReturnType, getContract, parseEther, toFunctionSelector } from 'viem';
|
|
26
28
|
|
|
27
|
-
import {
|
|
29
|
+
import { ensureAccountContractsPublished } from '../fixtures/utils.js';
|
|
28
30
|
import { CrossChainTestHarness } from './cross_chain_test_harness.js';
|
|
29
31
|
|
|
30
32
|
// PSA: This tests works on forked mainnet. There is a dump of the data in `dumpedState` such that we
|
|
@@ -45,10 +47,8 @@ export type UniswapSetupContext = {
|
|
|
45
47
|
pxe: PXE;
|
|
46
48
|
/** Logger instance named as the current test. */
|
|
47
49
|
logger: Logger;
|
|
48
|
-
/**
|
|
49
|
-
|
|
50
|
-
/** Viem Wallet Client instance. */
|
|
51
|
-
walletClient: ViemWalletClient;
|
|
50
|
+
/** The L1 wallet client, extended with public actions. */
|
|
51
|
+
l1Client: ExtendedViemWalletClient;
|
|
52
52
|
/** The owner wallet. */
|
|
53
53
|
ownerWallet: AccountWallet;
|
|
54
54
|
/** The sponsor wallet. */
|
|
@@ -76,22 +76,21 @@ export const uniswapL1L2TestSuite = (
|
|
|
76
76
|
let pxe: PXE;
|
|
77
77
|
let logger: Logger;
|
|
78
78
|
|
|
79
|
-
let
|
|
80
|
-
let publicClient: ViemPublicClient;
|
|
79
|
+
let l1Client: ExtendedViemWalletClient;
|
|
81
80
|
|
|
82
81
|
let ownerWallet: AccountWallet;
|
|
83
82
|
let ownerAddress: AztecAddress;
|
|
84
83
|
let ownerEthAddress: EthAddress;
|
|
85
84
|
// does transactions on behalf of owner on Aztec:
|
|
86
85
|
let sponsorWallet: AccountWallet;
|
|
87
|
-
|
|
86
|
+
let sponsorAddress: AztecAddress;
|
|
88
87
|
|
|
89
88
|
let daiCrossChainHarness: CrossChainTestHarness;
|
|
90
89
|
let wethCrossChainHarness: CrossChainTestHarness;
|
|
91
90
|
|
|
92
91
|
let deployL1ContractsValues: DeployL1ContractsReturnType;
|
|
93
|
-
let rollup:
|
|
94
|
-
let uniswapPortal: GetContractReturnType<typeof UniswapPortalAbi,
|
|
92
|
+
let rollup: RollupContract;
|
|
93
|
+
let uniswapPortal: GetContractReturnType<typeof UniswapPortalAbi, ExtendedViemWalletClient>;
|
|
95
94
|
let uniswapPortalAddress: EthAddress;
|
|
96
95
|
let uniswapL2Contract: UniswapContract;
|
|
97
96
|
|
|
@@ -100,43 +99,33 @@ export const uniswapL1L2TestSuite = (
|
|
|
100
99
|
const minimumOutputAmount = 0n;
|
|
101
100
|
|
|
102
101
|
let cheatCodes: CheatCodes;
|
|
103
|
-
|
|
102
|
+
let version: number;
|
|
104
103
|
beforeAll(async () => {
|
|
105
|
-
({
|
|
106
|
-
|
|
107
|
-
pxe,
|
|
108
|
-
logger,
|
|
109
|
-
publicClient,
|
|
110
|
-
walletClient,
|
|
111
|
-
ownerWallet,
|
|
112
|
-
sponsorWallet,
|
|
113
|
-
deployL1ContractsValues,
|
|
114
|
-
cheatCodes,
|
|
115
|
-
} = await setup());
|
|
104
|
+
({ aztecNode, pxe, logger, l1Client, ownerWallet, sponsorWallet, deployL1ContractsValues, cheatCodes } =
|
|
105
|
+
await setup());
|
|
116
106
|
|
|
117
|
-
if (Number(await
|
|
107
|
+
if (Number(await l1Client.getBlockNumber()) < expectedForkBlockNumber) {
|
|
118
108
|
throw new Error('This test must be run on a fork of mainnet with the expected fork block');
|
|
119
109
|
}
|
|
120
110
|
|
|
121
|
-
rollup =
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
111
|
+
rollup = new RollupContract(
|
|
112
|
+
deployL1ContractsValues.l1Client,
|
|
113
|
+
deployL1ContractsValues.l1ContractAddresses.rollupAddress,
|
|
114
|
+
);
|
|
115
|
+
version = Number(await rollup.getVersion());
|
|
127
116
|
ownerAddress = ownerWallet.getAddress();
|
|
128
|
-
|
|
129
|
-
ownerEthAddress = EthAddress.fromString((await
|
|
117
|
+
sponsorAddress = sponsorWallet.getAddress();
|
|
118
|
+
ownerEthAddress = EthAddress.fromString((await l1Client.getAddresses())[0]);
|
|
130
119
|
|
|
131
|
-
await
|
|
120
|
+
await ensureAccountContractsPublished(ownerWallet, [ownerWallet, sponsorWallet]);
|
|
132
121
|
|
|
133
122
|
logger.info('Deploying DAI Portal, initializing and deploying l2 contract...');
|
|
134
123
|
daiCrossChainHarness = await CrossChainTestHarness.new(
|
|
135
124
|
aztecNode,
|
|
136
125
|
pxe,
|
|
137
|
-
|
|
138
|
-
walletClient,
|
|
126
|
+
deployL1ContractsValues.l1Client,
|
|
139
127
|
ownerWallet,
|
|
128
|
+
ownerAddress,
|
|
140
129
|
logger,
|
|
141
130
|
DAI_ADDRESS,
|
|
142
131
|
);
|
|
@@ -145,28 +134,27 @@ export const uniswapL1L2TestSuite = (
|
|
|
145
134
|
wethCrossChainHarness = await CrossChainTestHarness.new(
|
|
146
135
|
aztecNode,
|
|
147
136
|
pxe,
|
|
148
|
-
|
|
149
|
-
walletClient,
|
|
137
|
+
l1Client,
|
|
150
138
|
ownerWallet,
|
|
139
|
+
ownerAddress,
|
|
151
140
|
logger,
|
|
152
141
|
WETH9_ADDRESS,
|
|
153
142
|
);
|
|
154
143
|
|
|
155
144
|
logger.info('Deploy Uniswap portal on L1 and L2...');
|
|
156
|
-
uniswapPortalAddress = await deployL1Contract(
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
UniswapPortalAbi,
|
|
160
|
-
UniswapPortalBytecode,
|
|
161
|
-
).then(({ address }) => address);
|
|
145
|
+
uniswapPortalAddress = await deployL1Contract(l1Client, UniswapPortalAbi, UniswapPortalBytecode).then(
|
|
146
|
+
({ address }) => address,
|
|
147
|
+
);
|
|
162
148
|
|
|
163
149
|
uniswapPortal = getContract({
|
|
164
150
|
address: uniswapPortalAddress.toString(),
|
|
165
151
|
abi: UniswapPortalAbi,
|
|
166
|
-
client:
|
|
152
|
+
client: l1Client,
|
|
167
153
|
});
|
|
168
154
|
// deploy l2 uniswap contract and attach to portal
|
|
169
|
-
uniswapL2Contract = await UniswapContract.deploy(ownerWallet, uniswapPortalAddress)
|
|
155
|
+
uniswapL2Contract = await UniswapContract.deploy(ownerWallet, uniswapPortalAddress)
|
|
156
|
+
.send({ from: ownerAddress })
|
|
157
|
+
.deployed();
|
|
170
158
|
|
|
171
159
|
const registryAddress = (await pxe.getNodeInfo()).l1ContractAddresses.registryAddress;
|
|
172
160
|
|
|
@@ -177,8 +165,8 @@ export const uniswapL1L2TestSuite = (
|
|
|
177
165
|
|
|
178
166
|
// Give me some WETH so I can deposit to L2 and do the swap...
|
|
179
167
|
logger.info('Getting some weth');
|
|
180
|
-
const hash = await
|
|
181
|
-
await
|
|
168
|
+
const hash = await l1Client.sendTransaction({ to: WETH9_ADDRESS.toString(), value: parseEther('1000') });
|
|
169
|
+
await l1Client.waitForTransactionReceipt({ hash });
|
|
182
170
|
|
|
183
171
|
const wethBalance = await wethCrossChainHarness.getL1BalanceOf(ownerEthAddress);
|
|
184
172
|
expect(wethBalance).toBe(parseEther('1000'));
|
|
@@ -218,7 +206,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
218
206
|
// 3. Owner gives uniswap approval to transfer the funds to public to self on its behalf
|
|
219
207
|
logger.info('Approving uniswap to transfer funds to public to self on my behalf');
|
|
220
208
|
const nonceForWETHTransferToPublicApproval = new Fr(1n);
|
|
221
|
-
await ownerWallet.createAuthWit({
|
|
209
|
+
const transferToPublicAuhtwit = await ownerWallet.createAuthWit({
|
|
222
210
|
caller: uniswapL2Contract.address,
|
|
223
211
|
action: wethCrossChainHarness.l2Token.methods.transfer_to_public(
|
|
224
212
|
ownerAddress,
|
|
@@ -244,7 +232,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
244
232
|
secretHashForDepositingSwappedDai,
|
|
245
233
|
ownerEthAddress,
|
|
246
234
|
)
|
|
247
|
-
.send()
|
|
235
|
+
.send({ from: ownerAddress, authWitnesses: [transferToPublicAuhtwit] })
|
|
248
236
|
.wait();
|
|
249
237
|
|
|
250
238
|
const swapPrivateFunction = 'swap_private(address,uint256,uint24,address,uint256,bytes32,address)';
|
|
@@ -259,13 +247,13 @@ export const uniswapL1L2TestSuite = (
|
|
|
259
247
|
ownerEthAddress.toBuffer32(),
|
|
260
248
|
]);
|
|
261
249
|
|
|
262
|
-
const swapPrivateLeaf =
|
|
263
|
-
uniswapL2Contract.address,
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
new Fr(
|
|
267
|
-
|
|
268
|
-
|
|
250
|
+
const swapPrivateLeaf = computeL2ToL1MessageHash({
|
|
251
|
+
l2Sender: uniswapL2Contract.address,
|
|
252
|
+
l1Recipient: EthAddress.fromString(uniswapPortal.address),
|
|
253
|
+
content: swapPrivateContent,
|
|
254
|
+
rollupVersion: new Fr(version),
|
|
255
|
+
chainId: new Fr(l1Client.chain.id),
|
|
256
|
+
});
|
|
269
257
|
|
|
270
258
|
const withdrawContent = sha256ToField([
|
|
271
259
|
Buffer.from(toFunctionSelector('withdraw(address,uint256,address)').substring(2), 'hex'),
|
|
@@ -274,13 +262,13 @@ export const uniswapL1L2TestSuite = (
|
|
|
274
262
|
uniswapPortalAddress.toBuffer32(),
|
|
275
263
|
]);
|
|
276
264
|
|
|
277
|
-
const withdrawLeaf =
|
|
278
|
-
wethCrossChainHarness.l2Bridge.address,
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
new Fr(
|
|
282
|
-
|
|
283
|
-
|
|
265
|
+
const withdrawLeaf = computeL2ToL1MessageHash({
|
|
266
|
+
l2Sender: wethCrossChainHarness.l2Bridge.address,
|
|
267
|
+
l1Recipient: wethCrossChainHarness.tokenPortalAddress,
|
|
268
|
+
content: withdrawContent,
|
|
269
|
+
rollupVersion: new Fr(version),
|
|
270
|
+
chainId: new Fr(l1Client.chain.id),
|
|
271
|
+
});
|
|
284
272
|
|
|
285
273
|
// ensure that user's funds were burnt
|
|
286
274
|
await wethCrossChainHarness.expectPrivateBalanceOnL2(ownerAddress, wethL2BalanceBeforeSwap - wethAmountToBridge);
|
|
@@ -288,23 +276,30 @@ export const uniswapL1L2TestSuite = (
|
|
|
288
276
|
await wethCrossChainHarness.expectPublicBalanceOnL2(uniswapL2Contract.address, 0n);
|
|
289
277
|
|
|
290
278
|
// Since the outbox is only consumable when the block is proven, we need to set the block to be proven
|
|
291
|
-
await cheatCodes.rollup.markAsProven(await rollup.
|
|
279
|
+
await cheatCodes.rollup.markAsProven(await rollup.getBlockNumber());
|
|
292
280
|
|
|
293
281
|
// 5. Consume L2 to L1 message by calling uniswapPortal.swap_private()
|
|
294
282
|
logger.info('Execute withdraw and swap on the uniswapPortal!');
|
|
295
283
|
const daiL1BalanceOfPortalBeforeSwap = await daiCrossChainHarness.getL1BalanceOf(
|
|
296
284
|
daiCrossChainHarness.tokenPortalAddress,
|
|
297
285
|
);
|
|
298
|
-
|
|
299
|
-
|
|
286
|
+
const swapResult = await computeL2ToL1MembershipWitness(
|
|
287
|
+
aztecNode,
|
|
300
288
|
l2UniswapInteractionReceipt.blockNumber!,
|
|
301
289
|
swapPrivateLeaf,
|
|
302
290
|
);
|
|
303
|
-
const
|
|
291
|
+
const withdrawResult = await computeL2ToL1MembershipWitness(
|
|
292
|
+
aztecNode,
|
|
304
293
|
l2UniswapInteractionReceipt.blockNumber!,
|
|
305
294
|
withdrawLeaf,
|
|
306
295
|
);
|
|
307
296
|
|
|
297
|
+
const swapPrivateL2MessageIndex = swapResult!.leafIndex;
|
|
298
|
+
const swapPrivateSiblingPath = swapResult!.siblingPath;
|
|
299
|
+
|
|
300
|
+
const withdrawL2MessageIndex = withdrawResult!.leafIndex;
|
|
301
|
+
const withdrawSiblingPath = withdrawResult!.siblingPath;
|
|
302
|
+
|
|
308
303
|
const withdrawMessageMetadata = {
|
|
309
304
|
_l2BlockNumber: BigInt(l2UniswapInteractionReceipt.blockNumber!),
|
|
310
305
|
_leafIndex: BigInt(withdrawL2MessageIndex),
|
|
@@ -333,7 +328,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
333
328
|
] as const;
|
|
334
329
|
|
|
335
330
|
// this should also insert a message into the inbox.
|
|
336
|
-
const txReceipt = await daiCrossChainHarness.
|
|
331
|
+
const txReceipt = await daiCrossChainHarness.l1Client.waitForTransactionReceipt({
|
|
337
332
|
hash: await uniswapPortal.write.swapPrivate(swapArgs),
|
|
338
333
|
});
|
|
339
334
|
|
|
@@ -643,7 +638,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
643
638
|
Fr.random(),
|
|
644
639
|
ownerEthAddress,
|
|
645
640
|
)
|
|
646
|
-
.
|
|
641
|
+
.simulate({ from: ownerAddress }),
|
|
647
642
|
).rejects.toThrow(`Unknown auth witness for message hash ${expectedMessageHash.toString()}`);
|
|
648
643
|
});
|
|
649
644
|
|
|
@@ -655,7 +650,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
655
650
|
// 2. owner gives uniswap approval to transfer the funds to public:
|
|
656
651
|
logger.info('Approving uniswap to transfer funds to public to self on my behalf');
|
|
657
652
|
const nonceForWETHTransferToPublicApproval = new Fr(3n);
|
|
658
|
-
await ownerWallet.createAuthWit({
|
|
653
|
+
const transferToPublicAuthwith = await ownerWallet.createAuthWit({
|
|
659
654
|
caller: uniswapL2Contract.address,
|
|
660
655
|
action: wethCrossChainHarness.l2Token.methods.transfer_to_public(
|
|
661
656
|
ownerAddress,
|
|
@@ -680,7 +675,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
680
675
|
Fr.random(),
|
|
681
676
|
ownerEthAddress,
|
|
682
677
|
)
|
|
683
|
-
.prove(),
|
|
678
|
+
.prove({ from: ownerAddress, authWitnesses: [transferToPublicAuthwith] }),
|
|
684
679
|
).rejects.toThrow('Assertion failed: input_asset address is not the same as seen in the bridge contract');
|
|
685
680
|
});
|
|
686
681
|
|
|
@@ -704,7 +699,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
704
699
|
},
|
|
705
700
|
true,
|
|
706
701
|
);
|
|
707
|
-
await validateActionInteraction.send().wait();
|
|
702
|
+
await validateActionInteraction.send({ from: ownerAddress }).wait();
|
|
708
703
|
|
|
709
704
|
// No approval to call `swap` but should work even without it:
|
|
710
705
|
const [_, secretHashForDepositingSwappedDai] = await generateClaimSecret();
|
|
@@ -723,7 +718,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
723
718
|
ownerEthAddress,
|
|
724
719
|
Fr.ZERO, // nonce for swap -> doesn't matter
|
|
725
720
|
)
|
|
726
|
-
.send()
|
|
721
|
+
.send({ from: ownerAddress })
|
|
727
722
|
.wait();
|
|
728
723
|
// check weth balance of owner on L2 (we first bridged `wethAmountToBridge` into L2 and now withdrew it!)
|
|
729
724
|
await wethCrossChainHarness.expectPublicBalanceOnL2(ownerAddress, 0n);
|
|
@@ -752,9 +747,9 @@ export const uniswapL1L2TestSuite = (
|
|
|
752
747
|
nonceForSwap,
|
|
753
748
|
);
|
|
754
749
|
const validateActionInteraction = await ownerWallet.setPublicAuthWit({ caller: approvedUser, action }, true);
|
|
755
|
-
await validateActionInteraction.send().wait();
|
|
750
|
+
await validateActionInteraction.send({ from: ownerAddress }).wait();
|
|
756
751
|
|
|
757
|
-
await expect(action.simulate()).rejects.toThrow(/unauthorized/);
|
|
752
|
+
await expect(action.simulate({ from: sponsorAddress })).rejects.toThrow(/unauthorized/);
|
|
758
753
|
});
|
|
759
754
|
|
|
760
755
|
it("uniswap can't pull funds without transfer approval", async () => {
|
|
@@ -773,7 +768,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
773
768
|
},
|
|
774
769
|
true,
|
|
775
770
|
);
|
|
776
|
-
await validateActionInteraction.send().wait();
|
|
771
|
+
await validateActionInteraction.send({ from: ownerAddress }).wait();
|
|
777
772
|
|
|
778
773
|
await expect(
|
|
779
774
|
uniswapL2Contract.methods
|
|
@@ -790,7 +785,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
790
785
|
ownerEthAddress,
|
|
791
786
|
Fr.ZERO,
|
|
792
787
|
)
|
|
793
|
-
.simulate(),
|
|
788
|
+
.simulate({ from: ownerAddress }),
|
|
794
789
|
).rejects.toThrow(/unauthorized/);
|
|
795
790
|
});
|
|
796
791
|
|
|
@@ -803,7 +798,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
803
798
|
// Owner gives uniswap approval to transfer the funds to public to self on its behalf
|
|
804
799
|
logger.info('Approving uniswap to transfer the funds to public to self on my behalf');
|
|
805
800
|
const nonceForWETHTransferToPublicApproval = new Fr(4n);
|
|
806
|
-
await ownerWallet.createAuthWit({
|
|
801
|
+
const transferToPublicAuhtwit = await ownerWallet.createAuthWit({
|
|
807
802
|
caller: uniswapL2Contract.address,
|
|
808
803
|
action: wethCrossChainHarness.l2Token.methods.transfer_to_public(
|
|
809
804
|
ownerAddress,
|
|
@@ -830,7 +825,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
830
825
|
secretHashForDepositingSwappedDai,
|
|
831
826
|
ownerEthAddress,
|
|
832
827
|
)
|
|
833
|
-
.send()
|
|
828
|
+
.send({ from: ownerAddress, authWitnesses: [transferToPublicAuhtwit] })
|
|
834
829
|
.wait();
|
|
835
830
|
|
|
836
831
|
const swapPrivateContent = sha256ToField([
|
|
@@ -847,13 +842,13 @@ export const uniswapL1L2TestSuite = (
|
|
|
847
842
|
ownerEthAddress.toBuffer32(),
|
|
848
843
|
]);
|
|
849
844
|
|
|
850
|
-
const swapPrivateLeaf =
|
|
851
|
-
uniswapL2Contract.address,
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
new Fr(
|
|
855
|
-
|
|
856
|
-
|
|
845
|
+
const swapPrivateLeaf = computeL2ToL1MessageHash({
|
|
846
|
+
l2Sender: uniswapL2Contract.address,
|
|
847
|
+
l1Recipient: EthAddress.fromString(uniswapPortal.address),
|
|
848
|
+
content: swapPrivateContent,
|
|
849
|
+
rollupVersion: new Fr(version),
|
|
850
|
+
chainId: new Fr(l1Client.chain.id),
|
|
851
|
+
});
|
|
857
852
|
|
|
858
853
|
const withdrawContent = sha256ToField([
|
|
859
854
|
Buffer.from(toFunctionSelector('withdraw(address,uint256,address)').substring(2), 'hex'),
|
|
@@ -862,23 +857,27 @@ export const uniswapL1L2TestSuite = (
|
|
|
862
857
|
uniswapPortalAddress.toBuffer32(),
|
|
863
858
|
]);
|
|
864
859
|
|
|
865
|
-
const withdrawLeaf =
|
|
866
|
-
wethCrossChainHarness.l2Bridge.address,
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
new Fr(
|
|
870
|
-
|
|
871
|
-
|
|
860
|
+
const withdrawLeaf = computeL2ToL1MessageHash({
|
|
861
|
+
l2Sender: wethCrossChainHarness.l2Bridge.address,
|
|
862
|
+
l1Recipient: wethCrossChainHarness.tokenPortalAddress,
|
|
863
|
+
content: withdrawContent,
|
|
864
|
+
rollupVersion: new Fr(version),
|
|
865
|
+
chainId: new Fr(l1Client.chain.id),
|
|
866
|
+
});
|
|
872
867
|
|
|
873
|
-
const
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
);
|
|
877
|
-
const [withdrawL2MessageIndex, withdrawSiblingPath] = await aztecNode.getL2ToL1MessageMembershipWitness(
|
|
868
|
+
const swapResult = await computeL2ToL1MembershipWitness(aztecNode, withdrawReceipt.blockNumber!, swapPrivateLeaf);
|
|
869
|
+
const withdrawResult = await computeL2ToL1MembershipWitness(
|
|
870
|
+
aztecNode,
|
|
878
871
|
withdrawReceipt.blockNumber!,
|
|
879
872
|
withdrawLeaf,
|
|
880
873
|
);
|
|
881
874
|
|
|
875
|
+
const swapPrivateL2MessageIndex = swapResult!.leafIndex;
|
|
876
|
+
const swapPrivateSiblingPath = swapResult!.siblingPath;
|
|
877
|
+
|
|
878
|
+
const withdrawL2MessageIndex = withdrawResult!.leafIndex;
|
|
879
|
+
const withdrawSiblingPath = withdrawResult!.siblingPath;
|
|
880
|
+
|
|
882
881
|
const withdrawMessageMetadata = {
|
|
883
882
|
_l2BlockNumber: BigInt(withdrawReceipt.blockNumber!),
|
|
884
883
|
_leafIndex: BigInt(withdrawL2MessageIndex),
|
|
@@ -899,7 +898,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
899
898
|
await wethCrossChainHarness.expectPrivateBalanceOnL2(ownerAddress, wethL2BalanceBeforeSwap - wethAmountToBridge);
|
|
900
899
|
|
|
901
900
|
// Since the outbox is only consumable when the block is proven, we need to set the block to be proven
|
|
902
|
-
await cheatCodes.rollup.markAsProven(await rollup.
|
|
901
|
+
await cheatCodes.rollup.markAsProven(await rollup.getBlockNumber());
|
|
903
902
|
|
|
904
903
|
// On L1 call swap_public!
|
|
905
904
|
logger.info('call swap_public on L1');
|
|
@@ -939,7 +938,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
939
938
|
},
|
|
940
939
|
true,
|
|
941
940
|
);
|
|
942
|
-
await validateActionInteraction.send().wait();
|
|
941
|
+
await validateActionInteraction.send({ from: ownerAddress }).wait();
|
|
943
942
|
|
|
944
943
|
// Call swap_public on L2
|
|
945
944
|
const secretHashForDepositingSwappedDai = Fr.random();
|
|
@@ -957,7 +956,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
957
956
|
ownerEthAddress,
|
|
958
957
|
Fr.ZERO,
|
|
959
958
|
)
|
|
960
|
-
.send()
|
|
959
|
+
.send({ from: ownerAddress })
|
|
961
960
|
.wait();
|
|
962
961
|
|
|
963
962
|
const swapPublicContent = sha256ToField([
|
|
@@ -977,13 +976,13 @@ export const uniswapL1L2TestSuite = (
|
|
|
977
976
|
ownerEthAddress.toBuffer32(),
|
|
978
977
|
]);
|
|
979
978
|
|
|
980
|
-
const swapPublicLeaf =
|
|
981
|
-
uniswapL2Contract.address,
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
new Fr(
|
|
985
|
-
|
|
986
|
-
|
|
979
|
+
const swapPublicLeaf = computeL2ToL1MessageHash({
|
|
980
|
+
l2Sender: uniswapL2Contract.address,
|
|
981
|
+
l1Recipient: EthAddress.fromString(uniswapPortal.address),
|
|
982
|
+
content: swapPublicContent,
|
|
983
|
+
rollupVersion: new Fr(version),
|
|
984
|
+
chainId: new Fr(l1Client.chain.id),
|
|
985
|
+
});
|
|
987
986
|
|
|
988
987
|
const withdrawContent = sha256ToField([
|
|
989
988
|
Buffer.from(toFunctionSelector('withdraw(address,uint256,address)').substring(2), 'hex'),
|
|
@@ -992,23 +991,27 @@ export const uniswapL1L2TestSuite = (
|
|
|
992
991
|
uniswapPortalAddress.toBuffer32(),
|
|
993
992
|
]);
|
|
994
993
|
|
|
995
|
-
const withdrawLeaf =
|
|
996
|
-
wethCrossChainHarness.l2Bridge.address,
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
new Fr(
|
|
1000
|
-
|
|
1001
|
-
|
|
994
|
+
const withdrawLeaf = computeL2ToL1MessageHash({
|
|
995
|
+
l2Sender: wethCrossChainHarness.l2Bridge.address,
|
|
996
|
+
l1Recipient: wethCrossChainHarness.tokenPortalAddress,
|
|
997
|
+
content: withdrawContent,
|
|
998
|
+
rollupVersion: new Fr(version),
|
|
999
|
+
chainId: new Fr(l1Client.chain.id),
|
|
1000
|
+
});
|
|
1002
1001
|
|
|
1003
|
-
const
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
);
|
|
1007
|
-
const [withdrawL2MessageIndex, withdrawSiblingPath] = await aztecNode.getL2ToL1MessageMembershipWitness(
|
|
1002
|
+
const swapResult = await computeL2ToL1MembershipWitness(aztecNode, withdrawReceipt.blockNumber!, swapPublicLeaf);
|
|
1003
|
+
const withdrawResult = await computeL2ToL1MembershipWitness(
|
|
1004
|
+
aztecNode,
|
|
1008
1005
|
withdrawReceipt.blockNumber!,
|
|
1009
1006
|
withdrawLeaf,
|
|
1010
1007
|
);
|
|
1011
1008
|
|
|
1009
|
+
const swapPublicL2MessageIndex = swapResult!.leafIndex;
|
|
1010
|
+
const swapPublicSiblingPath = swapResult!.siblingPath;
|
|
1011
|
+
|
|
1012
|
+
const withdrawL2MessageIndex = withdrawResult!.leafIndex;
|
|
1013
|
+
const withdrawSiblingPath = withdrawResult!.siblingPath;
|
|
1014
|
+
|
|
1012
1015
|
const withdrawMessageMetadata = {
|
|
1013
1016
|
_l2BlockNumber: BigInt(withdrawReceipt.blockNumber!),
|
|
1014
1017
|
_leafIndex: BigInt(withdrawL2MessageIndex),
|
|
@@ -1029,7 +1032,7 @@ export const uniswapL1L2TestSuite = (
|
|
|
1029
1032
|
await wethCrossChainHarness.expectPublicBalanceOnL2(ownerAddress, 0n);
|
|
1030
1033
|
|
|
1031
1034
|
// Since the outbox is only consumable when the block is proven, we need to set the block to be proven
|
|
1032
|
-
await cheatCodes.rollup.markAsProven(await rollup.
|
|
1035
|
+
await cheatCodes.rollup.markAsProven(await rollup.getBlockNumber());
|
|
1033
1036
|
|
|
1034
1037
|
// Call swap_private on L1
|
|
1035
1038
|
logger.info('Execute withdraw and swap on the uniswapPortal!');
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
// Convenience struct to hold an account's address and secret that can easily be passed around.
|
|
2
|
-
import { AztecAddress,
|
|
2
|
+
import { AztecAddress, Fr } from '@aztec/aztec.js';
|
|
3
|
+
import { CheatCodes } from '@aztec/aztec/testing';
|
|
4
|
+
import type { RollupContract } from '@aztec/ethereum';
|
|
3
5
|
import { pedersenHash } from '@aztec/foundation/crypto';
|
|
4
6
|
import type { TestDateProvider } from '@aztec/foundation/timer';
|
|
5
|
-
import type { RollupAbi } from '@aztec/l1-artifacts';
|
|
6
7
|
import type { LendingContract } from '@aztec/noir-contracts.js/Lending';
|
|
7
8
|
|
|
8
|
-
import type { Account, GetContractReturnType, HttpTransport, WalletClient } from 'viem';
|
|
9
|
-
import type * as chains from 'viem/chains';
|
|
10
|
-
|
|
11
9
|
import type { TokenSimulator } from './token_simulator.js';
|
|
12
10
|
|
|
13
11
|
/**
|
|
@@ -83,7 +81,7 @@ export class LendingSimulator {
|
|
|
83
81
|
private rate: bigint,
|
|
84
82
|
private ethereumSlotDuration: number,
|
|
85
83
|
/** the rollup contract */
|
|
86
|
-
public rollup:
|
|
84
|
+
public rollup: RollupContract,
|
|
87
85
|
/** the lending contract */
|
|
88
86
|
public lendingContract: LendingContract,
|
|
89
87
|
/** the collateral asset used in the lending contract */
|
|
@@ -94,10 +92,8 @@ export class LendingSimulator {
|
|
|
94
92
|
|
|
95
93
|
async prepare() {
|
|
96
94
|
this.accumulator = BASE;
|
|
97
|
-
const slot = await this.rollup.
|
|
98
|
-
|
|
99
|
-
]);
|
|
100
|
-
this.time = Number(await this.rollup.read.getTimestampForSlot([slot]));
|
|
95
|
+
const slot = await this.rollup.getSlotAt(BigInt(await this.cc.eth.timestamp()) + BigInt(this.ethereumSlotDuration));
|
|
96
|
+
this.time = Number(await this.rollup.getTimestampForSlot(slot));
|
|
101
97
|
}
|
|
102
98
|
|
|
103
99
|
async progressSlots(diff: number, dateProvider?: TestDateProvider) {
|
|
@@ -105,8 +101,8 @@ export class LendingSimulator {
|
|
|
105
101
|
return;
|
|
106
102
|
}
|
|
107
103
|
|
|
108
|
-
const slot = await this.rollup.
|
|
109
|
-
const ts = Number(await this.rollup.
|
|
104
|
+
const slot = await this.rollup.getSlotAt(BigInt(await this.cc.eth.timestamp()));
|
|
105
|
+
const ts = Number(await this.rollup.getTimestampForSlot(slot + BigInt(diff)));
|
|
110
106
|
const timeDiff = ts - this.time;
|
|
111
107
|
this.time = ts;
|
|
112
108
|
|
|
@@ -115,7 +111,7 @@ export class LendingSimulator {
|
|
|
115
111
|
if (dateProvider) {
|
|
116
112
|
dateProvider.setTime(this.time * 1000);
|
|
117
113
|
}
|
|
118
|
-
await this.cc.rollup.markAsProven(await this.rollup.
|
|
114
|
+
await this.cc.rollup.markAsProven(await this.rollup.getBlockNumber());
|
|
119
115
|
this.accumulator = muldivDown(this.accumulator, computeMultiplier(this.rate, BigInt(timeDiff)), BASE);
|
|
120
116
|
}
|
|
121
117
|
|
|
@@ -187,14 +183,14 @@ export class LendingSimulator {
|
|
|
187
183
|
|
|
188
184
|
expect(this.borrowed).toEqual(this.stableCoin.totalSupply - this.mintedOutside);
|
|
189
185
|
|
|
190
|
-
const asset = await this.lendingContract.methods.get_asset(0).simulate();
|
|
186
|
+
const asset = await this.lendingContract.methods.get_asset(0).simulate({ from: this.account.address });
|
|
191
187
|
|
|
192
188
|
const interestAccumulator = asset['interest_accumulator'];
|
|
193
189
|
expect(interestAccumulator).toEqual(this.accumulator);
|
|
194
190
|
expect(asset['last_updated_ts']).toEqual(BigInt(this.time));
|
|
195
191
|
|
|
196
192
|
for (const key of [this.account.address, AztecAddress.fromField(await this.account.key())]) {
|
|
197
|
-
const privatePos = await this.lendingContract.methods.get_position(key).simulate();
|
|
193
|
+
const privatePos = await this.lendingContract.methods.get_position(key).simulate({ from: key });
|
|
198
194
|
expect(new Fr(privatePos['collateral'])).toEqual(this.collateral[key.toString()] ?? Fr.ZERO);
|
|
199
195
|
expect(new Fr(privatePos['static_debt'])).toEqual(this.staticDebt[key.toString()] ?? Fr.ZERO);
|
|
200
196
|
expect(privatePos['debt']).toEqual(
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* eslint-disable jsdoc/require-jsdoc */
|
|
2
1
|
import { type AztecAddress, BatchCall, type Logger, type Wallet } from '@aztec/aztec.js';
|
|
3
2
|
import type { TokenContract } from '@aztec/noir-contracts.js/Token';
|
|
4
3
|
|
|
@@ -14,6 +13,7 @@ export class TokenSimulator {
|
|
|
14
13
|
constructor(
|
|
15
14
|
protected token: TokenContract,
|
|
16
15
|
protected defaultWallet: Wallet,
|
|
16
|
+
protected defaultAddress: AztecAddress,
|
|
17
17
|
protected logger: Logger,
|
|
18
18
|
protected accounts: AztecAddress[],
|
|
19
19
|
) {}
|
|
@@ -97,13 +97,15 @@ export class TokenSimulator {
|
|
|
97
97
|
|
|
98
98
|
async checkPublic() {
|
|
99
99
|
// public calls
|
|
100
|
-
const calls = [
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
100
|
+
const calls = [
|
|
101
|
+
this.token.methods.total_supply(),
|
|
102
|
+
...this.accounts.map(address => this.token.methods.balance_of_public(address)),
|
|
103
|
+
];
|
|
104
104
|
|
|
105
105
|
const results = (
|
|
106
|
-
await Promise.all(
|
|
106
|
+
await Promise.all(
|
|
107
|
+
chunk(calls, 4).map(batch => new BatchCall(this.defaultWallet, batch).simulate({ from: this.defaultAddress })),
|
|
108
|
+
)
|
|
107
109
|
).flat();
|
|
108
110
|
expect(results[0]).toEqual(this.totalSupply);
|
|
109
111
|
|
|
@@ -126,12 +128,13 @@ export class TokenSimulator {
|
|
|
126
128
|
}
|
|
127
129
|
}
|
|
128
130
|
|
|
129
|
-
const defaultCalls =
|
|
130
|
-
for (const address of defaultLookups) {
|
|
131
|
-
defaultCalls.push(await this.token.methods.balance_of_private(address).request());
|
|
132
|
-
}
|
|
131
|
+
const defaultCalls = defaultLookups.map(address => this.token.methods.balance_of_private(address));
|
|
133
132
|
const results = (
|
|
134
|
-
await Promise.all(
|
|
133
|
+
await Promise.all(
|
|
134
|
+
chunk(defaultCalls, 4).map(batch =>
|
|
135
|
+
new BatchCall(this.defaultWallet, batch).simulate({ from: this.defaultAddress }),
|
|
136
|
+
),
|
|
137
|
+
)
|
|
135
138
|
).flat();
|
|
136
139
|
for (let i = 0; i < defaultLookups.length; i++) {
|
|
137
140
|
expect(results[i]).toEqual(this.balanceOfPrivate(defaultLookups[i]));
|
|
@@ -143,7 +146,9 @@ export class TokenSimulator {
|
|
|
143
146
|
const wallet = this.lookupProvider.get(address.toString());
|
|
144
147
|
const asset = wallet ? this.token.withWallet(wallet) : this.token;
|
|
145
148
|
|
|
146
|
-
const actualPrivateBalance = await asset.methods
|
|
149
|
+
const actualPrivateBalance = await asset.methods
|
|
150
|
+
.balance_of_private({ address })
|
|
151
|
+
.simulate({ from: this.defaultAddress });
|
|
147
152
|
expect(actualPrivateBalance).toEqual(this.balanceOfPrivate(address));
|
|
148
153
|
}
|
|
149
154
|
}
|