Skip to content

Commit

Permalink
Fix tests zombie_tanssi_rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
tmpolaczyk committed Oct 17, 2023
1 parent 1573957 commit a3b77c9
Showing 1 changed file with 34 additions and 24 deletions.
58 changes: 34 additions & 24 deletions test/suites/rotation-para/test_rotation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describeSuite({
let container2001Api: ApiPromise;
let ethersSigner: Signer;
let assignment3;
let assignment4;
let assignment5;
let allCollators: string[];
let collatorName: Record<string, string>;
Expand Down Expand Up @@ -89,16 +90,18 @@ describeSuite({

it({
id: "T02",
title: "Set 1 collator per parachain",
title: "Set 1 collator per parachain, and full_rotation every session",
timeout: 60000,
test: async function () {
const keyring = new Keyring({ type: "sr25519" });
const alice = keyring.addFromUri("//Alice", { name: "Alice default" });

const tx1 = await paraApi.tx.configuration.setCollatorsPerContainer(1);
const tx2 = await paraApi.tx.configuration.setMinOrchestratorCollators(1);
const tx3 = await paraApi.tx.configuration.setMaxOrchestratorCollators(1);
const tx123 = paraApi.tx.utility.batchAll([tx1, tx2, tx3]);
await signAndSendAndInclude(paraApi.tx.sudo.sudo(tx123), alice);
const tx4 = await paraApi.tx.configuration.setFullRotationPeriod(1);
const tx1234 = paraApi.tx.utility.batchAll([tx1, tx2, tx3, tx4]);
await signAndSendAndInclude(paraApi.tx.sudo.sudo(tx1234), alice);
},
});

Expand Down Expand Up @@ -229,7 +232,7 @@ describeSuite({
it({
id: "T11",
title: "Transactions can be made with ethers",
timeout: 30000,
timeout: 60000,
test: async function () {
const randomAccount = generateKeyringPair();
const tx = await createTransfer(context, randomAccount.address, 1_000_000_000_000, {
Expand Down Expand Up @@ -266,24 +269,19 @@ describeSuite({
});
it({
id: "T13",
title: "On session 4 collators start syncing the new chains",
title: "On session 3 collators start syncing the new chains",
timeout: 90000,
test: async function () {
await waitToSession(context, paraApi, 4);

// The node detects assignment when the block is finalized, but "waitSessions" ignores finality.
// So wait a few blocks more hoping that the current block will be finalized by then.
await context.waitBlock(3, "Tanssi");
const futureAssignment = await paraApi.query.collatorAssignment.pendingCollatorContainerChain();
// The assignment is random, so there is a small chance that it will be the same,
// and in that case this test shouldn't fail
if (futureAssignment.isNone) {
assignment5 = assignment3;
assignment4 = assignment3;
} else {
assignment5 = futureAssignment.toJSON();
assignment4 = futureAssignment.toJSON();
}
console.log("assignment session 5:");
logAssignment(collatorName, assignment5);
console.log("assignment session 4:");
logAssignment(collatorName, assignment4);

// First, check that nodes are still running in their previously assigned chain
const oldC2000 = collatorName[assignment3.containerChains[2000][0]];
Expand All @@ -298,8 +296,8 @@ describeSuite({
expect(await directoryExists(oldContainer2001DbPath)).to.be.true;

// Check that new assigned collators have started syncing
const c2000 = collatorName[assignment5.containerChains[2000][0]];
const c2001 = collatorName[assignment5.containerChains[2001][0]];
const c2000 = collatorName[assignment4.containerChains[2000][0]];
const c2001 = collatorName[assignment4.containerChains[2001][0]];
let unassignedCollators = getUnassignedCollators(allCollators, [c2000, c2001]);
// Remove old collators because they will still have some chains running
unassignedCollators = unassignedCollators.filter((x) => x !== oldC2000);
Expand All @@ -321,12 +319,22 @@ describeSuite({
});
it({
id: "T14",
title: "On session 5 collators stop the previously assigned chains",
title: "On session 4 collators stop the previously assigned chains",
timeout: 90000,
test: async function () {
await waitToSession(context, paraApi, 5);
await waitToSession(context, paraApi, 4);
const assignment = await paraApi.query.collatorAssignment.collatorContainerChain();
expect(assignment.toJSON()).to.deep.equal(assignment5);
expect(assignment.toJSON()).to.deep.equal(assignment4);
const futureAssignment = await paraApi.query.collatorAssignment.pendingCollatorContainerChain();
// The assignment is random, so there is a small chance that it will be the same,
// and in that case this test shouldn't fail
if (futureAssignment.isNone) {
assignment5 = assignment4;
} else {
assignment5 = futureAssignment.toJSON();
}
console.log("assignment session 5:");
logAssignment(collatorName, assignment5);

// The node detects assignment when the block is finalized, but "waitSessions" ignores finality.
// So wait a few blocks more hoping that the current block will be finalized by then.
Expand All @@ -336,24 +344,26 @@ describeSuite({
// First, check that nodes have stopped in their previously assigned chain
const oldC2000 = collatorName[assignment3.containerChains[2000][0]];
const oldC2001 = collatorName[assignment3.containerChains[2001][0]];
const c2000 = collatorName[assignment5.containerChains[2000][0]];
const c2001 = collatorName[assignment5.containerChains[2001][0]];
const c2000 = collatorName[assignment4.containerChains[2000][0]];
const c2001 = collatorName[assignment4.containerChains[2001][0]];
const futc2000 = collatorName[assignment5.containerChains[2000][0]];
const futc2001 = collatorName[assignment5.containerChains[2001][0]];
const oldContainer2000DbPath =
getTmpZombiePath() +
`/${oldC2000}/data/containers/chains/simple_container_2000/db/full-container-2000`;
const oldContainer2001DbPath =
getTmpZombiePath() +
`/${oldC2001}/data/containers/chains/frontier_container_2001/db/full-container-2001`;
// Edge case: collators may be assigned to the same chain, in that case the directory will still exist
if (oldC2000 != c2000) {
if (oldC2000 != c2000 && oldC2000 != futc2000) {
expect(await directoryExists(oldContainer2000DbPath)).to.be.false;
}
if (oldC2001 != c2001) {
if (oldC2001 != c2001 && oldC2001 != futc2001) {
expect(await directoryExists(oldContainer2001DbPath)).to.be.false;
}

// Check that new assigned collators are running
const unassignedCollators = getUnassignedCollators(allCollators, [c2000, c2001]);
const unassignedCollators = getUnassignedCollators(allCollators, [c2000, c2001, futc2000, futc2001]);

// Verify that collators have container chain running by looking at db path,
// and unassignedCollators should not have any db path
Expand Down

0 comments on commit a3b77c9

Please sign in to comment.