Skip to content

chore: return the crate's semver from version() in all three contracts - #67

Merged
codemagician1949 merged 1 commit into
IntensifierLab:mainfrom
Alheriii:chore/version-string-1
Aug 25, 2026
Merged

codemagician1949 merged 1 commit into
IntensifierLab:mainfrom
Alheriii:chore/version-string-1

Conversation

@Alheriii

Copy link
Copy Markdown

Closes #1

Summary

All three contracts already exposed version(), but as a hand-maintained u32 ABI marker — invoice-registry returned 2, pool-manager 1, repayment-waterfall 2.

Those numbers were not tied to anything. Nothing stopped a release from bumping Cargo.toml while the on-chain value stayed put, and an integrator reading version() off a deployed contract could not map the answer back to a published crate. That is the gap the issue is closing.

version() now returns the crate's semver as a soroban_sdk::String, read from CARGO_PKG_VERSION at compile time — so the manifest and the on-chain value cannot drift by construction, rather than by discipline.

pub fn version(env: Env) -> soroban_sdk::String {
    soroban_sdk::String::from_str(&env, env!("CARGO_PKG_VERSION"))
}

soroban_sdk::String is written fully qualified rather than imported. Each of the three crates would otherwise need String added to its use soroban_sdk::{...} block, and the codebase already uses the qualified form elsewhere (invoice_transfer_history returns soroban_sdk::Vec<TransferRecord>) — so this follows existing practice rather than introducing a style.

Tests

One per crate, asserting against CARGO_PKG_VERSION rather than a literal, so a future version bump cannot leave a stale assertion passing:

  • invoice-registry — replaces test_version_returns_two, whose name and assertion both had to change anyway
  • pool-manager, repayment-waterfall — new tests alongside the existing suites

tests/integration.rs asserted the three old integers and now asserts "0.1.0" as a literal. Deliberately not written against that test crate's own CARGO_PKG_VERSION: the root crate happens to share the version today, so doing so would look like a coupling that does not exist. Binding each contract to its own manifest is what the per-crate unit tests do.

Acceptance criteria

  • version() in invoice-registry, pool-manager, repayment-waterfall
  • Unit test per crate
  • Matches Cargo.toml version — via CARGO_PKG_VERSION, so it cannot stop matching

Migration note

Interface change for integrators: version() returns String, not u32. Any caller comparing against 1 or 2 needs updating. governance is left alone — it is outside this issue's scope and still returns u32, so it is worth a follow-up if the intent is workspace-wide consistency.

Wasm size — worth a look before merging

pool_manager.wasm is the constraint here, and it was already tight:

bytes headroom vs 65,536
main 64,262 1,274
this PR 64,939 597

The String return costs 677 bytes in that crate. It still passes the 64KB job, but pool-manager is now at 99.1% of the limit, and the next addition to it is likely to break the build. Flagging rather than burying it — #66 recovers 22 of those bytes via a Clippy fix, and if more headroom is wanted, splitting pool-manager is the real answer.

Verification

cargo test --workspace passing (141 tests), cargo check --workspace clean, release Wasm build within the size limit.

Conflicts

This and #66 both touch pool-manager/src/lib.rs, repayment-waterfall/src/lib.rs and invoice-registry/src/lib.rs — unavoidable, since #66 reformats the same files this one edits.

They were written to not collide: the version() bodies and the new tests were deliberately placed in the gaps between #66's reformatting hunks, not at the ends of the files where the nearest hunk would have been ~5 lines away. Every hunk here is at least 22 lines from every hunk there.

Both merge orders were tested locally against main. Clean either way, and on the combined result the fmt and clippy gates #66 introduces pass against this PR's code: fmt clean, clippy clean under -D warnings, 141 tests passing, Wasm within limits.

All three contracts already exposed version(), but as a hand-maintained u32
ABI marker — invoice-registry returned 2, pool-manager 1, repayment-waterfall
2. Those numbers were not tied to anything: nothing stopped a release from
bumping Cargo.toml while the on-chain value stayed where it was, and an
integrator reading version() off a deployed contract could not map the answer
back to a published crate.

version() now returns the crate's semver as a soroban_sdk::String, read from
CARGO_PKG_VERSION at compile time so the manifest and the on-chain value
cannot drift by construction.

soroban_sdk::String is written fully qualified rather than imported. Each of
the three crates would otherwise need String added to its `use
soroban_sdk::{...}` block, and the codebase already uses the qualified form
elsewhere (invoice_transfer_history returns soroban_sdk::Vec<TransferRecord>),
so this follows existing practice rather than introducing a style.

Tests, one per crate, assert version() equals CARGO_PKG_VERSION rather than a
literal, so a version bump cannot leave a stale assertion passing:

- invoice-registry: replaces test_version_returns_two, whose name and its
  assertion both had to change anyway
- pool-manager and repayment-waterfall: new tests alongside the existing suites

tests/integration.rs asserted the three old integers and now asserts "0.1.0"
as a literal. Deliberately not written against that test crate's own
CARGO_PKG_VERSION — the root crate happens to share the version today, so
doing so would look like a coupling that does not exist. Binding each contract
to its own manifest is what the per-crate unit tests do.

Interface change for integrators: version() returns String, not u32.

cargo test --workspace passes (141 tests), cargo check --workspace is clean,
and the release wasm build stays inside the 64KB per-contract CI limit.
@codemagician1949

Copy link
Copy Markdown
Contributor

Nice job @Alheriii

@codemagician1949
codemagician1949 merged commit f88bca4 into IntensifierLab:main Aug 25, 2026
3 checks passed
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.

chore: add version() to all three crates

2 participants