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

feat: option to set msg::value in unit tests and track balances #31

Open
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

qalisander
Copy link
Member

Resolves #26

PR Checklist

  • Tests
  • Documentation
  • Changelog

proxy3.fund(TEN);

// Call the first proxy.
proxy1.sender_and_value(alice, ONE).pay_proxy();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the "lazy" builder pattern should be optimal in our use case, since we are not expecting many arguments to trigger a call

assert_eq!(result, TEN + ONE + ONE + ONE);
}

#[motsu_proc::test]
Copy link
Member Author

@qalisander qalisander Feb 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can add test cases with #[should_panic = "account ... has not enough balance"] assertion once our addresses will be deterministic

});

// Fund accounts.
alice.fund(TEN);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the new api to fund an account.
But we can actually add a default balance @0xNeshi wdt?

@@ -302,8 +490,16 @@ impl<ST: StorageType> ContractCall<'_, ST> {
self.contract_ref.address
}

/// Apply previously not reverted transactions.
fn apply_not_reverted_transactions() {
Copy link
Member Author

@qalisander qalisander Feb 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Soon within this function we can can apply state from the previous transaction, if it wasn't reverted due to error (#32)

@qalisander qalisander marked this pull request as ready for review February 4, 2025 14:42
@qalisander
Copy link
Member Author

@0xNeshi, @bidzyyys may be actually rename MockStorage to smth else? like ContextStorage
And how do you think to rename STORAGE to MOTSU_VM?

Copy link
Collaborator

@bidzyyys bidzyyys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good in general, left few comments.

crates/motsu/src/context.rs Outdated Show resolved Hide resolved
crates/motsu/src/context.rs Outdated Show resolved Hide resolved
crates/motsu/src/context.rs Outdated Show resolved Hide resolved
crates/motsu/src/context.rs Outdated Show resolved Hide resolved
crates/motsu/src/context.rs Show resolved Hide resolved
@qalisander qalisander requested a review from bidzyyys February 4, 2025 15:07
Copy link
Collaborator

@bidzyyys bidzyyys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me but let's wait also for @0xNeshi review.

@@ -93,6 +90,22 @@ impl Context {
self.storage().contract_address.replace(address)
}

/// Set message value to `value` and return the previous value if any.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Set message value to `value` and return the previous value if any.
/// Set the message value to `value` and return the previous value if any.


match self.call_contract(address, selector, &input[4..]) {
/// Based on `result`, set the return data.
/// Return 0 if `result` is `Ok`, otherwise return 1.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Return 0 if `result` is `Ok`, otherwise return 1.
/// Return 0 if `result` is `Ok`, otherwise 1.

@@ -242,6 +300,91 @@ impl Context {
self.router(address).exists()
}

/// Check if `address` has enough funds to transfer `value`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Check if `address` has enough funds to transfer `value`
/// Check if `address` has enough funds to transfer `value`.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: Allow setting msg::value in unit tests
2 participants