Skip to content

test: Move relevant tests to stacks-codec and add some new ones#7219

Open
jbencin-stacks wants to merge 12 commits into
stacks-network:developfrom
jbencin-stacks:test/stacks-codec
Open

test: Move relevant tests to stacks-codec and add some new ones#7219
jbencin-stacks wants to merge 12 commits into
stacks-network:developfrom
jbencin-stacks:test/stacks-codec

Conversation

@jbencin-stacks
Copy link
Copy Markdown
Contributor

Description

Following up on the refactoring work in #7200, this PR lowers the associated tests from stackslib down into stacks-codec, and also adds some new tests to address missing coverage

Note

This PR may be easier to review by commit

  • In the first commit, we are only moving code
  • In the second commit, we add new tests

Applicable issues

Checklist

  • Test coverage for new or modified code paths
  • Changelog fragment(s) or "no changelog" label added (see changelog.d/README.md)

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 20, 2026

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ jbencin-stacks
❌ claude
You have signed the CLA already but the status is still pending? Let us recheck it.

Addresses the PR stacks-network#7200 reviewer comment about missing tests in
stacks-codec by relocating tests whose dependencies are already
satisfied by stacks-codec + stacks-common + clarity-types.

Moves from stackslib/src/chainstate/stacks/transaction.rs:
- test_transaction_payload_token_transfer (rstest)
- clarity_version_codec_is_consistent (replaces the cross-crate
  test_clarity_versions rstest template with an inline #[case]
  enumeration so stacks-codec does not pick up a clarity dev-dep)
- test_transaction_contract_call_codec
- test_transaction_smart_contract_codec
- test_transaction_payload_versioned_contracts_codec (rstest)
- tx_stacks_transaction_payload_coinbase
- tx_stacks_transaction_payload_nakamoto_coinbase
- tx_stacks_transaction_payload_nakamoto_coinbase_alt_recipient
- tx_stacks_transaction_payload_microblock_poison
- tx_stacks_transaction_payload_invalid (and contract/function name
  variants)
- tx_stacks_asset
- tx_stacks_postcondition (and nft_maybe_sent variant)
- tx_stacks_transaction_codec_originator_mode_and_nft_maybe_sent
- tx_stacks_postcondition_invalid

Moves from stackslib/src/util_lib/strings.rs:
- tx_stacks_strings_codec (renamed stacks_strings_codec)
- tx_stacks_string_invalid (renamed stacks_string_rejects_non_printable)

Supporting changes:
- Add a local copy of check_codec_and_corruption to stacks-codec so
  tests don't reach into stackslib's net codec helpers.
- Add rstest plus testing-feature stacks-common/clarity-types as
  dev-dependencies on stacks-codec.
- Prune now-unused imports in stackslib's test modules.

stackslib retains StacksTransactionSigner, all sign/verify integration
tests, and tx_stacks_transaction_codec (which depends on
codec_all_transactions). 28 tests pass in stacks-codec; the remaining
transaction tests still pass in stackslib.
Adds tests in stacks-codec that target boundaries the relocated
stackslib tests did not cover.

stacks-codec/src/transaction.rs additions:
- Byte-value pins for the wire-format-critical enum discriminants
  (TransactionPayloadID, TransactionAnchorMode,
  TransactionPostConditionMode, TransactionVersion,
  TransactionAuthFlags, AssetInfoID, PostConditionPrincipalID) so any
  silent reordering trips a test instead of breaking consensus.
- Exhaustive TenureChangeCause codec across all 7 variants plus
  rejection of unknown bytes (previously only BlockFound/Extended were
  covered indirectly via codec_all_transactions).
- Roundtrip for TenureChangePayload (compares field-by-field since
  TenureChangeCause intentionally does not implement PartialEq).
- Standalone StacksMicroblockHeader codec roundtrip (previously only
  exercised via PoisonMicroblock).
- Fixed-size assertions for TokenTransferMemo and CoinbasePayload.
- stacks_transaction_empty_post_conditions_codec roundtrip.
- stacks_transaction_header_layout pins the version-then-chain_id
  ordering at the start of the serialized transaction.
- Exhaustive FungibleConditionCode and NonfungibleConditionCode
  from_u8 roundtrips.

stacks-codec/src/strings.rs additions:
- Tab/newline acceptance.
- 0x20/0x7e printable boundary, 0x1f/0x7f rejection.
- Deserialize rejection of valid UTF-8 but non-printable bytes.
- is_clarity_variable detection.
- From<ClarityName> conversion.
- Refactor `tx_stacks_transaction_payload_microblock_poison` to use a
  local `header_bytes` closure with a documented byte-layout comment,
  removing the rustfmt-orphaned `// header_2` placement and making each
  variant (matching, equal, bad-parent) read as a header constructor
  call rather than three near-identical blocks of `extend_from_slice`.
- Clarify the `stacks_string_deserialize_rejects_non_printable_bytes`
  body comment and tighten the assertion to `matches!` the error
  variant before checking the message substring.
- Rename `fungible_/nonfungible_condition_code_roundtrip` to
  `..._from_u8_roundtrip` to reflect what they actually test (these
  codes are serialized inline, not via their own codec impl).
- Add a `clarity_version_cases_are_exhaustive` test that pattern-matches
  on `ClarityVersion::latest()` to recover the compile-time
  exhaustiveness guarantee that the original cross-crate
  `test_clarity_versions` rstest template used to provide.
- Extract the duplicated `check_codec_and_corruption` helper into a new
  `stacks_common::codec::testing` module gated on the `testing`
  feature. `stackslib::net::codec::test::check_codec_and_corruption`
  becomes a re-export; `stacks-codec` imports the canonical version
  directly, removing the local copies in `transaction.rs` and
  `strings.rs`.
@jbencin-stacks jbencin-stacks marked this pull request as ready for review May 22, 2026 17:59
@federico-stacks federico-stacks self-requested a review May 25, 2026 08:12
@coveralls
Copy link
Copy Markdown

coveralls commented May 25, 2026

Coverage Report for CI Build 26529130192

Warning

Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes.
Quick fix: rebase this PR. Learn more →

Coverage decreased (-0.1%) to 85.602%

Details

  • Coverage decreased (-0.1%) from the base build.
  • Patch coverage: 8 uncovered changes across 2 files (783 of 791 lines covered, 98.99%).
  • 6592 coverage regressions across 115 files.

Uncovered Changes

File Changed Covered %
stacks-common/src/codec/mod.rs 24 17 70.83%
stacks-codec/src/transaction.rs 696 695 99.86%
Total (3 files) 791 783 98.99%

Coverage Regressions

6592 previously-covered lines in 115 files lost coverage.

Top 10 Files by Coverage Loss Lines Losing Coverage Coverage
stackslib/src/config/mod.rs 376 68.96%
stackslib/src/net/mod.rs 311 77.84%
stackslib/src/chainstate/stacks/index/storage.rs 260 80.65%
stackslib/src/chainstate/stacks/miner.rs 251 83.56%
stackslib/src/net/inv/epoch2x.rs 241 78.23%
clarity/src/vm/database/clarity_db.rs 239 82.49%
stackslib/src/chainstate/stacks/db/transactions.rs 222 97.16%
stackslib/src/net/chat.rs 202 92.95%
stackslib/src/chainstate/stacks/db/mod.rs 196 86.23%
stackslib/src/core/mempool.rs 193 86.44%

Coverage Stats

Coverage Status
Relevant Lines: 220730
Covered Lines: 188950
Line Coverage: 85.6%
Coverage Strength: 18995333.68 hits per line

💛 - Coveralls

Comment thread Cargo.lock Outdated
Comment thread stacks-codec/src/strings.rs
Comment thread stacks-codec/src/transaction.rs
Comment thread stacks-codec/src/transaction.rs Outdated
Comment thread stacks-codec/Cargo.toml Outdated
Copy link
Copy Markdown
Contributor

@federico-stacks federico-stacks left a comment

Choose a reason for hiding this comment

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

LGTM!

You'll just need to fix https://github.com/stacks-network/stacks-core/actions/runs/26468364840/job/78037311978?pr=7219.

It is about updating this cargo lock files due to the new added dependency:

  • clarity/fuzz/Cargo.lock
  • stackslib/fuzz/Cargo.lock

Copy link
Copy Markdown
Contributor

@federico-stacks federico-stacks left a comment

Choose a reason for hiding this comment

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

heads-up: @jbencin-stacks CI was updated and you need to merge the develop branch otherwise the jobs will show as stuck.

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.

4 participants