-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Unit Tests for Staker-Calculator Interactions
This commit introduces a mock calculator with adjustable earning power to expand test coverage, validating staker responses to varied earning scenarios such as scaled and boosted staking amounts.
- Loading branch information
Showing
2 changed files
with
176 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
pragma solidity ^0.8.23; | ||
|
||
import {IEarningPowerCalculator} from "src/GovernanceStaker.sol"; | ||
|
||
contract MockConfigurableEarningPowerCalculator is IEarningPowerCalculator { | ||
// multiplier applied to all earning power calculations (in basis points) | ||
// 10000 = 100% (no change), 5000 = 50%, 20000 = 200% etc | ||
uint256 public multiplierBips = 10_000; | ||
|
||
// Optional fixed return value that overrides multiplier if set | ||
uint256 public fixedReturnValue; | ||
bool public useFixedReturn; | ||
|
||
function __setMultiplierBips(uint256 _multiplierBips) external { | ||
multiplierBips = _multiplierBips; | ||
useFixedReturn = false; | ||
} | ||
|
||
function __setFixedReturn(uint256 _value) external { | ||
fixedReturnValue = _value; | ||
useFixedReturn = true; | ||
} | ||
|
||
function getEarningPower( | ||
uint256 _amountStaked, | ||
address, // _staker, | ||
address // _delegatee | ||
) external view returns (uint256) { | ||
if (useFixedReturn) return fixedReturnValue; | ||
return (_amountStaked * multiplierBips) / 10_000; | ||
} | ||
|
||
function getNewEarningPower( | ||
uint256 _amountStaked, | ||
address, // _staker, | ||
address, // _delegatee, | ||
uint256 // _oldEarningPower | ||
) external view returns (uint256, bool) { | ||
if (useFixedReturn) return (fixedReturnValue, true); | ||
return ((_amountStaked * multiplierBips) / 10_000, true); | ||
} | ||
} |