@aztec/end-to-end 0.0.0-test.1 → 0.0.1-commit.24de95ac
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 +61 -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 +73 -0
- package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -0
- package/dest/bench/client_flows/client_flows_benchmark.js +311 -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 -36
- package/dest/bench/utils.d.ts.map +1 -1
- package/dest/bench/utils.js +26 -66
- package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +20 -12
- 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 +85 -57
- package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +18 -24
- 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 +48 -69
- package/dest/e2e_deploy_contract/deploy_test.d.ts +14 -6
- package/dest/e2e_deploy_contract/deploy_test.d.ts.map +1 -1
- package/dest/e2e_deploy_contract/deploy_test.js +13 -19
- package/dest/e2e_epochs/epochs_test.d.ts +58 -17
- package/dest/e2e_epochs/epochs_test.d.ts.map +1 -1
- package/dest/e2e_epochs/epochs_test.js +224 -43
- 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 +63 -0
- package/dest/e2e_fees/fees_test.d.ts +20 -9
- package/dest/e2e_fees/fees_test.d.ts.map +1 -1
- package/dest/e2e_fees/fees_test.js +98 -107
- package/dest/e2e_l1_publisher/write_json.d.ts +10 -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 +9 -6
- package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +1 -1
- package/dest/e2e_nested_contract/nested_contract_test.js +22 -19
- 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 +135 -0
- package/dest/e2e_p2p/p2p_network.d.ts +69 -22
- package/dest/e2e_p2p/p2p_network.d.ts.map +1 -1
- package/dest/e2e_p2p/p2p_network.js +180 -129
- package/dest/e2e_p2p/shared.d.ts +41 -5
- package/dest/e2e_p2p/shared.d.ts.map +1 -1
- package/dest/e2e_p2p/shared.js +163 -19
- package/dest/e2e_token_contract/token_contract_test.d.ts +11 -5
- package/dest/e2e_token_contract/token_contract_test.d.ts.map +1 -1
- package/dest/e2e_token_contract/token_contract_test.js +50 -26
- package/dest/{e2e_prover → fixtures}/e2e_prover_test.d.ts +14 -9
- package/dest/fixtures/e2e_prover_test.d.ts.map +1 -0
- package/dest/{e2e_prover → fixtures}/e2e_prover_test.js +95 -100
- 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 +1 -1
- 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 +1 -1
- package/dest/fixtures/get_bb_config.d.ts.map +1 -1
- package/dest/fixtures/get_bb_config.js +10 -17
- 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 +4 -4
- package/dest/fixtures/setup_p2p_test.d.ts +14 -13
- 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 +15 -7
- package/dest/fixtures/snapshot_manager.d.ts.map +1 -1
- package/dest/fixtures/snapshot_manager.js +147 -121
- package/dest/fixtures/token_utils.d.ts +6 -3
- package/dest/fixtures/token_utils.d.ts.map +1 -1
- package/dest/fixtures/token_utils.js +23 -10
- package/dest/fixtures/utils.d.ts +76 -37
- package/dest/fixtures/utils.d.ts.map +1 -1
- package/dest/fixtures/utils.js +464 -368
- package/dest/fixtures/web3signer.d.ts +5 -0
- package/dest/fixtures/web3signer.d.ts.map +1 -0
- package/dest/fixtures/web3signer.js +53 -0
- package/dest/quality_of_service/alert_checker.d.ts +1 -1
- package/dest/quality_of_service/alert_checker.d.ts.map +1 -1
- package/dest/shared/cross_chain_test_harness.d.ts +41 -25
- package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
- package/dest/shared/cross_chain_test_harness.js +104 -50
- package/dest/shared/gas_portal_test_harness.d.ts +32 -24
- package/dest/shared/gas_portal_test_harness.d.ts.map +1 -1
- package/dest/shared/gas_portal_test_harness.js +50 -29
- package/dest/shared/jest_setup.js +1 -1
- package/dest/shared/submit-transactions.d.ts +5 -3
- package/dest/shared/submit-transactions.d.ts.map +1 -1
- package/dest/shared/submit-transactions.js +8 -7
- package/dest/shared/uniswap_l1_l2.d.ts +13 -11
- package/dest/shared/uniswap_l1_l2.d.ts.map +1 -1
- package/dest/shared/uniswap_l1_l2.js +138 -108
- package/dest/simulators/lending_simulator.d.ts +6 -6
- package/dest/simulators/lending_simulator.d.ts.map +1 -1
- package/dest/simulators/lending_simulator.js +13 -16
- package/dest/simulators/token_simulator.d.ts +5 -2
- 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 +23 -10
- package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
- package/dest/spartan/setup_test_wallets.js +167 -58
- package/dest/spartan/utils.d.ts +106 -303
- package/dest/spartan/utils.d.ts.map +1 -1
- package/dest/spartan/utils.js +434 -130
- package/package.json +61 -56
- package/src/bench/client_flows/benchmark.ts +341 -0
- package/src/bench/client_flows/client_flows_benchmark.ts +402 -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 +22 -76
- package/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +80 -77
- package/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +63 -105
- package/src/e2e_deploy_contract/deploy_test.ts +23 -38
- package/src/e2e_epochs/epochs_test.ts +274 -54
- package/src/e2e_fees/bridging_race.notest.ts +80 -0
- package/src/e2e_fees/fees_test.ts +137 -136
- package/src/e2e_l1_publisher/write_json.ts +76 -0
- package/src/e2e_multi_validator/utils.ts +258 -0
- package/src/e2e_nested_contract/nested_contract_test.ts +27 -18
- package/src/e2e_p2p/inactivity_slash_test.ts +178 -0
- package/src/e2e_p2p/p2p_network.ts +272 -166
- package/src/e2e_p2p/shared.ts +244 -29
- package/src/e2e_token_contract/token_contract_test.ts +43 -39
- package/src/fixtures/dumps/epoch_proof_result.json +1 -1
- package/src/{e2e_prover → fixtures}/e2e_prover_test.ts +101 -145
- package/src/fixtures/fixtures.ts +4 -3
- package/src/fixtures/get_acvm_config.ts +3 -11
- package/src/fixtures/get_bb_config.ts +18 -13
- package/src/fixtures/l1_to_l2_messaging.ts +53 -23
- package/src/fixtures/setup_l1_contracts.ts +6 -7
- package/src/fixtures/setup_p2p_test.ts +112 -38
- package/src/fixtures/snapshot_manager.ts +187 -139
- package/src/fixtures/token_utils.ts +29 -12
- package/src/fixtures/utils.ts +552 -425
- package/src/fixtures/web3signer.ts +63 -0
- package/src/guides/up_quick_start.sh +6 -14
- package/src/quality_of_service/alert_checker.ts +1 -1
- package/src/shared/cross_chain_test_harness.ts +108 -79
- package/src/shared/gas_portal_test_harness.ts +58 -49
- package/src/shared/jest_setup.ts +1 -1
- package/src/shared/submit-transactions.ts +12 -8
- package/src/shared/uniswap_l1_l2.ts +173 -176
- package/src/simulators/lending_simulator.ts +12 -15
- package/src/simulators/token_simulator.ts +21 -13
- package/src/spartan/DEVELOP.md +121 -0
- package/src/spartan/setup_test_wallets.ts +215 -93
- package/src/spartan/utils.ts +490 -130
- 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
package/src/e2e_p2p/shared.ts
CHANGED
|
@@ -1,16 +1,29 @@
|
|
|
1
|
-
import { getSchnorrAccount } from '@aztec/accounts/schnorr';
|
|
2
1
|
import type { InitialAccountData } from '@aztec/accounts/testing';
|
|
3
2
|
import type { AztecNodeService } from '@aztec/aztec-node';
|
|
4
|
-
import {
|
|
5
|
-
import type
|
|
6
|
-
import {
|
|
3
|
+
import { AztecAddress } from '@aztec/aztec.js/addresses';
|
|
4
|
+
import { type SentTx, getContractInstanceFromInstantiationParams } from '@aztec/aztec.js/contracts';
|
|
5
|
+
import { Fr } from '@aztec/aztec.js/fields';
|
|
6
|
+
import type { Logger } from '@aztec/aztec.js/log';
|
|
7
|
+
import { Tx, TxStatus } from '@aztec/aztec.js/tx';
|
|
8
|
+
import type { RollupCheatCodes } from '@aztec/aztec/testing';
|
|
9
|
+
import type { EmpireSlashingProposerContract, RollupContract, TallySlashingProposerContract } from '@aztec/ethereum';
|
|
10
|
+
import { timesAsync, unique } from '@aztec/foundation/collection';
|
|
11
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
12
|
+
import { pluralize } from '@aztec/foundation/string';
|
|
13
|
+
import type { SpamContract } from '@aztec/noir-test-contracts.js/Spam';
|
|
14
|
+
import { TestContract, TestContractArtifact } from '@aztec/noir-test-contracts.js/Test';
|
|
15
|
+
import { getPXEConfig, getPXEConfig as getRpcConfig } from '@aztec/pxe/server';
|
|
16
|
+
import { getRoundForOffense } from '@aztec/slasher';
|
|
17
|
+
import type { AztecNodeAdmin } from '@aztec/stdlib/interfaces/client';
|
|
18
|
+
import type { SlashFactoryContract } from '@aztec/stdlib/l1-contracts';
|
|
19
|
+
import { TestWallet, proveInteraction } from '@aztec/test-wallet/server';
|
|
7
20
|
|
|
8
|
-
import type { NodeContext } from '../fixtures/setup_p2p_test.js';
|
|
9
21
|
import { submitTxsTo } from '../shared/submit-transactions.js';
|
|
10
22
|
|
|
11
23
|
// submits a set of transactions to the provided Private eXecution Environment (PXE)
|
|
12
24
|
export const submitComplexTxsTo = async (
|
|
13
25
|
logger: Logger,
|
|
26
|
+
from: AztecAddress,
|
|
14
27
|
spamContract: SpamContract,
|
|
15
28
|
numTxs: number,
|
|
16
29
|
opts: { callPublic?: boolean } = {},
|
|
@@ -20,12 +33,10 @@ export const submitComplexTxsTo = async (
|
|
|
20
33
|
const seed = 1234n;
|
|
21
34
|
const spamCount = 15;
|
|
22
35
|
for (let i = 0; i < numTxs; i++) {
|
|
23
|
-
const tx = spamContract.methods
|
|
24
|
-
.spam(seed + BigInt(i * spamCount), spamCount, !!opts.callPublic)
|
|
25
|
-
.send({ skipPublicSimulation: true });
|
|
36
|
+
const tx = spamContract.methods.spam(seed + BigInt(i * spamCount), spamCount, !!opts.callPublic).send({ from });
|
|
26
37
|
const txHash = await tx.getTxHash();
|
|
27
38
|
|
|
28
|
-
logger.info(`Tx sent with hash ${txHash}`);
|
|
39
|
+
logger.info(`Tx sent with hash ${txHash.toString()}`);
|
|
29
40
|
const receipt = await tx.getReceipt();
|
|
30
41
|
expect(receipt).toEqual(
|
|
31
42
|
expect.objectContaining({
|
|
@@ -33,35 +44,239 @@ export const submitComplexTxsTo = async (
|
|
|
33
44
|
error: '',
|
|
34
45
|
}),
|
|
35
46
|
);
|
|
36
|
-
logger.info(`Receipt received for ${txHash}`);
|
|
47
|
+
logger.info(`Receipt received for ${txHash.toString()}`);
|
|
37
48
|
txs.push(tx);
|
|
38
49
|
}
|
|
39
50
|
return txs;
|
|
40
51
|
};
|
|
41
52
|
|
|
42
|
-
// creates
|
|
43
|
-
export const
|
|
53
|
+
// creates a wallet and submit a given number of transactions through it.
|
|
54
|
+
export const submitTransactions = async (
|
|
44
55
|
logger: Logger,
|
|
45
56
|
node: AztecNodeService,
|
|
46
57
|
numTxs: number,
|
|
47
58
|
fundedAccount: InitialAccountData,
|
|
48
|
-
): Promise<
|
|
59
|
+
): Promise<SentTx[]> => {
|
|
49
60
|
const rpcConfig = getRpcConfig();
|
|
50
|
-
|
|
61
|
+
rpcConfig.proverEnabled = false;
|
|
62
|
+
const wallet = await TestWallet.create(node, { ...getPXEConfig(), proverEnabled: false }, { useLogSuffix: true });
|
|
63
|
+
const fundedAccountManager = await wallet.createSchnorrAccount(fundedAccount.secret, fundedAccount.salt);
|
|
64
|
+
return submitTxsTo(wallet, fundedAccountManager.address, numTxs, logger);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export async function prepareTransactions(
|
|
68
|
+
logger: Logger,
|
|
69
|
+
node: AztecNodeService,
|
|
70
|
+
numTxs: number,
|
|
71
|
+
fundedAccount: InitialAccountData,
|
|
72
|
+
): Promise<Tx[]> {
|
|
73
|
+
const rpcConfig = getRpcConfig();
|
|
74
|
+
rpcConfig.proverEnabled = false;
|
|
75
|
+
|
|
76
|
+
const wallet = await TestWallet.create(node, { ...getPXEConfig(), proverEnabled: false }, { useLogSuffix: true });
|
|
77
|
+
const fundedAccountManager = await wallet.createSchnorrAccount(fundedAccount.secret, fundedAccount.salt);
|
|
78
|
+
|
|
79
|
+
const testContractInstance = await getContractInstanceFromInstantiationParams(TestContractArtifact, {
|
|
80
|
+
salt: Fr.random(),
|
|
81
|
+
});
|
|
82
|
+
await wallet.registerContract(testContractInstance, TestContractArtifact);
|
|
83
|
+
const contract = await TestContract.at(testContractInstance.address, wallet);
|
|
51
84
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
85
|
+
return timesAsync(numTxs, async () => {
|
|
86
|
+
const tx = await proveInteraction(wallet, contract.methods.emit_nullifier(Fr.random()), {
|
|
87
|
+
from: fundedAccountManager.address,
|
|
88
|
+
});
|
|
89
|
+
const txHash = tx.getTxHash();
|
|
90
|
+
logger.info(`Tx prepared with hash ${txHash}`);
|
|
91
|
+
return tx;
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function awaitProposalExecution(
|
|
96
|
+
slashingProposer: EmpireSlashingProposerContract | TallySlashingProposerContract,
|
|
97
|
+
timeoutSeconds: number,
|
|
98
|
+
logger: Logger,
|
|
99
|
+
): Promise<bigint> {
|
|
100
|
+
return new Promise<bigint>((resolve, reject) => {
|
|
101
|
+
const timeout = setTimeout(() => {
|
|
102
|
+
logger.warn(`Timed out waiting for proposal execution`);
|
|
103
|
+
reject(new Error(`Timeout waiting for proposal execution after ${timeoutSeconds}s`));
|
|
104
|
+
}, timeoutSeconds * 1000);
|
|
105
|
+
|
|
106
|
+
if (slashingProposer.type === 'empire') {
|
|
107
|
+
const unwatch = slashingProposer.listenToPayloadSubmitted(args => {
|
|
108
|
+
logger.warn(`Proposal ${args.payload} from round ${args.round} executed`);
|
|
109
|
+
clearTimeout(timeout);
|
|
110
|
+
unwatch();
|
|
111
|
+
resolve(args.round);
|
|
112
|
+
});
|
|
113
|
+
} else if (slashingProposer.type === 'tally') {
|
|
114
|
+
const unwatch = slashingProposer.listenToRoundExecuted(args => {
|
|
115
|
+
logger.warn(`Slash from round ${args.round} executed`);
|
|
116
|
+
clearTimeout(timeout);
|
|
117
|
+
unwatch();
|
|
118
|
+
resolve(args.round);
|
|
119
|
+
});
|
|
120
|
+
} else {
|
|
121
|
+
clearTimeout(timeout);
|
|
122
|
+
reject(new Error(`Unknown slashing proposer type: ${(slashingProposer as any).type}`));
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export async function awaitCommitteeExists({
|
|
128
|
+
rollup,
|
|
129
|
+
logger,
|
|
130
|
+
}: {
|
|
131
|
+
rollup: RollupContract;
|
|
132
|
+
logger: Logger;
|
|
133
|
+
}): Promise<readonly `0x${string}`[]> {
|
|
134
|
+
logger.info(`Waiting for committee to be set`);
|
|
135
|
+
let committee: readonly `0x${string}`[] | undefined;
|
|
136
|
+
await retryUntil(
|
|
137
|
+
async () => {
|
|
138
|
+
committee = await rollup.getCurrentEpochCommittee();
|
|
139
|
+
return committee && committee.length > 0;
|
|
140
|
+
},
|
|
141
|
+
'non-empty committee',
|
|
142
|
+
60,
|
|
57
143
|
);
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
144
|
+
return committee!;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export async function awaitOffenseDetected({
|
|
148
|
+
logger,
|
|
149
|
+
nodeAdmin,
|
|
150
|
+
slashingRoundSize,
|
|
151
|
+
epochDuration,
|
|
152
|
+
waitUntilOffenseCount,
|
|
153
|
+
timeoutSeconds = 120,
|
|
154
|
+
}: {
|
|
155
|
+
nodeAdmin: AztecNodeAdmin;
|
|
156
|
+
logger: Logger;
|
|
157
|
+
slashingRoundSize: number;
|
|
158
|
+
epochDuration: number;
|
|
159
|
+
waitUntilOffenseCount?: number;
|
|
160
|
+
timeoutSeconds?: number;
|
|
161
|
+
}) {
|
|
162
|
+
const targetOffenseCount = waitUntilOffenseCount ?? 1;
|
|
163
|
+
logger.warn(`Waiting for ${pluralize('offense', targetOffenseCount)} to be detected`);
|
|
164
|
+
const offenses = await retryUntil(
|
|
165
|
+
async () => {
|
|
166
|
+
const offenses = await nodeAdmin.getSlashOffenses('all');
|
|
167
|
+
if (offenses.length >= targetOffenseCount) {
|
|
168
|
+
return offenses;
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
'non-empty offenses',
|
|
172
|
+
timeoutSeconds,
|
|
173
|
+
);
|
|
174
|
+
logger.info(
|
|
175
|
+
`Hit ${offenses.length} offenses on rounds ${unique(offenses.map(o => getRoundForOffense(o, { slashingRoundSize, epochDuration })))}`,
|
|
176
|
+
{ offenses },
|
|
177
|
+
);
|
|
178
|
+
return offenses;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Await the committee to be slashed out of the validator set.
|
|
183
|
+
* Currently assumes that the committee is the same size as the validator set.
|
|
184
|
+
*/
|
|
185
|
+
export async function awaitCommitteeKicked({
|
|
186
|
+
rollup,
|
|
187
|
+
cheatCodes,
|
|
188
|
+
committee,
|
|
189
|
+
slashFactory,
|
|
190
|
+
slashingProposer,
|
|
191
|
+
slashingRoundSize,
|
|
192
|
+
aztecSlotDuration,
|
|
193
|
+
aztecEpochDuration,
|
|
194
|
+
logger,
|
|
195
|
+
offenseEpoch,
|
|
196
|
+
}: {
|
|
197
|
+
rollup: RollupContract;
|
|
198
|
+
cheatCodes: RollupCheatCodes;
|
|
199
|
+
committee: readonly `0x${string}`[];
|
|
200
|
+
slashFactory: SlashFactoryContract;
|
|
201
|
+
slashingProposer: EmpireSlashingProposerContract | TallySlashingProposerContract | undefined;
|
|
202
|
+
slashingRoundSize: number;
|
|
203
|
+
aztecSlotDuration: number;
|
|
204
|
+
aztecEpochDuration: number;
|
|
205
|
+
logger: Logger;
|
|
206
|
+
offenseEpoch: number;
|
|
207
|
+
}) {
|
|
208
|
+
if (!slashingProposer) {
|
|
209
|
+
throw new Error('No slashing proposer configured. Cannot test slashing.');
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
await cheatCodes.debugRollup();
|
|
213
|
+
|
|
214
|
+
if (slashingProposer.type === 'empire') {
|
|
215
|
+
// Await for the slash payload to be created if empire (no payload is created on tally until execution time)
|
|
216
|
+
const targetEpoch = (await cheatCodes.getEpoch()) + (await rollup.getLagInEpochs()) + 1n;
|
|
217
|
+
logger.info(`Advancing to epoch ${targetEpoch} so we start slashing`);
|
|
218
|
+
await cheatCodes.advanceToEpoch(targetEpoch);
|
|
219
|
+
|
|
220
|
+
const slashPayloadEvents = await retryUntil(
|
|
221
|
+
async () => {
|
|
222
|
+
const events = await slashFactory.getSlashPayloadCreatedEvents();
|
|
223
|
+
return events.length > 0 ? events : undefined;
|
|
224
|
+
},
|
|
225
|
+
'slash payload created',
|
|
226
|
+
120,
|
|
227
|
+
1,
|
|
228
|
+
);
|
|
229
|
+
expect(slashPayloadEvents.length).toBe(1);
|
|
230
|
+
// The uniqueness check is needed since a validator may be slashed more than once on the same round (eg because they let two epochs be pruned)
|
|
231
|
+
expect(unique(slashPayloadEvents[0].slashes.map(slash => slash.validator.toString()))).toHaveLength(
|
|
232
|
+
committee.length,
|
|
233
|
+
);
|
|
234
|
+
} else {
|
|
235
|
+
// Use the slash offset to ensure we are in the right epoch for tally
|
|
236
|
+
const slashOffsetInRounds = await slashingProposer.getSlashOffsetInRounds();
|
|
237
|
+
const slashingRoundSizeInEpochs = slashingRoundSize / aztecEpochDuration;
|
|
238
|
+
const slashingOffsetInEpochs = Number(slashOffsetInRounds) * slashingRoundSizeInEpochs;
|
|
239
|
+
const firstEpochInOffenseRound = offenseEpoch - (offenseEpoch % slashingRoundSizeInEpochs);
|
|
240
|
+
const targetEpoch = firstEpochInOffenseRound + slashingOffsetInEpochs;
|
|
241
|
+
logger.info(`Advancing to epoch ${targetEpoch} so we start slashing`);
|
|
242
|
+
await cheatCodes.advanceToEpoch(targetEpoch, { offset: -aztecSlotDuration / 2 });
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const attestersPre = await rollup.getAttesters();
|
|
246
|
+
expect(attestersPre.length).toBe(committee.length);
|
|
247
|
+
|
|
248
|
+
for (const attester of attestersPre) {
|
|
249
|
+
const attesterInfo = await rollup.getAttesterView(attester);
|
|
250
|
+
expect(attesterInfo.status).toEqual(1); // Validating
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const timeout = slashingRoundSize * 2 * aztecSlotDuration + 30;
|
|
254
|
+
logger.info(`Waiting for slash to be executed (timeout ${timeout}s)`);
|
|
255
|
+
await awaitProposalExecution(slashingProposer, timeout, logger);
|
|
256
|
+
|
|
257
|
+
// The attesters should still form the committee but they should be reduced to the "living" status
|
|
258
|
+
await cheatCodes.debugRollup();
|
|
259
|
+
const committeePostSlashing = await rollup.getCurrentEpochCommittee();
|
|
260
|
+
expect(committeePostSlashing?.length).toBe(attestersPre.length);
|
|
261
|
+
|
|
262
|
+
const attestersPostSlashing = await rollup.getAttesters();
|
|
263
|
+
expect(attestersPostSlashing.length).toBe(0);
|
|
264
|
+
|
|
265
|
+
for (const attester of attestersPre) {
|
|
266
|
+
const attesterInfo = await rollup.getAttesterView(attester);
|
|
267
|
+
expect(attesterInfo.status).toEqual(2); // Living
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
logger.info(`Advancing to check current committee`);
|
|
271
|
+
await cheatCodes.debugRollup();
|
|
272
|
+
await cheatCodes.advanceToEpoch((await cheatCodes.getEpoch()) + (await rollup.getLagInEpochs()) + 1n);
|
|
273
|
+
await cheatCodes.debugRollup();
|
|
274
|
+
|
|
275
|
+
const committeeNextEpoch = await rollup.getCurrentEpochCommittee();
|
|
276
|
+
// The committee should be undefined, since the validator set is empty
|
|
277
|
+
// and the tests currently using this helper always set a target committee size.
|
|
278
|
+
expect(committeeNextEpoch).toBeUndefined();
|
|
279
|
+
|
|
280
|
+
const attestersNextEpoch = await rollup.getAttesters();
|
|
281
|
+
expect(attestersNextEpoch.length).toBe(0);
|
|
282
|
+
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { type
|
|
3
|
-
import {
|
|
1
|
+
import { AztecAddress } from '@aztec/aztec.js/addresses';
|
|
2
|
+
import { type Logger, createLogger } from '@aztec/aztec.js/log';
|
|
3
|
+
import type { AztecNode } from '@aztec/aztec.js/node';
|
|
4
4
|
import { TokenContract } from '@aztec/noir-contracts.js/Token';
|
|
5
|
+
import { InvalidAccountContract } from '@aztec/noir-test-contracts.js/InvalidAccount';
|
|
6
|
+
import type { TestWallet } from '@aztec/test-wallet/server';
|
|
5
7
|
|
|
6
8
|
import { jest } from '@jest/globals';
|
|
7
9
|
|
|
@@ -23,11 +25,15 @@ export class TokenContractTest {
|
|
|
23
25
|
static TOKEN_DECIMALS = 18n;
|
|
24
26
|
private snapshotManager: ISnapshotManager;
|
|
25
27
|
logger: Logger;
|
|
26
|
-
wallets: AccountWallet[] = [];
|
|
27
|
-
accounts: CompleteAddress[] = [];
|
|
28
28
|
asset!: TokenContract;
|
|
29
29
|
tokenSim!: TokenSimulator;
|
|
30
|
-
|
|
30
|
+
node!: AztecNode;
|
|
31
|
+
|
|
32
|
+
badAccount!: InvalidAccountContract;
|
|
33
|
+
wallet!: TestWallet;
|
|
34
|
+
adminAddress!: AztecAddress;
|
|
35
|
+
account1Address!: AztecAddress;
|
|
36
|
+
account2Address!: AztecAddress;
|
|
31
37
|
|
|
32
38
|
constructor(testName: string) {
|
|
33
39
|
this.logger = createLogger(`e2e:e2e_token_contract:${testName}`);
|
|
@@ -48,9 +54,11 @@ export class TokenContractTest {
|
|
|
48
54
|
await this.snapshotManager.snapshot(
|
|
49
55
|
'3_accounts',
|
|
50
56
|
deployAccounts(3, this.logger),
|
|
51
|
-
|
|
52
|
-
this.
|
|
53
|
-
this.
|
|
57
|
+
({ deployedAccounts }, { wallet, aztecNode }) => {
|
|
58
|
+
this.node = aztecNode;
|
|
59
|
+
this.wallet = wallet;
|
|
60
|
+
[this.adminAddress, this.account1Address, this.account2Address] = deployedAccounts.map(acc => acc.address);
|
|
61
|
+
return Promise.resolve();
|
|
54
62
|
},
|
|
55
63
|
);
|
|
56
64
|
|
|
@@ -60,42 +68,42 @@ export class TokenContractTest {
|
|
|
60
68
|
// Create the token contract state.
|
|
61
69
|
// Move this account thing to addAccounts above?
|
|
62
70
|
this.logger.verbose(`Public deploy accounts...`);
|
|
63
|
-
await publicDeployAccounts(this.
|
|
71
|
+
await publicDeployAccounts(this.wallet, [this.adminAddress, this.account1Address]);
|
|
64
72
|
|
|
65
73
|
this.logger.verbose(`Deploying TokenContract...`);
|
|
66
74
|
const asset = await TokenContract.deploy(
|
|
67
|
-
this.
|
|
68
|
-
this.
|
|
75
|
+
this.wallet,
|
|
76
|
+
this.adminAddress,
|
|
69
77
|
TokenContractTest.TOKEN_NAME,
|
|
70
78
|
TokenContractTest.TOKEN_SYMBOL,
|
|
71
79
|
TokenContractTest.TOKEN_DECIMALS,
|
|
72
80
|
)
|
|
73
|
-
.send()
|
|
81
|
+
.send({ from: this.adminAddress })
|
|
74
82
|
.deployed();
|
|
75
83
|
this.logger.verbose(`Token deployed to ${asset.address}`);
|
|
76
84
|
|
|
77
85
|
this.logger.verbose(`Deploying bad account...`);
|
|
78
|
-
this.badAccount = await
|
|
86
|
+
this.badAccount = await InvalidAccountContract.deploy(this.wallet).send({ from: this.adminAddress }).deployed();
|
|
79
87
|
this.logger.verbose(`Deployed to ${this.badAccount.address}.`);
|
|
80
88
|
|
|
81
89
|
return { tokenContractAddress: asset.address, badAccountAddress: this.badAccount.address };
|
|
82
90
|
},
|
|
83
91
|
async ({ tokenContractAddress, badAccountAddress }) => {
|
|
84
92
|
// Restore the token contract state.
|
|
85
|
-
this.asset = await TokenContract.at(tokenContractAddress, this.
|
|
93
|
+
this.asset = await TokenContract.at(tokenContractAddress, this.wallet);
|
|
86
94
|
this.logger.verbose(`Token contract address: ${this.asset.address}`);
|
|
87
95
|
|
|
88
|
-
this.tokenSim = new TokenSimulator(
|
|
89
|
-
this.
|
|
90
|
-
this.
|
|
91
|
-
|
|
92
|
-
this.accounts.map(a => a.address),
|
|
93
|
-
);
|
|
96
|
+
this.tokenSim = new TokenSimulator(this.asset, this.wallet, this.adminAddress, this.logger, [
|
|
97
|
+
this.adminAddress,
|
|
98
|
+
this.account1Address,
|
|
99
|
+
]);
|
|
94
100
|
|
|
95
|
-
this.badAccount = await
|
|
101
|
+
this.badAccount = await InvalidAccountContract.at(badAccountAddress, this.wallet);
|
|
96
102
|
this.logger.verbose(`Bad account address: ${this.badAccount.address}`);
|
|
97
103
|
|
|
98
|
-
expect(await this.asset.methods.get_admin().simulate()).toBe(
|
|
104
|
+
expect(await this.asset.methods.get_admin().simulate({ from: this.adminAddress })).toBe(
|
|
105
|
+
this.adminAddress.toBigInt(),
|
|
106
|
+
);
|
|
99
107
|
},
|
|
100
108
|
);
|
|
101
109
|
|
|
@@ -123,36 +131,32 @@ export class TokenContractTest {
|
|
|
123
131
|
await this.snapshotManager.snapshot(
|
|
124
132
|
'mint',
|
|
125
133
|
async () => {
|
|
126
|
-
const { asset,
|
|
134
|
+
const { asset, adminAddress } = this;
|
|
127
135
|
const amount = 10000n;
|
|
128
136
|
|
|
129
137
|
this.logger.verbose(`Minting ${amount} publicly...`);
|
|
130
|
-
await asset.methods.mint_to_public(
|
|
138
|
+
await asset.methods.mint_to_public(adminAddress, amount).send({ from: adminAddress }).wait();
|
|
131
139
|
|
|
132
140
|
this.logger.verbose(`Minting ${amount} privately...`);
|
|
133
|
-
await mintTokensToPrivate(asset,
|
|
141
|
+
await mintTokensToPrivate(asset, adminAddress, adminAddress, amount);
|
|
134
142
|
this.logger.verbose(`Minting complete.`);
|
|
135
143
|
|
|
136
144
|
return { amount };
|
|
137
145
|
},
|
|
138
146
|
async ({ amount }) => {
|
|
139
|
-
const {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
} = this;
|
|
144
|
-
tokenSim.mintPublic(address, amount);
|
|
145
|
-
|
|
146
|
-
const publicBalance = await asset.methods.balance_of_public(address).simulate();
|
|
147
|
+
const { asset, adminAddress, tokenSim } = this;
|
|
148
|
+
tokenSim.mintPublic(adminAddress, amount);
|
|
149
|
+
|
|
150
|
+
const publicBalance = await asset.methods.balance_of_public(adminAddress).simulate({ from: adminAddress });
|
|
147
151
|
this.logger.verbose(`Public balance of wallet 0: ${publicBalance}`);
|
|
148
|
-
expect(publicBalance).toEqual(this.tokenSim.balanceOfPublic(
|
|
152
|
+
expect(publicBalance).toEqual(this.tokenSim.balanceOfPublic(adminAddress));
|
|
149
153
|
|
|
150
|
-
tokenSim.mintPrivate(
|
|
151
|
-
const privateBalance = await asset.methods.balance_of_private(
|
|
154
|
+
tokenSim.mintPrivate(adminAddress, amount);
|
|
155
|
+
const privateBalance = await asset.methods.balance_of_private(adminAddress).simulate({ from: adminAddress });
|
|
152
156
|
this.logger.verbose(`Private balance of wallet 0: ${privateBalance}`);
|
|
153
|
-
expect(privateBalance).toEqual(tokenSim.balanceOfPrivate(
|
|
157
|
+
expect(privateBalance).toEqual(tokenSim.balanceOfPrivate(adminAddress));
|
|
154
158
|
|
|
155
|
-
const totalSupply = await asset.methods.total_supply().simulate();
|
|
159
|
+
const totalSupply = await asset.methods.total_supply().simulate({ from: adminAddress });
|
|
156
160
|
this.logger.verbose(`Total supply: ${totalSupply}`);
|
|
157
161
|
expect(totalSupply).toEqual(tokenSim.totalSupply);
|
|
158
162
|
|