5 unstable releases

new 0.2.1 Dec 17, 2024
0.2.0 Nov 7, 2024
0.1.0 Oct 17, 2024
0.1.0-rc Sep 13, 2024
0.0.1 Jun 3, 2024

#8 in #arbitrum

Download history 79/week @ 2024-09-09 40/week @ 2024-09-16 21/week @ 2024-09-23 8/week @ 2024-09-30 3/week @ 2024-10-07 144/week @ 2024-10-14 10/week @ 2024-10-21 129/week @ 2024-11-04 25/week @ 2024-11-11 10/week @ 2024-11-18 13/week @ 2024-11-25 2/week @ 2024-12-02 61/week @ 2024-12-09

88 downloads per month

MIT license

20KB
185 lines

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.

The name motsu is an analogy to the place where you put your fingers to hold a stylus pen.

Usage

Annotate tests with #[motsu::test] instead of #[test] to get access to VM affordances.

Note that we require contracts to implement stylus_sdk::prelude::StorageType. This trait is typically implemented by default with stylus_proc::sol_storage or stylus_proc::storage macros.

#[cfg(test)]
mod tests {
    use contracts::token::erc20::Erc20;

    #[motsu::test]
    fn reads_balance(contract: Erc20) {
        let balance = contract.balance_of(Address::ZERO); // Access storage.
        assert_eq!(balance, U256::ZERO);
    }
}

Annotating a test function that accepts no parameters will make #[motsu::test] behave the same as #[test].

#[cfg(test)]
mod tests {
    #[motsu::test] // Equivalent to #[test]
    fn test_fn() {
        ...
    }
}

Dependencies

~11–18MB
~238K SLoC