Skip to content

Commit

Permalink
update remaining dancelight smoke tests
Browse files Browse the repository at this point in the history
  • Loading branch information
timbrinded committed Feb 10, 2025
1 parent c7ba6cd commit a9ad1a1
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 37 deletions.
11 changes: 5 additions & 6 deletions test/suites/smoke-test-dancelight/test-babe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describeSuite({
filteredDigests[0].asConsensus[1].toHex()
);

expect(babeConsensusLog[1]).toEqual(babeAuthoritiesFromPallet);
expect(babeConsensusLog[1].eq(babeAuthoritiesFromPallet)).toBe(true);

const keyOwnersArray: string[] = [];
const keyOwnersInPalletSession = await keyOwners(babeAuthoritiesFromPallet, api);
Expand Down Expand Up @@ -140,7 +140,7 @@ describeSuite({
babeLogs[0].asPreRuntime[1].toHex()
);

expect(babeLogEnum.isSecondaryVRF || babeLogEnum.isPrimary).toBeTruthy();
expect(babeLogEnum.isSecondaryVRF || babeLogEnum.isPrimary).toBe(true);
const babeLog = babeLogEnum.isSecondaryVRF ? babeLogEnum.asSecondaryVRF : babeLogEnum.asPrimary;

// Get expected author from BABE log and on chain authorities
Expand Down Expand Up @@ -214,10 +214,9 @@ async function keyOwners(
for (const authority of babeAuthoritiesFromPallet) {
const keyOwner = await api.query.session.keyOwner([stringToHex("babe"), authority[0].toHex()]);

expect(
keyOwner.isSome,
`Validator with babe key ${authority[0].toHuman()} not found in pallet session!`
).toBeTruthy();
expect(keyOwner.isSome, `Validator with babe key ${authority[0].toHuman()} not found in pallet session!`).toBe(
true
);
keyOwnersInPalletSession.push([keyOwner.unwrap().toHuman(), authority[0].toJSON()]);
}

Expand Down
74 changes: 43 additions & 31 deletions test/suites/smoke-test-dancelight/test-para-inclusion.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import "@tanssi/api-augment/dancelight";
import { beforeAll, describeSuite, expect } from "@moonwall/cli";
import { getBlockArray } from "@moonwall/util";
import type { ApiPromise } from "@polkadot/api";
import type { GenericExtrinsic } from "@polkadot/types";
import type { FrameSystemEventRecord } from "@polkadot/types/lookup";
import type { AnyTuple } from "@polkadot/types/types";
import type {
PolkadotRuntimeParachainsConfigurationHostConfiguration,
PolkadotPrimitivesV8InherentData,
} from "@polkadot/types/lookup";
import Bottleneck from "bottleneck";
import type { DigestItem } from "@polkadot/types/interfaces";

const timePeriod = process.env.TIME_PERIOD ? Number(process.env.TIME_PERIOD) : 1 * 60 * 60 * 1000;
const timeout = Math.max(Math.floor(timePeriod / 12), 5000);
Expand All @@ -14,22 +20,25 @@ type BlockFilteredRecord = {
blockNum: number;
extrinsics: GenericExtrinsic<AnyTuple>[];
events: FrameSystemEventRecord[];
logs;
config;
paraInherent;
logs: DigestItem[];
config: PolkadotRuntimeParachainsConfigurationHostConfiguration;
paraInherents: GenericExtrinsic[];
};

interface CollatorAssignment {
orchestratorChain: string[];
containerChains: { [paraId: number]: string[] };
}

describeSuite({
id: "SMOK07",
title: "Sample suite that only runs on Dancelight chains",
foundationMethods: "read_only",
testCases: ({ it, context, log }) => {
let api: ApiPromise;
let blockData: BlockFilteredRecord[];
// block hash to block number
const blockNumberMap: Map<string, number> = new Map();
// block hash to collators
const collatorsMap: Map<string, any> = new Map();
const collatorsMap: Map<string, CollatorAssignment> = new Map();

beforeAll(async () => {
api = context.polkadotJs();
Expand All @@ -41,23 +50,19 @@ describeSuite({
const blockHash = await api.rpc.chain.getBlockHash(blockNum);
const signedBlock = await api.rpc.chain.getBlock(blockHash);
const apiAt = await api.at(blockHash);
const config = await apiAt.query.configuration.activeConfig();
const config =
(await apiAt.query.configuration.activeConfig()) as unknown as PolkadotRuntimeParachainsConfigurationHostConfiguration;
const extrinsics = signedBlock.block.extrinsics;

const paraInherent = extrinsics.filter((ex) => {
const {
method: { method, section },
} = ex;
return section === "paraInherent" && method === "enter";
});
const paraInherents = extrinsics.filter(
({ method: { method, section } }) => section === "paraInherent" && method === "enter"
);

const {
method: { args },
} = paraInherent[0];
} = paraInherents[0];

const arg = args[0];

const backedCandidates = arg.backedCandidates;
const { backedCandidates } = args[0] as PolkadotPrimitivesV8InherentData;

for (const cand of backedCandidates) {
const relayParent = cand.candidate.descriptor.relayParent.toHex();
Expand All @@ -71,11 +76,20 @@ describeSuite({

if (!collatorsMap.has(relayParent)) {
const apiAtP = await api.at(relayParent);
const collators = (
await apiAtP.query.tanssiCollatorAssignment.collatorContainerChain()
).toJSON();

collatorsMap.set(relayParent, collators);
const collators = await apiAtP.query.tanssiCollatorAssignment.collatorContainerChain();
const containerChainsMap = [...collators.containerChains.entries()].reduce(
(acc, [key, value]) => {
acc[key.toNumber()] = value.map((a) => a.toHuman());
return acc;
},
{} as { [paraId: number]: string[] }
);

const blob: CollatorAssignment = {
orchestratorChain: collators.orchestratorChain.map((a) => a.toHuman()),
containerChains: containerChainsMap,
};
collatorsMap.set(relayParent, blob);
}
}

Expand All @@ -85,7 +99,7 @@ describeSuite({
events: await apiAt.query.system.events(),
logs: signedBlock.block.header.digest.logs,
config,
paraInherent,
paraInherents,
};
};
const limiter = new Bottleneck({ maxConcurrent: 5, minTime: 100 });
Expand All @@ -96,17 +110,16 @@ describeSuite({
id: "C01",
title: "Included paras valid",
test: async () => {
blockData.map(({ blockNum, config, paraInherent }) => {
blockData.map(({ blockNum, config, paraInherents }) => {
// Should have exactly 1 paraInherent
expect(paraInherent.length, "Block #{blockNum}: missing paraInherent in block").toBeGreaterThan(0);
expect(paraInherent.length, "Block #{blockNum}: duplicate paraInherent in block").toBeLessThan(2);
expect(paraInherents.length, `Block ${blockNum}: missing paraInherent in block`).toBeGreaterThan(0);
expect(paraInherents.length, `Block ${blockNum}: duplicate paraInherent in block`).toBeLessThan(2);

const {
method: { args },
} = paraInherent[0];
const arg = args[0];
} = paraInherents[0];

const backedCandidates = arg.backedCandidates;
const { backedCandidates } = args[0] as PolkadotPrimitivesV8InherentData;

const numBackedCandidates = backedCandidates.length;

Expand All @@ -124,7 +137,6 @@ describeSuite({
for (const cand of backedCandidates) {
const paraId = cand.candidate.descriptor.paraId.toNumber();
const relayParent = cand.candidate.descriptor.relayParent.toHex();

const parentBlockNumber = blockNumberMap.get(relayParent);

// allowedAncestryLen = 0 means that we only allow building on top of the parent block
Expand All @@ -139,7 +151,7 @@ describeSuite({
const collators = collatorsMap.get(relayParent);
expect(
collators.containerChains[paraId],
`Block #${blockNum}: Found backed candidate for para id ${paraId}, but that para id has no collators assigned. Collator assignment: ${collators}`
`Block #${blockNum}: Found backed candidate for para id ${paraId}, but that para id has no collators assigned. Collator assignment: {containerChains: ${collators.containerChains} , orchestratorChain: ${collators.orchestratorChain}}`
).toBeTruthy();
}
});
Expand Down

0 comments on commit a9ad1a1

Please sign in to comment.