-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
62 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
test/suites/dev-tanssi-relay/paras-candidate-inherent/test_paras_candidate_inherent.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import "@tanssi/api-augment"; | ||
import { describeSuite, customDevRpcRequest, expect } from "@moonwall/cli"; | ||
import { ApiPromise } from "@polkadot/api"; | ||
import { jumpBlocks, jumpSessions, jumpToSession } from "util/block"; | ||
import { filterAndApply } from "@moonwall/util"; | ||
import { EventRecord } from "@polkadot/types/interfaces"; | ||
import { bool, u32, u8, Vec } from "@polkadot/types-codec"; | ||
import { before } from "node:test"; | ||
import { getHeaderFromRelay } from "util/relayInterface.ts"; | ||
|
||
describeSuite({ | ||
id: "DTR1401", | ||
title: "Paras inherent tests", | ||
foundationMethods: "dev", | ||
|
||
testCases: ({ it, context }) => { | ||
let polkadotJs: ApiPromise; | ||
|
||
before(async () => { | ||
polkadotJs = context.polkadotJs(); | ||
}); | ||
|
||
it({ | ||
id: "E01", | ||
title: "Paras heads should be updated every block", | ||
test: async function () { | ||
const parasHeadGenesis = await context.polkadotJs().query.paras.heads(2000); | ||
await context.createBlock(); | ||
// Send RPC call to enable para inherent candidate generation | ||
await customDevRpcRequest("mock_enableParaInherentCandidate", []); | ||
// Since collators are not assigned until session 2, we need to go till session 2 to actually see heads being injected | ||
await jumpToSession(context, 3); | ||
await context.createBlock(); | ||
const parasHeadAfterOneBlock = await context.polkadotJs().query.paras.heads(2000); | ||
expect(parasHeadAfterOneBlock).to.not.be.eq(parasHeadGenesis); | ||
await context.createBlock(); | ||
// we create one more block to test we are persisting candidates every block | ||
const parasHeadAfterTwoBlocks = await context.polkadotJs().query.paras.heads(2000); | ||
expect(parasHeadAfterOneBlock).to.not.be.eq(parasHeadAfterTwoBlocks); | ||
const header2000 = await getHeaderFromRelay(context.polkadotJs(), 2000); | ||
expect(header2000.number.toBigInt()).to.be.equal(31n); | ||
}, | ||
}); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,16 @@ | ||
import { ApiPromise } from "@polkadot/api"; | ||
import type { Header, ParaId } from "@polkadot/types/interfaces"; | ||
import type { Header, ParaId, HeadData } from "@polkadot/types/interfaces"; | ||
import { u8aToHex, u8aToU8a, isU8a, hexToU8a, compactToU8a, compactFromU8a, compactFromU8aLim } from "@polkadot/util" | ||
import { bool, u32, u8, Bytes } from "@polkadot/types-codec"; | ||
import { TypeRegistry } from "@polkadot/types"; | ||
|
||
export async function getHeaderFromRelay(relayApi: ApiPromise, paraId: ParaId): Promise<Header | null> { | ||
// Get the latest header from relay storage | ||
const encoded = await relayApi.query.paras.heads(paraId); | ||
const header = await relayApi.createType("Header", encoded); | ||
const registry = new TypeRegistry(); | ||
const headerEncoded: HeadData = await relayApi.createType("HeadData", encoded.toHex()); | ||
const nonEncodedHeader = new Bytes(registry, headerEncoded.toU8a(true)).toHex() | ||
|
||
const header = await relayApi.createType("SpRuntimeHeader", nonEncodedHeader); | ||
return header; | ||
} | ||
} |