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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

pragma solidity 0.8.25;

import {Test} from "@forge-std/Test.sol";
import {PoSValidatorManagerTest} from "./PoSValidatorManagerTests.t.sol";
import {NativeTokenStakingManager} from "../NativeTokenStakingManager.sol";
import {PoSValidatorManager} from "../PoSValidatorManager.sol";
Expand Down Expand Up @@ -249,25 +250,15 @@ contract NativeTokenStakingManagerTest is PoSValidatorManagerTest {
}

function _expectRewardIssuance(address account, uint256 amount) internal override {
vm.mockCall(
address(app.NATIVE_MINTER()),
abi.encodeCall(INativeMinter.mintNativeCoin, (account, amount)),
""
);
// empty calldata implies the receive function will be called:
vm.mockCall({
callee: account,
msgValue: amount,
data: "", // implies receive()
returnData: ""
});
Comment on lines -258 to -263
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

// Units tests don't have access to the native minter precompile, so use vm.deal instead.
vm.deal(account, account.balance + amount);
address nativeMinter = address(app.NATIVE_MINTER());
bytes memory callData = abi.encodeCall(INativeMinter.mintNativeCoin, (account, amount));
vm.mockCall(nativeMinter, callData, "");
vm.expectCall(nativeMinter, callData);
}

function _setUp() internal override returns (IValidatorManager) {
// Construct the object under test
app = new NativeTokenStakingManager(ICMInitializable.Allowed);
app = new TestableNativeTokenStakingManager(ICMInitializable.Allowed);
rewardCalculator = new ExampleRewardCalculator(DEFAULT_REWARD_RATE);
app.initialize(
PoSValidatorManagerSettings({
Expand All @@ -294,3 +285,13 @@ contract NativeTokenStakingManagerTest is PoSValidatorManagerTest {
return account.balance;
}
}

contract TestableNativeTokenStakingManager is NativeTokenStakingManager, Test {
constructor(ICMInitializable init) NativeTokenStakingManager(init) {}

function _reward(address account, uint256 amount) internal virtual override {
super._reward(account, amount);
// Units tests don't have access to the native minter precompile, so use vm.deal instead.
vm.deal(account, account.balance + amount);
}
}