Skip to content

Commit

Permalink
more tests, some renames
Browse files Browse the repository at this point in the history
  • Loading branch information
toninorair committed Jul 3, 2024
1 parent b39b8c2 commit e9cbaf4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/WrappedMToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ contract WrappedMToken is IWrappedMToken, Migratable, ERC20Extended {
}

function startEarningM() external {
if (mIndexWhenEarningStopped != 0) revert OnlyEarningOnce();
if (mIndexWhenEarningStopped != 0) revert AllowedToEarnOnlyOnce();

IMTokenLike(mToken).startEarning();
}
Expand Down
6 changes: 3 additions & 3 deletions src/interfaces/IWrappedMToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ interface IWrappedMToken is IMigratable, IERC20Extended {
/// @notice Emitted when calling `startEarning` for an account not approved as earner by TTG.
error NotApprovedEarner();

/// @notice Emitted when calling `startEarningM` after wrapper was already in earning state once.
error OnlyEarningOnce();
/// @notice Emitted when calling `startEarningM` after Wrapped M was already earning M yield once.
error AllowedToEarnOnlyOnce();

/// @notice Emitted when method is called when Wrapped M is not in earning state.
/// @notice Emitted when calling `startEarningFor` if Wrapped M is not in earning state.
error NotInEarningState();

/// @notice Emitted in constructor if M Token is 0x0.
Expand Down
13 changes: 11 additions & 2 deletions test/WrappedMToken.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,15 @@ contract WrappedMTokenTests is Test {
_wrappedMToken.startEarningFor(_alice);
}

function test_startEarningFor_notInEarningState() external {
_mToken.stopEarning(address(_wrappedMToken));

_registrar.setListContains(_EARNERS_LIST, _alice, true);

vm.expectRevert(IWrappedMToken.NotInEarningState.selector);
_wrappedMToken.startEarningFor(_alice);
}

function test_startEarningFor() external {
_wrappedMToken.setTotalNonEarningSupply(1_000);

Expand Down Expand Up @@ -433,12 +442,12 @@ contract WrappedMTokenTests is Test {
}

/* ============ startEarningM ============ */
function test_startEarningM_onlyEarningOnce() external {
function test_startEarningM_allowedToEarnOnlyOnce() external {
assertEq(_mToken.isEarning(address(_wrappedMToken)), true);

_wrappedMToken.stopEarningM();

vm.expectRevert(IWrappedMToken.OnlyEarningOnce.selector);
vm.expectRevert(IWrappedMToken.AllowedToEarnOnlyOnce.selector);
_wrappedMToken.startEarningM();
}

Expand Down
4 changes: 4 additions & 0 deletions test/utils/Mocks.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ contract MockM {
function stopEarning() external {
isEarning[msg.sender] = false;
}

function stopEarning(address earner) external {
isEarning[earner] = false;
}
}

contract MockRegistrar {
Expand Down

0 comments on commit e9cbaf4

Please sign in to comment.