Refactor library architecture#19
Open
LesterEvSe wants to merge 3 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 itselfThe standard-library functions. Unchanged in this PR; only the surrounding
scaffolding (parts 2 and 3) is touched.
2.
simf/—main-function contractsThe test entry-point contracts, one
mainper area. Cleaned up with a clearerstructure and a shared helper.
*_mock.simf→*_test.simf: these are test entry points, not mocks.IF_TEST_OVERFLOWwitness flag. The overflow vs. fitting caseis now encoded in the data: a
checked_*result is compared against anexpected: Option<T>witness, whereNonemeans overflow andSome(x)thefitting result. This drops one
matchlevel and one witness field from everycontract.
3.
tests/— the Rust test suiteRewritten. Previously,
fund_script/spend_scriptand the spend-and-assertlogic were duplicated in every file, and
u8_test.rsthroughu64_test.rswerenear-identical, differing only by type.
Shared spend plumbing —
tests/common/mod.rsUsed 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.rsCovers operations uniform across every unsigned width (
safe_add_N,checked_mul_N, etc.). Built on aTestUinttrait: each operation's logic iswritten once as a generic function and instantiated per width. The only
per-width code is a short
impl TestUintblock.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 amatcharm atfn_idx == 192inu64_test.rswithout touching the shared interface.