Skip to content

Commit

Permalink
test claim reward
Browse files Browse the repository at this point in the history
  • Loading branch information
thang14 committed Aug 21, 2024
1 parent 2769709 commit 97e431a
Show file tree
Hide file tree
Showing 3 changed files with 264 additions and 56 deletions.
1 change: 0 additions & 1 deletion contracts/sfc/SFCLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,6 @@ contract SFCLib is SFCBase {
_checkAllowedToWithdraw(delegator, toValidatorID),
"outstanding sU2U balance"
);
_stashRewards(delegator, toValidatorID);
_stashRewards(delegator, toValidatorID, lId);
rewards = _rewardsStash[delegator][toValidatorID];
uint256 totalReward = rewards
Expand Down
285 changes: 230 additions & 55 deletions contracts/test/UnitTestSFCV2.sol
Original file line number Diff line number Diff line change
@@ -1,24 +1,74 @@
pragma solidity ^0.5.0;

interface SFCUnitTestIV2 {

function currentSealedEpoch() external view returns (uint256);

function getEpochSnapshot(uint256) external view returns (uint256 endTime, uint256 epochFee, uint256 totalBaseRewardWeight, uint256 totalTxRewardWeight, uint256 _baseRewardPerSecond, uint256 totalStake, uint256 totalSupply);

function getLockupInfo(address, uint256) external view returns (uint256 lockedStake, uint256 fromEpoch, uint256 endTime, uint256 duration);
function getEpochSnapshot(
uint256
)
external
view
returns (
uint256 endTime,
uint256 epochFee,
uint256 totalBaseRewardWeight,
uint256 totalTxRewardWeight,
uint256 _baseRewardPerSecond,
uint256 totalStake,
uint256 totalSupply
);

function getLockupInfo(
address,
uint256
)
external
view
returns (
uint256 lockedStake,
uint256 fromEpoch,
uint256 endTime,
uint256 duration
);

function getStake(address, uint256) external view returns (uint256);

function getStashedLockupRewards(address, uint256) external view returns (uint256 lockupExtraReward, uint256 lockupBaseReward, uint256 unlockedReward);

function getValidator(uint256) external view returns (uint256 status, uint256 deactivatedTime, uint256 deactivatedEpoch, uint256 receivedStake, uint256 createdEpoch, uint256 createdTime, address auth);
function getStashedLockupRewards(
address,
uint256
)
external
view
returns (
uint256 lockupExtraReward,
uint256 lockupBaseReward,
uint256 unlockedReward
);

function getValidator(
uint256
)
external
view
returns (
uint256 status,
uint256 deactivatedTime,
uint256 deactivatedEpoch,
uint256 receivedStake,
uint256 createdEpoch,
uint256 createdTime,
address auth
);

function getValidatorID(address) external view returns (uint256);

function getValidatorPubkey(uint256) external view returns (bytes memory);

function getWithdrawalRequest(address, uint256, uint256) external view returns (uint256 epoch, uint256 time, uint256 amount);
function getWithdrawalRequest(
address,
uint256,
uint256
) external view returns (uint256 epoch, uint256 time, uint256 amount);

function isOwner() external view returns (bool);

Expand All @@ -34,7 +84,10 @@ interface SFCUnitTestIV2 {

function stakeTokenizerAddress() external view returns (address);

function stashedRewardsUntilEpoch(address, uint256) external view returns (uint256);
function stashedRewardsUntilEpoch(
address,
uint256
) external view returns (uint256);

function targetGasPowerPerSecond() external view returns (uint256);

Expand All @@ -58,79 +111,177 @@ interface SFCUnitTestIV2 {

function constsAddress() external view returns (address);

function getEpochValidatorIDs(uint256 epoch) external view returns (uint256[] memory);

function getEpochReceivedStake(uint256 epoch, uint256 validatorID) external view returns (uint256);

function getEpochAccumulatedRewardPerToken(uint256 epoch, uint256 validatorID) external view returns (uint256);

function getEpochAccumulatedUptime(uint256 epoch, uint256 validatorID) external view returns (uint256);

function getEpochAccumulatedOriginatedTxsFee(uint256 epoch, uint256 validatorID) external view returns (uint256);

function getEpochOfflineTime(uint256 epoch, uint256 validatorID) external view returns (uint256);

function getEpochOfflineBlocks(uint256 epoch, uint256 validatorID) external view returns (uint256);

function rewardsStash(address delegator, uint256 validatorID) external view returns (uint256);

function getLockedStake(address delegator, uint256 toValidatorID) external view returns (uint256);
function getEpochValidatorIDs(
uint256 epoch
) external view returns (uint256[] memory);

function getEpochReceivedStake(
uint256 epoch,
uint256 validatorID
) external view returns (uint256);

function getEpochAccumulatedRewardPerToken(
uint256 epoch,
uint256 validatorID
) external view returns (uint256);

function getEpochAccumulatedUptime(
uint256 epoch,
uint256 validatorID
) external view returns (uint256);

function getEpochAccumulatedOriginatedTxsFee(
uint256 epoch,
uint256 validatorID
) external view returns (uint256);

function getEpochOfflineTime(
uint256 epoch,
uint256 validatorID
) external view returns (uint256);

function getEpochOfflineBlocks(
uint256 epoch,
uint256 validatorID
) external view returns (uint256);

function rewardsStash(
address delegator,
uint256 validatorID
) external view returns (uint256);

function getLockedStake(
address delegator,
uint256 toValidatorID
) external view returns (uint256);

function createValidator(bytes calldata pubkey) external payable;

function getSelfStake(uint256 validatorID) external view returns (uint256);

function delegate(uint256 toValidatorID) external payable;

function undelegate(uint256 toValidatorID, uint256 wrID, uint256 amount) external;
function undelegate(
uint256 toValidatorID,
uint256 wrID,
uint256 amount
) external;

function isSlashed(uint256 validatorID) external view returns (bool);

function withdraw(uint256 toValidatorID, uint256 wrID) external;

function deactivateValidator(uint256 validatorID, uint256 status) external;

function pendingRewards(address delegator, uint256 toValidatorID,uint256 lId) external view returns (uint256);
function pendingRewards(
address delegator,
uint256 toValidatorID,
uint256 lId
) external view returns (uint256);

function stashRewards(address delegator, uint256 toValidatorID, uint256 idx) external;
function stashRewards(
address delegator,
uint256 toValidatorID,
uint256 idx
) external;

function claimRewards(uint256 toValidatorID, uint256 lId) external;

function restakeRewards(uint256 toValidatorID) external;

function offlinePenaltyThreshold() external view returns (uint256 blocksNum, uint256 time);
function offlinePenaltyThreshold()
external
view
returns (uint256 blocksNum, uint256 time);

function updateBaseRewardPerSecond(uint256 value) external;

function updateOfflinePenaltyThreshold(uint256 blocksNum, uint256 time) external;
function updateOfflinePenaltyThreshold(
uint256 blocksNum,
uint256 time
) external;

function updateSlashingRefundRatio(uint256 validatorID, uint256 refundRatio) external;
function updateSlashingRefundRatio(
uint256 validatorID,
uint256 refundRatio
) external;

function updateStakeTokenizerAddress(address addr) external;

function updateTreasuryAddress(address v) external;

function mintU2U(address receiver, uint256 amount, string calldata justification) external;
function mintU2U(
address receiver,
uint256 amount,
string calldata justification
) external;

function burnU2U(uint256 amount) external;

function sealEpoch(uint256[] calldata offlineTime, uint256[] calldata offlineBlocks, uint256[] calldata uptimes, uint256[] calldata originatedTxsFee, uint256 epochGas) external;
function sealEpoch(
uint256[] calldata offlineTime,
uint256[] calldata offlineBlocks,
uint256[] calldata uptimes,
uint256[] calldata originatedTxsFee,
uint256 epochGas
) external;

function sealEpochValidators(uint256[] calldata nextValidatorIDs) external;

function isLockedUp(address delegator, uint256 toValidatorID) external view returns (bool);

function getUnlockedStake(address delegator, uint256 toValidatorID) external view returns (uint256);

function lockStake(uint256 toValidatorID, uint256 lockupDuration, uint256 amount) external;

function relockStake(uint256 toValidatorID, uint256 lId, uint256 lockupDuration, uint256 amount) external;

function initialize(uint256 sealedEpoch, uint256 _totalSupply, address nodeDriver, address lib, address consts, address _owner) external;

function setGenesisValidator(address auth, uint256 validatorID, bytes calldata pubkey, uint256 status, uint256 createdEpoch, uint256 createdTime, uint256 deactivatedEpoch, uint256 deactivatedTime) external;

function setGenesisDelegation(address delegator, uint256 toValidatorID, uint256 stake, uint256 lockedStake, uint256 lockupFromEpoch, uint256 lockupEndTime, uint256 lockupDuration, uint256 earlyUnlockPenalty, uint256 rewards) external;
function isLockedUp(
address delegator,
uint256 toValidatorID
) external view returns (bool);

function getUnlockedStake(
address delegator,
uint256 toValidatorID
) external view returns (uint256);

function lockStake(
uint256 toValidatorID,
uint256 lockupDuration,
uint256 amount
) external;

function relockStake(
uint256 toValidatorID,
uint256 lId,
uint256 lockupDuration,
uint256 amount
) external;

function initialize(
uint256 sealedEpoch,
uint256 _totalSupply,
address nodeDriver,
address lib,
address consts,
address _owner
) external;

function setGenesisValidator(
address auth,
uint256 validatorID,
bytes calldata pubkey,
uint256 status,
uint256 createdEpoch,
uint256 createdTime,
uint256 deactivatedEpoch,
uint256 deactivatedTime
) external;

function setGenesisDelegation(
address delegator,
uint256 toValidatorID,
uint256 stake,
uint256 lockedStake,
uint256 lockupFromEpoch,
uint256 lockupEndTime,
uint256 lockupDuration,
uint256 earlyUnlockPenalty,
uint256 rewards
) external;

function _syncValidator(uint256 validatorID, bool syncPubkey) external;

Expand All @@ -142,7 +293,10 @@ interface SFCUnitTestIV2 {

function advanceTime(uint256) external;

function highestLockupEpoch(address, uint256) external view returns (uint256);
function highestLockupEpoch(
address,
uint256
) external view returns (uint256);

function enableNonNodeCalls() external;

Expand All @@ -154,13 +308,34 @@ interface SFCUnitTestIV2 {

function voteBookAddress(address v) external view returns (address);

function createLockStake(uint256 validatorId, uint256 duration, uint256 amount) external;
function unlockStake(uint256 validatorId, uint256 lockStakeIdx, uint256 amount) external returns (uint256);
function getDelegatorLockStake(address delAddr, uint256 valIdx, uint256 lId) external view returns (uint256 stashedLockupExtraReward, uint256 stashedLockupBaseReward);
function createLockStake(
uint256 validatorId,
uint256 duration,
uint256 amount
) external;

function unlockStake(
uint256 validatorId,
uint256 lockStakeIdx,
uint256 amount
) external returns (uint256);

function getDelegatorLockStake(
address delAddr,
uint256 valIdx,
uint256 lId
)
external
view
returns (
uint256 fromEpoch,
uint256 endTime,
uint256 duration,
uint256 stashedLockupExtraReward,
uint256 stashedLockupBaseReward,
uint256 lockStashedRewardsUntilEpoch
);

function setAuthorizedRelockAddress(uint256 valId, address addr) external;
function setEnabledAutoRelock(uint256 valId, bool enabled) external;
function relockByAuthorizedAddress(uint256 valId) external;
function claimRewards(uint256 toValidatorID, uint256[] calldata lIds) external;
}


Loading

0 comments on commit 97e431a

Please sign in to comment.