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

[Investigation]: expect_call-like Assertion(s) #36

Open
1 task done
0xNeshi opened this issue Feb 6, 2025 · 4 comments
Open
1 task done

[Investigation]: expect_call-like Assertion(s) #36

0xNeshi opened this issue Feb 6, 2025 · 4 comments
Labels
enhancement New feature or request uphill Some research/design is needed before this can be implemented.

Comments

@0xNeshi
Copy link
Collaborator

0xNeshi commented Feb 6, 2025

What is the feature you would like to see?

Something similar to Foundry's expectCall.

Contribution Guidelines

  • I agree to follow this project's Contribution Guidelines
@0xNeshi 0xNeshi added enhancement New feature or request uphill Some research/design is needed before this can be implemented. labels Feb 6, 2025
@qalisander
Copy link
Member

qalisander commented Feb 24, 2025

Why we cannot test it with current setup? Check that transaction failed and assert that balance hasn't changed more than expected?

@0xNeshi
Copy link
Collaborator Author

0xNeshi commented Feb 25, 2025

This was an idea I had at the time that I wanted to document. I don't see it as a "must have" in motsu, but a "nice to have", a utility to be used by devs who wanted to ensure certain function calls are called or that they cannot be called some number of times.

Anyway, maybe instead of testing for reentrancy directly, motsu could provide an assertion that a specific contract function call has occurred? This would be a general assert method and reentrant calls would be covered by it, so that we wouldn't need reentrant-specific assertions 🤔

Solidity Foundry has expectCall that does this.

I think even this more general expect_call (or whatever) method could be replaced by some combination of state-change assertions (which is what you pointed out), but it could be a utility assertion in case some devs need it.

Though because implementing this would require yet a new refactor of motsu (*sarcasticly* yippee), we could leave the issue in the backlog and on low priority until:

  • motsu users show interest in this feature
  • we see a need for this and have bandwidth to implement it

@qalisander
Copy link
Member

I think even this more general expect_call (or whatever) method could be replaced by some combination of state-change

Yeah. If I understand correctly we're checking, that re-entrant call would fail. In case of e2e tests we would implement it with deployed mock attacker contract. That is not an actual attacker, but it contains assertion (will change state) in case it can successfully perform reentrant call and drain funds. We can do same in motsu.

Also I see the whole "practical" problem with reentrancy is cause vulnerable contract can lose funds. So asserting that no fund loss happened after reentrant call seems reasonable to me.

@0xNeshi 0xNeshi changed the title [Investigation]: Reentrant Pattern Assertions [Investigation]: expect_call-like Pattern Assertions Feb 27, 2025
@0xNeshi 0xNeshi changed the title [Investigation]: expect_call-like Pattern Assertions [Investigation]: expect_call-like Assertion(s) Feb 27, 2025
@0xNeshi
Copy link
Collaborator Author

0xNeshi commented Feb 27, 2025

Considering the low priority of this feature, I'd say we should leave it in the backlog just for tracking, but focus on it if there's actual interest from motsu users

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request uphill Some research/design is needed before this can be implemented.
Projects
None yet
Development

No branches or pull requests

2 participants