Skip to content

Commit 67f6d67

Browse files
authored
Merge pull request #470 from OriginTrail/feature/conviction-lazy-settlement
feat(conviction): lazy-settle PCAs — active + passive sinks, escrow at create
2 parents c412b6e + 5f78c20 commit 67f6d67

32 files changed

Lines changed: 3413 additions & 469 deletions

devnet/agent-provenance/automated.test.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,8 @@ async function detectDevnet(): Promise<DevnetState | null> {
426426
'function createAccount(uint96) external returns (uint256)',
427427
'function registerAgent(uint256, address) external',
428428
'function agentToAccountId(address) view returns (uint256)',
429-
'function epochSpent(uint256, uint40) view returns (uint96)',
429+
'function windowSpent(uint256, uint40) view returns (uint96)',
430+
'function getCurrentBillingWindow(uint256) view returns (uint40)',
430431
],
431432
provider,
432433
);
@@ -521,20 +522,26 @@ describe('Agent provenance — automated 5-node devnet validation', () => {
521522
// 4. Assert:
522523
// - publish status == confirmed
523524
// - kcs.getLatestMerkleRootAuthor(kcId) == node5.submitter.address
524-
// - nft.epochSpent(accountId, currentEpoch) increased
525+
// - nft.windowSpent(accountId, currentBillingWindow) increased
525526
// - eps.getNodeEpochProducedKnowledgeValue(core1.id, epoch) increased
526527
// =========================================================================
527-
it('mode (a) — edge op-wallet on core1 PCA, attribution to core1, NFT epochSpent grows', async () => {
528+
it('mode (a) — edge op-wallet on core1 PCA, attribution to core1, NFT windowSpent grows', async () => {
528529
const s = state.v!;
529530
const core1 = s.nodes[1]!;
530531
const edge = s.nodes[5]!;
531532
if (core1.identityId === 0n) throw new Error('core1 has no identity');
532533

533534
const accountId = await ensurePcaAccountForOpWallets(s, edge);
534535

535-
// 3. Snapshot pre-publish state.
536+
// 3. Snapshot pre-publish state. Lazy-settlement keys spend by the
537+
// billing-window index (0-based, relative to the account's
538+
// createdAtTimestamp), NOT by chain epoch. Sum the current window plus
539+
// the next one so a tx that straddles a window boundary still counts.
536540
const epoch: bigint = await s.chronos.getCurrentEpoch();
537-
const beforeSpent: bigint = await s.nft.epochSpent(accountId, epoch);
541+
const beforeWindow: bigint = BigInt(await s.nft.getCurrentBillingWindow(accountId));
542+
const beforeSpent: bigint =
543+
(await s.nft.windowSpent(accountId, beforeWindow)) +
544+
(await s.nft.windowSpent(accountId, beforeWindow + 1n));
538545
const beforeEps: bigint = await s.eps.getNodeEpochProducedKnowledgeValue(core1.identityId, epoch);
539546
const beforeBalance = await sumOpBalances(s.token, edge);
540547

@@ -554,7 +561,13 @@ describe('Agent provenance — automated 5-node devnet validation', () => {
554561
);
555562
expect(matchesAnyOpWallet).toBe(true);
556563

557-
const afterSpent: bigint = await s.nft.epochSpent(accountId, epoch);
564+
const afterWindow: bigint = BigInt(await s.nft.getCurrentBillingWindow(accountId));
565+
const afterSpent: bigint =
566+
(await s.nft.windowSpent(accountId, beforeWindow)) +
567+
(await s.nft.windowSpent(accountId, beforeWindow + 1n)) +
568+
(afterWindow > beforeWindow + 1n
569+
? await s.nft.windowSpent(accountId, afterWindow)
570+
: 0n);
558571
expect(afterSpent - beforeSpent).toBeGreaterThan(0n);
559572

560573
const afterEps: bigint = await s.eps.getNodeEpochProducedKnowledgeValue(core1.identityId, epoch);

0 commit comments

Comments
 (0)