diff --git a/test/suites/dev-tanssi-relay/collator-assignment/test-configurable-priority.ts b/test/suites/dev-tanssi-relay/collator-assignment/test-configurable-priority.ts new file mode 100644 index 000000000..2452079ba --- /dev/null +++ b/test/suites/dev-tanssi-relay/collator-assignment/test-configurable-priority.ts @@ -0,0 +1,113 @@ +import "@tanssi/api-augment"; +import { describeSuite, expect, beforeAll } from "@moonwall/cli"; +import { ApiPromise, Keyring } from "@polkadot/api"; +import { jumpBlocks, jumpSessions, jumpToSession, signAndSendAndInclude, waitSessions } from "util/block"; +import { filterAndApply } from "@moonwall/util"; +import { EventRecord } from "@polkadot/types/interfaces"; +import { bool, u32, u8, Vec } from "@polkadot/types-codec"; +import fs from "fs/promises"; +import { chainSpecToContainerChainGenesisData } from "../../../util/genesis_data.ts"; +import jsonBg from "json-bigint"; +const JSONbig = jsonBg({ useNativeBigInt: true }); + +describeSuite({ + id: "DTR0401", + title: "Collator assignment tests", + foundationMethods: "dev", + + testCases: ({ it, context }) => { + let polkadotJs: ApiPromise; + + beforeAll(async () => { + polkadotJs = context.polkadotJs(); + }); + + it({ + id: "E01", + title: "Set of Parachains should be sort by tip and truncated according to max cores allocated if we have less cores", + test: async function () { + + }, + }); + + it({ + id: "E02", + title: "Set of Parathreads would not be truncated", + test: async function () { + const keyring = new Keyring({ type: "sr25519" }); + const alice = keyring.addFromUri("//Alice", { name: "Alice default" }); + const nextProfileId = await polkadotJs.query.dataPreservers.nextProfileId(); + const slotFrequency2000 = polkadotJs.createType("TpTraitsSlotFrequency", { + min: 6, + max: 6, + }); + + const responseFor2002 = await createTxBatchForCreatingParathread( + polkadotJs, + alice.address, + 2002, + slotFrequency2000, + nextProfileId + ); + + const txs = []; + await signAndSendAndInclude(polkadotJs.tx.sudo.sudo(polkadotJs.tx.utility.batch(txs)), alice); + + // Checking that in session 2 paras are registered + await waitSessions(context, polkadotJs, 2); + + const pendingParas = await polkadotJs.query.registrar.pendingParaIds(); + expect(pendingParas.length).to.be.eq(1); + const parasScheduled = pendingParas[0][1]; + expect(parasScheduled.toJSON()).to.deep.equal([2002]); + }, + }); + }, +}); + + +async function createTxBatchForCreatingParathread(api, manager, paraId, slotFreq, nextProfileId, headData?: null) { + const specPaths = { + 2002: "specs/parathreads-template-container-2002.json", + 2003: "specs/parathreads-template-container-2003.json", + }; + if (!specPaths[paraId]) { + throw new Error(`Unknown chain spec path for paraId ${paraId}`); + } + const chain = specPaths[paraId]; + const rawSpec = JSONbig.parse(await fs.readFile(chain, "utf8")); + + const containerChainGenesisData = chainSpecToContainerChainGenesisData(api, rawSpec); + const txs = []; + const tx1 = api.tx.containerRegistrar.registerParathread(rawSpec.para_id, slotFreq, containerChainGenesisData, headData); + txs.push( + api.tx.utility.dispatchAs( + { + system: { Signed: manager }, + } as any, + tx1 + ) + ); + if (rawSpec.bootNodes?.length) { + for (const bootnode of rawSpec.bootNodes) { + const profileTx = api.tx.dataPreservers.forceCreateProfile( + { + url: bootnode, + paraIds: "AnyParaId", + mode: "Bootnode", + assignmentRequest: "Free", + }, + manager + ); + txs.push(profileTx); + + const tx2 = api.tx.dataPreservers.forceStartAssignment(nextProfileId++, rawSpec.para_id, "Free"); + const tx2s = api.tx.sudo.sudo(tx2); + txs.push(tx2s); + } + } + const tx3 = api.tx.containerRegistrar.markValidForCollating(rawSpec.para_id); + txs.push(tx3); + + return { txs: txs, nextProfileId: nextProfileId }; +}