This repository was archived by the owner on Jul 10, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathutils.ts
More file actions
109 lines (98 loc) · 3.25 KB
/
Copy pathutils.ts
File metadata and controls
109 lines (98 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import {
createLogger,
Fr,
AztecAddress,
UniqueNote,
AccountWallet,
Contract,
DeployOptions,
createAztecNodeClient,
waitForPXE,
Wallet,
} from '@aztec/aztec.js';
import { getPXEServiceConfig, type PXEServiceConfig } from '@aztec/pxe/config';
import { createPXEService } from '@aztec/pxe/server';
import { createStore } from '@aztec/kv-store/lmdb';
import { type L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
import { TokenContract, TokenContractArtifact } from '../../artifacts/Token.js';
import { NFTContractArtifact } from '../../artifacts/NFT.js';
export const logger = createLogger('aztec:aztec-standards');
const { NODE_URL = 'http://localhost:8080' } = process.env;
let l1Contracts: L1ContractAddresses;
let fullConfig: PXEServiceConfig & { l1Contracts: L1ContractAddresses };
const initializeConfig = async () => {
if (!l1Contracts) {
const node = createAztecNodeClient(NODE_URL);
l1Contracts = await node.getL1ContractAddresses();
const config = getPXEServiceConfig();
fullConfig = {
...config,
l1Contracts,
proverEnabled: false,
};
}
return fullConfig;
};
export const setupPXE = async () => {
const config = await initializeConfig();
const node = createAztecNodeClient(NODE_URL);
const store = await createStore('pxe', {
dataDirectory: 'store',
dataStoreMapSizeKB: 1e6,
});
const pxe = await createPXEService(node, config, { store });
await waitForPXE(pxe);
return { pxe, store };
};
// --- Token Utils ---
export const expectUintNote = (expect: any, note: UniqueNote, amount: bigint, owner: AztecAddress) => {
expect(note.note.items[0]).toEqual(new Fr(owner.toBigInt()));
expect(note.note.items[2]).toEqual(new Fr(amount));
};
export const expectTokenBalances = async (
expect: any,
token: TokenContract,
address: AztecAddress,
publicBalance: bigint,
privateBalance: bigint,
caller?: AccountWallet,
) => {
logger.info('checking balances for', address.toString());
const t = caller ? token.withWallet(caller) : token;
expect(await t.methods.balance_of_public(address).simulate()).toBe(publicBalance);
expect(await t.methods.balance_of_private(address).simulate()).toBe(privateBalance);
};
export const AMOUNT = 1000n;
export const wad = (n: number = 1) => AMOUNT * BigInt(n);
/**
* Deploys the Token contract with a specified minter.
* @param deployer - The wallet to deploy the contract with.
* @returns A deployed contract instance.
*/
export async function deployTokenWithMinter(deployer: Wallet, options?: DeployOptions) {
const contract = await Contract.deploy(
deployer,
TokenContractArtifact,
['PrivateToken', 'PT', 18, deployer.getAddress(), AztecAddress.ZERO],
'constructor_with_minter',
)
.send(options)
.deployed();
return contract;
}
/**
* Deploys the NFT contract with a specified minter.
* @param deployer - The wallet to deploy the contract with.
* @returns A deployed contract instance.
*/
export async function deployNFTWithMinter(deployer: AccountWallet, options?: DeployOptions) {
const contract = await Contract.deploy(
deployer,
NFTContractArtifact,
['NFT', 'NFT', deployer.getAddress(), deployer.getAddress()],
'constructor_with_minter',
)
.send(options)
.deployed();
return contract;
}