From d8b40334ebe99a27a73c465395fba835803a245e Mon Sep 17 00:00:00 2001 From: Mike-CZ Date: Wed, 9 Oct 2024 17:08:32 +0200 Subject: [PATCH] Add epoch end block getters and test --- contracts/sfc/SFC.sol | 4 ++++ contracts/sfc/SFCI.sol | 3 +++ contracts/test/UnitTestSFC.sol | 3 +++ test/SFC.ts | 11 +++++++++++ 4 files changed, 21 insertions(+) diff --git a/contracts/sfc/SFC.sol b/contracts/sfc/SFC.sol index 026500b..a202a17 100644 --- a/contracts/sfc/SFC.sol +++ b/contracts/sfc/SFC.sol @@ -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; diff --git a/contracts/sfc/SFCI.sol b/contracts/sfc/SFCI.sol index 9ca168b..f6751cb 100644 --- a/contracts/sfc/SFCI.sol +++ b/contracts/sfc/SFCI.sol @@ -44,6 +44,7 @@ interface SFCI { view returns ( uint256 endTime, + uint256 endBlock, uint256 epochFee, uint256 totalBaseRewardWeight, uint256 totalTxRewardWeight, @@ -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); diff --git a/contracts/test/UnitTestSFC.sol b/contracts/test/UnitTestSFC.sol index a64d325..bbdf895 100644 --- a/contracts/test/UnitTestSFC.sol +++ b/contracts/test/UnitTestSFC.sol @@ -120,6 +120,7 @@ interface SFCUnitTestI { view returns ( uint256 endTime, + uint256 endBlock, uint256 epochFee, uint256 totalBaseRewardWeight, uint256 totalTxRewardWeight, @@ -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); diff --git a/test/SFC.ts b/test/SFC.ts index 2df1df6..5fd6d6b 100644 --- a/test/SFC.ts +++ b/test/SFC.ts @@ -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); + }); }); });