Skip to content

Commit

Permalink
Add epoch end block getters and test
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike-CZ committed Oct 9, 2024
1 parent 761858d commit d8b4033
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions contracts/sfc/SFC.sol
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ contract SFC is SFCBase, Version {
return getEpochSnapshot[epoch].offlineBlocks[validatorID];
}

function getEpochEndBlock(uint256 epoch) public view returns (uint256) {
return getEpochSnapshot[epoch].endBlock;
}

function rewardsStash(address delegator, uint256 validatorID) public view returns (uint256) {
Rewards memory stash = _rewardsStash[delegator][validatorID];
return stash.lockupBaseReward + stash.lockupExtraReward + stash.unlockedReward;
Expand Down
3 changes: 3 additions & 0 deletions contracts/sfc/SFCI.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ interface SFCI {
view
returns (
uint256 endTime,
uint256 endBlock,
uint256 epochFee,
uint256 totalBaseRewardWeight,
uint256 totalTxRewardWeight,
Expand Down Expand Up @@ -139,6 +140,8 @@ interface SFCI {

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

function getEpochEndBlock(uint256 epoch) external view returns (uint256);

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

function getLockedStake(address delegator, uint256 toValidatorID) external view returns (uint256);
Expand Down
3 changes: 3 additions & 0 deletions contracts/test/UnitTestSFC.sol
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ interface SFCUnitTestI {
view
returns (
uint256 endTime,
uint256 endBlock,
uint256 epochFee,
uint256 totalBaseRewardWeight,
uint256 totalTxRewardWeight,
Expand Down Expand Up @@ -217,6 +218,8 @@ interface SFCUnitTestI {

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

function getEpochEndBlock(uint256 epoch) external view returns (uint256);

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

function getLockedStake(address delegator, uint256 toValidatorID) external view returns (uint256);
Expand Down
11 changes: 11 additions & 0 deletions test/SFC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,17 @@ describe('SFC', () => {
expect(await this.sfc.currentEpoch.call()).to.equal(6);
expect(await this.sfc.currentSealedEpoch()).to.equal(5);
});

it('Should succeed and return endBlock', async function () {
const epochNumber = await this.sfc.currentEpoch();
await this.sfc.enableNonNodeCalls();
await this.sfc.sealEpoch([100, 101, 102], [100, 101, 102], [100, 101, 102], [100, 101, 102], 0);
const lastBlock = await ethers.provider.getBlock('latest');
expect(lastBlock).to.not.equal(null);
// endBlock is on second position
expect((await this.sfc.getEpochSnapshot(epochNumber))[1]).to.equal(lastBlock!.number);
expect(await this.sfc.getEpochEndBlock(epochNumber)).to.equal(lastBlock!.number);
});
});
});

Expand Down

0 comments on commit d8b4033

Please sign in to comment.