Skip to content

test(node): add unit tests and extract testable seams in NewBee#5471

Draft
martinconic wants to merge 1 commit into
masterfrom
chore/pkg-node-coverage
Draft

test(node): add unit tests and extract testable seams in NewBee#5471
martinconic wants to merge 1 commit into
masterfrom
chore/pkg-node-coverage

Conversation

@martinconic
Copy link
Copy Markdown
Contributor

Checklist

  • I have read the coding guide.
  • My change requires a documentation update, and I have done it.
  • I have added tests to cover my changes.
  • I have filled out the description and linked the related issues.

Description

pkg/node/node.go (the NewBee bootstrap) had almost no test coverage, so
changes to it carried a high risk of silently breaking node startup. This PR
adds unit tests around the parts of pkg/node that can be tested in isolation,
and extracts three orchestration blocks from NewBee behind small
dependency-injection seams so their gating logic and error paths can be tested
without standing up a real chain backend, libp2p, or disk.

Validators / helpers

  • validateOptions extended to cover PaymentThreshold (parse + min/max
    range), PaymentTolerance, PaymentEarly, and TargetNeighborhood.
  • New validateChainContractOptions(o, chainID) covering postage / staking /
    redistribution contract-address validation, the missing postage start-block
    case, and the unknown-chain case.
  • New parsePaymentThreshold shared between validation and NewBee.
  • New tests for InitStateStore, InitStamperStore, overlayNonceExists,
    setOverlay, checkOverlay, InitChain (chain-disabled path), and the
    full Shutdown lifecycle.

Orchestration seams

  • setupSwap, setupPostageContract, setupSwapService extracted from
    NewBee. Each takes a deps struct wired to the real constructors in
    production (defaultXxxDeps) and to fakes in tests, enabling table-driven
    coverage of every config combination and error path.

Behavior changes

  • Config-shape and contract-address errors are now reported earlier in
    NewBee (at entry / right after InitChain) rather than mid-startup. The
    error strings themselves are unchanged.
  • A malformed RedistributionContractAddress with EnableStorageIncentives
    disabled is still silently accepted — preserved deliberately to avoid a
    behavior change.

Open API Spec Version Changes (if applicable)

Motivation and Context (Optional)

Related Issue (Optional)

Screenshots (if appropriate):

AI Disclosure

  • This PR contains code that has been generated by an LLM.
  • I have reviewed the AI generated code thoroughly.
  • I possess the technical expertise to responsibly review the code generated in this PR.

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