Skip to content

Commit 7c09062

Browse files
authored
chore: network test fixes for terraform (#16815)
- Fixes 1tps, ntps, and 4epochs, and reorg test for use under terraform deployment. - Adds an optional fee argument that defaults to the sponsored fee in the test wallet setup. This is needed for the reorg test. - Fixes terraform main file variable name mismatch note: Currently the tests all use real proofs enabled due to proofs being invalid if they are mocked.
2 parents 8727851 + 60ee3dd commit 7c09062

File tree

6 files changed

+613
-691
lines changed

6 files changed

+613
-691
lines changed

spartan/environments/scenario.local.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ LABS_INFRA_MNEMONIC="test test test test test test test test test test test junk
66
FUNDING_PRIVATE_KEY="0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
77
REAL_VERIFIER=false
88
SENTINEL_ENABLED=true
9+
# CREATE_CHAOS_MESH=true
910

1011
AZTEC_EPOCH_DURATION=4
1112
AZTEC_SLOT_DURATION=24
Lines changed: 168 additions & 179 deletions
Original file line numberDiff line numberDiff line change
@@ -1,179 +1,168 @@
1-
// // TODO(#11825) finalize (probably once we have nightly tests setup for GKE) & enable in bootstrap.sh
2-
// import {
3-
// type PXE,
4-
// ProvenTx,
5-
// SentTx,
6-
// SponsoredFeePaymentMethod,
7-
// Tx,
8-
// readFieldCompressedString,
9-
// sleep,
10-
// } from '@aztec/aztec.js';
11-
// import { Fr } from '@aztec/foundation/fields';
12-
// import { createLogger } from '@aztec/foundation/log';
13-
// import { TokenContract } from '@aztec/noir-contracts.js/Token';
14-
15-
// import { jest } from '@jest/globals';
16-
// import type { ChildProcess } from 'child_process';
17-
18-
// import { getSponsoredFPCAddress } from '../fixtures/utils.js';
19-
// import {
20-
// type TestWallets,
21-
// deploySponsoredTestWallets,
22-
// setupTestWalletsWithTokens,
23-
// startCompatiblePXE,
24-
// } from './setup_test_wallets.js';
25-
// import { setupEnvironment, startPortForward } from './utils.js';
26-
27-
// const config = setupEnvironment(process.env);
28-
29-
// describe('token transfer test', () => {
30-
// jest.setTimeout(10 * 60 * 2000); // 20 minutes
31-
32-
// const logger = createLogger(`e2e:spartan-test:transfer`);
33-
// const MINT_AMOUNT = 1000n;
34-
35-
// const ROUNDS = 1n;
36-
37-
// let testWallets: TestWallets;
38-
// const forwardProcesses: ChildProcess[] = [];
39-
// let pxe: PXE;
40-
// let cleanup: undefined | (() => Promise<void>);
41-
42-
// afterAll(async () => {
43-
// await cleanup?.();
44-
// forwardProcesses.forEach(p => p.kill());
45-
// });
46-
47-
// beforeAll(async () => {
48-
// if (isK8sConfig(config)) {
49-
// const { process: sequencerProcess, port: sequencerPort } = await startPortForward({
50-
// resource: `svc/${config.INSTANCE_NAME}-aztec-network-validator`,
51-
// namespace: config.NAMESPACE,
52-
// containerPort: config.CONTAINER_SEQUENCER_PORT,
53-
// });
54-
// forwardProcesses.push(sequencerProcess);
55-
// const NODE_URL = `http://127.0.0.1:${sequencerPort}`;
56-
57-
// ({ pxe, cleanup } = await startCompatiblePXE(NODE_URL, ['1', 'true'].includes(config.AZTEC_REAL_PROOFS), logger));
58-
// testWallets = await deploySponsoredTestWallets(pxe, MINT_AMOUNT, logger);
59-
// } else {
60-
// const PXE_URL = config.PXE_URL;
61-
// testWallets = await setupTestWalletsWithTokens(PXE_URL, MINT_AMOUNT, logger);
62-
// }
63-
// expect(ROUNDS).toBeLessThanOrEqual(MINT_AMOUNT);
64-
// });
65-
66-
// it('can get info', async () => {
67-
// const name = readFieldCompressedString(
68-
// await testWallets.tokenAdminWallet.methods.private_get_name().simulate({ from: testWallets.tokenAdminAddress }),
69-
// );
70-
// expect(name).toBe(testWallets.tokenName);
71-
// });
72-
73-
// it('can transfer 1 token privately and publicly', async () => {
74-
// const recipient = testWallets.recipientWallet.getAddress();
75-
// const transferAmount = 1n;
76-
77-
// for (const w of testWallets.wallets) {
78-
// expect(MINT_AMOUNT).toBe(
79-
// await testWallets.tokenAdminWallet.methods
80-
// .balance_of_public(w.getAddress())
81-
// .simulate({ from: testWallets.tokenAdminAddress }),
82-
// );
83-
// }
84-
85-
// expect(0n).toBe(
86-
// await testWallets.tokenAdminWallet.methods
87-
// .balance_of_public(recipient)
88-
// .simulate({ from: testWallets.tokenAdminAddress }),
89-
// );
90-
91-
// // For each round, make both private and public transfers
92-
// // for (let i = 1n; i <= ROUNDS; i++) {
93-
// // const interactions = await Promise.all([
94-
// // ...testWallets.wallets.map(async w =>
95-
// // (
96-
// // await TokenContract.at(testWallets.tokenAddress, w)
97-
// // ).methods.transfer_in_public(w.getAddress(), recipient, transferAmount, 0),
98-
// // ),
99-
// // ]);
100-
101-
// // const txs = await Promise.all(interactions.map(async i => await i.prove()));
102-
103-
// // await Promise.all(txs.map(t => t.send().wait({ timeout: 600 })));
104-
// // }
105-
106-
// const wallet = testWallets.wallets[0];
107-
108-
// const baseTx = await (await TokenContract.at(testWallets.tokenAddress, wallet)).methods
109-
// .transfer_in_public(wallet.getAddress(), recipient, transferAmount, 0)
110-
// .prove({
111-
// from: testWallets.tokenAdminAddress,
112-
// fee: { paymentMethod: new SponsoredFeePaymentMethod(await getSponsoredFPCAddress()) },
113-
// });
114-
115-
// const txs: ProvenTx[] = [];
116-
// for (let i = 0; i < 20; i++) {
117-
// const clonedTxData = Tx.clone(baseTx);
118-
119-
// // Modify the first nullifier to make it unique
120-
// const nullifiers = clonedTxData.data.getNonEmptyNullifiers();
121-
// if (nullifiers.length > 0) {
122-
// // Create a new nullifier by adding the index to the original
123-
// const newNullifier = nullifiers[0].add(Fr.fromString(i.toString()));
124-
// // Replace the first nullifier with our new unique one
125-
// if (clonedTxData.data.forRollup) {
126-
// clonedTxData.data.forRollup.end.nullifiers[0] = newNullifier;
127-
// } else if (clonedTxData.data.forPublic) {
128-
// clonedTxData.data.forPublic.nonRevertibleAccumulatedData.nullifiers[0] = newNullifier;
129-
// }
130-
// }
131-
132-
// const clonedTx = new ProvenTx(wallet, clonedTxData, []);
133-
// txs.push(clonedTx);
134-
// }
135-
136-
// const sentTxs: SentTx[] = [];
137-
138-
// // dump all txs at requested TPS
139-
// const TPS = 1;
140-
// logger.info(`Sending ${txs.length} txs at a rate of ${TPS} tx/s`);
141-
// while (txs.length > 0) {
142-
// const start = performance.now();
143-
144-
// const chunk = txs.splice(0, TPS);
145-
// sentTxs.push(...chunk.map(tx => tx.send()));
146-
// logger.info(`Sent txs: [${(await Promise.all(chunk.map(tx => tx.getTxHash()))).map(h => h.toString())}]`);
147-
148-
// const end = performance.now();
149-
// const delta = end - start;
150-
// if (1000 - delta > 0) {
151-
// await sleep(1000 - delta);
152-
// }
153-
// }
154-
155-
// await Promise.all(
156-
// sentTxs.map(async sentTx => {
157-
// await sentTx.wait({ timeout: 600 });
158-
// const receipt = await sentTx.getReceipt();
159-
// logger.info(`tx ${receipt.txHash} included in block: ${receipt.blockNumber}`);
160-
// }),
161-
// );
162-
163-
// const recipientBalance = await testWallets.tokenAdminWallet.methods
164-
// .balance_of_public(recipient)
165-
// .simulate({ from: testWallets.tokenAdminAddress });
166-
// logger.info(`recipientBalance: ${recipientBalance}`);
167-
// // expect(recipientBalance).toBe(100n * transferAmount);
168-
169-
// // for (const w of testWallets.wallets) {
170-
// // expect(MINT_AMOUNT - ROUNDS * transferAmount).toBe(
171-
// // await testWallets.tokenAdminWallet.methods.balance_of_public(w.getAddress()).simulate(),
172-
// // );
173-
// // }
174-
175-
// // expect(ROUNDS * transferAmount * BigInt(testWallets.wallets.length)).toBe(
176-
// // await testWallets.tokenAdminWallet.methods.balance_of_public(recipient).simulate(),
177-
// // );
178-
// });
179-
// });
1+
// TODO(#11825) finalize (probably once we have nightly tests setup for GKE) & enable in bootstrap.sh
2+
import {
3+
type PXE,
4+
ProvenTx,
5+
SentTx,
6+
SponsoredFeePaymentMethod,
7+
Tx,
8+
readFieldCompressedString,
9+
sleep,
10+
} from '@aztec/aztec.js';
11+
import { Fr } from '@aztec/foundation/fields';
12+
import { createLogger } from '@aztec/foundation/log';
13+
import { TokenContract } from '@aztec/noir-contracts.js/Token';
14+
15+
import { jest } from '@jest/globals';
16+
import type { ChildProcess } from 'child_process';
17+
18+
import { getSponsoredFPCAddress } from '../fixtures/utils.js';
19+
import { type TestWallets, deploySponsoredTestWallets, startCompatiblePXE } from './setup_test_wallets.js';
20+
import { setupEnvironment, startPortForwardForRPC } from './utils.js';
21+
22+
const config = { ...setupEnvironment(process.env), REAL_VERIFIER: true }; // TODO: remove REAL_VERIFIER: true
23+
describe('token transfer test', () => {
24+
jest.setTimeout(10 * 60 * 2000); // 20 minutes
25+
26+
const logger = createLogger(`e2e:spartan-test:transfer`);
27+
const MINT_AMOUNT = 1000n;
28+
29+
const ROUNDS = 1n;
30+
31+
let testWallets: TestWallets;
32+
const forwardProcesses: ChildProcess[] = [];
33+
let pxe: PXE;
34+
let cleanup: undefined | (() => Promise<void>);
35+
36+
afterAll(async () => {
37+
await cleanup?.();
38+
forwardProcesses.forEach(p => p.kill());
39+
});
40+
41+
beforeAll(async () => {
42+
logger.info('Starting port forward for PXE');
43+
const { process: aztecRpcProcess, port: aztecRpcPort } = await startPortForwardForRPC(config.NAMESPACE);
44+
forwardProcesses.push(aztecRpcProcess);
45+
const rpcUrl = `http://127.0.0.1:${aztecRpcPort}`;
46+
47+
({ pxe, cleanup } = await startCompatiblePXE(rpcUrl, config.REAL_VERIFIER, logger));
48+
49+
// Setup wallets
50+
testWallets = await deploySponsoredTestWallets(pxe, MINT_AMOUNT, logger);
51+
52+
expect(ROUNDS).toBeLessThanOrEqual(MINT_AMOUNT);
53+
});
54+
55+
it('can get info', async () => {
56+
const name = readFieldCompressedString(
57+
await testWallets.tokenAdminWallet.methods.private_get_name().simulate({ from: testWallets.tokenAdminAddress }),
58+
);
59+
expect(name).toBe(testWallets.tokenName);
60+
});
61+
62+
it('can transfer 1 token privately and publicly', async () => {
63+
const recipient = testWallets.recipientWallet.getAddress();
64+
const transferAmount = 1n;
65+
66+
for (const w of testWallets.wallets) {
67+
expect(MINT_AMOUNT).toBe(
68+
await testWallets.tokenAdminWallet.methods
69+
.balance_of_public(w.getAddress())
70+
.simulate({ from: testWallets.tokenAdminAddress }),
71+
);
72+
}
73+
74+
expect(0n).toBe(
75+
await testWallets.tokenAdminWallet.methods
76+
.balance_of_public(recipient)
77+
.simulate({ from: testWallets.tokenAdminAddress }),
78+
);
79+
80+
// For each round, make both private and public transfers
81+
// for (let i = 1n; i <= ROUNDS; i++) {
82+
// const interactions = await Promise.all([
83+
// ...testWallets.wallets.map(async w =>
84+
// (
85+
// await TokenContract.at(testWallets.tokenAddress, w)
86+
// ).methods.transfer_in_public(w.getAddress(), recipient, transferAmount, 0),
87+
// ),
88+
// ]);
89+
90+
// const txs = await Promise.all(interactions.map(async i => await i.prove()));
91+
92+
// await Promise.all(txs.map(t => t.send().wait({ timeout: 600 })));
93+
// }
94+
95+
const wallet = testWallets.wallets[0];
96+
97+
const baseTx = await (await TokenContract.at(testWallets.tokenAddress, wallet)).methods
98+
.transfer_in_public(wallet.getAddress(), recipient, transferAmount, 0)
99+
.prove({
100+
from: testWallets.tokenAdminAddress,
101+
fee: { paymentMethod: new SponsoredFeePaymentMethod(await getSponsoredFPCAddress()) },
102+
});
103+
104+
const txs: ProvenTx[] = [];
105+
for (let i = 0; i < 20; i++) {
106+
const clonedTxData = Tx.clone(baseTx);
107+
108+
// Modify the first nullifier to make it unique
109+
const nullifiers = clonedTxData.data.getNonEmptyNullifiers();
110+
if (nullifiers.length > 0) {
111+
// Create a new nullifier by adding the index to the original
112+
const newNullifier = nullifiers[0].add(Fr.fromString(i.toString()));
113+
// Replace the first nullifier with our new unique one
114+
if (clonedTxData.data.forRollup) {
115+
clonedTxData.data.forRollup.end.nullifiers[0] = newNullifier;
116+
} else if (clonedTxData.data.forPublic) {
117+
clonedTxData.data.forPublic.nonRevertibleAccumulatedData.nullifiers[0] = newNullifier;
118+
}
119+
}
120+
121+
const clonedTx = new ProvenTx(wallet, clonedTxData, []);
122+
txs.push(clonedTx);
123+
}
124+
125+
const sentTxs: SentTx[] = [];
126+
127+
// dump all txs at requested TPS
128+
const TPS = 1;
129+
logger.info(`Sending ${txs.length} txs at a rate of ${TPS} tx/s`);
130+
while (txs.length > 0) {
131+
const start = performance.now();
132+
133+
const chunk = txs.splice(0, TPS);
134+
sentTxs.push(...chunk.map(tx => tx.send()));
135+
logger.info(`Sent txs: [${(await Promise.all(chunk.map(tx => tx.getTxHash()))).map(h => h.toString())}]`);
136+
137+
const end = performance.now();
138+
const delta = end - start;
139+
if (1000 - delta > 0) {
140+
await sleep(1000 - delta);
141+
}
142+
}
143+
144+
await Promise.all(
145+
sentTxs.map(async sentTx => {
146+
await sentTx.wait({ timeout: 600 });
147+
const receipt = await sentTx.getReceipt();
148+
logger.info(`tx ${receipt.txHash} included in block: ${receipt.blockNumber}`);
149+
}),
150+
);
151+
152+
const recipientBalance = await testWallets.tokenAdminWallet.methods
153+
.balance_of_public(recipient)
154+
.simulate({ from: testWallets.tokenAdminAddress });
155+
logger.info(`recipientBalance: ${recipientBalance}`);
156+
// expect(recipientBalance).toBe(100n * transferAmount);
157+
158+
// for (const w of testWallets.wallets) {
159+
// expect(MINT_AMOUNT - ROUNDS * transferAmount).toBe(
160+
// await testWallets.tokenAdminWallet.methods.balance_of_public(w.getAddress()).simulate(),
161+
// );
162+
// }
163+
164+
// expect(ROUNDS * transferAmount * BigInt(testWallets.wallets.length)).toBe(
165+
// await testWallets.tokenAdminWallet.methods.balance_of_public(recipient).simulate(),
166+
// );
167+
});
168+
});

0 commit comments

Comments
 (0)