Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MASM test runner #1308

Open
hackaugusto opened this issue Apr 5, 2024 · 1 comment
Open

MASM test runner #1308

hackaugusto opened this issue Apr 5, 2024 · 1 comment
Labels
assembly Related to Miden assembly enhancement New feature or request tests Related to tests tools Tools for interacting with Miden VM

Comments

@hackaugusto
Copy link
Contributor

hackaugusto commented Apr 5, 2024

Idea

Add support to doctest for MASM code

Rationale

Increase test coverage, by making stupidly easy to write unit tests

Proposal

I would imitate the doctests from languages like rust/python, something like:

#! Validates that a non fungible asset is well formed. Panics if the asset is not well formed.
#!
#! ```test
#! push.0.0.0.0 exec.validate_non_fungible_asset
#! > FailedAssertion { err_code: 131128 }
#! ```
#!
#! Stack: [ASSET]
#! Outputs: [ASSET]
#!
#! ASSET is the asset to validate.
export.validate_non_fungible_asset
    # assert that ASSET[1] is a valid account id
    dup.2 exec.account::validate_id
    # => [ASSET]

    # assert that ASSET[1] is a fungible faucet
    dup.2 exec.account::is_non_fungible_faucet assert.err=ERR_NON_FUNGIBLE_ASSET_FORMAT_POSITION_ONE_MUST_FUNGIBLE
    # => [ASSET]

    # assert the fungible bit is set to 0
    dup u32split swap drop
    push.FUNGIBLE_BITMASK_U32 u32and assertz.err=ERR_NON_FUNGIBLE_ASSET_HIGH_BIT_SET
    # => [ASSET]
end

Another approach is to add test.<name> ... end.

Test execution would be as simple as parsing the code and calling a method in the module to collect/run the tests.

@hackaugusto hackaugusto added enhancement New feature or request assembly Related to Miden assembly tests Related to tests tools Tools for interacting with Miden VM labels Apr 5, 2024
@hackaugusto
Copy link
Contributor Author

hackaugusto commented Apr 5, 2024

The approach above is intentionally simple. There tons of things that could be done around testing. And IMO anything fancier should be discussed as another issue. Here I'm trying to propose the minimum that would quickly improve productivity when testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
assembly Related to Miden assembly enhancement New feature or request tests Related to tests tools Tools for interacting with Miden VM
Projects
None yet
Development

No branches or pull requests

1 participant