From 16277ebef2fa99afc714fc4c6b3c55b22cfc8650 Mon Sep 17 00:00:00 2001 From: oXtxNt9U <120286271+oXtxNt9U@users.noreply.github.com> Date: Tue, 1 Sep 2026 15:55:30 +0900 Subject: [PATCH 1/3] fix more flaky tests --- .../consensus/source/double-sign.test.ts | 6 ++-- .../consensus/source/prevote.test.ts | 15 ++++----- .../consensus/source/propose.test.ts | 32 ++++++++++++++++--- 3 files changed, 39 insertions(+), 14 deletions(-) diff --git a/tests/functional/consensus/source/double-sign.test.ts b/tests/functional/consensus/source/double-sign.test.ts index da844d114..0292ba119 100644 --- a/tests/functional/consensus/source/double-sign.test.ts +++ b/tests/functional/consensus/source/double-sign.test.ts @@ -9,13 +9,13 @@ import { assertBlockHash, assertBlockNumber, assertBlockRound } from "./asserts. import { Validator } from "./contracts.js"; import { P2PRegistry } from "./p2p.js"; import { bootMany, bootstrapMany, runMany, setup, stopMany } from "./setup.js"; -import { getValidators, prepareNodeValidators, snoozeForBlock } from "./utilities.js"; +import { getValidators, prepareNodeValidators, snoozeForBlock, snoozeUntil } from "./utilities.js"; import type { Contracts } from "@mainsail/contracts"; const { Propose, Prevote } = Enums.Consensus.Step; describe<{ - nodes: Contracts.Kernel.Application[], + nodes: Contracts.Kernel.Application[]; validators: Validator[]; p2p: P2PRegistry; }>("DoubleSign", ({ beforeEach, afterEach, it, assert }) => { @@ -110,6 +110,8 @@ describe<{ // No proposal went out at round 0; every validator (the proposer included) prevoted nil // after the propose timeout, which is a later step and past the watermark. + await snoozeUntil(() => p2p.prevotes.getMessages(1, 0).length === totalNodes); + assert.equal(p2p.proposals.getMessages(1, 0).length, 0); assert.equal(p2p.prevotes.getMessages(1, 0).length, totalNodes); diff --git a/tests/functional/consensus/source/prevote.test.ts b/tests/functional/consensus/source/prevote.test.ts index 6fd40c055..d0fcdc28d 100644 --- a/tests/functional/consensus/source/prevote.test.ts +++ b/tests/functional/consensus/source/prevote.test.ts @@ -16,11 +16,12 @@ import { makeProposal, prepareNodeValidators, snoozeForBlock, + snoozeUntil, } from "./utilities.js"; import type { Contracts } from "@mainsail/contracts"; describe<{ - nodes: Contracts.Kernel.Application[], + nodes: Contracts.Kernel.Application[]; validators: Validator[]; p2p: P2PRegistry; }>("Propose", ({ beforeEach, afterEach, it, assert, stub }) => { @@ -121,13 +122,7 @@ describe<{ .getMessages(1, 0) .map((prevote) => prevote.blockHash) .sort(), - [ - undefined, - commit.block.hash, - commit.block.hash, - commit.block.hash, - commit.block.hash, - ].sort(), + [undefined, commit.block.hash, commit.block.hash, commit.block.hash, commit.block.hash].sort(), ); // Next block @@ -164,6 +159,8 @@ describe<{ await assertBlockRound(nodes, 1); await assertBlockHash(nodes); + await snoozeUntil(() => p2p.precommits.getMessages(1, 0).length === totalNodes); + assert.equal(p2p.proposals.getMessages(1, 0).length, 1); // Assert number of proposals assert.equal(p2p.prevotes.getMessages(1, 0).length, totalNodes); // Assert number of prevotes assert.equal(p2p.precommits.getMessages(1, 0).length, totalNodes); // Assert number of precommits @@ -260,6 +257,8 @@ describe<{ await assertBlockRound(nodes, 1); await assertBlockHash(nodes); + await snoozeUntil(() => p2p.precommits.getMessages(1, 0).length === totalNodes); + assert.equal(p2p.proposals.getMessages(1, 0).length, 1); // Assert number of proposals assert.equal(p2p.prevotes.getMessages(1, 0).length, totalNodes); // Assert number of prevotes assert.equal(p2p.precommits.getMessages(1, 0).length, totalNodes); // Assert number of precommits diff --git a/tests/functional/consensus/source/propose.test.ts b/tests/functional/consensus/source/propose.test.ts index 1affebf37..36b3b16bd 100644 --- a/tests/functional/consensus/source/propose.test.ts +++ b/tests/functional/consensus/source/propose.test.ts @@ -16,6 +16,7 @@ import { prepareNodeValidators, snoozeForBlock, snoozeForRound, + snoozeUntil, } from "./utilities.js"; import { makeCustomProposal, makeTransactionBuilderContext } from "./custom-proposal.js"; import { EvmCalls } from "@mainsail/test-transaction-builders"; @@ -137,6 +138,12 @@ describe<{ await assertBlockRound(nodes, 1); await assertBlockHash(nodes); + await snoozeUntil( + () => + p2p.prevotes.getMessages(1, 0).length === totalNodes && + p2p.precommits.getMessages(1, 0).length === totalNodes, + ); + assert.equal(p2p.proposals.getMessages(1, 0).length, 1); // Assert number of proposals assert.equal(p2p.prevotes.getMessages(1, 0).length, totalNodes); // Assert number of prevotes assert.equal(p2p.precommits.getMessages(1, 0).length, totalNodes); // Assert number of precommits @@ -232,6 +239,8 @@ describe<{ await assertBlockRound(nodes, 1); await assertBlockHash(nodes); + await snoozeUntil(() => p2p.precommits.getMessages(1, 0).length === totalNodes); + assert.equal(p2p.proposals.getMessages(1, 0).length, 2); // Assert number of proposals assert.equal(p2p.prevotes.getMessages(1, 0).length, totalNodes); // Assert number of prevotes assert.equal(p2p.precommits.getMessages(1, 0).length, totalNodes); // Assert number of precommits @@ -281,6 +290,8 @@ describe<{ await snoozeForRound(nodes, round); + await snoozeUntil(() => p2p.precommits.getMessages(1, round).length === totalNodes); + assert.equal(p2p.proposals.getMessages(1, round).length, 2); // Assert number of proposals assert.equal(p2p.prevotes.getMessages(1, round).length, totalNodes); // Assert number of prevotes assert.equal(p2p.precommits.getMessages(1, round).length, totalNodes); // Assert number of precommits @@ -346,9 +357,11 @@ describe<{ await assertBlockRound(nodesSubset, 0); await assertBlockHash(nodesSubset); + await snoozeUntil(() => p2p.precommits.getMessages(1, 0).length === totalNodes); + assert.equal(p2p.proposals.getMessages(1, 0).length, 2); // Assert number of proposals assert.equal(p2p.prevotes.getMessages(1, 0).length, totalNodes); // Assert number of prevotes - assert.equal(p2p.precommits.getMessages(1, 0).length, totalNodes - 1); // Assert number of precommits + assert.equal(p2p.precommits.getMessages(1, 0).length, totalNodes); // Assert number of precommits // Assert all nodes prevote assert.equal( @@ -365,10 +378,19 @@ describe<{ ].sort(), ); - // // Assert all nodes precommit (null) + // The majority precommits the block; the partitioned node precommits nil. assert.equal( - p2p.precommits.getMessages(1, 0).map((precommit) => precommit.blockHash), - Array.from({ length: totalNodes - 1 }).fill(proposal0.getPayload().block.hash), + p2p.precommits + .getMessages(1, 0) + .map((precommit) => precommit.blockHash) + .sort(), + [ + proposal0.getPayload().block.hash, + proposal0.getPayload().block.hash, + proposal0.getPayload().block.hash, + proposal0.getPayload().block.hash, + undefined, + ].sort(), ); // Download blocks @@ -408,6 +430,8 @@ describe<{ await assertBlockRound(nodes, 1); await assertBlockHash(nodes); + await snoozeUntil(() => p2p.precommits.getMessages(1, 0).length === totalNodes); + assert.equal(p2p.proposals.getMessages(1, 0).length, 5); // Assert number of proposals assert.equal(p2p.prevotes.getMessages(1, 0).length, totalNodes); // Assert number of prevotes assert.equal(p2p.precommits.getMessages(1, 0).length, totalNodes); // Assert number of precommits From c6b07be49c0649541cffece38e62ce44a19c04b7 Mon Sep 17 00:00:00 2001 From: oXtxNt9U <120286271+oXtxNt9U@users.noreply.github.com> Date: Tue, 1 Sep 2026 06:55:34 +0000 Subject: [PATCH 2/3] empty commit From 53366eb3a5c5d25b0beef20cff3a8f49b50b1334 Mon Sep 17 00:00:00 2001 From: oXtxNt9U <120286271+oXtxNt9U@users.noreply.github.com> Date: Wed, 2 Sep 2026 08:34:15 +0900 Subject: [PATCH 3/3] fix --- tests/functional/consensus/source/double-sign.test.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/functional/consensus/source/double-sign.test.ts b/tests/functional/consensus/source/double-sign.test.ts index 97e3aef08..e9715e679 100644 --- a/tests/functional/consensus/source/double-sign.test.ts +++ b/tests/functional/consensus/source/double-sign.test.ts @@ -9,7 +9,13 @@ import { assertBlockHash, assertBlockNumber, assertBlockRound } from "./asserts. import { Validator } from "./contracts.js"; import { P2PRegistry } from "./p2p.js"; import { boot, bootMany, bootstrap, bootstrapMany, runMany, setup, stop, stopMany } from "./setup.js"; -import { getNodeForValidator, getValidatorsInSlotOrder, prepareNodeValidators, snoozeForBlock } from "./utilities.js"; +import { + getNodeForValidator, + getValidatorsInSlotOrder, + prepareNodeValidators, + snoozeForBlock, + snoozeUntil, +} from "./utilities.js"; import type { Contracts } from "@mainsail/contracts"; const { Propose, Prevote } = Enums.Consensus.Step;