moonwall 1.0.0-dev.0
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/LICENSE +681 -0
- package/README.md +54 -0
- package/config_schema.json +811 -0
- package/dist/api/constants/accounts.d.ts +36 -0
- package/dist/api/constants/accounts.d.ts.map +1 -0
- package/dist/api/constants/accounts.js +67 -0
- package/dist/api/constants/chain.d.ts +134 -0
- package/dist/api/constants/chain.d.ts.map +1 -0
- package/dist/api/constants/chain.js +149 -0
- package/dist/api/constants/index.d.ts +4 -0
- package/dist/api/constants/index.d.ts.map +1 -0
- package/dist/api/constants/index.js +3 -0
- package/dist/api/constants/smartContract.d.ts +29 -0
- package/dist/api/constants/smartContract.d.ts.map +1 -0
- package/dist/api/constants/smartContract.js +118 -0
- package/dist/api/testing/blocks.d.ts +59 -0
- package/dist/api/testing/blocks.d.ts.map +1 -0
- package/dist/api/testing/blocks.js +147 -0
- package/dist/api/testing/contracts.d.ts +5 -0
- package/dist/api/testing/contracts.d.ts.map +1 -0
- package/dist/api/testing/contracts.js +32 -0
- package/dist/api/testing/ethers.d.ts +3 -0
- package/dist/api/testing/ethers.d.ts.map +1 -0
- package/dist/api/testing/ethers.js +38 -0
- package/dist/api/testing/events.d.ts +12 -0
- package/dist/api/testing/events.d.ts.map +1 -0
- package/dist/api/testing/events.js +23 -0
- package/dist/api/testing/extrinsics.d.ts +5 -0
- package/dist/api/testing/extrinsics.d.ts.map +1 -0
- package/dist/api/testing/extrinsics.js +10 -0
- package/dist/api/testing/index.d.ts +9 -0
- package/dist/api/testing/index.d.ts.map +1 -0
- package/dist/api/testing/index.js +8 -0
- package/dist/api/testing/jumping.d.ts +8 -0
- package/dist/api/testing/jumping.d.ts.map +1 -0
- package/dist/api/testing/jumping.js +78 -0
- package/dist/api/testing/providers.d.ts +18 -0
- package/dist/api/testing/providers.d.ts.map +1 -0
- package/dist/api/testing/providers.js +34 -0
- package/dist/api/testing/viem.d.ts +139 -0
- package/dist/api/testing/viem.d.ts.map +1 -0
- package/dist/api/testing/viem.js +247 -0
- package/dist/api/types/config.d.ts +609 -0
- package/dist/api/types/config.d.ts.map +1 -0
- package/dist/api/types/config.js +1 -0
- package/dist/api/types/context.d.ts +125 -0
- package/dist/api/types/context.d.ts.map +1 -0
- package/dist/api/types/context.js +1 -0
- package/dist/api/types/contracts.d.ts +66 -0
- package/dist/api/types/contracts.d.ts.map +1 -0
- package/dist/api/types/contracts.js +1 -0
- package/dist/api/types/eth.d.ts +3 -0
- package/dist/api/types/eth.d.ts.map +1 -0
- package/dist/api/types/eth.js +1 -0
- package/dist/api/types/foundations.d.ts +11 -0
- package/dist/api/types/foundations.d.ts.map +1 -0
- package/dist/api/types/foundations.js +1 -0
- package/dist/api/types/helpers.d.ts +7 -0
- package/dist/api/types/helpers.d.ts.map +1 -0
- package/dist/api/types/helpers.js +1 -0
- package/dist/api/types/index.d.ts +8 -0
- package/dist/api/types/index.d.ts.map +1 -0
- package/dist/api/types/index.js +7 -0
- package/dist/api/types/runner.d.ts +490 -0
- package/dist/api/types/runner.d.ts.map +1 -0
- package/dist/api/types/runner.js +1 -0
- package/dist/cli/cmds/components/LogViewer.d.ts +17 -0
- package/dist/cli/cmds/components/LogViewer.d.ts.map +1 -0
- package/dist/cli/cmds/components/LogViewer.js +171 -0
- package/dist/cli/cmds/entrypoint.d.ts +6 -0
- package/dist/cli/cmds/entrypoint.d.ts.map +1 -0
- package/dist/cli/cmds/entrypoint.js +192 -0
- package/dist/cli/cmds/interactiveCmds/chopsticksIntCmds.d.ts +2 -0
- package/dist/cli/cmds/interactiveCmds/chopsticksIntCmds.d.ts.map +1 -0
- package/dist/cli/cmds/interactiveCmds/chopsticksIntCmds.js +117 -0
- package/dist/cli/cmds/interactiveCmds/devIntCmds.d.ts +2 -0
- package/dist/cli/cmds/interactiveCmds/devIntCmds.d.ts.map +1 -0
- package/dist/cli/cmds/interactiveCmds/devIntCmds.js +103 -0
- package/dist/cli/cmds/interactiveCmds/index.d.ts +4 -0
- package/dist/cli/cmds/interactiveCmds/index.d.ts.map +1 -0
- package/dist/cli/cmds/interactiveCmds/index.js +3 -0
- package/dist/cli/cmds/interactiveCmds/zombieIntCmds.d.ts +2 -0
- package/dist/cli/cmds/interactiveCmds/zombieIntCmds.d.ts.map +1 -0
- package/dist/cli/cmds/interactiveCmds/zombieIntCmds.js +32 -0
- package/dist/cli/cmds/main.d.ts +2 -0
- package/dist/cli/cmds/main.d.ts.map +1 -0
- package/dist/cli/cmds/main.js +336 -0
- package/dist/cli/cmds/runNetwork.d.ts +3 -0
- package/dist/cli/cmds/runNetwork.d.ts.map +1 -0
- package/dist/cli/cmds/runNetwork.js +292 -0
- package/dist/cli/cmds/runTests.d.ts +12 -0
- package/dist/cli/cmds/runTests.d.ts.map +1 -0
- package/dist/cli/cmds/runTests.js +257 -0
- package/dist/cli/internal/cmdFunctions/downloader.d.ts +4 -0
- package/dist/cli/internal/cmdFunctions/downloader.d.ts.map +1 -0
- package/dist/cli/internal/cmdFunctions/downloader.js +49 -0
- package/dist/cli/internal/cmdFunctions/fetchArtifact.d.ts +10 -0
- package/dist/cli/internal/cmdFunctions/fetchArtifact.d.ts.map +1 -0
- package/dist/cli/internal/cmdFunctions/fetchArtifact.js +145 -0
- package/dist/cli/internal/cmdFunctions/index.d.ts +5 -0
- package/dist/cli/internal/cmdFunctions/index.d.ts.map +1 -0
- package/dist/cli/internal/cmdFunctions/index.js +4 -0
- package/dist/cli/internal/cmdFunctions/initialisation.d.ts +20 -0
- package/dist/cli/internal/cmdFunctions/initialisation.d.ts.map +1 -0
- package/dist/cli/internal/cmdFunctions/initialisation.js +150 -0
- package/dist/cli/internal/cmdFunctions/tempLogs.d.ts +3 -0
- package/dist/cli/internal/cmdFunctions/tempLogs.d.ts.map +1 -0
- package/dist/cli/internal/cmdFunctions/tempLogs.js +37 -0
- package/dist/cli/internal/commandParsers.d.ts +59 -0
- package/dist/cli/internal/commandParsers.d.ts.map +1 -0
- package/dist/cli/internal/commandParsers.js +305 -0
- package/dist/cli/internal/deriveTestIds.d.ts +8 -0
- package/dist/cli/internal/deriveTestIds.d.ts.map +1 -0
- package/dist/cli/internal/deriveTestIds.js +123 -0
- package/dist/cli/internal/effect/index.d.ts +6 -0
- package/dist/cli/internal/effect/index.d.ts.map +1 -0
- package/dist/cli/internal/effect/index.js +5 -0
- package/dist/cli/internal/fileCheckers.d.ts +11 -0
- package/dist/cli/internal/fileCheckers.d.ts.map +1 -0
- package/dist/cli/internal/fileCheckers.js +165 -0
- package/dist/cli/internal/foundations/index.d.ts +4 -0
- package/dist/cli/internal/foundations/index.d.ts.map +1 -0
- package/dist/cli/internal/foundations/index.js +4 -0
- package/dist/cli/internal/index.d.ts +12 -0
- package/dist/cli/internal/index.d.ts.map +1 -0
- package/dist/cli/internal/index.js +11 -0
- package/dist/cli/internal/launcherCommon.d.ts +4 -0
- package/dist/cli/internal/launcherCommon.d.ts.map +1 -0
- package/dist/cli/internal/launcherCommon.js +130 -0
- package/dist/cli/internal/localNode.d.ts +16 -0
- package/dist/cli/internal/localNode.d.ts.map +1 -0
- package/dist/cli/internal/localNode.js +362 -0
- package/dist/cli/internal/logging.d.ts +2 -0
- package/dist/cli/internal/logging.d.ts.map +1 -0
- package/dist/cli/internal/logging.js +26 -0
- package/dist/cli/internal/node.d.ts +33 -0
- package/dist/cli/internal/node.d.ts.map +1 -0
- package/dist/cli/internal/node.js +228 -0
- package/dist/cli/internal/processHelpers.d.ts +17 -0
- package/dist/cli/internal/processHelpers.d.ts.map +1 -0
- package/dist/cli/internal/processHelpers.js +56 -0
- package/dist/cli/internal/providerFactories.d.ts +48 -0
- package/dist/cli/internal/providerFactories.d.ts.map +1 -0
- package/dist/cli/internal/providerFactories.js +442 -0
- package/dist/cli/internal/testIdParser.d.ts +34 -0
- package/dist/cli/internal/testIdParser.d.ts.map +1 -0
- package/dist/cli/internal/testIdParser.js +167 -0
- package/dist/cli/lib/binariesHelpers.d.ts +15 -0
- package/dist/cli/lib/binariesHelpers.d.ts.map +1 -0
- package/dist/cli/lib/binariesHelpers.js +99 -0
- package/dist/cli/lib/configReader.d.ts +8 -0
- package/dist/cli/lib/configReader.d.ts.map +1 -0
- package/dist/cli/lib/configReader.js +115 -0
- package/dist/cli/lib/contractFunctions.d.ts +2 -0
- package/dist/cli/lib/contractFunctions.d.ts.map +1 -0
- package/dist/cli/lib/contractFunctions.js +2 -0
- package/dist/cli/lib/globalContext.d.ts +46 -0
- package/dist/cli/lib/globalContext.d.ts.map +1 -0
- package/dist/cli/lib/globalContext.js +710 -0
- package/dist/cli/lib/governanceProcedures.d.ts +27 -0
- package/dist/cli/lib/governanceProcedures.d.ts.map +1 -0
- package/dist/cli/lib/governanceProcedures.js +458 -0
- package/dist/cli/lib/handlers/index.d.ts +5 -0
- package/dist/cli/lib/handlers/index.d.ts.map +1 -0
- package/dist/cli/lib/handlers/index.js +5 -0
- package/dist/cli/lib/repoDefinitions/index.d.ts +6 -0
- package/dist/cli/lib/repoDefinitions/index.d.ts.map +1 -0
- package/dist/cli/lib/repoDefinitions/index.js +21 -0
- package/dist/cli/lib/repoDefinitions/moonbeam.d.ts +4 -0
- package/dist/cli/lib/repoDefinitions/moonbeam.d.ts.map +1 -0
- package/dist/cli/lib/repoDefinitions/moonbeam.js +30 -0
- package/dist/cli/lib/repoDefinitions/polkadot.d.ts +4 -0
- package/dist/cli/lib/repoDefinitions/polkadot.d.ts.map +1 -0
- package/dist/cli/lib/repoDefinitions/polkadot.js +11 -0
- package/dist/cli/lib/repoDefinitions/tanssi.d.ts +4 -0
- package/dist/cli/lib/repoDefinitions/tanssi.d.ts.map +1 -0
- package/dist/cli/lib/repoDefinitions/tanssi.js +14 -0
- package/dist/cli/lib/rpcFunctions.d.ts +2 -0
- package/dist/cli/lib/rpcFunctions.d.ts.map +1 -0
- package/dist/cli/lib/rpcFunctions.js +26 -0
- package/dist/cli/lib/runnerContext.d.ts +32 -0
- package/dist/cli/lib/runnerContext.d.ts.map +1 -0
- package/dist/cli/lib/runnerContext.js +156 -0
- package/dist/cli/lib/shardManager.d.ts +40 -0
- package/dist/cli/lib/shardManager.d.ts.map +1 -0
- package/dist/cli/lib/shardManager.js +80 -0
- package/dist/cli/lib/upgradeProcedures.d.ts +5 -0
- package/dist/cli/lib/upgradeProcedures.d.ts.map +1 -0
- package/dist/cli/lib/upgradeProcedures.js +221 -0
- package/dist/cli.d.ts +4 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +3 -0
- package/dist/contracts/contractInteraction.d.ts +17 -0
- package/dist/contracts/contractInteraction.d.ts.map +1 -0
- package/dist/contracts/contractInteraction.js +170 -0
- package/dist/contracts/index.d.ts +2 -0
- package/dist/contracts/index.d.ts.map +1 -0
- package/dist/contracts/index.js +1 -0
- package/dist/foundations/chopsticks/handler.d.ts +3 -0
- package/dist/foundations/chopsticks/handler.d.ts.map +1 -0
- package/dist/foundations/chopsticks/handler.js +93 -0
- package/dist/foundations/chopsticks/helpers.d.ts +27 -0
- package/dist/foundations/chopsticks/helpers.d.ts.map +1 -0
- package/dist/foundations/chopsticks/helpers.js +133 -0
- package/dist/foundations/dev/handler.d.ts +3 -0
- package/dist/foundations/dev/handler.d.ts.map +1 -0
- package/dist/foundations/dev/handler.js +136 -0
- package/dist/foundations/dev/helpers.d.ts +27 -0
- package/dist/foundations/dev/helpers.d.ts.map +1 -0
- package/dist/foundations/dev/helpers.js +161 -0
- package/dist/foundations/read-only/handler.d.ts +3 -0
- package/dist/foundations/read-only/handler.d.ts.map +1 -0
- package/dist/foundations/read-only/handler.js +32 -0
- package/dist/foundations/zombie/handler.d.ts +3 -0
- package/dist/foundations/zombie/handler.d.ts.map +1 -0
- package/dist/foundations/zombie/handler.js +92 -0
- package/dist/foundations/zombie/helpers.d.ts +16 -0
- package/dist/foundations/zombie/helpers.d.ts.map +1 -0
- package/dist/foundations/zombie/helpers.js +97 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +47 -0
- package/dist/internal/common.d.ts +3 -0
- package/dist/internal/common.d.ts.map +1 -0
- package/dist/internal/common.js +41 -0
- package/dist/internal/index.d.ts +4 -0
- package/dist/internal/index.d.ts.map +1 -0
- package/dist/internal/index.js +3 -0
- package/dist/internal/logger.d.ts +24 -0
- package/dist/internal/logger.d.ts.map +1 -0
- package/dist/internal/logger.js +66 -0
- package/dist/internal/logging.d.ts +7 -0
- package/dist/internal/logging.d.ts.map +1 -0
- package/dist/internal/logging.js +36 -0
- package/dist/moondebug.d.ts +3 -0
- package/dist/moondebug.d.ts.map +1 -0
- package/dist/moondebug.js +2 -0
- package/dist/services/cache/FileLock.d.ts +11 -0
- package/dist/services/cache/FileLock.d.ts.map +1 -0
- package/dist/services/cache/FileLock.js +68 -0
- package/dist/services/cache/StartupCacheService.d.ts +23 -0
- package/dist/services/cache/StartupCacheService.d.ts.map +1 -0
- package/dist/services/cache/StartupCacheService.js +159 -0
- package/dist/services/cache/index.d.ts +3 -0
- package/dist/services/cache/index.d.ts.map +1 -0
- package/dist/services/cache/index.js +2 -0
- package/dist/services/chopsticks/ChopsticksMultiChain.d.ts +158 -0
- package/dist/services/chopsticks/ChopsticksMultiChain.d.ts.map +1 -0
- package/dist/services/chopsticks/ChopsticksMultiChain.js +282 -0
- package/dist/services/chopsticks/ChopsticksService.d.ts +313 -0
- package/dist/services/chopsticks/ChopsticksService.d.ts.map +1 -0
- package/dist/services/chopsticks/ChopsticksService.js +77 -0
- package/dist/services/chopsticks/chopsticksConfigParser.d.ts +40 -0
- package/dist/services/chopsticks/chopsticksConfigParser.d.ts.map +1 -0
- package/dist/services/chopsticks/chopsticksConfigParser.js +201 -0
- package/dist/services/chopsticks/index.d.ts +5 -0
- package/dist/services/chopsticks/index.d.ts.map +1 -0
- package/dist/services/chopsticks/index.js +4 -0
- package/dist/services/chopsticks/launchChopsticksEffect.d.ts +225 -0
- package/dist/services/chopsticks/launchChopsticksEffect.d.ts.map +1 -0
- package/dist/services/chopsticks/launchChopsticksEffect.js +623 -0
- package/dist/services/config/configAccessors.d.ts +41 -0
- package/dist/services/config/configAccessors.d.ts.map +1 -0
- package/dist/services/config/configAccessors.js +149 -0
- package/dist/services/config/index.d.ts +2 -0
- package/dist/services/config/index.d.ts.map +1 -0
- package/dist/services/config/index.js +1 -0
- package/dist/services/errors.d.ts +72 -0
- package/dist/services/errors.d.ts.map +1 -0
- package/dist/services/errors.js +31 -0
- package/dist/services/index.d.ts +7 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +6 -0
- package/dist/services/network/NodeReadinessService.d.ts +35 -0
- package/dist/services/network/NodeReadinessService.d.ts.map +1 -0
- package/dist/services/network/NodeReadinessService.js +120 -0
- package/dist/services/network/PortDiscoveryService.d.ts +22 -0
- package/dist/services/network/PortDiscoveryService.d.ts.map +1 -0
- package/dist/services/network/PortDiscoveryService.js +77 -0
- package/dist/services/network/RpcPortDiscoveryService.d.ts +25 -0
- package/dist/services/network/RpcPortDiscoveryService.d.ts.map +1 -0
- package/dist/services/network/RpcPortDiscoveryService.js +136 -0
- package/dist/services/network/index.d.ts +4 -0
- package/dist/services/network/index.d.ts.map +1 -0
- package/dist/services/network/index.js +3 -0
- package/dist/services/process/ProcessManagerService.d.ts +49 -0
- package/dist/services/process/ProcessManagerService.d.ts.map +1 -0
- package/dist/services/process/ProcessManagerService.js +162 -0
- package/dist/services/process/index.d.ts +3 -0
- package/dist/services/process/index.d.ts.map +1 -0
- package/dist/services/process/index.js +2 -0
- package/dist/services/process/launchNodeEffect.d.ts +40 -0
- package/dist/services/process/launchNodeEffect.d.ts.map +1 -0
- package/dist/services/process/launchNodeEffect.js +86 -0
- package/dist/util/functions/index.d.ts +3 -0
- package/dist/util/functions/index.d.ts.map +1 -0
- package/dist/util/functions/index.js +4 -0
- package/dist/util/index.d.ts +4 -0
- package/dist/util/index.d.ts.map +1 -0
- package/dist/util/index.js +2 -0
- package/package.json +157 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import Bottleneck from "bottleneck";
|
|
2
|
+
import { createLogger } from "../../internal/logger.js";
|
|
3
|
+
const logger = createLogger({ name: "test:blocks" });
|
|
4
|
+
const debug = logger.debug.bind(logger);
|
|
5
|
+
export async function createAndFinalizeBlock(api, parentHash, finalize = false) {
|
|
6
|
+
const startTime = Date.now();
|
|
7
|
+
// TODO: any/raw rpc request can be removed once api-augment is updated
|
|
8
|
+
const block = parentHash
|
|
9
|
+
? await api.rpc("engine_createBlock", true, finalize, parentHash)
|
|
10
|
+
: await api.rpc("engine_createBlock", true, finalize);
|
|
11
|
+
return {
|
|
12
|
+
duration: Date.now() - startTime,
|
|
13
|
+
hash: block.hash, // toString doesn't work for block hashes
|
|
14
|
+
proofSize: block.proof_size, // TODO: casting can be removed once api-augment is updated
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
// Given a deposit amount, returns the amount burned (80%) and deposited to treasury (20%).
|
|
18
|
+
// This is meant to precisely mimic the logic in the Moonbeam runtimes where the burn amount
|
|
19
|
+
// is calculated and the treasury is treated as the remainder. This precision is important to
|
|
20
|
+
// avoid off-by-one errors.
|
|
21
|
+
export function calculateFeePortions(amount) {
|
|
22
|
+
const burnt = (amount * 80n) / 100n; // 20% goes to treasury
|
|
23
|
+
return { burnt, treasury: amount - burnt };
|
|
24
|
+
}
|
|
25
|
+
export const getBlockExtrinsic = async (api, blockHash, section, method) => {
|
|
26
|
+
const apiAt = await api.at(blockHash);
|
|
27
|
+
const [{ block }, records] = await Promise.all([
|
|
28
|
+
api.rpc.chain.getBlock(blockHash),
|
|
29
|
+
apiAt.query.system.events(),
|
|
30
|
+
]);
|
|
31
|
+
const extIndex = block.extrinsics.findIndex((ext) => ext.method.section === section && ext.method.method === method);
|
|
32
|
+
const extrinsic = extIndex > -1 ? block.extrinsics[extIndex] : null;
|
|
33
|
+
const events = records
|
|
34
|
+
.filter(({ phase }) => phase.isApplyExtrinsic && phase.asApplyExtrinsic.eq(extIndex))
|
|
35
|
+
.map(({ event }) => event);
|
|
36
|
+
const resultEvent = events.find((event) => event.section === "system" &&
|
|
37
|
+
(event.method === "ExtrinsicSuccess" || event.method === "ExtrinsicFailed"));
|
|
38
|
+
return { block, extrinsic, events, resultEvent };
|
|
39
|
+
};
|
|
40
|
+
export const getBlockTime = (signedBlock) => signedBlock.block.extrinsics.find((item) => item.method.section === "timestamp")
|
|
41
|
+
.method.args[0].toNumber();
|
|
42
|
+
export const checkBlockFinalized = async (api, number) => {
|
|
43
|
+
return {
|
|
44
|
+
number,
|
|
45
|
+
//@ts-expect-error - remove once pJs exposes this
|
|
46
|
+
finalized: await api._rpcCore.provider.send("moon_isBlockFinalized", [
|
|
47
|
+
await api.rpc.chain.getBlockHash(number),
|
|
48
|
+
]),
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
const fetchBlockTime = async (api, blockNum) => {
|
|
52
|
+
const hash = await api.rpc.chain.getBlockHash(blockNum);
|
|
53
|
+
const block = await api.rpc.chain.getBlock(hash);
|
|
54
|
+
return getBlockTime(block);
|
|
55
|
+
};
|
|
56
|
+
export const fetchHistoricBlockNum = async (api, blockNumber, targetTime) => {
|
|
57
|
+
if (blockNumber <= 1) {
|
|
58
|
+
return 1;
|
|
59
|
+
}
|
|
60
|
+
const time = await fetchBlockTime(api, blockNumber);
|
|
61
|
+
if (time <= targetTime) {
|
|
62
|
+
return blockNumber;
|
|
63
|
+
}
|
|
64
|
+
return fetchHistoricBlockNum(api, blockNumber - Math.ceil((time - targetTime) / 30_000), targetTime);
|
|
65
|
+
};
|
|
66
|
+
export const getBlockArray = async (api, timePeriod, bottleneck) => {
|
|
67
|
+
/**
|
|
68
|
+
@brief Returns an sequential array of block numbers from a given period of time in the past
|
|
69
|
+
@param api Connected ApiPromise to perform queries on
|
|
70
|
+
@param timePeriod Moment in the past to search until
|
|
71
|
+
@param limiter Bottleneck rate limiter to throttle requests
|
|
72
|
+
*/
|
|
73
|
+
let limiter = bottleneck;
|
|
74
|
+
if (!limiter) {
|
|
75
|
+
limiter = new Bottleneck({ maxConcurrent: 10, minTime: 100 });
|
|
76
|
+
}
|
|
77
|
+
const finalizedHead = await limiter.schedule(() => api.rpc.chain.getFinalizedHead());
|
|
78
|
+
const signedBlock = await limiter.schedule(() => api.rpc.chain.getBlock(finalizedHead));
|
|
79
|
+
const lastBlockNumber = signedBlock.block.header.number.toNumber();
|
|
80
|
+
const lastBlockTime = getBlockTime(signedBlock);
|
|
81
|
+
const firstBlockTime = lastBlockTime - timePeriod;
|
|
82
|
+
debug(`Searching for the block at: ${new Date(firstBlockTime)}`);
|
|
83
|
+
const firstBlockNumber = (await limiter.wrap(fetchHistoricBlockNum)(api, lastBlockNumber, firstBlockTime));
|
|
84
|
+
const length = lastBlockNumber - firstBlockNumber;
|
|
85
|
+
return Array.from({ length }, (_, i) => firstBlockNumber + i);
|
|
86
|
+
};
|
|
87
|
+
export function extractWeight(weightV1OrV2) {
|
|
88
|
+
if ("isSome" in weightV1OrV2) {
|
|
89
|
+
const weight = weightV1OrV2.unwrap();
|
|
90
|
+
if ("refTime" in weight) {
|
|
91
|
+
return weight.refTime.unwrap();
|
|
92
|
+
}
|
|
93
|
+
return weight;
|
|
94
|
+
}
|
|
95
|
+
if ("refTime" in weightV1OrV2) {
|
|
96
|
+
return weightV1OrV2.refTime.unwrap();
|
|
97
|
+
}
|
|
98
|
+
return weightV1OrV2;
|
|
99
|
+
}
|
|
100
|
+
export function extractPreimageDeposit(request) {
|
|
101
|
+
const deposit = "deposit" in request ? request.deposit : request;
|
|
102
|
+
if ("isSome" in deposit && deposit.isSome) {
|
|
103
|
+
return {
|
|
104
|
+
accountId: deposit.unwrap()[0].toHex(),
|
|
105
|
+
amount: deposit.unwrap()[1],
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
if ("isNone" in deposit && deposit.isNone) {
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
accountId: deposit[0].toHex(),
|
|
113
|
+
amount: deposit[1],
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
export function mapExtrinsics(extrinsics, records, fees) {
|
|
117
|
+
return extrinsics.map((extrinsic, index) => {
|
|
118
|
+
let dispatchError;
|
|
119
|
+
let dispatchInfo;
|
|
120
|
+
const events = records
|
|
121
|
+
.filter(({ phase }) => phase.isApplyExtrinsic && phase.asApplyExtrinsic.eq(index))
|
|
122
|
+
.map(({ event }) => {
|
|
123
|
+
if (event.section === "system") {
|
|
124
|
+
if (event.method === "ExtrinsicSuccess") {
|
|
125
|
+
dispatchInfo = event.data[0];
|
|
126
|
+
}
|
|
127
|
+
else if (event.method === "ExtrinsicFailed") {
|
|
128
|
+
dispatchError = event.data[0];
|
|
129
|
+
dispatchInfo = event.data[1];
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return event;
|
|
133
|
+
});
|
|
134
|
+
return {
|
|
135
|
+
dispatchError,
|
|
136
|
+
dispatchInfo,
|
|
137
|
+
events,
|
|
138
|
+
extrinsic,
|
|
139
|
+
fee: fees ? fees[index] : undefined,
|
|
140
|
+
};
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
export async function checkTimeSliceForUpgrades(api, blockNumbers, currentVersion) {
|
|
144
|
+
const apiAt = await api.at(await api.rpc.chain.getBlockHash(blockNumbers[0]));
|
|
145
|
+
const onChainRt = (await apiAt.query.system.lastRuntimeUpgrade()).unwrap().specVersion;
|
|
146
|
+
return { result: !onChainRt.eq(currentVersion), specVersion: onChainRt };
|
|
147
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { CompiledContract } from "../types/index.js";
|
|
2
|
+
import type { Abi } from "viem";
|
|
3
|
+
export declare function getAllCompiledContracts(contractsDir?: string, recurse?: boolean): string[];
|
|
4
|
+
export declare function getCompiled<TAbi extends Abi>(contractPath: string): CompiledContract<TAbi>;
|
|
5
|
+
//# sourceMappingURL=contracts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contracts.d.ts","sourceRoot":"","sources":["../../../src/api/testing/contracts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,0BAA0B;AAG1D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAEhC,wBAAgB,uBAAuB,CAAC,YAAY,SAAO,EAAE,OAAO,UAAQ,GAAG,MAAM,EAAE,CAmBtF;AAED,wBAAgB,WAAW,CAAC,IAAI,SAAS,GAAG,EAAE,YAAY,EAAE,MAAM,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAc1F"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
export function getAllCompiledContracts(contractsDir = "./", recurse = false) {
|
|
4
|
+
const contractsPath = path.isAbsolute(contractsDir)
|
|
5
|
+
? contractsDir
|
|
6
|
+
: path.join(process.cwd(), contractsDir);
|
|
7
|
+
const contracts = fs.readdirSync(contractsPath, { withFileTypes: true });
|
|
8
|
+
let contractNames = [];
|
|
9
|
+
for (const dirent of contracts) {
|
|
10
|
+
const fullDirentPath = path.join(contractsPath, dirent.name);
|
|
11
|
+
if (dirent.isDirectory() && recurse) {
|
|
12
|
+
contractNames = contractNames.concat(getAllCompiledContracts(fullDirentPath, recurse));
|
|
13
|
+
}
|
|
14
|
+
else if (dirent.isFile() && path.extname(dirent.name) === ".json") {
|
|
15
|
+
contractNames.push(path.basename(dirent.name, ".json"));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return contractNames;
|
|
19
|
+
}
|
|
20
|
+
export function getCompiled(contractPath) {
|
|
21
|
+
const filePath = path.join(process.cwd(), `${contractPath}.json`);
|
|
22
|
+
if (!fs.existsSync(filePath)) {
|
|
23
|
+
throw new Error(`Contract name (${contractPath}) doesn't exist in test suite`);
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
const json = fs.readFileSync(filePath, "utf8");
|
|
27
|
+
return JSON.parse(json);
|
|
28
|
+
}
|
|
29
|
+
catch (_error) {
|
|
30
|
+
throw new Error(`Contract name ${contractPath} is not compiled. Please check compiled json exists`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { GenericContext, EthersTransactionOptions } from "../types/index.js";
|
|
2
|
+
export declare function createEthersTransaction<TOptions extends EthersTransactionOptions>(context: GenericContext, params: TOptions): Promise<`0x${string}`>;
|
|
3
|
+
//# sourceMappingURL=ethers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ethers.d.ts","sourceRoot":"","sources":["../../../src/api/testing/ethers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,wBAAwB,EAAE,0BAA0B;AAqClF,wBAAsB,uBAAuB,CAAC,QAAQ,SAAS,wBAAwB,EACrF,OAAO,EAAE,cAAc,EACvB,MAAM,EAAE,QAAQ,0BAqBjB"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Wallet } from "ethers";
|
|
2
|
+
import { ALITH_ADDRESS } from "../constants/accounts.js";
|
|
3
|
+
const transactionHandlers = {
|
|
4
|
+
legacy: (blob, params) => {
|
|
5
|
+
blob.gasPrice = params.gasPrice || "10000000000";
|
|
6
|
+
blob.gasLimit = params.gasLimit || "200000";
|
|
7
|
+
blob.type = 0;
|
|
8
|
+
},
|
|
9
|
+
eip2930: (blob, params) => {
|
|
10
|
+
blob.gasPrice = params.gasPrice || "10000000000";
|
|
11
|
+
blob.gasLimit = params.gasLimit || "200000";
|
|
12
|
+
blob.accessList = params.accessList || [];
|
|
13
|
+
blob.type = 1;
|
|
14
|
+
},
|
|
15
|
+
eip1559: (blob, params) => {
|
|
16
|
+
blob.accessList = params.accessList || [];
|
|
17
|
+
blob.maxFeePerGas = params.maxFeePerGas || "10000000000";
|
|
18
|
+
blob.maxPriorityFeePerGas = params.maxPriorityFeePerGas || 0;
|
|
19
|
+
blob.gasLimit = params.gasLimit || "200000";
|
|
20
|
+
blob.type = 2;
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
export async function createEthersTransaction(context, params) {
|
|
24
|
+
const nonce = "nonce" in params
|
|
25
|
+
? params.nonce
|
|
26
|
+
: await context.viem().getTransactionCount({ address: ALITH_ADDRESS });
|
|
27
|
+
const blob = { nonce, ...params };
|
|
28
|
+
const handler = transactionHandlers[params.txnType || "legacy"];
|
|
29
|
+
if (!handler) {
|
|
30
|
+
throw new Error("Unknown transaction type, update createRawEthersTxn fn");
|
|
31
|
+
}
|
|
32
|
+
handler(blob, params);
|
|
33
|
+
const signer = params.privateKey
|
|
34
|
+
? new Wallet(params.privateKey, context.ethers().provider)
|
|
35
|
+
: context.ethers();
|
|
36
|
+
const txn = await signer.populateTransaction(blob);
|
|
37
|
+
return (await signer.signTransaction(txn));
|
|
38
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { u128 } from "@polkadot/types-codec";
|
|
2
|
+
import type { AccountId20, DispatchError, DispatchInfo, EventRecord } from "@polkadot/types/interfaces";
|
|
3
|
+
export declare function filterAndApply<T>(events: EventRecord[], section: string, methods: string[], onFound: (record: EventRecord) => T): T[];
|
|
4
|
+
export declare function getDispatchError({ event: { data: [dispatchError], }, }: EventRecord): DispatchError;
|
|
5
|
+
export declare function extractError(events?: EventRecord[]): DispatchError | undefined;
|
|
6
|
+
export declare function isExtrinsicSuccessful(events?: EventRecord[]): boolean;
|
|
7
|
+
export declare function extractInfo(events?: EventRecord[]): DispatchInfo | undefined;
|
|
8
|
+
export declare function extractFee(events?: EventRecord[]): {
|
|
9
|
+
who: AccountId20;
|
|
10
|
+
amount: u128;
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../../src/api/testing/events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,KAAK,EACV,WAAW,EACX,aAAa,EACb,YAAY,EACZ,WAAW,EACZ,MAAM,4BAA4B,CAAC;AAEpC,wBAAgB,cAAc,CAAC,CAAC,EAC9B,MAAM,EAAE,WAAW,EAAE,EACrB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EAAE,EACjB,OAAO,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,CAAC,GAClC,CAAC,EAAE,CAIL;AAED,wBAAgB,gBAAgB,CAAC,EAC/B,KAAK,EAAE,EACL,IAAI,EAAE,CAAC,aAAa,CAAC,GACtB,GACF,EAAE,WAAW,GAAG,aAAa,CAE7B;AAMD,wBAAgB,YAAY,CAAC,MAAM,GAAE,WAAW,EAAO,GAAG,aAAa,GAAG,SAAS,CAElF;AAED,wBAAgB,qBAAqB,CAAC,MAAM,GAAE,WAAW,EAAO,GAAG,OAAO,CAEzE;AAED,wBAAgB,WAAW,CAAC,MAAM,GAAE,WAAW,EAAO,GAAG,YAAY,GAAG,SAAS,CAOhF;AAED,wBAAgB,UAAU,CAAC,MAAM,GAAE,WAAW,EAAO;SAKW,WAAW;YAAU,IAAI;EAExF"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export function filterAndApply(events, section, methods, onFound) {
|
|
2
|
+
return events
|
|
3
|
+
.filter(({ event }) => section === event.section && methods.includes(event.method))
|
|
4
|
+
.map((record) => onFound(record));
|
|
5
|
+
}
|
|
6
|
+
export function getDispatchError({ event: { data: [dispatchError], }, }) {
|
|
7
|
+
return dispatchError;
|
|
8
|
+
}
|
|
9
|
+
function getDispatchInfo({ event: { data, method } }) {
|
|
10
|
+
return method === "ExtrinsicSuccess" ? data[0] : data[1];
|
|
11
|
+
}
|
|
12
|
+
export function extractError(events = []) {
|
|
13
|
+
return filterAndApply(events, "system", ["ExtrinsicFailed"], getDispatchError)[0];
|
|
14
|
+
}
|
|
15
|
+
export function isExtrinsicSuccessful(events = []) {
|
|
16
|
+
return filterAndApply(events, "system", ["ExtrinsicSuccess"], () => true).length > 0;
|
|
17
|
+
}
|
|
18
|
+
export function extractInfo(events = []) {
|
|
19
|
+
return filterAndApply(events, "system", ["ExtrinsicFailed", "ExtrinsicSuccess"], getDispatchInfo)[0];
|
|
20
|
+
}
|
|
21
|
+
export function extractFee(events = []) {
|
|
22
|
+
return filterAndApply(events, "balances", ["Withdraw"], ({ event }) => event.data)[0];
|
|
23
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { SubmittableExtrinsic } from "@polkadot/api/types";
|
|
2
|
+
import type { ISubmittableResult } from "@polkadot/types/types";
|
|
3
|
+
import type { KeyringPair } from "@polkadot/keyring/types";
|
|
4
|
+
export declare const signAndSend: (tx: SubmittableExtrinsic<"promise", ISubmittableResult>, account?: KeyringPair, nonce?: number) => Promise<unknown>;
|
|
5
|
+
//# sourceMappingURL=extrinsics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extrinsics.d.ts","sourceRoot":"","sources":["../../../src/api/testing/extrinsics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAG3D,eAAO,MAAM,WAAW,GACtB,IAAI,oBAAoB,CAAC,SAAS,EAAE,kBAAkB,CAAC,EACvD,UAAS,WAAmB,EAC5B,cAAU,qBAcT,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { alith } from "../constants/index.js";
|
|
2
|
+
export const signAndSend = async (tx, account = alith, nonce = -1) => new Promise((resolve) => tx.signAndSend(account, { nonce }, ({ status }) => {
|
|
3
|
+
if (status.isInBlock) {
|
|
4
|
+
process.stdout.write("Extrinsic submitted and included in block, waiting for finalization...");
|
|
5
|
+
}
|
|
6
|
+
if (status.isFinalized) {
|
|
7
|
+
process.stdout.write("✅\n");
|
|
8
|
+
resolve(true);
|
|
9
|
+
}
|
|
10
|
+
}));
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./blocks.js";
|
|
2
|
+
export * from "./contracts.js";
|
|
3
|
+
export * from "./ethers.js";
|
|
4
|
+
export * from "./events.js";
|
|
5
|
+
export * from "./extrinsics.js";
|
|
6
|
+
export * from "./jumping.js";
|
|
7
|
+
export * from "./providers.js";
|
|
8
|
+
export * from "./viem.js";
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/testing/index.ts"],"names":[],"mappings":"AAAA,4BAA4B;AAC5B,+BAA+B;AAC/B,4BAA4B;AAC5B,4BAA4B;AAC5B,gCAAgC;AAChC,6BAA6B;AAC7B,+BAA+B;AAC/B,0BAA0B"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ApiPromise } from "@polkadot/api";
|
|
2
|
+
export declare function jumpBlocksDev(polkadotJsApi: ApiPromise, blocks: number): Promise<void>;
|
|
3
|
+
export declare function jumpRoundsDev(polkadotJsApi: ApiPromise, count: number): Promise<string | null>;
|
|
4
|
+
export declare function jumpToRoundDev(polkadotJsApi: ApiPromise, round: number): Promise<string | null>;
|
|
5
|
+
export declare function jumpRoundsChopsticks(polkadotJsApi: ApiPromise, port: number, count: number): Promise<string>;
|
|
6
|
+
export declare function jumpToRoundChopsticks(polkadotJsApi: ApiPromise, port: number, round: number): Promise<string>;
|
|
7
|
+
export declare function jumpBlocksChopsticks(port: number, blockCount: number): Promise<string>;
|
|
8
|
+
//# sourceMappingURL=jumping.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jumping.d.ts","sourceRoot":"","sources":["../../../src/api/testing/jumping.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAOhD,wBAAsB,aAAa,CAAC,aAAa,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,iBAO5E;AAED,wBAAsB,aAAa,CACjC,aAAa,EAAE,UAAU,EACzB,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAOxB;AAED,wBAAsB,cAAc,CAAC,aAAa,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,0BAiB5E;AAoBD,wBAAsB,oBAAoB,CAAC,aAAa,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,mBAMhG;AAED,wBAAsB,qBAAqB,CACzC,aAAa,EAAE,UAAU,EACzB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,mBAId;AAED,wBAAsB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,mBAE1E"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import WebSocket from "ws";
|
|
2
|
+
//**************************
|
|
3
|
+
// DEV
|
|
4
|
+
//**************************
|
|
5
|
+
export async function jumpBlocksDev(polkadotJsApi, blocks) {
|
|
6
|
+
let blockCount = blocks;
|
|
7
|
+
while (blockCount > 0) {
|
|
8
|
+
await polkadotJsApi.rpc.engine.createBlock(true, true);
|
|
9
|
+
blockCount--;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export async function jumpRoundsDev(polkadotJsApi, count) {
|
|
13
|
+
// Calculate the number of blocks to create via arithmetic
|
|
14
|
+
const round = (await polkadotJsApi.query.parachainStaking.round()).current
|
|
15
|
+
.addn(count.valueOf())
|
|
16
|
+
.toNumber();
|
|
17
|
+
return jumpToRoundDev(polkadotJsApi, round);
|
|
18
|
+
}
|
|
19
|
+
export async function jumpToRoundDev(polkadotJsApi, round) {
|
|
20
|
+
// Calculate the number of blocks to create via arithmetic
|
|
21
|
+
let lastBlockHash = "";
|
|
22
|
+
for (;;) {
|
|
23
|
+
const currentRound = (await polkadotJsApi.query.parachainStaking.round()).current.toNumber();
|
|
24
|
+
if (currentRound === round) {
|
|
25
|
+
return lastBlockHash;
|
|
26
|
+
}
|
|
27
|
+
if (currentRound > round) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
lastBlockHash = (await polkadotJsApi.rpc.engine.createBlock(true, true)).blockHash.toString();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//**************************
|
|
34
|
+
// CHOPSTICKS
|
|
35
|
+
//**************************
|
|
36
|
+
async function calculateBlocks(polkadotJsApi, targetRound) {
|
|
37
|
+
const roundInfo = (await polkadotJsApi.query.parachainStaking.round());
|
|
38
|
+
if (roundInfo.current.toNumber() >= targetRound) {
|
|
39
|
+
return 0;
|
|
40
|
+
}
|
|
41
|
+
const roundsToJump = targetRound - roundInfo.current.toNumber();
|
|
42
|
+
const heightToJump = roundInfo.first.toNumber() + roundsToJump * roundInfo.length.toNumber();
|
|
43
|
+
const currentBlock = (await polkadotJsApi.rpc.chain.getHeader()).number.toNumber();
|
|
44
|
+
return heightToJump - currentBlock;
|
|
45
|
+
}
|
|
46
|
+
export async function jumpRoundsChopsticks(polkadotJsApi, port, count) {
|
|
47
|
+
const round = (await polkadotJsApi.query.parachainStaking.round()).current
|
|
48
|
+
.addn(count.valueOf())
|
|
49
|
+
.toNumber();
|
|
50
|
+
return jumpToRoundChopsticks(polkadotJsApi, port, round);
|
|
51
|
+
}
|
|
52
|
+
export async function jumpToRoundChopsticks(polkadotJsApi, port, round) {
|
|
53
|
+
const blockToJump = await calculateBlocks(polkadotJsApi, round);
|
|
54
|
+
return jumpBlocksChopsticks(port, blockToJump);
|
|
55
|
+
}
|
|
56
|
+
export async function jumpBlocksChopsticks(port, blockCount) {
|
|
57
|
+
return await sendNewBlockCmd(port, blockCount);
|
|
58
|
+
}
|
|
59
|
+
const sendNewBlockCmd = async (port, count = 1) => {
|
|
60
|
+
const websocketUrl = `ws://127.0.0.1:${port}`;
|
|
61
|
+
const socket = new WebSocket(websocketUrl);
|
|
62
|
+
const result = await new Promise((resolve) => {
|
|
63
|
+
socket.on("open", () => {
|
|
64
|
+
socket.send(JSON.stringify({
|
|
65
|
+
jsonrpc: "2.0",
|
|
66
|
+
id: 1,
|
|
67
|
+
method: "dev_newBlock",
|
|
68
|
+
params: [{ count }],
|
|
69
|
+
}));
|
|
70
|
+
});
|
|
71
|
+
socket.on("message", (chunk) => {
|
|
72
|
+
const data = JSON.parse(chunk.toString());
|
|
73
|
+
resolve(data.result);
|
|
74
|
+
socket.close();
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
return result;
|
|
78
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Web3 } from "web3";
|
|
2
|
+
export declare function customWeb3Request(web3: Web3, method: string, params: any[]): Promise<unknown>;
|
|
3
|
+
export interface Web3EthCallOptions {
|
|
4
|
+
from?: string | number;
|
|
5
|
+
to: string;
|
|
6
|
+
value?: number | string | bigint;
|
|
7
|
+
gas?: number | string;
|
|
8
|
+
gasPrice?: number | string | bigint;
|
|
9
|
+
maxPriorityFeePerGas?: number | string | bigint;
|
|
10
|
+
maxFeePerGas?: number | string | bigint;
|
|
11
|
+
data?: string;
|
|
12
|
+
nonce?: number;
|
|
13
|
+
}
|
|
14
|
+
export declare function web3EthCall(web3: Web3, options: Web3EthCallOptions): Promise<unknown>;
|
|
15
|
+
export type EnhancedWeb3 = Web3 & {
|
|
16
|
+
customRequest: (method: string, params: any[]) => Promise<any>;
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=providers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"providers.d.ts","sourceRoot":"","sources":["../../../src/api/testing/providers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAIjC,wBAAsB,iBAAiB,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,oBAwBhF;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IACjC,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IACpC,oBAAoB,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IAChD,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IACxC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,wBAAsB,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,kBAAkB,oBAWxE;AAED,MAAM,MAAM,YAAY,GAAG,IAAI,GAAG;IAChC,aAAa,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;CAChE,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { alith } from "../constants/accounts.js";
|
|
2
|
+
import { MIN_GAS_PRICE } from "../constants/chain.js";
|
|
3
|
+
export async function customWeb3Request(web3, method, params) {
|
|
4
|
+
return new Promise((resolve, reject) => {
|
|
5
|
+
web3.eth.currentProvider.send({
|
|
6
|
+
jsonrpc: "2.0",
|
|
7
|
+
id: 1,
|
|
8
|
+
method,
|
|
9
|
+
params,
|
|
10
|
+
}, (error, result) => {
|
|
11
|
+
if (error) {
|
|
12
|
+
reject(`Failed to send custom request (${method} (${params
|
|
13
|
+
.map((p) => {
|
|
14
|
+
const str = p.toString();
|
|
15
|
+
return str.length > 128 ? `${str.slice(0, 96)}...${str.slice(-28)}` : str;
|
|
16
|
+
})
|
|
17
|
+
.join(",")})): ${error.message || error.toString()}`);
|
|
18
|
+
}
|
|
19
|
+
resolve(result);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
export async function web3EthCall(web3, options) {
|
|
24
|
+
return await customWeb3Request(web3, "eth_call", [
|
|
25
|
+
{
|
|
26
|
+
from: options.from === undefined ? options.from : alith.address,
|
|
27
|
+
value: options.value,
|
|
28
|
+
gas: options.gas === undefined ? options.gas : 256000,
|
|
29
|
+
gasPrice: options.gas === undefined ? options.gas : `0x${MIN_GAS_PRICE}`,
|
|
30
|
+
to: options.to,
|
|
31
|
+
data: options.data,
|
|
32
|
+
},
|
|
33
|
+
]);
|
|
34
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import type { ContractDeploymentOptions, DeepPartial, DevModeContext, GenericContext, ViemTransactionOptions } from "../types/index.js";
|
|
2
|
+
import type { Abi } from "viem";
|
|
3
|
+
import { type BlockTag, type TransactionSerializable } from "viem";
|
|
4
|
+
/**
|
|
5
|
+
* @name getDevChain
|
|
6
|
+
* @description This function returns a development chain object for Moonbeam.
|
|
7
|
+
* @param url - The WebSocket URL of the development chain.
|
|
8
|
+
*
|
|
9
|
+
* @returns Returns an object that represents the Moonbeam development chain.
|
|
10
|
+
* The object includes properties such as the chain's ID, name, network, native currency, and RPC URLs.
|
|
11
|
+
*
|
|
12
|
+
* @property id - The ID of the development chain. For Moonbeam Dev, this is 1281.
|
|
13
|
+
* @property name - The name of the development chain. For this function, it's "Moonbeam Dev".
|
|
14
|
+
* @property network - The network name of the development chain. For this function, it's "moonbeam".
|
|
15
|
+
* @property nativeCurrency - An object containing the native currency's details:
|
|
16
|
+
* - decimals: The number of decimal places the native currency supports.
|
|
17
|
+
* - name: The name of the native currency. For Moonbeam Dev, it's "Glimmer".
|
|
18
|
+
* - symbol: The symbol of the native currency. For Moonbeam Dev, it's "GLMR".
|
|
19
|
+
* @property rpcUrls - An object that includes the RPC URLs for the chain:
|
|
20
|
+
* - public: The public HTTP URL(s) for the chain.
|
|
21
|
+
* - default: The default HTTP URL(s) for the chain.
|
|
22
|
+
*/
|
|
23
|
+
export declare function getDevChain(url: string): Promise<{
|
|
24
|
+
readonly id: 1281;
|
|
25
|
+
readonly name: "Moonbeam Dev";
|
|
26
|
+
readonly nativeCurrency: {
|
|
27
|
+
readonly decimals: 18;
|
|
28
|
+
readonly name: "Glimmer";
|
|
29
|
+
readonly symbol: "GLMR";
|
|
30
|
+
};
|
|
31
|
+
readonly rpcUrls: {
|
|
32
|
+
readonly public: {
|
|
33
|
+
http: string[];
|
|
34
|
+
};
|
|
35
|
+
readonly default: {
|
|
36
|
+
http: string[];
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
}>;
|
|
40
|
+
/**
|
|
41
|
+
* Derives a Viem chain object from a given HTTP endpoint.
|
|
42
|
+
*
|
|
43
|
+
* @export
|
|
44
|
+
* @param endpoint The endpoint for the JSON RPC requests.
|
|
45
|
+
* @param maxRetries Maximum number of retry attempts (default: 3)
|
|
46
|
+
* @returns A promise that resolves to an object satisfying the Chain interface, which includes
|
|
47
|
+
* properties such as the chain id, chain name, network name, native currency information,
|
|
48
|
+
* and RPC URLs.
|
|
49
|
+
* @throws Will throw an error if the RPC request fails after all retries.
|
|
50
|
+
* @example
|
|
51
|
+
* const chain = await deriveViemChain('http://localhost:8545');
|
|
52
|
+
*/
|
|
53
|
+
export declare function deriveViemChain(endpoint: string, maxRetries?: number): Promise<{
|
|
54
|
+
readonly id: number;
|
|
55
|
+
readonly name: any;
|
|
56
|
+
readonly nativeCurrency: {
|
|
57
|
+
readonly decimals: any;
|
|
58
|
+
readonly name: any;
|
|
59
|
+
readonly symbol: any;
|
|
60
|
+
};
|
|
61
|
+
readonly rpcUrls: {
|
|
62
|
+
readonly public: {
|
|
63
|
+
http: string[];
|
|
64
|
+
};
|
|
65
|
+
readonly default: {
|
|
66
|
+
http: string[];
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
}>;
|
|
70
|
+
/**
|
|
71
|
+
* @name deployViemContract
|
|
72
|
+
* @description This function deploys a contract to the Moonbeam development chain.
|
|
73
|
+
* @param context - The DevModeContext object.
|
|
74
|
+
* @param abi - The Application Binary Interface (ABI) of the contract.
|
|
75
|
+
* @param bytecode - The compiled bytecode of the contract.
|
|
76
|
+
* @param privateKey - The private key used for the deployment transaction (defaults to ALITH_PRIVATE_KEY).
|
|
77
|
+
*
|
|
78
|
+
* @returns Returns an object containing the deployed contract's address, the transaction status, and any logs.
|
|
79
|
+
*
|
|
80
|
+
* @throws This function will throw an error if the contract deployment fails.
|
|
81
|
+
*
|
|
82
|
+
* @async This function returns a Promise that resolves when the contract has been successfully deployed.
|
|
83
|
+
*
|
|
84
|
+
* @property contractAddress - The address of the deployed contract.
|
|
85
|
+
* @property status - The status of the contract deployment transaction.
|
|
86
|
+
* @property logs - Any logs produced during the contract deployment transaction.
|
|
87
|
+
*/
|
|
88
|
+
export declare function deployViemContract<TOptions extends ContractDeploymentOptions>(context: DevModeContext, abi: Abi, bytecode: `0x${string}`, options?: TOptions): Promise<{
|
|
89
|
+
contractAddress: `0x${string}` | null | undefined;
|
|
90
|
+
status: "success" | "reverted";
|
|
91
|
+
logs: import("viem").Log<bigint, number, false>[];
|
|
92
|
+
hash: `0x${string}`;
|
|
93
|
+
}>;
|
|
94
|
+
export type InputAmountFormats = number | bigint | string | `0x${string}`;
|
|
95
|
+
export type TransferOptions = (Omit<TransactionSerializable, "to" | "value"> & {
|
|
96
|
+
privateKey?: `0x${string}`;
|
|
97
|
+
}) | undefined;
|
|
98
|
+
/**
|
|
99
|
+
* createRawTransfer function creates and signs a transfer, as a hex string, that can be submitted to the network via public client."
|
|
100
|
+
*
|
|
101
|
+
* @export
|
|
102
|
+
* @template TOptions - Optional parameters of Viem's TransferOptions
|
|
103
|
+
* @param {DevModeContext} context - the DevModeContext instance
|
|
104
|
+
* @param {`0x${string}`} to - the destination address of the transfer
|
|
105
|
+
* @param {InputAmountFormats} value - the amount to transfer. It accepts different formats including number, bigint, string or hexadecimal strings
|
|
106
|
+
* @param {TOptions} [options] - (optional) additional transaction options
|
|
107
|
+
* @returns {Promise<`0x${string}`>} - the signed raw transaction in hexadecimal string format
|
|
108
|
+
*/
|
|
109
|
+
export declare function createRawTransfer<TOptions extends TransferOptions>(context: DevModeContext, to: `0x${string}`, value: InputAmountFormats, options?: TOptions): Promise<`0x${string}`>;
|
|
110
|
+
/**
|
|
111
|
+
* createViemTransaction function creates and signs a raw transaction, as a hex string, that can be submitted to the network via public client."
|
|
112
|
+
*
|
|
113
|
+
* @export
|
|
114
|
+
* @template TOptions - Optional parameters of Viem's TransactionOptions
|
|
115
|
+
* @param {GenericContext} context - the GenericContext instance
|
|
116
|
+
* @param {TOptions} options - transaction options including type, privateKey, value, to, chainId, gasPrice, estimatedGas, accessList, data
|
|
117
|
+
* @returns {Promise<string>} - the signed raw transaction in hexadecimal string format
|
|
118
|
+
*/
|
|
119
|
+
export declare function createViemTransaction<TOptions extends DeepPartial<ViemTransactionOptions>>(context: GenericContext, options: TOptions): Promise<`0x${string}`>;
|
|
120
|
+
/**
|
|
121
|
+
* checkBalance function checks the balance of a given account.
|
|
122
|
+
*
|
|
123
|
+
* @export
|
|
124
|
+
* @param {DevModeContext} context - the DevModeContext instance
|
|
125
|
+
* @param {`0x${string}`} [account=ALITH_ADDRESS] - the account address whose balance is to be checked. If no account is provided, it defaults to ALITH_ADDRESS
|
|
126
|
+
* @returns {Promise<bigint>} - returns a Promise that resolves to the account's balance as a BigInt
|
|
127
|
+
*/
|
|
128
|
+
export declare function checkBalance(context: DevModeContext, account?: `0x${string}`, block?: BlockTag | bigint): Promise<bigint>;
|
|
129
|
+
/**
|
|
130
|
+
* Sends a raw signed transaction on to RPC node for execution.
|
|
131
|
+
*
|
|
132
|
+
* @async
|
|
133
|
+
* @function
|
|
134
|
+
* @param {GenericContext} context - The DevModeContext for the Ethereum client interaction.
|
|
135
|
+
* @param {`0x${string}`} rawTx - The signed and serialized hexadecimal transaction string.
|
|
136
|
+
* @returns {Promise<any>} A Promise resolving when the transaction is sent or rejecting with an error.
|
|
137
|
+
*/
|
|
138
|
+
export declare function sendRawTransaction(context: GenericContext, rawTx: `0x${string}`): Promise<`0x${string}`>;
|
|
139
|
+
//# sourceMappingURL=viem.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"viem.d.ts","sourceRoot":"","sources":["../../../src/api/testing/viem.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,yBAAyB,EACzB,WAAW,EACX,cAAc,EACd,cAAc,EACd,sBAAsB,EACvB,0BAA0B;AAC3B,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAChC,OAAO,EACL,KAAK,QAAQ,EAEb,KAAK,uBAAuB,EAI7B,MAAM,MAAM,CAAC;AAOd;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,WAAW,CAAC,GAAG,EAAE,MAAM;;;;;;;;;;;;;;;;GAiB5C;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,GAAE,MAAU;;;;;;;;;;;;;;;;GA2C7E;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,kBAAkB,CAAC,QAAQ,SAAS,yBAAyB,EAEjF,OAAO,EAAE,cAAc,EACvB,GAAG,EAAE,GAAG,EACR,QAAQ,EAAE,KAAK,MAAM,EAAE,EACvB,OAAO,CAAC,EAAE,QAAQ;;;;;GAoCnB;AAED,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,MAAM,EAAE,CAAC;AAE1E,MAAM,MAAM,eAAe,GACvB,CAAC,IAAI,CAAC,uBAAuB,EAAE,IAAI,GAAG,OAAO,CAAC,GAAG;IAC/C,UAAU,CAAC,EAAE,KAAK,MAAM,EAAE,CAAC;CAC5B,CAAC,GACF,SAAS,CAAC;AAEd;;;;;;;;;;GAUG;AACH,wBAAsB,iBAAiB,CAAC,QAAQ,SAAS,eAAe,EACtE,OAAO,EAAE,cAAc,EACvB,EAAE,EAAE,KAAK,MAAM,EAAE,EACjB,KAAK,EAAE,kBAAkB,EACzB,OAAO,CAAC,EAAE,QAAQ,GACjB,OAAO,CAAC,KAAK,MAAM,EAAE,CAAC,CAOxB;AAED;;;;;;;;GAQG;AACH,wBAAsB,qBAAqB,CAAC,QAAQ,SAAS,WAAW,CAAC,sBAAsB,CAAC,EAC9F,OAAO,EAAE,cAAc,EACvB,OAAO,EAAE,QAAQ,GAChB,OAAO,CAAC,KAAK,MAAM,EAAE,CAAC,CA4DxB;AAED;;;;;;;GAOG;AACH,wBAAsB,YAAY,CAChC,OAAO,EAAE,cAAc,EACvB,OAAO,GAAE,KAAK,MAAM,EAAkB,EACtC,KAAK,GAAE,QAAQ,GAAG,MAAiB,GAClC,OAAO,CAAC,MAAM,CAAC,CAMjB;AAED;;;;;;;;GAQG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,cAAc,EACvB,KAAK,EAAE,KAAK,MAAM,EAAE,GACnB,OAAO,CAAC,KAAK,MAAM,EAAE,CAAC,CAExB"}
|