6 releases (3 breaking)

new 0.3.0 Jan 7, 2025
0.2.1 Dec 17, 2024
0.2.0 Nov 7, 2024
0.1.0 Oct 17, 2024
0.0.1 Jun 3, 2024

#384 in Magic Beans

Download history 22/week @ 2024-09-22 9/week @ 2024-09-29 3/week @ 2024-10-06 136/week @ 2024-10-13 17/week @ 2024-10-20 1/week @ 2024-10-27 120/week @ 2024-11-03 32/week @ 2024-11-10 11/week @ 2024-11-17 11/week @ 2024-11-24 5/week @ 2024-12-01 24/week @ 2024-12-08 184/week @ 2024-12-15 22/week @ 2024-12-22 80/week @ 2024-12-29 291/week @ 2025-01-05

579 downloads per month

MIT license

22KB
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.

motsu means "to hold" in Japanese -- we hold a stylus in our hand.

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]
     fn t() { // If no params, it expands to a `#[test]`.
        // ...
    }
}

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.

Dependencies

~11–20MB
~273K SLoC