@aztec/end-to-end 2.0.0-nightly.20250825 → 2.0.0-nightly.20250827
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/e2e_epochs/epochs_test.d.ts +1 -1
- package/dest/e2e_epochs/epochs_test.d.ts.map +1 -1
- package/dest/e2e_epochs/epochs_test.js +8 -3
- package/dest/e2e_fees/fees_test.d.ts.map +1 -1
- package/dest/e2e_fees/fees_test.js +1 -5
- 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 +220 -0
- package/dest/e2e_p2p/p2p_network.d.ts.map +1 -1
- package/dest/e2e_p2p/p2p_network.js +2 -2
- package/dest/fixtures/e2e_prover_test.js +4 -2
- package/dest/fixtures/setup_p2p_test.js +3 -1
- package/dest/fixtures/snapshot_manager.d.ts.map +1 -1
- package/dest/fixtures/snapshot_manager.js +9 -6
- package/dest/fixtures/utils.d.ts +6 -1
- package/dest/fixtures/utils.d.ts.map +1 -1
- package/dest/fixtures/utils.js +27 -9
- package/package.json +36 -35
- package/src/e2e_epochs/epochs_test.ts +11 -4
- package/src/e2e_fees/fees_test.ts +1 -2
- package/src/e2e_multi_validator/utils.ts +264 -0
- package/src/e2e_p2p/p2p_network.ts +2 -2
- package/src/fixtures/e2e_prover_test.ts +2 -2
- package/src/fixtures/setup_p2p_test.ts +1 -1
- package/src/fixtures/snapshot_manager.ts +6 -3
- package/src/fixtures/utils.ts +39 -9
- package/dest/sample-dapp/connect.d.mts +0 -2
- package/dest/sample-dapp/connect.d.mts.map +0 -1
- package/dest/sample-dapp/connect.js +0 -12
- package/dest/sample-dapp/contracts.d.mts +0 -3
- package/dest/sample-dapp/contracts.d.mts.map +0 -1
- package/dest/sample-dapp/contracts.js +0 -10
- package/dest/sample-dapp/deploy.d.mts +0 -3
- package/dest/sample-dapp/deploy.d.mts.map +0 -1
- package/dest/sample-dapp/deploy.js +0 -39
- package/dest/sample-dapp/index.d.mts +0 -2
- package/dest/sample-dapp/index.d.mts.map +0 -1
- package/dest/sample-dapp/index.js +0 -108
- package/src/sample-dapp/connect.mjs +0 -16
- package/src/sample-dapp/contracts.mjs +0 -14
- package/src/sample-dapp/deploy.mjs +0 -42
- package/src/sample-dapp/index.mjs +0 -131
package/src/fixtures/utils.ts
CHANGED
|
@@ -43,7 +43,13 @@ import {
|
|
|
43
43
|
getL1ContractsConfigEnvVars,
|
|
44
44
|
isAnvilTestChain,
|
|
45
45
|
} from '@aztec/ethereum';
|
|
46
|
-
import {
|
|
46
|
+
import {
|
|
47
|
+
DelayedTxUtils,
|
|
48
|
+
EthCheatCodes,
|
|
49
|
+
EthCheatCodesWithState,
|
|
50
|
+
createDelayedL1TxUtilsFromViemWallet,
|
|
51
|
+
startAnvil,
|
|
52
|
+
} from '@aztec/ethereum/test';
|
|
47
53
|
import { SecretValue } from '@aztec/foundation/config';
|
|
48
54
|
import { randomBytes } from '@aztec/foundation/crypto';
|
|
49
55
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
@@ -93,7 +99,7 @@ import getPort from 'get-port';
|
|
|
93
99
|
import { tmpdir } from 'os';
|
|
94
100
|
import * as path from 'path';
|
|
95
101
|
import { type Chain, type HDAccount, type Hex, type PrivateKeyAccount, getContract } from 'viem';
|
|
96
|
-
import { mnemonicToAccount, privateKeyToAccount } from 'viem/accounts';
|
|
102
|
+
import { generatePrivateKey, mnemonicToAccount, privateKeyToAccount } from 'viem/accounts';
|
|
97
103
|
import { foundry } from 'viem/chains';
|
|
98
104
|
|
|
99
105
|
import { MNEMONIC, TEST_PEER_CHECK_INTERVAL_MS } from './fixtures.js';
|
|
@@ -236,6 +242,7 @@ async function setupWithRemoteEnvironment(
|
|
|
236
242
|
l1Client,
|
|
237
243
|
rollupVersion,
|
|
238
244
|
};
|
|
245
|
+
const ethCheatCodes = new EthCheatCodes(config.l1RpcUrls);
|
|
239
246
|
const cheatCodes = await CheatCodes.create(config.l1RpcUrls, pxeClient!);
|
|
240
247
|
const teardown = () => Promise.resolve();
|
|
241
248
|
|
|
@@ -262,6 +269,7 @@ async function setupWithRemoteEnvironment(
|
|
|
262
269
|
accounts: wallets.slice(0, numberOfAccounts).map(w => w.getAddress()),
|
|
263
270
|
logger,
|
|
264
271
|
cheatCodes,
|
|
272
|
+
ethCheatCodes,
|
|
265
273
|
prefilledPublicData: undefined,
|
|
266
274
|
mockGossipSubNetwork: undefined,
|
|
267
275
|
watcher: undefined,
|
|
@@ -316,6 +324,8 @@ export type SetupOptions = {
|
|
|
316
324
|
anvilAccounts?: number;
|
|
317
325
|
/** Port to start anvil (defaults to 8545) */
|
|
318
326
|
anvilPort?: number;
|
|
327
|
+
/** Key to use for publishing L1 contracts */
|
|
328
|
+
l1PublisherKey?: SecretValue<`0x${string}`>;
|
|
319
329
|
} & Partial<AztecNodeConfig>;
|
|
320
330
|
|
|
321
331
|
/** Context for an end-to-end test as returned by the `setup` function */
|
|
@@ -346,6 +356,8 @@ export type EndToEndContext = {
|
|
|
346
356
|
logger: Logger;
|
|
347
357
|
/** The cheat codes. */
|
|
348
358
|
cheatCodes: CheatCodes;
|
|
359
|
+
/** The cheat codes for L1 */
|
|
360
|
+
ethCheatCodes: EthCheatCodes;
|
|
349
361
|
/** The anvil test watcher (undefined if connected to remote environment) */
|
|
350
362
|
watcher: AnvilTestWatcher | undefined;
|
|
351
363
|
/** Allows tweaking current system time, used by the epoch cache only (undefined if connected to remote environment) */
|
|
@@ -438,17 +450,25 @@ export async function setup(
|
|
|
438
450
|
let publisherPrivKey = undefined;
|
|
439
451
|
let publisherHdAccount = undefined;
|
|
440
452
|
|
|
441
|
-
if (
|
|
442
|
-
publisherHdAccount = privateKeyToAccount(
|
|
453
|
+
if (opts.l1PublisherKey && opts.l1PublisherKey.getValue() && opts.l1PublisherKey.getValue() != NULL_KEY) {
|
|
454
|
+
publisherHdAccount = privateKeyToAccount(opts.l1PublisherKey.getValue());
|
|
455
|
+
} else if (
|
|
456
|
+
config.publisherPrivateKeys &&
|
|
457
|
+
config.publisherPrivateKeys.length > 0 &&
|
|
458
|
+
config.publisherPrivateKeys[0].getValue() != NULL_KEY
|
|
459
|
+
) {
|
|
460
|
+
publisherHdAccount = privateKeyToAccount(config.publisherPrivateKeys[0].getValue());
|
|
443
461
|
} else if (!MNEMONIC) {
|
|
444
462
|
throw new Error(`Mnemonic not provided and no publisher private key`);
|
|
445
463
|
} else {
|
|
446
464
|
publisherHdAccount = mnemonicToAccount(MNEMONIC, { addressIndex: 0 });
|
|
447
465
|
const publisherPrivKeyRaw = publisherHdAccount.getHdKey().privateKey;
|
|
448
466
|
publisherPrivKey = publisherPrivKeyRaw === null ? null : Buffer.from(publisherPrivKeyRaw);
|
|
449
|
-
config.
|
|
467
|
+
config.publisherPrivateKeys = [new SecretValue(`0x${publisherPrivKey!.toString('hex')}` as const)];
|
|
450
468
|
}
|
|
451
469
|
|
|
470
|
+
config.coinbase = EthAddress.fromString(publisherHdAccount.address);
|
|
471
|
+
|
|
452
472
|
if (PXE_URL) {
|
|
453
473
|
// we are setting up against a remote environment, l1 contracts are assumed to already be deployed
|
|
454
474
|
return await setupWithRemoteEnvironment(publisherHdAccount!, config, logger, numberOfAccounts);
|
|
@@ -603,6 +623,13 @@ export async function setup(
|
|
|
603
623
|
|
|
604
624
|
config.p2pEnabled = opts.mockGossipSubNetwork || config.p2pEnabled;
|
|
605
625
|
config.p2pIp = opts.p2pIp ?? config.p2pIp ?? '127.0.0.1';
|
|
626
|
+
|
|
627
|
+
if (!config.disableValidator) {
|
|
628
|
+
if ((config.validatorPrivateKeys?.getValue().length ?? 0) === 0) {
|
|
629
|
+
config.validatorPrivateKeys = new SecretValue([generatePrivateKey()]);
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
|
|
606
633
|
const aztecNode = await AztecNodeService.createAndSync(
|
|
607
634
|
config, // REFACTOR: createAndSync mutates this config
|
|
608
635
|
{ dateProvider, blobSinkClient, telemetry, p2pClientDeps, logger: createLogger('node:MAIN-aztec-node') },
|
|
@@ -612,7 +639,7 @@ export async function setup(
|
|
|
612
639
|
|
|
613
640
|
if (sequencerClient) {
|
|
614
641
|
const publisher = (sequencerClient as TestSequencerClient).sequencer.publisher;
|
|
615
|
-
publisher.l1TxUtils = DelayedTxUtils.fromL1TxUtils(publisher.l1TxUtils, config.ethereumSlotDuration);
|
|
642
|
+
publisher.l1TxUtils = DelayedTxUtils.fromL1TxUtils(publisher.l1TxUtils, config.ethereumSlotDuration, l1Client);
|
|
616
643
|
}
|
|
617
644
|
|
|
618
645
|
let proverNode: ProverNode | undefined = undefined;
|
|
@@ -687,8 +714,9 @@ export async function setup(
|
|
|
687
714
|
await bbConfig.cleanup();
|
|
688
715
|
}
|
|
689
716
|
|
|
690
|
-
await tryStop(anvil, logger);
|
|
691
717
|
await tryStop(watcher, logger);
|
|
718
|
+
await tryStop(anvil, logger);
|
|
719
|
+
|
|
692
720
|
await tryStop(blobSink, logger);
|
|
693
721
|
await tryRmDir(directoryToCleanup, logger);
|
|
694
722
|
} catch (err) {
|
|
@@ -701,6 +729,7 @@ export async function setup(
|
|
|
701
729
|
aztecNodeAdmin: aztecNode,
|
|
702
730
|
blobSink,
|
|
703
731
|
cheatCodes,
|
|
732
|
+
ethCheatCodes,
|
|
704
733
|
config,
|
|
705
734
|
dateProvider,
|
|
706
735
|
deployL1ContractsValues,
|
|
@@ -924,7 +953,7 @@ export function createAndSyncProverNode(
|
|
|
924
953
|
txCollectionNodeRpcUrls: [],
|
|
925
954
|
realProofs: false,
|
|
926
955
|
proverAgentCount: 2,
|
|
927
|
-
|
|
956
|
+
publisherPrivateKeys: [new SecretValue(proverNodePrivateKey)],
|
|
928
957
|
proverNodeMaxPendingJobs: 10,
|
|
929
958
|
proverNodeMaxParallelBlocksPerEpoch: 32,
|
|
930
959
|
proverNodePollingIntervalMs: 200,
|
|
@@ -933,6 +962,7 @@ export function createAndSyncProverNode(
|
|
|
933
962
|
txGatheringMaxParallelRequestsPerNode: 10,
|
|
934
963
|
txGatheringTimeoutMs: 24_000,
|
|
935
964
|
proverNodeFailedEpochStore: undefined,
|
|
965
|
+
proverId: EthAddress.fromNumber(1),
|
|
936
966
|
...proverNodeConfig,
|
|
937
967
|
};
|
|
938
968
|
|
|
@@ -963,7 +993,7 @@ function createDelayedL1TxUtils(
|
|
|
963
993
|
const l1Client = createExtendedL1Client(aztecNodeConfig.l1RpcUrls, privateKey, foundry);
|
|
964
994
|
|
|
965
995
|
const log = createLogger(logName);
|
|
966
|
-
const l1TxUtils =
|
|
996
|
+
const l1TxUtils = createDelayedL1TxUtilsFromViemWallet(l1Client, log, dateProvider, aztecNodeConfig);
|
|
967
997
|
l1TxUtils.enableDelayer(aztecNodeConfig.ethereumSlotDuration);
|
|
968
998
|
return l1TxUtils;
|
|
969
999
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"connect.d.mts","sourceRoot":"","sources":["../../src/sample-dapp/connect.mjs"],"names":[],"mappings":""}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
// docs:start:all
|
|
2
|
-
import { createPXEClient } from '@aztec/aztec.js';
|
|
3
|
-
const { PXE_URL = 'http://localhost:8080' } = process.env;
|
|
4
|
-
async function main() {
|
|
5
|
-
const pxe = createPXEClient(PXE_URL);
|
|
6
|
-
const { l1ChainId } = await pxe.getNodeInfo();
|
|
7
|
-
console.log(`Connected to chain ${l1ChainId}`);
|
|
8
|
-
}
|
|
9
|
-
main().catch((err)=>{
|
|
10
|
-
console.error(`Error in app: ${err}`);
|
|
11
|
-
process.exit(1);
|
|
12
|
-
}); // docs:end:all
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"contracts.d.mts","sourceRoot":"","sources":["../../src/sample-dapp/contracts.mjs"],"names":[],"mappings":"AASA,yDAGC;yBAZsC,iBAAiB"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { AztecAddress, Contract } from '@aztec/aztec.js';
|
|
2
|
-
import { TokenContract } from '@aztec/noir-contracts.js/Token';
|
|
3
|
-
import { readFileSync } from 'fs';
|
|
4
|
-
// This syntax is helpful for the referencing tutorial
|
|
5
|
-
const TokenContractArtifact = TokenContract.artifact;
|
|
6
|
-
// docs:start:get-tokens
|
|
7
|
-
export function getToken(wallet) {
|
|
8
|
-
const addresses = JSON.parse(readFileSync('addresses.json'));
|
|
9
|
-
return Contract.at(AztecAddress.fromString(addresses.token), TokenContractArtifact, wallet);
|
|
10
|
-
} // docs:end:get-tokens
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"deploy.d.mts","sourceRoot":"","sources":["../../src/sample-dapp/deploy.mjs"],"names":[],"mappings":";AAeA,uCAeC"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
// docs:start:deploy-imports
|
|
2
|
-
import { getInitialTestAccountsWallets } from '@aztec/accounts/testing';
|
|
3
|
-
import { Contract, createPXEClient, waitForPXE } from '@aztec/aztec.js';
|
|
4
|
-
// docs:end:deploy-imports
|
|
5
|
-
// docs:start:import_artifact
|
|
6
|
-
import { TokenContractArtifact } from '@aztec/noir-contracts.js/Token';
|
|
7
|
-
// docs:end:import_artifact
|
|
8
|
-
import { writeFileSync } from 'fs';
|
|
9
|
-
import { fileURLToPath } from 'url';
|
|
10
|
-
// docs:start:dapp-deploy
|
|
11
|
-
const { PXE_URL = 'http://localhost:8080' } = process.env;
|
|
12
|
-
async function main() {
|
|
13
|
-
const pxe = createPXEClient(PXE_URL);
|
|
14
|
-
await waitForPXE(pxe);
|
|
15
|
-
const [ownerWallet] = await getInitialTestAccountsWallets(pxe);
|
|
16
|
-
const ownerAddress = ownerWallet.getAddress();
|
|
17
|
-
const token = await Contract.deploy(ownerWallet, TokenContractArtifact, [
|
|
18
|
-
ownerAddress,
|
|
19
|
-
'TokenName',
|
|
20
|
-
'TKN',
|
|
21
|
-
18
|
|
22
|
-
]).send({
|
|
23
|
-
from: ownerAddress
|
|
24
|
-
}).deployed();
|
|
25
|
-
console.log(`Token deployed at ${token.address.toString()}`);
|
|
26
|
-
const addresses = {
|
|
27
|
-
token: token.address.toString()
|
|
28
|
-
};
|
|
29
|
-
writeFileSync('addresses.json', JSON.stringify(addresses, null, 2));
|
|
30
|
-
}
|
|
31
|
-
// docs:end:dapp-deploy
|
|
32
|
-
// Execute main only if run directly
|
|
33
|
-
if (process.argv[1].replace(/\/index\.m?js$/, '') === fileURLToPath(import.meta.url).replace(/\/index\.m?js$/, '')) {
|
|
34
|
-
main().catch((err)=>{
|
|
35
|
-
console.error(`Error in deployment script: ${err}`);
|
|
36
|
-
process.exit(1);
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
export { main as deploy };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/sample-dapp/index.mjs"],"names":[],"mappings":"AAwGA,sCAcC"}
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
// docs:start:imports
|
|
2
|
-
import { getInitialTestAccountsWallets } from '@aztec/accounts/testing';
|
|
3
|
-
import { createPXEClient, waitForPXE } from '@aztec/aztec.js';
|
|
4
|
-
import { fileURLToPath } from '@aztec/foundation/url';
|
|
5
|
-
import { getToken } from './contracts.mjs';
|
|
6
|
-
// docs:end:imports
|
|
7
|
-
const { PXE_URL = 'http://localhost:8080' } = process.env;
|
|
8
|
-
// docs:start:showAccounts
|
|
9
|
-
async function showAccounts(pxe) {
|
|
10
|
-
const accounts = await pxe.getRegisteredAccounts();
|
|
11
|
-
console.log(`User accounts:\n${accounts.map((a)=>a.address).join('\n')}`);
|
|
12
|
-
}
|
|
13
|
-
// docs:end:showAccounts
|
|
14
|
-
// docs:start:showPrivateBalances
|
|
15
|
-
async function showPrivateBalances(pxe) {
|
|
16
|
-
const [owner] = await getInitialTestAccountsWallets(pxe);
|
|
17
|
-
const token = await getToken(owner);
|
|
18
|
-
const accounts = await pxe.getRegisteredAccounts();
|
|
19
|
-
for (const account of accounts){
|
|
20
|
-
// highlight-next-line:showPrivateBalances
|
|
21
|
-
const balance = await token.methods.balance_of_private(account.address).simulate({
|
|
22
|
-
from: account.address
|
|
23
|
-
});
|
|
24
|
-
console.log(`Balance of ${account.address}: ${balance}`);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
// docs:end:showPrivateBalances
|
|
28
|
-
// docs:start:mintPrivateFunds
|
|
29
|
-
async function mintPrivateFunds(pxe) {
|
|
30
|
-
const [ownerWallet] = await getInitialTestAccountsWallets(pxe);
|
|
31
|
-
const token = await getToken(ownerWallet);
|
|
32
|
-
await showPrivateBalances(pxe);
|
|
33
|
-
// We mint tokens to the owner
|
|
34
|
-
const mintAmount = 20n;
|
|
35
|
-
await token.methods.mint_to_private(ownerWallet.getAddress(), mintAmount).send({
|
|
36
|
-
from: ownerWallet.getAddress()
|
|
37
|
-
}).wait();
|
|
38
|
-
await showPrivateBalances(pxe);
|
|
39
|
-
}
|
|
40
|
-
// docs:end:mintPrivateFunds
|
|
41
|
-
// docs:start:transferPrivateFunds
|
|
42
|
-
async function transferPrivateFunds(pxe) {
|
|
43
|
-
const [owner, recipient] = await getInitialTestAccountsWallets(pxe);
|
|
44
|
-
const token = await getToken(owner);
|
|
45
|
-
await showPrivateBalances(pxe);
|
|
46
|
-
console.log(`Sending transaction, awaiting transaction to be mined`);
|
|
47
|
-
const receipt = await token.methods.transfer(recipient.getAddress(), 1).send({
|
|
48
|
-
from: owner.getAddress()
|
|
49
|
-
}).wait();
|
|
50
|
-
console.log(`Transaction ${receipt.txHash} has been mined on block ${receipt.blockNumber}`);
|
|
51
|
-
await showPrivateBalances(pxe);
|
|
52
|
-
}
|
|
53
|
-
// docs:end:transferPrivateFunds
|
|
54
|
-
// docs:start:showPublicBalances
|
|
55
|
-
async function showPublicBalances(pxe) {
|
|
56
|
-
const [owner] = await getInitialTestAccountsWallets(pxe);
|
|
57
|
-
const token = await getToken(owner);
|
|
58
|
-
const accounts = await pxe.getRegisteredAccounts();
|
|
59
|
-
for (const account of accounts){
|
|
60
|
-
// highlight-next-line:showPublicBalances
|
|
61
|
-
const balance = await token.methods.balance_of_public(account.address).simulate({
|
|
62
|
-
from: account.address
|
|
63
|
-
});
|
|
64
|
-
console.log(`Balance of ${account.address}: ${balance}`);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
// docs:end:showPublicBalances
|
|
68
|
-
// docs:start:mintPublicFunds
|
|
69
|
-
async function mintPublicFunds(pxe) {
|
|
70
|
-
const [owner] = await getInitialTestAccountsWallets(pxe);
|
|
71
|
-
const token = await getToken(owner);
|
|
72
|
-
await showPublicBalances(pxe);
|
|
73
|
-
console.log(`Sending transaction, awaiting transaction to be mined`);
|
|
74
|
-
const receipt = await token.methods.mint_to_public(owner.getAddress(), 100).send({
|
|
75
|
-
from: owner.getAddress()
|
|
76
|
-
}).wait();
|
|
77
|
-
console.log(`Transaction ${receipt.txHash} has been mined on block ${receipt.blockNumber}`);
|
|
78
|
-
await showPublicBalances(pxe);
|
|
79
|
-
// docs:start:showLogs
|
|
80
|
-
const blockNumber = await pxe.getBlockNumber();
|
|
81
|
-
const logs = (await pxe.getPublicLogs({
|
|
82
|
-
fromBlock: blockNumber - 1
|
|
83
|
-
})).logs;
|
|
84
|
-
const textLogs = logs.map((extendedLog)=>extendedLog.toHumanReadable().slice(0, 200));
|
|
85
|
-
for (const log of textLogs){
|
|
86
|
-
console.log(`Log emitted: ${log}`);
|
|
87
|
-
}
|
|
88
|
-
// docs:end:showLogs
|
|
89
|
-
}
|
|
90
|
-
// docs:end:mintPublicFunds
|
|
91
|
-
async function main() {
|
|
92
|
-
const pxe = createPXEClient(PXE_URL);
|
|
93
|
-
await waitForPXE(pxe);
|
|
94
|
-
const { l1ChainId } = await pxe.getNodeInfo();
|
|
95
|
-
console.log(`Connected to chain ${l1ChainId}`);
|
|
96
|
-
await showAccounts(pxe);
|
|
97
|
-
await mintPrivateFunds(pxe);
|
|
98
|
-
await transferPrivateFunds(pxe);
|
|
99
|
-
await mintPublicFunds(pxe);
|
|
100
|
-
}
|
|
101
|
-
// Execute main only if run directly
|
|
102
|
-
if (process.argv[1].replace(/\/index\.m?js$/, '') === fileURLToPath(import.meta.url).replace(/\/index\.m?js$/, '')) {
|
|
103
|
-
main().then(()=>process.exit(0)).catch((err)=>{
|
|
104
|
-
console.error(`Error in app: ${err}`);
|
|
105
|
-
process.exit(1);
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
export { main };
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
// docs:start:all
|
|
2
|
-
import { createPXEClient } from '@aztec/aztec.js';
|
|
3
|
-
|
|
4
|
-
const { PXE_URL = 'http://localhost:8080' } = process.env;
|
|
5
|
-
|
|
6
|
-
async function main() {
|
|
7
|
-
const pxe = createPXEClient(PXE_URL);
|
|
8
|
-
const { l1ChainId } = await pxe.getNodeInfo();
|
|
9
|
-
console.log(`Connected to chain ${l1ChainId}`);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
main().catch(err => {
|
|
13
|
-
console.error(`Error in app: ${err}`);
|
|
14
|
-
process.exit(1);
|
|
15
|
-
});
|
|
16
|
-
// docs:end:all
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { AztecAddress, Contract } from '@aztec/aztec.js';
|
|
2
|
-
import { TokenContract } from '@aztec/noir-contracts.js/Token';
|
|
3
|
-
|
|
4
|
-
import { readFileSync } from 'fs';
|
|
5
|
-
|
|
6
|
-
// This syntax is helpful for the referencing tutorial
|
|
7
|
-
const TokenContractArtifact = TokenContract.artifact;
|
|
8
|
-
|
|
9
|
-
// docs:start:get-tokens
|
|
10
|
-
export function getToken(wallet) {
|
|
11
|
-
const addresses = JSON.parse(readFileSync('addresses.json'));
|
|
12
|
-
return Contract.at(AztecAddress.fromString(addresses.token), TokenContractArtifact, wallet);
|
|
13
|
-
}
|
|
14
|
-
// docs:end:get-tokens
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
// docs:start:deploy-imports
|
|
2
|
-
import { getInitialTestAccountsWallets } from '@aztec/accounts/testing';
|
|
3
|
-
import { Contract, createPXEClient, waitForPXE } from '@aztec/aztec.js';
|
|
4
|
-
// docs:end:deploy-imports
|
|
5
|
-
// docs:start:import_artifact
|
|
6
|
-
import { TokenContractArtifact } from '@aztec/noir-contracts.js/Token';
|
|
7
|
-
|
|
8
|
-
// docs:end:import_artifact
|
|
9
|
-
|
|
10
|
-
import { writeFileSync } from 'fs';
|
|
11
|
-
import { fileURLToPath } from 'url';
|
|
12
|
-
|
|
13
|
-
// docs:start:dapp-deploy
|
|
14
|
-
const { PXE_URL = 'http://localhost:8080' } = process.env;
|
|
15
|
-
|
|
16
|
-
async function main() {
|
|
17
|
-
const pxe = createPXEClient(PXE_URL);
|
|
18
|
-
await waitForPXE(pxe);
|
|
19
|
-
|
|
20
|
-
const [ownerWallet] = await getInitialTestAccountsWallets(pxe);
|
|
21
|
-
const ownerAddress = ownerWallet.getAddress();
|
|
22
|
-
|
|
23
|
-
const token = await Contract.deploy(ownerWallet, TokenContractArtifact, [ownerAddress, 'TokenName', 'TKN', 18])
|
|
24
|
-
.send({ from: ownerAddress })
|
|
25
|
-
.deployed();
|
|
26
|
-
|
|
27
|
-
console.log(`Token deployed at ${token.address.toString()}`);
|
|
28
|
-
|
|
29
|
-
const addresses = { token: token.address.toString() };
|
|
30
|
-
writeFileSync('addresses.json', JSON.stringify(addresses, null, 2));
|
|
31
|
-
}
|
|
32
|
-
// docs:end:dapp-deploy
|
|
33
|
-
|
|
34
|
-
// Execute main only if run directly
|
|
35
|
-
if (process.argv[1].replace(/\/index\.m?js$/, '') === fileURLToPath(import.meta.url).replace(/\/index\.m?js$/, '')) {
|
|
36
|
-
main().catch(err => {
|
|
37
|
-
console.error(`Error in deployment script: ${err}`);
|
|
38
|
-
process.exit(1);
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export { main as deploy };
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
// docs:start:imports
|
|
2
|
-
import { getInitialTestAccountsWallets } from '@aztec/accounts/testing';
|
|
3
|
-
import { createPXEClient, waitForPXE } from '@aztec/aztec.js';
|
|
4
|
-
import { fileURLToPath } from '@aztec/foundation/url';
|
|
5
|
-
|
|
6
|
-
import { getToken } from './contracts.mjs';
|
|
7
|
-
|
|
8
|
-
// docs:end:imports
|
|
9
|
-
|
|
10
|
-
const { PXE_URL = 'http://localhost:8080' } = process.env;
|
|
11
|
-
|
|
12
|
-
// docs:start:showAccounts
|
|
13
|
-
async function showAccounts(pxe) {
|
|
14
|
-
const accounts = await pxe.getRegisteredAccounts();
|
|
15
|
-
console.log(`User accounts:\n${accounts.map(a => a.address).join('\n')}`);
|
|
16
|
-
}
|
|
17
|
-
// docs:end:showAccounts
|
|
18
|
-
|
|
19
|
-
// docs:start:showPrivateBalances
|
|
20
|
-
async function showPrivateBalances(pxe) {
|
|
21
|
-
const [owner] = await getInitialTestAccountsWallets(pxe);
|
|
22
|
-
const token = await getToken(owner);
|
|
23
|
-
|
|
24
|
-
const accounts = await pxe.getRegisteredAccounts();
|
|
25
|
-
|
|
26
|
-
for (const account of accounts) {
|
|
27
|
-
// highlight-next-line:showPrivateBalances
|
|
28
|
-
const balance = await token.methods.balance_of_private(account.address).simulate({ from: account.address });
|
|
29
|
-
console.log(`Balance of ${account.address}: ${balance}`);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
// docs:end:showPrivateBalances
|
|
33
|
-
|
|
34
|
-
// docs:start:mintPrivateFunds
|
|
35
|
-
async function mintPrivateFunds(pxe) {
|
|
36
|
-
const [ownerWallet] = await getInitialTestAccountsWallets(pxe);
|
|
37
|
-
const token = await getToken(ownerWallet);
|
|
38
|
-
|
|
39
|
-
await showPrivateBalances(pxe);
|
|
40
|
-
|
|
41
|
-
// We mint tokens to the owner
|
|
42
|
-
const mintAmount = 20n;
|
|
43
|
-
await token.methods
|
|
44
|
-
.mint_to_private(ownerWallet.getAddress(), mintAmount)
|
|
45
|
-
.send({ from: ownerWallet.getAddress() })
|
|
46
|
-
.wait();
|
|
47
|
-
|
|
48
|
-
await showPrivateBalances(pxe);
|
|
49
|
-
}
|
|
50
|
-
// docs:end:mintPrivateFunds
|
|
51
|
-
|
|
52
|
-
// docs:start:transferPrivateFunds
|
|
53
|
-
async function transferPrivateFunds(pxe) {
|
|
54
|
-
const [owner, recipient] = await getInitialTestAccountsWallets(pxe);
|
|
55
|
-
const token = await getToken(owner);
|
|
56
|
-
|
|
57
|
-
await showPrivateBalances(pxe);
|
|
58
|
-
console.log(`Sending transaction, awaiting transaction to be mined`);
|
|
59
|
-
const receipt = await token.methods.transfer(recipient.getAddress(), 1).send({ from: owner.getAddress() }).wait();
|
|
60
|
-
|
|
61
|
-
console.log(`Transaction ${receipt.txHash} has been mined on block ${receipt.blockNumber}`);
|
|
62
|
-
await showPrivateBalances(pxe);
|
|
63
|
-
}
|
|
64
|
-
// docs:end:transferPrivateFunds
|
|
65
|
-
|
|
66
|
-
// docs:start:showPublicBalances
|
|
67
|
-
async function showPublicBalances(pxe) {
|
|
68
|
-
const [owner] = await getInitialTestAccountsWallets(pxe);
|
|
69
|
-
const token = await getToken(owner);
|
|
70
|
-
|
|
71
|
-
const accounts = await pxe.getRegisteredAccounts();
|
|
72
|
-
|
|
73
|
-
for (const account of accounts) {
|
|
74
|
-
// highlight-next-line:showPublicBalances
|
|
75
|
-
const balance = await token.methods.balance_of_public(account.address).simulate({ from: account.address });
|
|
76
|
-
console.log(`Balance of ${account.address}: ${balance}`);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
// docs:end:showPublicBalances
|
|
80
|
-
|
|
81
|
-
// docs:start:mintPublicFunds
|
|
82
|
-
async function mintPublicFunds(pxe) {
|
|
83
|
-
const [owner] = await getInitialTestAccountsWallets(pxe);
|
|
84
|
-
const token = await getToken(owner);
|
|
85
|
-
|
|
86
|
-
await showPublicBalances(pxe);
|
|
87
|
-
|
|
88
|
-
console.log(`Sending transaction, awaiting transaction to be mined`);
|
|
89
|
-
const receipt = await token.methods.mint_to_public(owner.getAddress(), 100).send({ from: owner.getAddress() }).wait();
|
|
90
|
-
console.log(`Transaction ${receipt.txHash} has been mined on block ${receipt.blockNumber}`);
|
|
91
|
-
|
|
92
|
-
await showPublicBalances(pxe);
|
|
93
|
-
|
|
94
|
-
// docs:start:showLogs
|
|
95
|
-
const blockNumber = await pxe.getBlockNumber();
|
|
96
|
-
const logs = (await pxe.getPublicLogs({ fromBlock: blockNumber - 1 })).logs;
|
|
97
|
-
const textLogs = logs.map(extendedLog => extendedLog.toHumanReadable().slice(0, 200));
|
|
98
|
-
for (const log of textLogs) {
|
|
99
|
-
console.log(`Log emitted: ${log}`);
|
|
100
|
-
}
|
|
101
|
-
// docs:end:showLogs
|
|
102
|
-
}
|
|
103
|
-
// docs:end:mintPublicFunds
|
|
104
|
-
|
|
105
|
-
async function main() {
|
|
106
|
-
const pxe = createPXEClient(PXE_URL);
|
|
107
|
-
await waitForPXE(pxe);
|
|
108
|
-
|
|
109
|
-
const { l1ChainId } = await pxe.getNodeInfo();
|
|
110
|
-
console.log(`Connected to chain ${l1ChainId}`);
|
|
111
|
-
|
|
112
|
-
await showAccounts(pxe);
|
|
113
|
-
|
|
114
|
-
await mintPrivateFunds(pxe);
|
|
115
|
-
|
|
116
|
-
await transferPrivateFunds(pxe);
|
|
117
|
-
|
|
118
|
-
await mintPublicFunds(pxe);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// Execute main only if run directly
|
|
122
|
-
if (process.argv[1].replace(/\/index\.m?js$/, '') === fileURLToPath(import.meta.url).replace(/\/index\.m?js$/, '')) {
|
|
123
|
-
main()
|
|
124
|
-
.then(() => process.exit(0))
|
|
125
|
-
.catch(err => {
|
|
126
|
-
console.error(`Error in app: ${err}`);
|
|
127
|
-
process.exit(1);
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export { main };
|