Motsu (持つ) - Unit Testing for Stylus
This crate enables unit-testing for Stylus contracts. It abstracts away the
machinery necessary for writing tests behind a #[motsu::test] procedural
macro.
motsu means "to hold" in
Japanese -- we hold a stylus in our hand.
Usage
This crate enables unit-testing for Stylus contracts. It abstracts away the
machinery necessary for writing tests behind a #[motsu::test] procedural macro.
Annotate tests with #[motsu::test] instead of #[test]
to get access to VM affordances:
Function Contract::sender() is necessary to trigger call
to a contract, and should accept an Account or Address as an argument.
Alternatively Contract::sender_and_value() can be used to
pass additional value to the contract.
To make a payable call work, user should be funded with
Account::fund method (there is no funding by default),
like in example below:
use *;
Multiple external calls are supported in Motsu.
Assuming Proxy is a contract that exposes (#[public]) function call_proxy,
where it adds one to the passed argument and calls next Proxy contract
at the address provided during initialization.
The following test case can emulate a call chain of three Proxy contracts:
use *;
Annotating a test function that accepts no parameters will make
#[motsu::test] behave the same as #[test].
Important: To use a contract in tests, you must ensure it implements the
unsafe trait stylus_sdk::prelude::TopLevelStorage.
While this trait is automatically derived for contracts marked with#[entrypoint],
you'll need to implement it manually for any contract without this attribute:
use ;
// Entry point is not implemented, so we should implement `TopLevelStorage` ourselves.
// #[entrypoint]
unsafe
Important: For motsu to work correctly, stylus-sdk should not have
a default hostio-caching feature enabled.
Notice
We maintain this crate on a best-effort basis. We use it extensively on our own tests, so we will add here any features and utilities we need for testing our library.
That being said, please do open an issue to start a discussion, keeping in mind our code of conduct and contribution guidelines.
Security
Refer to our Security Policy for more details.