Skip to content

Commit

Permalink
Merge branch 'master' into girazoki-fix-bridge-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
girazoki authored Nov 15, 2024
2 parents 46fdf66 + ce21610 commit b86979c
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describeSuite({
api = context.polkadotJs();
runtimeVersion = api.runtimeVersion.specVersion.toNumber();
chain = api.consts.system.version.specName.toString();
blocksPerSession = chain == "dancebox" ? 600n : 50n;
blocksPerSession = chain == "dancebox" || chain == "dancelight" ? 600n : 50n;
});

it({
Expand All @@ -30,8 +30,10 @@ describeSuite({
return;
}
const currentBlock = (await api.rpc.chain.getBlock()).block.header.number.toNumber();

const blockToCheck = Math.trunc(currentBlock / Number(blocksPerSession)) * Number(blocksPerSession);
const blockToCheck =
chain == "dancelight"
? (await api.query.babe.epochStart()).toJSON()[1]
: Math.trunc(currentBlock / Number(blocksPerSession)) * Number(blocksPerSession);
const apiBeforeLatestNewSession = await api.at(await api.rpc.chain.getBlockHash(blockToCheck - 1));

// If they have collators scheduled, they should have at least enough money to pay
Expand Down
77 changes: 77 additions & 0 deletions test/suites/smoke-test-dancelight/test-beefy-mmr-digests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { beforeAll, describeSuite, expect } from "@moonwall/cli";

import { stringToHex } from "@polkadot/util";
import { ApiPromise } from "@polkadot/api";

describeSuite({
id: "S19",
title: "Sample suite that only runs on Dancelight chains",
foundationMethods: "read_only",
testCases: ({ it, context }) => {
let api: ApiPromise;

beforeAll(() => {
api = context.polkadotJs();
});

it({
id: "C01",
title: "Session change block should update BEEFY and MMR root digests properly",
test: async function () {
const blockToCheck = (await api.query.babe.epochStart()).toJSON()[1];

const apiAtBeforeSessionChange = await api.at(await api.rpc.chain.getBlockHash(blockToCheck - 5));
const beefyNextAuthorities = await apiAtBeforeSessionChange.query.beefy.nextAuthorities();

const apiAtSessionChange = await api.at(await api.rpc.chain.getBlockHash(blockToCheck));

const digestsInSessionChange = (await apiAtSessionChange.query.system.digest()).logs;
const filteredDigests = digestsInSessionChange.filter(
(log) => log.isConsensus === true && log.asConsensus[0].toHex() == stringToHex("BEEF")
);

// As session changed, it should contain two BEEFY digests: AuthoritiesChange and MmrRoot.
expect(filteredDigests.length).to.eq(2);

// 0x01 corresponds to ConsensusLog::AuthoritiesChange enum variant.
expect(filteredDigests[0].asConsensus[1].toHex().startsWith("0x01")).to.be.true;

// Check if each authority is included in the BEEFY digest
for (const authority of Object.values(beefyNextAuthorities.toJSON())) {
expect(filteredDigests[0].asConsensus[1].toHex().includes(authority.slice(2))).to.be.true;
}

const firstMmrRootDigest = filteredDigests[1].asConsensus[1].toHex();

// 0x03 corresponds to ConsensusLog::MmrRoot enum variant.
expect(firstMmrRootDigest.startsWith("0x03")).to.be.true;

// Second BEEF log should contain the MMR root.
// Length should be 68 (0x03 + 32 bytes MMR root).
expect(firstMmrRootDigest.length).to.eq(68);

// Now let's check just after session change
const apiAtAfterSessionChange = await api.at(await api.rpc.chain.getBlockHash(blockToCheck + 1));
const digestsAfterSessionChange = (await apiAtAfterSessionChange.query.system.digest()).logs;
const filteredDigestsAfterSessionChange = digestsAfterSessionChange.filter(
(log) => log.isConsensus === true && log.asConsensus[0].toHex() == stringToHex("BEEF")
);

// Now we should only have the MmrRoot BEEFY digest (as session didn't change yet).
expect(filteredDigestsAfterSessionChange.length).to.eq(1);

const secondMmrRootDigest = filteredDigestsAfterSessionChange[0].asConsensus[1].toHex();

// New MmrRoot digest should be different than the first one found.
expect(secondMmrRootDigest).to.not.eq(firstMmrRootDigest);

// 0x03 corresponds to ConsensusLog::MmrRoot enum variant.
expect(secondMmrRootDigest.startsWith("0x03")).to.be.true;

// Second BEEF log should contain the MMR root.
// Length should be 68 (0x03 + 32 bytes MMR root).
expect(secondMmrRootDigest.length).to.eq(68);
},
});
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,24 @@ describeSuite({
foundationMethods: "read_only",
testCases: ({ it, context }) => {
let api: ApiPromise;
let blocksPerSession;
const blocksPerSession = 600n;
const costPerSession = 100_000_000n;
const costPerBlock = 1_000_000n;

beforeAll(() => {
api = context.polkadotJs();
const chain = api.consts.system.version.specName.toString();
blocksPerSession = chain == "dancebox" ? 600n : 50n;
});

it({
id: "C01",
title: "Config for registered paras should be consistent",
test: async function () {
const currentBlock = (await api.rpc.chain.getBlock()).block.header.number.toNumber();
const sessionIndex = (await api.query.session.currentIndex()).toNumber();
const blockToCheck = (await api.query.babe.epochStart()).toJSON()[1];

const blockToCheck = Math.trunc(currentBlock / Number(blocksPerSession)) * Number(blocksPerSession);
const apiBeforeLatestNewSession = await api.at(await api.rpc.chain.getBlockHash(blockToCheck - 1));

const config = await api.query.collatorConfiguration.activeConfig();
// get current session
const sessionIndex = (await api.query.session.currentIndex()).toNumber();

// get pending authorities
// the reason for getting pending is that the hasEnoughCredits check it's done over the pending ones
const pendingAuthorityAssignment = (
Expand Down

0 comments on commit b86979c

Please sign in to comment.