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