Skip to content

Refactor library architecture#19

Merged
Hrom131 merged 5 commits into
devfrom
feat/optimize-boilerplate
Jul 1, 2026
Merged

Refactor library architecture#19
Hrom131 merged 5 commits into
devfrom
feat/optimize-boilerplate

Conversation

@LesterEvSe

@LesterEvSe LesterEvSe commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

Refactor the standard library and test suite

Resolves #18 for current state.

Reorganises the standard library into three conceptual parts and rewrites the
Rust test suite to eliminate duplicated boilerplate.

1. simf/lib/ — the library itself

The standard-library functions. Unchanged in this PR; only the surrounding
scaffolding (parts 2 and 3) is touched.

2. simf/main-function contracts

The test entry-point contracts, one main per area. Cleaned up with a clearer
structure and a shared helper.

  • Renamed *_mock.simf*_test.simf: these are test entry points, not mocks.
  • Removed the IF_TEST_OVERFLOW witness flag. The overflow vs. fitting case
    is now encoded in the data: a checked_* result is compared against an
    expected: Option<T> witness, where None means overflow and Some(x) the
    fitting result. This drops one match level and one witness field from every
    contract.

3. tests/ — the Rust test suite

Rewritten. Previously, fund_script / spend_script and the spend-and-assert
logic were duplicated in every file, and u8_test.rs through u64_test.rs were
near-identical, differing only by type.

Shared spend plumbing — tests/common/mod.rs

Used by every test:

  • fund — send sats to a program's script so it has a UTXO to spend.
  • spend — build the transaction with a witness and broadcast it.
  • run — fund + spend + assert in one call.
  • Expect — the expected outcome of a spend.

uint test framework — tests/common/uint.rs

Covers operations uniform across every unsigned width (safe_add_N,
checked_mul_N, etc.). Built on a TestUint trait: each operation's logic is
written once as a generic function and instantiated per width. The only
per-width code is a short impl TestUint block.

Type-specific operations

Operations that exist for only one width are not forced into the common
interface. Dispatch indices leave room for them:

  • 0..=191 — reserved for common operations.
  • CUSTOM_BASE = 192 — start of type-specific operations.

A future u64_widen(...) -> u256, for example, adds a match arm at
fn_idx == 192 in u64_test.rs without touching the shared interface.

CUSTOM_BASE can be raised or lowered if 192 slots turn out to be the wrong
number.

@LesterEvSe LesterEvSe requested a review from Hrom131 June 29, 2026 15:52
@LesterEvSe LesterEvSe self-assigned this Jun 29, 2026
@LesterEvSe LesterEvSe added the enhancement New feature or request label Jun 29, 2026
@LesterEvSe LesterEvSe marked this pull request as draft June 29, 2026 15:52
@LesterEvSe LesterEvSe marked this pull request as ready for review June 30, 2026 11:36
Comment thread simf/u16_test.simf Outdated
Comment thread simf/u8_test.simf Outdated
Comment thread tests/common/mod.rs
@LesterEvSe LesterEvSe requested a review from Hrom131 July 1, 2026 13:02

@Hrom131 Hrom131 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM!

@Hrom131 Hrom131 merged commit 7d30e26 into dev Jul 1, 2026
1 check passed
@Hrom131 Hrom131 deleted the feat/optimize-boilerplate branch July 1, 2026 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants