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

Mock the reward functionality of the native-manager #646

Merged
merged 2 commits into from
Nov 18, 2024

Conversation

richardpringle
Copy link
Contributor

Why this should be merged

We were actually triggering logic in a function named _expect*. It was super misleading and really hard to track down why that was happening. Instead, I've properly mocked the functionality, triggering the vm.deal logic when the _reward function is called instead of afterwards.

How this works

I've effectively monkey-patched the _rewardFunction.

How this was tested

It is a test 😉

How is this docuomented

There's a code comment that was already there that I moved.

Comment on lines -258 to -263
vm.mockCall({
callee: account,
msgValue: amount,
data: "", // implies receive()
returnData: ""
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This wasn't doing anything

Copy link
Contributor

@iansuvak iansuvak left a comment

Choose a reason for hiding this comment

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

I'm not hard opposed to this and agree with your assessment that the current implementation has problems, but not sure that I love divergence (albeit tiny) from the actual contract we want to test and the contract we are actually testing. _reward is simple enough though that this is probably fine here.

}

function _setUp() internal override returns (IValidatorManager) {
// Construct the object under test
app = new NativeTokenStakingManager(ICMInitializable.Allowed);
app = new MockNativeTokenStakingManager(ICMInitializable.Allowed);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure that MockNativeTokenStakingManager is the best name here since you aren't really mocking here but monkeypatching instead. How about TestableNativeTokenStakingManager

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor

@iansuvak iansuvak left a comment

Choose a reason for hiding this comment

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

LGTM -- if others think that we don't want this divergence we could theoretically abstract it away behind an interface but I think this is fine for now and improvement over status quo.

Copy link
Contributor

@geoff-vball geoff-vball left a comment

Choose a reason for hiding this comment

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

I like this solution. Thanks @richardpringle :)

@richardpringle richardpringle merged commit d29f788 into main Nov 18, 2024
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants