@moonsong-labs/moonwall-cli
Version:
Testing framework for the Moon family of projects
129 lines (126 loc) • 3.92 kB
JavaScript
import {
upgradeRuntimeChopsticks
} from "./chunk-ZI72LISQ.js";
import {
createDevBlock
} from "./chunk-5HTJIM3P.js";
import {
createChopsticksBlock,
sendSetStorageRequest
} from "./chunk-CTJCM5IU.js";
import {
MoonwallContext,
contextCreator
} from "./chunk-WICDGWJQ.js";
import {
importJsonConfig
} from "./chunk-3P647NU6.js";
// src/lib/runner-functions.ts
import "@moonbeam-network/api-augment";
import { describe, it, beforeAll, afterAll } from "vitest";
import Debug from "debug";
var RT_VERSION = Number(process.env.MOON_RTVERSION);
var RT_NAME = process.env.MOON_RTNAME;
function describeSuite({
id,
title,
testCases,
foundationMethods,
minRtVersion,
chainType,
notChainType
}) {
let ctx;
if (minRtVersion && minRtVersion > RT_VERSION || chainType && chainType !== RT_NAME || notChainType && notChainType === RT_NAME) {
describe.skip(`\u{1F5C3}\uFE0F #${id} ${title}`);
return;
}
beforeAll(async function() {
const globalConfig = await importJsonConfig();
ctx = await contextCreator(globalConfig, process.env.MOON_TEST_ENV);
if (ctx.environment.foundationType === "dev") {
} else if (ctx.environment.foundationType === "chopsticks") {
}
});
afterAll(async function() {
await MoonwallContext.destroy();
});
describe(`\u{1F5C3}\uFE0F #${id} ${title}`, function() {
const context = {
providers: {},
getSubstrateApi: (options) => {
if (options && options.apiName) {
return context.providers[options.apiName];
} else if (options && options.type) {
return ctx.providers.find((a) => a.type == options.type).api;
} else {
return ctx.providers.find((a) => a.type == "moon" || a.type == "polkadotJs").api;
}
},
ethersSigner: (apiName) => {
if (apiName) {
return context.providers[apiName];
} else {
return ctx.providers.find((a) => a.type == "ethers").api;
}
},
web3: (apiName) => {
if (apiName) {
return context.providers[apiName];
} else {
return ctx.providers.find((a) => a.type == "web3").api;
}
}
};
const logger = () => {
process.env.DEBUG_COLORS = "1";
const debug = Debug(`test:${process.env.MOON_TEST_ENV}`);
Debug.enable("test:*");
Debug.log = console.info.bind(console);
return debug;
};
const testCase = (params) => {
if (params.modifier) {
it[params.modifier](
`\u{1F4C1} #${id.concat(params.id)} ${params.title}`,
params.test,
params.timeout
);
return;
}
if (params.minRtVersion && params.minRtVersion > RT_VERSION || params.chainType && params.chainType !== RT_NAME || params.notChainType && params.notChainType === RT_NAME) {
it.skip(`\u{1F4C1} #${id.concat(params.id)} ${params.title}`, params.test, params.timeout);
return;
}
it(`\u{1F4C1} #${id.concat(params.id)} ${params.title}`, params.test, params.timeout);
};
if (foundationMethods == "dev") {
testCases({
context: {
...context,
createBlock: async (transactions, options = {}) => await createDevBlock(context, transactions, options)
},
it: testCase,
log: logger()
});
} else if (foundationMethods == "chopsticks") {
testCases({
context: {
...context,
createBlock: async (options = {}) => await createChopsticksBlock(context, options),
setStorage: async (params) => await sendSetStorageRequest(params),
upgradeRuntime: async (chCtx) => {
await upgradeRuntimeChopsticks(chCtx, ctx.rtUpgradePath);
}
},
it: testCase,
log: logger()
});
} else {
testCases({ context, it: testCase, log: logger() });
}
});
}
export {
describeSuite
};