Skip to content

Commit 2992bc9

Browse files
added ensureNodeHasChunksThisEpoch helper , resolved inconsistency
1 parent 86a4d03 commit 2992bc9

1 file changed

Lines changed: 53 additions & 25 deletions

File tree

test/integration/Staking.test.ts

Lines changed: 53 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,44 @@ async function advanceToNextProofingPeriod(
283283
await contracts.randomSamplingStorage.updateAndGetActiveProofPeriodStartBlock();
284284
}
285285

286+
/**
287+
* Ensures a node has at least one knowledge chunk in the current epoch.
288+
* If not, it creates a small knowledge collection to facilitate proof submission.
289+
*/
290+
async function ensureNodeHasChunksThisEpoch(
291+
nodeId: bigint,
292+
node: { operational: SignerWithAddress; admin: SignerWithAddress },
293+
contracts: TestContracts,
294+
accounts: TestAccounts,
295+
receivingNodes: {
296+
operational: SignerWithAddress;
297+
admin: SignerWithAddress;
298+
}[],
299+
receivingNodesIdentityIds: number[],
300+
) {
301+
const produced =
302+
await contracts.epochStorage.getNodeCurrentEpochProducedKnowledgeValue(
303+
nodeId,
304+
);
305+
306+
if (produced === 0n) {
307+
await createKnowledgeCollection(
308+
accounts.kcCreator,
309+
node, // <- node that will prove
310+
Number(nodeId),
311+
receivingNodes,
312+
receivingNodesIdentityIds,
313+
{ KnowledgeCollection: contracts.kc, Token: contracts.token },
314+
merkleRoot,
315+
`ensure-chunks-${Date.now()}`, // unique op-id
316+
1,
317+
4,
318+
1,
319+
toTRAC(1), // 1-chunk, 1 TRAC KC
320+
);
321+
}
322+
}
323+
286324
/**
287325
* Setup initial test environment with accounts and contracts
288326
*/
@@ -2237,26 +2275,20 @@ describe(`Full complex scenario`, function () {
22372275
/* ------------------------------------------------------------------
22382276
* 3. NODE 1 SUBMITS PROOF
22392277
* ------------------------------------------------------------------ */
2240-
/* console.log('\n🔬 STEP A.3: Node1 submitting proof for current epoch...');
2278+
console.log('\n🔬 STEP A.3: Node1 submitting proof for current epoch...');
22412279
const curEpoch = await contracts.chronos.getCurrentEpoch(); // Should be epoch 5
22422280
expect(curEpoch).to.equal(5n);
22432281

2244-
// Create KC for Node1 in the current epoch so it can submit a proof
2245-
await createKnowledgeCollection(
2246-
accounts.kcCreator,
2282+
await advanceToNextProofingPeriod(contracts);
2283+
2284+
await ensureNodeHasChunksThisEpoch(
2285+
node1Id,
22472286
accounts.node1,
2248-
Number(node1Id),
2287+
contracts,
2288+
accounts,
22492289
receivingNodes,
22502290
receivingNodesIdentityIds,
2251-
{ KnowledgeCollection: contracts.kc, Token: contracts.token },
2252-
merkleRoot,
2253-
'test-op-id-node1-epoch5',
2254-
10,
2255-
1000,
2256-
10,
2257-
toTRAC(1000),
22582291
);
2259-
await advanceToNextProofingPeriod(contracts);
22602292

22612293
const n1StakeNow = await contracts.stakingStorage.getNodeStake(node1Id);
22622294
await submitProofAndVerifyScore(
@@ -2267,7 +2299,7 @@ describe(`Full complex scenario`, function () {
22672299
n1StakeNow,
22682300
);
22692301
console.log(' ✅ Node1 proof submitted.');
2270-
*/
2302+
22712303
console.log(
22722304
` [DEBUG2] D1 on N1: isDelegator=${d1StillOnN1}, lastStakeHeldEpoch=${lastStakeHeldEpochN1}`,
22732305
);
@@ -2339,22 +2371,18 @@ describe(`Full complex scenario`, function () {
23392371

23402372
/* ──────────────── 2. NODE-2 SUBMITS PROOF ───────── */
23412373
console.log(`🔬 [B.2] Node2 submitting proof...`);
2342-
await createKnowledgeCollection(
2343-
accounts.kcCreator,
2374+
2375+
await advanceToNextProofingPeriod(contracts);
2376+
2377+
await ensureNodeHasChunksThisEpoch(
2378+
nodeIds.node2Id,
23442379
accounts.node2,
2345-
Number(nodeIds.node2Id),
2380+
contracts,
2381+
accounts,
23462382
receivingNodes,
23472383
receivingNodesIdentityIds,
2348-
{ KnowledgeCollection: contracts.kc, Token: contracts.token },
2349-
merkleRoot,
2350-
'test-op-id-node2-epoch6',
2351-
10,
2352-
1000,
2353-
10,
2354-
toTRAC(1000),
23552384
);
23562385

2357-
await advanceToNextProofingPeriod(contracts);
23582386
const n2Stake_beforeProof = await contracts.stakingStorage.getNodeStake(
23592387
nodeIds.node2Id,
23602388
);

0 commit comments

Comments
 (0)