Skip to content

Commit

Permalink
rely on babe's epoch start
Browse files Browse the repository at this point in the history
  • Loading branch information
Agusrodri committed Nov 14, 2024
1 parent 117f585 commit 29f2ce9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 19 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,8 @@ 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
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,7 @@ describeSuite({
id: "C01",
title: "Session change block should update BEEFY and MMR root digests properly",
test: async function () {
const blocksPerSession = 600;
const sessionIndex = (await api.query.session.currentIndex()).toNumber();

// 636564 -> block in which session changed to 1061.
// 637164 -> actual block where next session (1062) will happen.
// 637200 -> computed block based on currentIndex * sessionLength (600 blocks).
// We have a small rounding diff of 36 blocks in all the cases.
const blockToCheck = (sessionIndex * blocksPerSession) - 36;
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();
Expand Down
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 29f2ce9

Please sign in to comment.