Skip to content

Commit

Permalink
Draft: ts test first draft
Browse files Browse the repository at this point in the history
  • Loading branch information
ParthDesai committed Sep 11, 2024
1 parent 9d98231 commit 9073965
Showing 1 changed file with 113 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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";

Check failure on line 4 in test/suites/dev-tanssi-relay/collator-assignment/test-configurable-priority.ts

View workflow job for this annotation

GitHub Actions / typescript-linting

'jumpBlocks' is defined but never used

Check failure on line 4 in test/suites/dev-tanssi-relay/collator-assignment/test-configurable-priority.ts

View workflow job for this annotation

GitHub Actions / typescript-linting

'jumpSessions' is defined but never used

Check failure on line 4 in test/suites/dev-tanssi-relay/collator-assignment/test-configurable-priority.ts

View workflow job for this annotation

GitHub Actions / typescript-linting

'jumpToSession' is defined but never used
import { filterAndApply } from "@moonwall/util";

Check failure on line 5 in test/suites/dev-tanssi-relay/collator-assignment/test-configurable-priority.ts

View workflow job for this annotation

GitHub Actions / typescript-linting

'filterAndApply' is defined but never used
import { EventRecord } from "@polkadot/types/interfaces";

Check failure on line 6 in test/suites/dev-tanssi-relay/collator-assignment/test-configurable-priority.ts

View workflow job for this annotation

GitHub Actions / typescript-linting

'EventRecord' is defined but never used
import { bool, u32, u8, Vec } from "@polkadot/types-codec";

Check failure on line 7 in test/suites/dev-tanssi-relay/collator-assignment/test-configurable-priority.ts

View workflow job for this annotation

GitHub Actions / typescript-linting

'bool' is defined but never used

Check failure on line 7 in test/suites/dev-tanssi-relay/collator-assignment/test-configurable-priority.ts

View workflow job for this annotation

GitHub Actions / typescript-linting

'u32' is defined but never used

Check failure on line 7 in test/suites/dev-tanssi-relay/collator-assignment/test-configurable-priority.ts

View workflow job for this annotation

GitHub Actions / typescript-linting

'u8' is defined but never used

Check failure on line 7 in test/suites/dev-tanssi-relay/collator-assignment/test-configurable-priority.ts

View workflow job for this annotation

GitHub Actions / typescript-linting

'Vec' is defined but never used
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(

Check failure on line 45 in test/suites/dev-tanssi-relay/collator-assignment/test-configurable-priority.ts

View workflow job for this annotation

GitHub Actions / typescript-linting

'responseFor2002' is assigned a value but never used
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 };
}

0 comments on commit 9073965

Please sign in to comment.