@aztec/end-to-end 0.75.0-commit.c03ba01a2a4122e43e90d5133ba017e54b90e9d2 → 0.77.0-testnet-ignition.17
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 +2 -0
- package/dest/bench/utils.d.ts +70 -0
- package/dest/bench/utils.d.ts.map +1 -0
- package/dest/bench/utils.js +24 -8
- package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +46 -0
- package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts.map +1 -0
- package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.js +17 -17
- package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +47 -0
- package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts.map +1 -0
- package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.js +27 -16
- package/dest/e2e_deploy_contract/deploy_test.d.ts +28 -0
- package/dest/e2e_deploy_contract/deploy_test.d.ts.map +1 -0
- package/dest/e2e_deploy_contract/deploy_test.js +4 -7
- package/dest/e2e_epochs/epochs_test.d.ts +51 -0
- package/dest/e2e_epochs/epochs_test.d.ts.map +1 -0
- package/dest/e2e_epochs/epochs_test.js +155 -0
- package/dest/e2e_fees/fees_test.d.ts +73 -0
- package/dest/e2e_fees/fees_test.d.ts.map +1 -0
- package/dest/e2e_fees/fees_test.js +75 -32
- package/dest/e2e_nested_contract/nested_contract_test.d.ts +26 -0
- package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +1 -0
- package/dest/e2e_nested_contract/nested_contract_test.js +14 -12
- package/dest/e2e_p2p/p2p_network.d.ts +61 -0
- package/dest/e2e_p2p/p2p_network.d.ts.map +1 -0
- package/dest/e2e_p2p/p2p_network.js +54 -30
- package/dest/e2e_p2p/shared.d.ts +10 -0
- package/dest/e2e_p2p/shared.d.ts.map +1 -0
- package/dest/e2e_p2p/shared.js +7 -8
- package/dest/e2e_prover/e2e_prover_test.d.ts +56 -0
- package/dest/e2e_prover/e2e_prover_test.d.ts.map +1 -0
- package/dest/e2e_prover/e2e_prover_test.js +20 -24
- package/dest/e2e_token_contract/token_contract_test.d.ts +29 -0
- package/dest/e2e_token_contract/token_contract_test.d.ts.map +1 -0
- package/dest/e2e_token_contract/token_contract_test.js +4 -7
- package/dest/fixtures/fixtures.d.ts +17 -0
- package/dest/fixtures/fixtures.d.ts.map +1 -0
- package/dest/fixtures/fixtures.js +2 -2
- package/dest/fixtures/get_acvm_config.d.ts +8 -0
- package/dest/fixtures/get_acvm_config.d.ts.map +1 -0
- package/dest/fixtures/get_acvm_config.js +10 -5
- package/dest/fixtures/get_bb_config.d.ts +6 -0
- package/dest/fixtures/get_bb_config.d.ts.map +1 -0
- package/dest/fixtures/get_bb_config.js +9 -4
- package/dest/fixtures/index.d.ts +6 -0
- package/dest/fixtures/index.d.ts.map +1 -0
- package/dest/fixtures/l1_to_l2_messaging.d.ts +13 -0
- package/dest/fixtures/l1_to_l2_messaging.d.ts.map +1 -0
- package/dest/fixtures/l1_to_l2_messaging.js +1 -1
- package/dest/fixtures/logging.d.ts +8 -0
- package/dest/fixtures/logging.d.ts.map +1 -0
- package/dest/fixtures/setup_l1_contracts.d.ts +6 -0
- package/dest/fixtures/setup_l1_contracts.d.ts.map +1 -0
- package/dest/fixtures/setup_l1_contracts.js +6 -4
- package/dest/fixtures/setup_p2p_test.d.ts +22 -0
- package/dest/fixtures/setup_p2p_test.d.ts.map +1 -0
- package/dest/fixtures/setup_p2p_test.js +5 -3
- package/dest/fixtures/snapshot_manager.d.ts +87 -0
- package/dest/fixtures/snapshot_manager.d.ts.map +1 -0
- package/dest/fixtures/snapshot_manager.js +67 -74
- package/dest/fixtures/token_utils.d.ts +6 -0
- package/dest/fixtures/token_utils.d.ts.map +1 -0
- package/dest/fixtures/token_utils.js +1 -1
- package/dest/fixtures/utils.d.ts +155 -0
- package/dest/fixtures/utils.d.ts.map +1 -0
- package/dest/fixtures/utils.js +97 -71
- package/dest/fixtures/with_telemetry_utils.d.ts +3 -0
- package/dest/fixtures/with_telemetry_utils.d.ts.map +1 -0
- package/dest/index.d.ts +2 -0
- package/dest/index.d.ts.map +1 -0
- package/dest/quality_of_service/alert_checker.d.ts +41 -0
- package/dest/quality_of_service/alert_checker.d.ts.map +1 -0
- package/dest/quality_of_service/alert_checker.js +4 -1
- package/dest/sample-dapp/index.js +1 -1
- package/dest/shared/cross_chain_test_harness.d.ts +124 -0
- package/dest/shared/cross_chain_test_harness.d.ts.map +1 -0
- package/dest/shared/cross_chain_test_harness.js +6 -17
- package/dest/shared/gas_portal_test_harness.d.ts +80 -0
- package/dest/shared/gas_portal_test_harness.d.ts.map +1 -0
- package/dest/shared/gas_portal_test_harness.js +11 -4
- package/dest/shared/index.d.ts +2 -0
- package/dest/shared/index.d.ts.map +1 -0
- package/dest/shared/index.js +0 -1
- package/dest/shared/jest_setup.d.ts +2 -0
- package/dest/shared/jest_setup.d.ts.map +1 -0
- package/dest/shared/submit-transactions.d.ts +4 -0
- package/dest/shared/submit-transactions.d.ts.map +1 -0
- package/dest/shared/submit-transactions.js +9 -17
- package/dest/shared/uniswap_l1_l2.d.ts +25 -0
- package/dest/shared/uniswap_l1_l2.d.ts.map +1 -0
- package/dest/shared/uniswap_l1_l2.js +5 -10
- package/dest/simulators/index.d.ts +3 -0
- package/dest/simulators/index.d.ts.map +1 -0
- package/dest/simulators/lending_simulator.d.ts +69 -0
- package/dest/simulators/lending_simulator.d.ts.map +1 -0
- package/dest/simulators/lending_simulator.js +1 -3
- package/dest/simulators/token_simulator.d.ts +29 -0
- package/dest/simulators/token_simulator.d.ts.map +1 -0
- package/dest/spartan/setup_test_wallets.d.ts +20 -0
- package/dest/spartan/setup_test_wallets.d.ts.map +1 -0
- package/dest/spartan/setup_test_wallets.js +72 -38
- package/dest/spartan/utils.d.ts +485 -0
- package/dest/spartan/utils.d.ts.map +1 -0
- package/dest/spartan/utils.js +110 -2
- package/package.json +35 -40
- package/src/bench/utils.ts +30 -13
- package/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +40 -30
- package/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +34 -18
- package/src/e2e_deploy_contract/deploy_test.ts +6 -11
- package/src/e2e_epochs/epochs_test.ts +217 -0
- package/src/e2e_fees/fees_test.ts +84 -38
- package/src/e2e_nested_contract/nested_contract_test.ts +14 -16
- package/src/e2e_p2p/p2p_network.ts +67 -47
- package/src/e2e_p2p/shared.ts +16 -10
- package/src/e2e_prover/e2e_prover_test.ts +56 -37
- package/src/e2e_token_contract/token_contract_test.ts +10 -11
- package/src/fixtures/fixtures.ts +2 -2
- package/src/fixtures/get_acvm_config.ts +7 -3
- package/src/fixtures/get_bb_config.ts +6 -2
- package/src/fixtures/l1_to_l2_messaging.ts +6 -13
- package/src/fixtures/setup_l1_contracts.ts +8 -7
- package/src/fixtures/setup_p2p_test.ts +8 -6
- package/src/fixtures/snapshot_manager.ts +72 -79
- package/src/fixtures/token_utils.ts +2 -2
- package/src/fixtures/utils.ts +135 -97
- package/src/guides/up_quick_start.sh +10 -5
- package/src/quality_of_service/alert_checker.ts +6 -2
- package/src/sample-dapp/index.mjs +1 -1
- package/src/shared/cross_chain_test_harness.ts +17 -35
- package/src/shared/gas_portal_test_harness.ts +21 -11
- package/src/shared/index.ts +0 -1
- package/src/shared/submit-transactions.ts +16 -20
- package/src/shared/uniswap_l1_l2.ts +35 -26
- package/src/simulators/lending_simulator.ts +5 -6
- package/src/simulators/token_simulator.ts +1 -1
- package/src/spartan/setup_test_wallets.ts +111 -37
- package/src/spartan/utils.ts +88 -3
- package/dest/shared/browser.js +0 -163
- package/src/shared/browser.ts +0 -272
package/dest/shared/browser.js
DELETED
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-console */ import * as AztecJs from '@aztec/aztec.js';
|
|
2
|
-
import { TokenContractArtifact } from '@aztec/noir-contracts.js/Token';
|
|
3
|
-
import { contractArtifactToBuffer } from '@aztec/types/abi';
|
|
4
|
-
import getPort from 'get-port';
|
|
5
|
-
import { launch } from 'puppeteer-core';
|
|
6
|
-
const privKey = AztecJs.GrumpkinScalar.random();
|
|
7
|
-
export const browserTestSuite = (setup, pageLogger)=>describe('e2e_aztec.js_browser', ()=>{
|
|
8
|
-
const initialBalance = 33n;
|
|
9
|
-
const transferAmount = 3n;
|
|
10
|
-
let contractAddress;
|
|
11
|
-
let testClient;
|
|
12
|
-
let server;
|
|
13
|
-
let webServerURL;
|
|
14
|
-
let pxeServer;
|
|
15
|
-
let pxeURL;
|
|
16
|
-
let browser;
|
|
17
|
-
let page;
|
|
18
|
-
beforeAll(async ()=>{
|
|
19
|
-
({ server, pxeURL, pxeServer, webServerURL } = await setup());
|
|
20
|
-
testClient = AztecJs.createPXEClient(pxeURL);
|
|
21
|
-
await AztecJs.waitForPXE(testClient);
|
|
22
|
-
const debuggingPort = await getPort({
|
|
23
|
-
port: 9222
|
|
24
|
-
});
|
|
25
|
-
browser = await launch({
|
|
26
|
-
executablePath: process.env.CHROME_BIN,
|
|
27
|
-
headless: true,
|
|
28
|
-
debuggingPort,
|
|
29
|
-
args: [
|
|
30
|
-
'--no-sandbox',
|
|
31
|
-
'--headless',
|
|
32
|
-
'--disable-gpu',
|
|
33
|
-
'--disable-dev-shm-usage',
|
|
34
|
-
'--disable-software-rasterizer',
|
|
35
|
-
`--remote-debugging-port=${debuggingPort}`
|
|
36
|
-
]
|
|
37
|
-
});
|
|
38
|
-
page = await browser.newPage();
|
|
39
|
-
page.on('console', (msg)=>{
|
|
40
|
-
pageLogger.info(msg.text());
|
|
41
|
-
});
|
|
42
|
-
page.on('pageerror', (err)=>{
|
|
43
|
-
pageLogger.error(`Error on web page`, err);
|
|
44
|
-
});
|
|
45
|
-
await page.goto(`${webServerURL}/index.html`);
|
|
46
|
-
while(!await page.evaluate(()=>!!window.AztecJs)){
|
|
47
|
-
pageLogger.verbose('Waiting for window.AztecJs...');
|
|
48
|
-
await AztecJs.sleep(1000);
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
afterAll(async ()=>{
|
|
52
|
-
await browser.close();
|
|
53
|
-
server.close();
|
|
54
|
-
pxeServer?.close();
|
|
55
|
-
});
|
|
56
|
-
it('Loads Aztec.js in the browser', async ()=>{
|
|
57
|
-
const generatePublicKeyExists = await page.evaluate(()=>{
|
|
58
|
-
const { generatePublicKey } = window.AztecJs;
|
|
59
|
-
return typeof generatePublicKey === 'function';
|
|
60
|
-
});
|
|
61
|
-
expect(generatePublicKeyExists).toBe(true);
|
|
62
|
-
});
|
|
63
|
-
it('Creates an account', async ()=>{
|
|
64
|
-
const result = await page.evaluate(async (rpcUrl, secretKeyString)=>{
|
|
65
|
-
const { Fr, createPXEClient, getUnsafeSchnorrAccount } = window.AztecJs;
|
|
66
|
-
const pxe = createPXEClient(rpcUrl);
|
|
67
|
-
const secretKey = Fr.fromHexString(secretKeyString);
|
|
68
|
-
const account = await getUnsafeSchnorrAccount(pxe, secretKey);
|
|
69
|
-
await account.waitSetup();
|
|
70
|
-
const completeAddress = await account.getCompleteAddress();
|
|
71
|
-
const addressString = completeAddress.address.toString();
|
|
72
|
-
console.log(`Created Account: ${addressString}`);
|
|
73
|
-
return addressString;
|
|
74
|
-
}, pxeURL, privKey.toString());
|
|
75
|
-
const accounts = await testClient.getRegisteredAccounts();
|
|
76
|
-
const stringAccounts = accounts.map((acc)=>acc.address.toString());
|
|
77
|
-
expect(stringAccounts.includes(result)).toBeTruthy();
|
|
78
|
-
});
|
|
79
|
-
it('Deploys Token contract', async ()=>{
|
|
80
|
-
await deployTokenContract();
|
|
81
|
-
});
|
|
82
|
-
it('Can access CompleteAddress class in browser', async ()=>{
|
|
83
|
-
const result = await page.evaluate(async ()=>{
|
|
84
|
-
const completeAddress = await window.AztecJs.CompleteAddress.fromString('0x2401bfdad7ac9282bd612e8a6bb0f6ce125b08e317e24dc04ddbba24694ac2e7261249d8b3ad8ad9ed075257eede1dcd8356bfd55e1518f07717c47609194b6500c926582f07fda6a53e3600251f2aa1401c0cd377cef064f3f59045222194541acc5f62d8907a6dc98b85e32f8097a152c3c795bb3981c64e576b014f23005e0891d109aa087560cf8720ae94098827aa009a0bcee09f98fd2a05a7cbc6185402a53516a379d7856d26e3bb5542f1fe57f1ee5a0e4c60f7a463205aa19e2f8e00bce110b9a89857b79e3f70777e38a262b04cf80c56bd833a3c4b58dde7dbdc25c807c4012229e08651fd0d48cf9d966d9ab18826692f48a4cf934bef78614023e9cb95711f532786c7c78e72c3752f03f2a4cafc1846ad9df47324e2b7683f0faaa2e6fe44f3ff68646ce7d8538cb6935ce25472c4c75a244ab0c5d2e3b74d');
|
|
85
|
-
// NOTE: browser does not know how to serialize CompleteAddress for return, so return a string
|
|
86
|
-
// otherwise returning a CompleteAddress makes result undefined.
|
|
87
|
-
return completeAddress.toString();
|
|
88
|
-
});
|
|
89
|
-
expect(result).toBe('0x2401bfdad7ac9282bd612e8a6bb0f6ce125b08e317e24dc04ddbba24694ac2e7261249d8b3ad8ad9ed075257eede1dcd8356bfd55e1518f07717c47609194b6500c926582f07fda6a53e3600251f2aa1401c0cd377cef064f3f59045222194541acc5f62d8907a6dc98b85e32f8097a152c3c795bb3981c64e576b014f23005e0891d109aa087560cf8720ae94098827aa009a0bcee09f98fd2a05a7cbc6185402a53516a379d7856d26e3bb5542f1fe57f1ee5a0e4c60f7a463205aa19e2f8e00bce110b9a89857b79e3f70777e38a262b04cf80c56bd833a3c4b58dde7dbdc25c807c4012229e08651fd0d48cf9d966d9ab18826692f48a4cf934bef78614023e9cb95711f532786c7c78e72c3752f03f2a4cafc1846ad9df47324e2b7683f0faaa2e6fe44f3ff68646ce7d8538cb6935ce25472c4c75a244ab0c5d2e3b74d');
|
|
90
|
-
});
|
|
91
|
-
it("Gets the owner's balance", async ()=>{
|
|
92
|
-
const result = await page.evaluate(async (rpcUrl, contractAddress, TokenContractArtifact)=>{
|
|
93
|
-
const { Contract, AztecAddress, createPXEClient: createPXEClient, getDeployedTestAccountsWallets } = window.AztecJs;
|
|
94
|
-
const pxe = createPXEClient(rpcUrl);
|
|
95
|
-
const [wallet] = await getDeployedTestAccountsWallets(pxe);
|
|
96
|
-
const owner = wallet.getCompleteAddress().address;
|
|
97
|
-
const contract = await Contract.at(AztecAddress.fromString(contractAddress), TokenContractArtifact, wallet);
|
|
98
|
-
const balance = await contract.methods.balance_of_private(owner).simulate({
|
|
99
|
-
from: owner
|
|
100
|
-
});
|
|
101
|
-
return balance;
|
|
102
|
-
}, pxeURL, (await getTokenAddress()).toString(), TokenContractArtifact);
|
|
103
|
-
expect(result).toEqual(initialBalance);
|
|
104
|
-
});
|
|
105
|
-
it('Sends a transfer TX', async ()=>{
|
|
106
|
-
const result = await page.evaluate(async (rpcUrl, contractAddress, transferAmount, TokenContractArtifact)=>{
|
|
107
|
-
console.log(`Starting transfer tx`);
|
|
108
|
-
const { AztecAddress, Contract, createPXEClient: createPXEClient, getDeployedTestAccountsWallets, getUnsafeSchnorrAccount } = window.AztecJs;
|
|
109
|
-
const pxe = createPXEClient(rpcUrl);
|
|
110
|
-
const newReceiverAccountManager = await getUnsafeSchnorrAccount(pxe, AztecJs.Fr.random());
|
|
111
|
-
const newReceiverAccount = await newReceiverAccountManager.waitSetup();
|
|
112
|
-
const receiverAddress = newReceiverAccount.getCompleteAddress().address;
|
|
113
|
-
const [wallet] = await getDeployedTestAccountsWallets(pxe);
|
|
114
|
-
const contract = await Contract.at(AztecAddress.fromString(contractAddress), TokenContractArtifact, wallet);
|
|
115
|
-
await contract.methods.transfer(receiverAddress, transferAmount).send().wait();
|
|
116
|
-
console.log(`Transferred ${transferAmount} tokens to new Account`);
|
|
117
|
-
return await contract.methods.balance_of_private(receiverAddress).simulate({
|
|
118
|
-
from: receiverAddress
|
|
119
|
-
});
|
|
120
|
-
}, pxeURL, (await getTokenAddress()).toString(), transferAmount, TokenContractArtifact);
|
|
121
|
-
expect(result).toEqual(transferAmount);
|
|
122
|
-
});
|
|
123
|
-
const deployTokenContract = async ()=>{
|
|
124
|
-
const [txHash, tokenAddress] = await page.evaluate(async (rpcUrl, initialBalance, serializedTokenContractArtifact)=>{
|
|
125
|
-
const { DeployMethod, createPXEClient, getSchnorrAccount, Contract, getDeployedTestAccountsWallets, INITIAL_TEST_SECRET_KEYS, INITIAL_TEST_SIGNING_KEYS, INITIAL_TEST_ACCOUNT_SALTS, Buffer, contractArtifactFromBuffer } = window.AztecJs;
|
|
126
|
-
// We serialize the artifact since buffers (used for bytecode) do not cross well from one realm to another
|
|
127
|
-
const TokenContractArtifact = await contractArtifactFromBuffer(Buffer.from(serializedTokenContractArtifact, 'base64'));
|
|
128
|
-
const pxe = createPXEClient(rpcUrl);
|
|
129
|
-
// we need to ensure that a known account is present in order to create a wallet
|
|
130
|
-
const knownAccounts = await getDeployedTestAccountsWallets(pxe);
|
|
131
|
-
if (!knownAccounts.length) {
|
|
132
|
-
const newAccountManager = await getSchnorrAccount(pxe, INITIAL_TEST_SECRET_KEYS[0], INITIAL_TEST_SIGNING_KEYS[0], INITIAL_TEST_ACCOUNT_SALTS[0]);
|
|
133
|
-
const newAccount = await newAccountManager.waitSetup();
|
|
134
|
-
knownAccounts.push(newAccount);
|
|
135
|
-
}
|
|
136
|
-
const owner = knownAccounts[0];
|
|
137
|
-
const tx = new DeployMethod(owner.getCompleteAddress().publicKeys, owner, TokenContractArtifact, (a)=>Contract.at(a, TokenContractArtifact, owner), [
|
|
138
|
-
owner.getCompleteAddress(),
|
|
139
|
-
'TokenName',
|
|
140
|
-
'TKN',
|
|
141
|
-
18
|
|
142
|
-
]).send();
|
|
143
|
-
const { contract: token, txHash } = await tx.wait();
|
|
144
|
-
console.log(`Contract Deployed: ${token.address}`);
|
|
145
|
-
// We mint tokens to the owner
|
|
146
|
-
const from = owner.getAddress(); // we are setting from to owner here because of TODO(#9887)
|
|
147
|
-
await token.methods.mint_to_private(from, owner.getAddress(), initialBalance).send().wait();
|
|
148
|
-
return [
|
|
149
|
-
txHash.toString(),
|
|
150
|
-
token.address.toString()
|
|
151
|
-
];
|
|
152
|
-
}, pxeURL, initialBalance, contractArtifactToBuffer(TokenContractArtifact).toString('base64'));
|
|
153
|
-
const txResult = await testClient.getTxReceipt(AztecJs.TxHash.fromString(txHash));
|
|
154
|
-
expect(txResult.status).toEqual(AztecJs.TxStatus.SUCCESS);
|
|
155
|
-
contractAddress = AztecJs.AztecAddress.fromString(tokenAddress);
|
|
156
|
-
};
|
|
157
|
-
const getTokenAddress = async ()=>{
|
|
158
|
-
if (!contractAddress) {
|
|
159
|
-
await deployTokenContract();
|
|
160
|
-
}
|
|
161
|
-
return contractAddress;
|
|
162
|
-
};
|
|
163
|
-
});
|
package/src/shared/browser.ts
DELETED
|
@@ -1,272 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
|
-
import type * as AztecAccountsSchnorr from '@aztec/accounts/schnorr';
|
|
3
|
-
import type * as AztecAccountsSingleKey from '@aztec/accounts/single_key';
|
|
4
|
-
import type * as AztecAccountsTesting from '@aztec/accounts/testing';
|
|
5
|
-
import * as AztecJs from '@aztec/aztec.js';
|
|
6
|
-
import { TokenContractArtifact } from '@aztec/noir-contracts.js/Token';
|
|
7
|
-
import { contractArtifactToBuffer } from '@aztec/types/abi';
|
|
8
|
-
|
|
9
|
-
import getPort from 'get-port';
|
|
10
|
-
import { type Server } from 'http';
|
|
11
|
-
import { type Browser, type Page, launch } from 'puppeteer-core';
|
|
12
|
-
|
|
13
|
-
declare global {
|
|
14
|
-
/**
|
|
15
|
-
* Helper interface to declare aztec.js within browser context.
|
|
16
|
-
*/
|
|
17
|
-
interface Window {
|
|
18
|
-
/**
|
|
19
|
-
* The aztec.js library.
|
|
20
|
-
*/
|
|
21
|
-
AztecJs: { Buffer: typeof Buffer } & typeof AztecJs &
|
|
22
|
-
typeof AztecAccountsSingleKey &
|
|
23
|
-
typeof AztecAccountsTesting &
|
|
24
|
-
typeof AztecAccountsSchnorr;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const privKey = AztecJs.GrumpkinScalar.random();
|
|
29
|
-
|
|
30
|
-
export const browserTestSuite = (
|
|
31
|
-
setup: () => Promise<{
|
|
32
|
-
/**
|
|
33
|
-
* The webserver instance.
|
|
34
|
-
*/
|
|
35
|
-
server: Server;
|
|
36
|
-
/**
|
|
37
|
-
* The webserver URL.
|
|
38
|
-
*/
|
|
39
|
-
webServerURL: string;
|
|
40
|
-
/**
|
|
41
|
-
* The PXE webserver instance.
|
|
42
|
-
*/
|
|
43
|
-
pxeServer: Server | undefined;
|
|
44
|
-
/**
|
|
45
|
-
* The url of the PXE
|
|
46
|
-
*/
|
|
47
|
-
pxeURL: string;
|
|
48
|
-
}>,
|
|
49
|
-
pageLogger: AztecJs.Logger,
|
|
50
|
-
) =>
|
|
51
|
-
describe('e2e_aztec.js_browser', () => {
|
|
52
|
-
const initialBalance = 33n;
|
|
53
|
-
const transferAmount = 3n;
|
|
54
|
-
|
|
55
|
-
let contractAddress: AztecJs.AztecAddress;
|
|
56
|
-
|
|
57
|
-
let testClient: AztecJs.PXE;
|
|
58
|
-
let server: Server;
|
|
59
|
-
let webServerURL: string;
|
|
60
|
-
let pxeServer: Server | undefined;
|
|
61
|
-
let pxeURL: string;
|
|
62
|
-
|
|
63
|
-
let browser: Browser;
|
|
64
|
-
let page: Page;
|
|
65
|
-
|
|
66
|
-
beforeAll(async () => {
|
|
67
|
-
({ server, pxeURL, pxeServer, webServerURL } = await setup());
|
|
68
|
-
testClient = AztecJs.createPXEClient(pxeURL);
|
|
69
|
-
await AztecJs.waitForPXE(testClient);
|
|
70
|
-
|
|
71
|
-
const debuggingPort = await getPort({ port: 9222 });
|
|
72
|
-
browser = await launch({
|
|
73
|
-
executablePath: process.env.CHROME_BIN,
|
|
74
|
-
headless: true,
|
|
75
|
-
debuggingPort,
|
|
76
|
-
args: [
|
|
77
|
-
'--no-sandbox',
|
|
78
|
-
'--headless',
|
|
79
|
-
'--disable-gpu',
|
|
80
|
-
'--disable-dev-shm-usage',
|
|
81
|
-
'--disable-software-rasterizer',
|
|
82
|
-
`--remote-debugging-port=${debuggingPort}`,
|
|
83
|
-
],
|
|
84
|
-
});
|
|
85
|
-
page = await browser.newPage();
|
|
86
|
-
page.on('console', msg => {
|
|
87
|
-
pageLogger.info(msg.text());
|
|
88
|
-
});
|
|
89
|
-
page.on('pageerror', err => {
|
|
90
|
-
pageLogger.error(`Error on web page`, err);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
await page.goto(`${webServerURL}/index.html`);
|
|
94
|
-
while (!(await page.evaluate(() => !!window.AztecJs))) {
|
|
95
|
-
pageLogger.verbose('Waiting for window.AztecJs...');
|
|
96
|
-
await AztecJs.sleep(1000);
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
afterAll(async () => {
|
|
101
|
-
await browser.close();
|
|
102
|
-
server.close();
|
|
103
|
-
pxeServer?.close();
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it('Loads Aztec.js in the browser', async () => {
|
|
107
|
-
const generatePublicKeyExists = await page.evaluate(() => {
|
|
108
|
-
const { generatePublicKey } = window.AztecJs;
|
|
109
|
-
return typeof generatePublicKey === 'function';
|
|
110
|
-
});
|
|
111
|
-
expect(generatePublicKeyExists).toBe(true);
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it('Creates an account', async () => {
|
|
115
|
-
const result = await page.evaluate(
|
|
116
|
-
async (rpcUrl, secretKeyString) => {
|
|
117
|
-
const { Fr, createPXEClient, getUnsafeSchnorrAccount } = window.AztecJs;
|
|
118
|
-
const pxe = createPXEClient(rpcUrl!);
|
|
119
|
-
const secretKey = Fr.fromHexString(secretKeyString);
|
|
120
|
-
const account = await getUnsafeSchnorrAccount(pxe, secretKey);
|
|
121
|
-
await account.waitSetup();
|
|
122
|
-
const completeAddress = await account.getCompleteAddress();
|
|
123
|
-
const addressString = completeAddress.address.toString();
|
|
124
|
-
console.log(`Created Account: ${addressString}`);
|
|
125
|
-
return addressString;
|
|
126
|
-
},
|
|
127
|
-
pxeURL,
|
|
128
|
-
privKey.toString(),
|
|
129
|
-
);
|
|
130
|
-
const accounts = await testClient.getRegisteredAccounts();
|
|
131
|
-
const stringAccounts = accounts.map(acc => acc.address.toString());
|
|
132
|
-
expect(stringAccounts.includes(result)).toBeTruthy();
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
it('Deploys Token contract', async () => {
|
|
136
|
-
await deployTokenContract();
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
it('Can access CompleteAddress class in browser', async () => {
|
|
140
|
-
const result: string = await page.evaluate(async () => {
|
|
141
|
-
const completeAddress = await window.AztecJs.CompleteAddress.fromString(
|
|
142
|
-
'0x2401bfdad7ac9282bd612e8a6bb0f6ce125b08e317e24dc04ddbba24694ac2e7261249d8b3ad8ad9ed075257eede1dcd8356bfd55e1518f07717c47609194b6500c926582f07fda6a53e3600251f2aa1401c0cd377cef064f3f59045222194541acc5f62d8907a6dc98b85e32f8097a152c3c795bb3981c64e576b014f23005e0891d109aa087560cf8720ae94098827aa009a0bcee09f98fd2a05a7cbc6185402a53516a379d7856d26e3bb5542f1fe57f1ee5a0e4c60f7a463205aa19e2f8e00bce110b9a89857b79e3f70777e38a262b04cf80c56bd833a3c4b58dde7dbdc25c807c4012229e08651fd0d48cf9d966d9ab18826692f48a4cf934bef78614023e9cb95711f532786c7c78e72c3752f03f2a4cafc1846ad9df47324e2b7683f0faaa2e6fe44f3ff68646ce7d8538cb6935ce25472c4c75a244ab0c5d2e3b74d',
|
|
143
|
-
);
|
|
144
|
-
// NOTE: browser does not know how to serialize CompleteAddress for return, so return a string
|
|
145
|
-
// otherwise returning a CompleteAddress makes result undefined.
|
|
146
|
-
return completeAddress.toString();
|
|
147
|
-
});
|
|
148
|
-
expect(result).toBe(
|
|
149
|
-
'0x2401bfdad7ac9282bd612e8a6bb0f6ce125b08e317e24dc04ddbba24694ac2e7261249d8b3ad8ad9ed075257eede1dcd8356bfd55e1518f07717c47609194b6500c926582f07fda6a53e3600251f2aa1401c0cd377cef064f3f59045222194541acc5f62d8907a6dc98b85e32f8097a152c3c795bb3981c64e576b014f23005e0891d109aa087560cf8720ae94098827aa009a0bcee09f98fd2a05a7cbc6185402a53516a379d7856d26e3bb5542f1fe57f1ee5a0e4c60f7a463205aa19e2f8e00bce110b9a89857b79e3f70777e38a262b04cf80c56bd833a3c4b58dde7dbdc25c807c4012229e08651fd0d48cf9d966d9ab18826692f48a4cf934bef78614023e9cb95711f532786c7c78e72c3752f03f2a4cafc1846ad9df47324e2b7683f0faaa2e6fe44f3ff68646ce7d8538cb6935ce25472c4c75a244ab0c5d2e3b74d',
|
|
150
|
-
);
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it("Gets the owner's balance", async () => {
|
|
154
|
-
const result = await page.evaluate(
|
|
155
|
-
async (rpcUrl, contractAddress, TokenContractArtifact) => {
|
|
156
|
-
const {
|
|
157
|
-
Contract,
|
|
158
|
-
AztecAddress,
|
|
159
|
-
createPXEClient: createPXEClient,
|
|
160
|
-
getDeployedTestAccountsWallets,
|
|
161
|
-
} = window.AztecJs;
|
|
162
|
-
const pxe = createPXEClient(rpcUrl!);
|
|
163
|
-
const [wallet] = await getDeployedTestAccountsWallets(pxe);
|
|
164
|
-
const owner = wallet.getCompleteAddress().address;
|
|
165
|
-
const contract = await Contract.at(AztecAddress.fromString(contractAddress), TokenContractArtifact, wallet);
|
|
166
|
-
const balance = await contract.methods.balance_of_private(owner).simulate({ from: owner });
|
|
167
|
-
return balance;
|
|
168
|
-
},
|
|
169
|
-
pxeURL,
|
|
170
|
-
(await getTokenAddress()).toString(),
|
|
171
|
-
TokenContractArtifact,
|
|
172
|
-
);
|
|
173
|
-
expect(result).toEqual(initialBalance);
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
it('Sends a transfer TX', async () => {
|
|
177
|
-
const result = await page.evaluate(
|
|
178
|
-
async (rpcUrl, contractAddress, transferAmount, TokenContractArtifact) => {
|
|
179
|
-
console.log(`Starting transfer tx`);
|
|
180
|
-
const {
|
|
181
|
-
AztecAddress,
|
|
182
|
-
Contract,
|
|
183
|
-
createPXEClient: createPXEClient,
|
|
184
|
-
getDeployedTestAccountsWallets,
|
|
185
|
-
getUnsafeSchnorrAccount,
|
|
186
|
-
} = window.AztecJs;
|
|
187
|
-
const pxe = createPXEClient(rpcUrl!);
|
|
188
|
-
const newReceiverAccountManager = await getUnsafeSchnorrAccount(pxe, AztecJs.Fr.random());
|
|
189
|
-
const newReceiverAccount = await newReceiverAccountManager.waitSetup();
|
|
190
|
-
const receiverAddress = newReceiverAccount.getCompleteAddress().address;
|
|
191
|
-
const [wallet] = await getDeployedTestAccountsWallets(pxe);
|
|
192
|
-
const contract = await Contract.at(AztecAddress.fromString(contractAddress), TokenContractArtifact, wallet);
|
|
193
|
-
await contract.methods.transfer(receiverAddress, transferAmount).send().wait();
|
|
194
|
-
console.log(`Transferred ${transferAmount} tokens to new Account`);
|
|
195
|
-
return await contract.methods.balance_of_private(receiverAddress).simulate({ from: receiverAddress });
|
|
196
|
-
},
|
|
197
|
-
pxeURL,
|
|
198
|
-
(await getTokenAddress()).toString(),
|
|
199
|
-
transferAmount,
|
|
200
|
-
TokenContractArtifact,
|
|
201
|
-
);
|
|
202
|
-
expect(result).toEqual(transferAmount);
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
const deployTokenContract = async () => {
|
|
206
|
-
const [txHash, tokenAddress] = await page.evaluate(
|
|
207
|
-
async (rpcUrl, initialBalance, serializedTokenContractArtifact) => {
|
|
208
|
-
const {
|
|
209
|
-
DeployMethod,
|
|
210
|
-
createPXEClient,
|
|
211
|
-
getSchnorrAccount,
|
|
212
|
-
Contract,
|
|
213
|
-
getDeployedTestAccountsWallets,
|
|
214
|
-
INITIAL_TEST_SECRET_KEYS,
|
|
215
|
-
INITIAL_TEST_SIGNING_KEYS,
|
|
216
|
-
INITIAL_TEST_ACCOUNT_SALTS,
|
|
217
|
-
Buffer,
|
|
218
|
-
contractArtifactFromBuffer,
|
|
219
|
-
} = window.AztecJs;
|
|
220
|
-
// We serialize the artifact since buffers (used for bytecode) do not cross well from one realm to another
|
|
221
|
-
const TokenContractArtifact = await contractArtifactFromBuffer(
|
|
222
|
-
Buffer.from(serializedTokenContractArtifact, 'base64'),
|
|
223
|
-
);
|
|
224
|
-
const pxe = createPXEClient(rpcUrl!);
|
|
225
|
-
|
|
226
|
-
// we need to ensure that a known account is present in order to create a wallet
|
|
227
|
-
const knownAccounts = await getDeployedTestAccountsWallets(pxe);
|
|
228
|
-
if (!knownAccounts.length) {
|
|
229
|
-
const newAccountManager = await getSchnorrAccount(
|
|
230
|
-
pxe,
|
|
231
|
-
INITIAL_TEST_SECRET_KEYS[0],
|
|
232
|
-
INITIAL_TEST_SIGNING_KEYS[0],
|
|
233
|
-
INITIAL_TEST_ACCOUNT_SALTS[0],
|
|
234
|
-
);
|
|
235
|
-
const newAccount = await newAccountManager.waitSetup();
|
|
236
|
-
knownAccounts.push(newAccount);
|
|
237
|
-
}
|
|
238
|
-
const owner = knownAccounts[0];
|
|
239
|
-
const tx = new DeployMethod(
|
|
240
|
-
owner.getCompleteAddress().publicKeys,
|
|
241
|
-
owner,
|
|
242
|
-
TokenContractArtifact,
|
|
243
|
-
(a: AztecJs.AztecAddress) => Contract.at(a, TokenContractArtifact, owner),
|
|
244
|
-
[owner.getCompleteAddress(), 'TokenName', 'TKN', 18],
|
|
245
|
-
).send();
|
|
246
|
-
const { contract: token, txHash } = await tx.wait();
|
|
247
|
-
|
|
248
|
-
console.log(`Contract Deployed: ${token.address}`);
|
|
249
|
-
|
|
250
|
-
// We mint tokens to the owner
|
|
251
|
-
const from = owner.getAddress(); // we are setting from to owner here because of TODO(#9887)
|
|
252
|
-
await token.methods.mint_to_private(from, owner.getAddress(), initialBalance).send().wait();
|
|
253
|
-
|
|
254
|
-
return [txHash.toString(), token.address.toString()];
|
|
255
|
-
},
|
|
256
|
-
pxeURL,
|
|
257
|
-
initialBalance,
|
|
258
|
-
contractArtifactToBuffer(TokenContractArtifact).toString('base64'),
|
|
259
|
-
);
|
|
260
|
-
|
|
261
|
-
const txResult = await testClient.getTxReceipt(AztecJs.TxHash.fromString(txHash));
|
|
262
|
-
expect(txResult.status).toEqual(AztecJs.TxStatus.SUCCESS);
|
|
263
|
-
contractAddress = AztecJs.AztecAddress.fromString(tokenAddress);
|
|
264
|
-
};
|
|
265
|
-
|
|
266
|
-
const getTokenAddress = async () => {
|
|
267
|
-
if (!contractAddress) {
|
|
268
|
-
await deployTokenContract();
|
|
269
|
-
}
|
|
270
|
-
return contractAddress;
|
|
271
|
-
};
|
|
272
|
-
});
|