Skip to content

How to test internals of a contract other than writing explicit end-to-end full transactions #129

Open

Description

@schoen

Describe the feature

Right now when we have a contract with various internal functions, Simplex tests basically synthesize calls to those specific functions by selecting them through the witness, the main mechanism being if_test_this_function(). I think this is a little cumbersome and hard to read, and I just had an AI complain about "how do I test my individual contract functions individually, as opposed to indirectly via transactions that happen to use them?" and my answer was basically "you can make a witness parameter and then use if_test_this_function(). Neither the AI nor I found this very aesthetically satisfying.

Is there a possibility of standardizing this more so that one would need less boilerplate in order to cause calls to individual contract functions as part of tests? I understand that it's tricky to literally call into the middle of the program because every real on-chain transaction only ever enters via main() with some witness, but maybe Simplex could help synthesize some of the boilerplate so that there could be some form of test that at least looks and feels more like calling individual SimplicityHL functions?

I'm sure this will look a little nicer when we have an if statement, but I do wonder if Simplex could literally write some form of the test/foo_test.simf functions for us, in a way that would make it appear that we could directly test inputs and output behaviors of functions other than main().

Activity

  1. schoen commented on Aug 21, 2026

    @schoen
    ContributorAuthor

    Perhaps I should rephrase this using the unit test versus integration test distinction: although many tests that have been built using Simplex look like unit tests (they are meant to test individual functions), the method of writing and running Simplex tests feels more like integration tests (let's literally run the whole tx on a real elementsd for maximum realism). This can be awkward if a user wanted to perform tests on parts of a contract that feel more like unit tests: the official way to do this seems to be "make or invoke a harness that builds a complete transaction around a call to that function" (with mechanisms like if_test_this_function()). I don't think Simplex will get away from the underlying mechanism of testing via a real regtest environment, as doing a literal minimalist unit test would require having a whole Simplicity interpreter inside of Simplex, but I suppose I wonder whether there could eventually be a more official way to write unit tests in a way that look and feel like unit tests. "I want to call this one SimplicityHL function and I expect it to return 7" or something, without writing the boilerplate like

    fn main() { match if_test_this_function(12, fn_idx) { true => { assert!(jet::eq_32(my_function(), 7)); }, false => (), }; }
    

    That probably gets at more of what I meant in the feature request above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions