-
Notifications
You must be signed in to change notification settings - Fork 3
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
feat: unit test external call + msg::sender mocks #14
Conversation
3838020
to
feb635a
Compare
85ce803
to
1ffba32
Compare
…ontract-deployment # Conflicts: # Cargo.lock # Cargo.toml # crates/motsu/README.md
Update documentation for the new test case structure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the design, left some minor comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm loving this refactor, it really seems to set us up for easier improvements later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't wait to have it published on crates.io 🚀
Great job @qalisander!
.ping(pong.address(), value) | ||
.expect("should ping successfully"); | ||
|
||
assert_eq!(ponged_value, value + uint!(1_U256)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about having:
let one = uint!(1_U256);
You have many repetitions.
//! fn reads_balance( | ||
//! contract: Contract<Erc20>, | ||
//! alice: Account, | ||
//! ) { | ||
//! let balance = contract.sender(alice).balance_of(Address::ZERO); // Access storage. | ||
//! assert_eq!(balance, U256::ZERO); | ||
//! } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
//! fn reads_balance( | |
//! contract: Contract<Erc20>, | |
//! alice: Account, | |
//! ) { | |
//! let balance = contract.sender(alice).balance_of(Address::ZERO); // Access storage. | |
//! assert_eq!(balance, U256::ZERO); | |
//! } | |
//! fn reads_balance( | |
//! contract: Contract<Erc20>, | |
//! alice: Account, | |
//! ) { | |
//! let balance = contract.sender(alice).balance_of(Address::ZERO); // Access storage. | |
//! assert_eq!(balance, U256::ZERO); | |
//! } | |
//! | |
//! #[motsu::test] | |
//! fn approve() { | |
//! let contract = Contract::<Erc20>::new(); | |
//! let alice = Account::random(); | |
//! let bob = Account::random(); | |
//! let result = contract.sender(alice).approve(bob, U256::from(1)); // Change state. | |
//! assert!(result.is_ok()); | |
//! } |
We should add another example documenting a test case that instantiates a contract manually within the test itself, while also showing that they can change state within a test.
This new example works with regular #[test]
, but we can leave #[motsu::test]
if you think it's better.
Based on this pr (OpenZeppelin/rust-contracts-stylus#423)
Resolves #8 , Resolves #12, Resolves #5
PR Checklist