Skip to content

Commit

Permalink
Mock the reward functionality of the native-manager
Browse files Browse the repository at this point in the history
  • Loading branch information
richardpringle committed Nov 15, 2024
1 parent 877bb36 commit d2aa93d
Showing 1 changed file with 16 additions and 15 deletions.
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: ""
});
// 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);
}
}

0 comments on commit d2aa93d

Please sign in to comment.