Skip to content

fix(contracts,chain): V10 dual-emit + ABI regen + hardhat test rewrites (1/4)#331

Open
Bojan131 wants to merge 1 commit intomainfrom
fix-contracts-v10-dual-emit
Open

fix(contracts,chain): V10 dual-emit + ABI regen + hardhat test rewrites (1/4)#331
Bojan131 wants to merge 1 commit intomainfrom
fix-contracts-v10-dual-emit

Conversation

@Bojan131
Copy link
Copy Markdown
Contributor

Summary

PR 1 of 4 in the split of #327. Each slice is a single architectural layer to keep reviews tractable.

This PR carries the on-chain layer: Solidity bug fixes, ABI regeneration, and Hardhat test rewrites.

Changes by category

Smart-contract bug fixes

  • E-2 / E-14 / E-16 — Hub access-control hardening on owner-only paths.
  • E-6DKGPublishingConvictionNFT now reverts on `AccountExpired` before any state mutation.
  • CH-5 — `KnowledgeAssetsV10` / `KnowledgeAssetsStorage` dual-emit `V10KnowledgeBatchEmitted` so off-chain consumers can filter on a single ABI'd event.
  • MigratorV10Staking — backfill helper for V10 staking aggregates (`totalStakeV10`, `getNodeStakeV10`).

ABI regeneration

  • `packages/chain/abi/{KnowledgeAssetsStorage,KnowledgeAssetsV10,DKGStakingConvictionNFT}.json` — synced so `ethers.js` Contract.filters exposes `V10KnowledgeBatchEmitted` (was missing, causing `evm-e2e.test.ts` TypeError on `main`).
  • `packages/evm-module/abi/{KnowledgeAssetsStorage,KnowledgeAssetsV10,MigratorV10Staking}.json` — same regen against canonical source.

Hardhat test rewrites (against actual V10 API)

The three files below were authored against a pre-Phase-5 NFT API that never shipped (`NFT.stake` / partial-withdraw / `stakingStorageAddress`). Rewritten to use `createConviction` / `withdraw` (full-only) / `stakingStorage` public state var, with assertions reading `Position` records directly from `ConvictionStakingStorage`:

  • `DKGStakingConvictionNFT-extra.test.ts` — full V10 NFT lifecycle.
  • `v10-conviction-extra.test.ts` — lock-tier multiplier ladder. `lock=1` expectation corrected from 1.0x → 1.5x to match `ConvictionStakingStorage._seedBaselineTiers`.
  • `v10-conviction-nft-audit.test.ts` — refocused on E-6 `AccountExpired` guard. Duplicated E-2/E-14/E-16 cases removed (covered in `v10-hub-audit` / `v10-kav10-audit`).

EVM-side tests

  • `evm-e2e.test.ts` — now compiles after ABI regen exposes the V10 filter.
  • `mock-adapter-behavioral.test.ts` — new coverage for the off-chain mock used in agent/publisher tests.

CI / infra (drive-by, on this layer's review surface)

  • `codex-review.yml`: timeout-minutes 15 → 30 (bot was hitting the cap on large PRs).
  • `release.yml` + `npm-continuous-publish.yml`: comment-only formatting.

Coverage ratchet

  • `tornadoChainCoverage` 24/28/14/23 → 73/80/58/72 (reflects new mock-adapter-behavioral coverage).

Sequencing context

This is slice 1 of 4 from the #327 split (by architectural layer):

  1. This PR — contracts + chain (~4.7k lines)
  2. storage + query (~7k lines) — landing next
  3. operator: cli + mcp-server + adapter-openclaw + core + epcis (~6.9k lines)
  4. pipeline: publisher + agent + network-sim (~10.2k lines)

`adapter-elizaos` overhaul (~8.5k) and `node-ui` chat-memory overhaul (~2.2k) parked on `fix_tests-overflow` for separate review — neither was failing on `main`'s CI.

Original umbrella branch backed up at `refs/backup/fix_tests-pre-split-1777483348`.

Test plan

  • CI green on this branch
  • `pnpm --filter @origintrail-official/dkg-chain test` locally
  • `pnpm --filter @origintrail-official/dkg-evm-module test` (Hardhat) locally
  • Verify ABI files match contract sources (`pnpm hardhat compile` regenerates identical bytes)

Made with Cursor

Fixes the on-chain layer of the bug-fix backlog from PR #327. This is
slice 1 of 4 (split by architectural layer for reviewability).

Bug fixes
- E-2/E-14/E-16: Hub access-control hardening on owner-only paths.
- E-6: DKGPublishingConvictionNFT now reverts AccountExpired guard before
  any state mutation (defence-in-depth around the lock-tier ladder).
- CH-5: KnowledgeAssetsV10 / KnowledgeAssetsStorage now dual-emit
  V10KnowledgeBatchEmitted so off-chain consumers can filter on a single
  ABI'd event regardless of which contract minted the batch.
- MigratorV10Staking: backfill helper for the V10 staking aggregates
  (totalStakeV10, getNodeStakeV10) used by the migrator path.

ABI regen
- packages/chain/abi/{KnowledgeAssetsStorage,KnowledgeAssetsV10,
  DKGStakingConvictionNFT}.json — synced so ethers.js Contract.filters
  exposes V10KnowledgeBatchEmitted (was missing → evm-e2e.test.ts
  TypeError on main).
- packages/evm-module/abi/{KnowledgeAssetsStorage,KnowledgeAssetsV10,
  MigratorV10Staking}.json — same regen against the canonical source.

Hardhat tests rewritten against actual V10 API
The three files below were authored against a pre-Phase-5 NFT API that
never shipped (NFT.stake / partial-withdraw / stakingStorageAddress).
Each was rewritten to use createConviction / withdraw (full-only) /
stakingStorage public state var, with assertions reading Position
records directly from ConvictionStakingStorage:

- DKGStakingConvictionNFT-extra.test.ts — full V10 NFT lifecycle.
- v10-conviction-extra.test.ts — lock-tier multiplier ladder. The
  lock=1 expectation was corrected from 1.0x → 1.5x to match the
  baseline tier table seeded by ConvictionStakingStorage._seedBaselineTiers.
- v10-conviction-nft-audit.test.ts — refocused on the E-6
  AccountExpired guard. Duplicated E-2/E-14/E-16 cases were removed
  (covered in v10-hub-audit / v10-kav10-audit).

EVM-side tests
- packages/chain/test/evm-e2e.test.ts: now compiles after the ABI
  regen exposes the V10KnowledgeBatchEmitted filter.
- mock-adapter-behavioral.test.ts: new behavioural coverage for the
  off-chain mock used in agent/publisher tests.

CI / infra (drive-by, all on this layer's review surface)
- codex-review.yml: timeout-minutes 15 → 30 (the bot was hitting the
  cap on >30k-line PRs; concurrency-cancel still kicks in on new pushes).
- release.yml + npm-continuous-publish.yml: comment-only formatting.

Coverage ratchet
- tornadoChainCoverage thresholds bumped to reflect the new
  mock-adapter-behavioral coverage (24/28/14/23 → 73/80/58/72).

Sequencing: this is PR 1 of 4. Independent off main; PRs 2-4 carry
the storage+query, operator (cli+mcp+openclaw), and pipeline
(publisher+agent+network-sim) layers respectively. Original umbrella
branch parked at refs/backup/fix_tests-pre-split-* and on
fix_tests-overflow (adapter-elizaos + node-ui drive-bys).

Made-with: Cursor
}

const tx = await nft.stake(identityId, amount, lockEpochs);
const tx = await nft.createConviction(identityId, amount, lockEpochs);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Bug: stakeWithLock still exposes the third argument as lockEpochs, but createConviction now interprets that value as a discrete lockTier (0/1/3/6/12). Callers that previously passed epoch counts like 2 will now revert with InvalidLockTier, while the mock adapter still treats 2 as valid and returns a 1.5x multiplier. Either translate epoch counts to tiers here, or rename/update the chain-adapter API and mock implementation so both adapters agree on the new contract semantics.

// so we cannot reconstruct the on-chain values without a wall
// clock — emit schema-compatible zeros and leave epoch-window
// assertions to the EVM e2e suite.
this.pushEvent('V10KnowledgeBatchEmitted', {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Bug: This is the legacy publishKnowledgeAssets path, but it now emits V10KnowledgeBatchEmitted, which the real EVM adapter only exposes for V10/KAV10 publishes. That gives mock-backed tests false positives for V10 listeners, and the actual mock V10 path (createKnowledgeAssetsV10) still does not emit this event at all. Keep legacy publishes on KnowledgeBatchCreated/KCCreated, and move the V10 audit event emission to the real V10 publish method.

).to.equal(true);
});

it('SPEC-GAP: MigratorV10Staking compiled artifact must resolve', () => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Bug: The new migrator writes to DelegatorsInfo, per-node stake, and global totalStake, but this suite only checks file/artifact/ABI presence. That means regressions in migrateDelegator/markNodeMigrated can still ship undetected. Please add a fixture-based test that deploys the contract, registers it in Hub, and verifies happy-path state changes plus the duplicate/unknown-id/finalize guards against real storage state.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant