From b836e001f4b9b10a02dcbf6f67e941548ed3548f Mon Sep 17 00:00:00 2001 From: Sameer Agarwal <52957842+SamAg19@users.noreply.github.com> Date: Thu, 12 Sep 2024 11:14:26 +0530 Subject: [PATCH] chore: test fixes (#1005) * chore: test fixes * chore: linting fixes * chore: lint fixes * chore: test fixes * chore: test files linting fixes * chore: logging removed and package version updated --- contracts/Core/BlockManager.sol | 17 +++------- contracts/Core/CollectionManager.sol | 10 +++--- contracts/Core/RewardManager.sol | 6 +--- contracts/Core/StakeManager.sol | 33 +++---------------- contracts/Core/StateManager.sol | 6 +--- contracts/Core/VoteManager.sol | 12 ++----- contracts/Core/interface/IStakeManager.sol | 28 +++------------- contracts/Core/interface/IVoteManager.sol | 12 ++----- contracts/Core/parameters/Governance.sol | 6 +--- .../parameters/child/BlockManagerParams.sol | 4 +-- .../parameters/child/RewardManagerParams.sol | 2 +- .../parameters/child/StakeManagerParams.sol | 10 ++---- .../parameters/child/VoteManagerParams.sol | 2 +- .../interfaces/IStakeManagerParams.sol | 6 +--- contracts/tokenization/IStakedToken.sol | 6 +--- contracts/tokenization/StakedToken.sol | 12 ++----- package.json | 2 +- scenarios/scenarios.js | 3 +- test/AssignCollectionsRandomly.js | 21 ++++++------ test/BlockManager.js | 13 +++----- test/CollectionManager.js | 2 +- test/RandomNoManager.js | 3 +- test/helpers/InternalEngine.js | 2 ++ test/helpers/constants.js | 4 +-- test/helpers/utils.js | 5 +-- 25 files changed, 62 insertions(+), 165 deletions(-) diff --git a/contracts/Core/BlockManager.sol b/contracts/Core/BlockManager.sol index 37c9bb72..72af118e 100644 --- a/contracts/Core/BlockManager.sol +++ b/contracts/Core/BlockManager.sol @@ -511,12 +511,7 @@ contract BlockManager is Initializable, BlockStorage, StateManager, BlockManager * @param biggestStake biggest Stake that was revealed * @return isAdded : whether the block was added to the array */ - function _insertAppropriately( - uint32 epoch, - uint32 blockId, - uint256 iteration, - uint256 biggestStake - ) internal returns (bool isAdded) { + function _insertAppropriately(uint32 epoch, uint32 blockId, uint256 iteration, uint256 biggestStake) internal returns (bool isAdded) { uint8 sortedProposedBlockslength = uint8(sortedProposedBlockIds[epoch].length); if (sortedProposedBlockslength == 0) { @@ -570,11 +565,7 @@ contract BlockManager is Initializable, BlockStorage, StateManager, BlockManager * @param blockIndex index of the block that is disputed * @param blockId id of the block being disputed */ - function _executeDispute( - uint32 epoch, - uint8 blockIndex, - uint32 blockId - ) internal { + function _executeDispute(uint32 epoch, uint8 blockIndex, uint32 blockId) internal { proposedBlocks[epoch][blockId].valid = false; uint8 sortedProposedBlocksLength = uint8(sortedProposedBlockIds[epoch].length); @@ -627,12 +618,12 @@ contract BlockManager is Initializable, BlockStorage, StateManager, BlockManager // stake * 2^32 < prng * 2^32 * biggestStake // multiplying by 2^32 since seed2 is bytes32 so rand2 goes from 0 to 2^32 bytes32 seed2 = Random.prngHash(salt, keccak256(abi.encode(stakerId, iteration))); - uint256 rand2 = Random.prng(2**32, seed2); + uint256 rand2 = Random.prng(2 ** 32, seed2); uint256 biggestStake = voteManager.getStakeSnapshot(epoch, biggestStakerId); uint256 stake = voteManager.getStakeSnapshot(epoch, stakerId); // Below line can't be tested since it can't be assured if it returns true or false - if (rand2 * (biggestStake) > stake * (2**32)) return (false); + if (rand2 * (biggestStake) > stake * (2 ** 32)) return (false); return true; } } diff --git a/contracts/Core/CollectionManager.sol b/contracts/Core/CollectionManager.sol index ee6a3a95..3cb55ba5 100644 --- a/contracts/Core/CollectionManager.sol +++ b/contracts/Core/CollectionManager.sol @@ -147,12 +147,10 @@ contract CollectionManager is Initializable, CollectionStorage, StateManager, Co * @param assetStatus the status that needs to be set for the collection * @param id the collection id for which the status needs to change */ - function setCollectionStatus(bool assetStatus, uint16 id) - external - initialized - onlyRole(COLLECTION_MODIFIER_ROLE) - checkState(State.Confirm, buffer) - { + function setCollectionStatus( + bool assetStatus, + uint16 id + ) external initialized onlyRole(COLLECTION_MODIFIER_ROLE) checkState(State.Confirm, buffer) { require(id != 0, "ID cannot be 0"); require(id <= numCollections, "ID does not exist"); diff --git a/contracts/Core/RewardManager.sol b/contracts/Core/RewardManager.sol index 1ea2454b..2308c5d5 100644 --- a/contracts/Core/RewardManager.sol +++ b/contracts/Core/RewardManager.sol @@ -164,11 +164,7 @@ contract RewardManager is Initializable, Constants, RewardManagerParams, IReward * @param stakeValue The Stake that staker had in last epoch * @param ageValue The age that staker had in last epoch */ - function _calculateInactivityPenalties( - uint32 epochs, - uint256 stakeValue, - uint32 ageValue - ) internal view returns (uint256, uint32) { + function _calculateInactivityPenalties(uint32 epochs, uint256 stakeValue, uint32 ageValue) internal view returns (uint256, uint32) { uint256 penalty = ((epochs) * (stakeValue * penaltyNotRevealNum)) / BASE_DENOMINATOR; uint256 newStake = penalty < stakeValue ? stakeValue - penalty : 0; uint256 penaltyAge = (uint256(epochs) * (uint256(ageValue) * uint256(penaltyAgeNotRevealNum))) / BASE_DENOMINATOR; diff --git a/contracts/Core/StakeManager.sol b/contracts/Core/StakeManager.sol index 26f5fef8..28847d06 100644 --- a/contracts/Core/StakeManager.sol +++ b/contracts/Core/StakeManager.sol @@ -424,12 +424,7 @@ contract StakeManager is Initializable, StakeStorage, StateManager, Pause, Stake } /// @inheritdoc IStakeManager - function srzrTransfer( - address from, - address to, - uint256 amount, - uint32 stakerId - ) external override initialized onlyRole(STOKEN_ROLE) { + function srzrTransfer(address from, address to, uint256 amount, uint32 stakerId) external override initialized onlyRole(STOKEN_ROLE) { emit SrzrTransfer(from, to, amount, stakerId); } @@ -513,11 +508,7 @@ contract StakeManager is Initializable, StakeStorage, StateManager, Pause, Stake } /// @inheritdoc IStakeManager - function slash( - uint32 epoch, - uint32 stakerId, - address bountyHunter - ) external override initialized onlyRole(STAKE_MODIFIER_ROLE) { + function slash(uint32 epoch, uint32 stakerId, address bountyHunter) external override initialized onlyRole(STAKE_MODIFIER_ROLE) { uint256 _stake = stakers[stakerId].stake; uint256 bounty; @@ -631,13 +622,7 @@ contract StakeManager is Initializable, StakeStorage, StateManager, Pause, Stake * @param _id of the staker * @param _stake the amount of Razor tokens staked */ - function _setStakerStake( - uint32 _epoch, - uint32 _id, - Constants.StakeChanged reason, - uint256 _prevStake, - uint256 _stake - ) internal { + function _setStakerStake(uint32 _epoch, uint32 _id, Constants.StakeChanged reason, uint256 _prevStake, uint256 _stake) internal { stakers[_id].stake = _stake; emit StakeChange(_epoch, _id, reason, _prevStake, _stake, block.timestamp); } @@ -667,11 +652,7 @@ contract StakeManager is Initializable, StakeStorage, StateManager, Pause, Stake * @param _sAmount The Amount in sRZR * @param _currentStake The cuurent stake of associated staker */ - function _convertSRZRToRZR( - uint256 _sAmount, - uint256 _currentStake, - uint256 _totalSupply - ) internal pure returns (uint256) { + function _convertSRZRToRZR(uint256 _sAmount, uint256 _currentStake, uint256 _totalSupply) internal pure returns (uint256) { return ((_sAmount * _currentStake) / _totalSupply); } @@ -681,11 +662,7 @@ contract StakeManager is Initializable, StakeStorage, StateManager, Pause, Stake * @param _currentStake The cuurent stake of associated staker * @param _totalSupply The totalSupply of sRZR */ - function _convertRZRtoSRZR( - uint256 _amount, - uint256 _currentStake, - uint256 _totalSupply - ) internal pure returns (uint256) { + function _convertRZRtoSRZR(uint256 _amount, uint256 _currentStake, uint256 _totalSupply) internal pure returns (uint256) { // Follwoing require is included to cover case where // CurrentStake Becomes zero beacues of penalties, //this is likely scenario when staker stakes is slashed to 0 for invalid block. diff --git a/contracts/Core/StateManager.sol b/contracts/Core/StateManager.sol index d8fd0c3a..fecb5223 100644 --- a/contracts/Core/StateManager.sol +++ b/contracts/Core/StateManager.sol @@ -38,11 +38,7 @@ contract StateManager is Constants { /** @notice a check to ensure the epoch value sent in the function is of the currect epoch * and was called in the state specified */ - modifier checkEpochAndState( - State state, - uint32 epoch, - uint8 buffer - ) { + modifier checkEpochAndState(State state, uint32 epoch, uint8 buffer) { // slither-disable-next-line incorrect-equality require(epoch == _getEpoch(), "incorrect epoch"); // slither-disable-next-line incorrect-equality diff --git a/contracts/Core/VoteManager.sol b/contracts/Core/VoteManager.sol index b3a652b7..cf6896aa 100644 --- a/contracts/Core/VoteManager.sol +++ b/contracts/Core/VoteManager.sol @@ -230,21 +230,13 @@ contract VoteManager is Initializable, VoteStorage, StateManager, VoteManagerPar } /// @inheritdoc IVoteManager - function getVoteValue( - uint32 epoch, - uint32 stakerId, - uint16 leafId - ) external view override returns (uint256) { + function getVoteValue(uint32 epoch, uint32 stakerId, uint16 leafId) external view override returns (uint256) { //epoch -> stakerid -> asserId return votes[epoch][stakerId][leafId]; } /// @inheritdoc IVoteManager - function getVoteWeight( - uint32 epoch, - uint16 leafId, - uint256 voteValue - ) external view override returns (uint256) { + function getVoteWeight(uint32 epoch, uint16 leafId, uint256 voteValue) external view override returns (uint256) { //epoch -> leafId -> voteValue -> weight return (voteWeights[epoch][leafId][voteValue]); } diff --git a/contracts/Core/interface/IStakeManager.sol b/contracts/Core/interface/IStakeManager.sol index 86c17430..7de6be88 100644 --- a/contracts/Core/interface/IStakeManager.sol +++ b/contracts/Core/interface/IStakeManager.sol @@ -14,13 +14,7 @@ interface IStakeManager { * @param prevStake previous stake of the staker * @param _stake updated stake of the staker */ - function setStakerStake( - uint32 _epoch, - uint32 _id, - Constants.StakeChanged reason, - uint256 prevStake, - uint256 _stake - ) external; + function setStakerStake(uint32 _epoch, uint32 _id, Constants.StakeChanged reason, uint256 prevStake, uint256 _stake) external; /** * @notice The function is used by the Votemanager reveal function and BlockManager FinalizeDispute @@ -29,11 +23,7 @@ interface IStakeManager { * @param stakerId The ID of the staker who is penalised * @param bountyHunter The address of the bounty hunter */ - function slash( - uint32 epoch, - uint32 stakerId, - address bountyHunter - ) external; + function slash(uint32 epoch, uint32 stakerId, address bountyHunter) external; /** * @notice External function for setting staker age of the staker @@ -43,12 +33,7 @@ interface IStakeManager { * @param _age the updated new age * @param reason the reason for age change */ - function setStakerAge( - uint32 _epoch, - uint32 _id, - uint32 _age, - Constants.AgeChanged reason - ) external; + function setStakerAge(uint32 _epoch, uint32 _id, uint32 _age, Constants.AgeChanged reason) external; /** * @notice External function for setting stakerReward of the staker @@ -86,12 +71,7 @@ interface IStakeManager { * @param amount srzr amount being transferred * @param stakerId of the staker */ - function srzrTransfer( - address from, - address to, - uint256 amount, - uint32 stakerId - ) external; + function srzrTransfer(address from, address to, uint256 amount, uint32 stakerId) external; /** * @param _address Address of the staker diff --git a/contracts/Core/interface/IVoteManager.sol b/contracts/Core/interface/IVoteManager.sol index 55eedbd0..85305275 100644 --- a/contracts/Core/interface/IVoteManager.sol +++ b/contracts/Core/interface/IVoteManager.sol @@ -24,11 +24,7 @@ interface IVoteManager { * @param leafId seq position of collection in merkle tree * @return vote value */ - function getVoteValue( - uint32 epoch, - uint32 stakerId, - uint16 leafId - ) external view returns (uint256); + function getVoteValue(uint32 epoch, uint32 stakerId, uint16 leafId) external view returns (uint256); /** * @notice returns vote weight of the value of the collection reported @@ -37,11 +33,7 @@ interface IVoteManager { * @param voteValue one of the values of the collection being reported * @return vote weight of the vote */ - function getVoteWeight( - uint32 epoch, - uint16 leafId, - uint256 voteValue - ) external view returns (uint256); + function getVoteWeight(uint32 epoch, uint16 leafId, uint256 voteValue) external view returns (uint256); /** * @notice returns snapshot of influence of the staker when they revealed diff --git a/contracts/Core/parameters/Governance.sol b/contracts/Core/parameters/Governance.sol index 05e93a6a..504d10f3 100644 --- a/contracts/Core/parameters/Governance.sol +++ b/contracts/Core/parameters/Governance.sol @@ -86,11 +86,7 @@ contract Governance is Initializable, ACL, Constants { * @param _burn updated percent value to be set for burn * @param _keep updated percent value to be set for keep */ - function setSlashParams( - uint32 _bounty, - uint32 _burn, - uint32 _keep - ) external initialized onlyRole(GOVERNER_ROLE) { + function setSlashParams(uint32 _bounty, uint32 _burn, uint32 _keep) external initialized onlyRole(GOVERNER_ROLE) { require(_bounty + _burn + _keep <= BASE_DENOMINATOR, "Slash nums addtion exceeds 10mil"); emit ParameterChanged(msg.sender, "bountySlashNum", _bounty, block.timestamp); emit ParameterChanged(msg.sender, "burnSlashNum", _burn, block.timestamp); diff --git a/contracts/Core/parameters/child/BlockManagerParams.sol b/contracts/Core/parameters/child/BlockManagerParams.sol index b265545a..c0bdaa0d 100644 --- a/contracts/Core/parameters/child/BlockManagerParams.sol +++ b/contracts/Core/parameters/child/BlockManagerParams.sol @@ -9,9 +9,9 @@ abstract contract BlockManagerParams is ACL, IBlockManagerParams, Constants { uint8 public maxAltBlocks = 5; uint8 public buffer = 5; /// @notice reward given to staker whose block is confirmed - uint256 public blockReward = 100 * (10**18); + uint256 public blockReward = 100 * (10 ** 18); /// @notice minimum amount of stake required to participate - uint256 public minStake = 20000 * (10**18); + uint256 public minStake = 20000 * (10 ** 18); /// @inheritdoc IBlockManagerParams function setMaxAltBlocks(uint8 _maxAltBlocks) external override onlyRole(GOVERNANCE_ROLE) { diff --git a/contracts/Core/parameters/child/RewardManagerParams.sol b/contracts/Core/parameters/child/RewardManagerParams.sol index 19f33351..c9536e6b 100644 --- a/contracts/Core/parameters/child/RewardManagerParams.sol +++ b/contracts/Core/parameters/child/RewardManagerParams.sol @@ -12,7 +12,7 @@ abstract contract RewardManagerParams is ACL, IRewardManagerParams, Constants { /// @notice maximum age a staker can have uint32 public maxAge = 100 * 10000; /// @notice reward given to staker whose block is confirmed - uint256 public blockReward = 100 * (10**18); + uint256 public blockReward = 100 * (10 ** 18); /// @notice maximum percentage deviation allowed from medians for all collections uint32 public maxTolerance = 1_000_000; /// @notice maximum commission stakers can charge from delegators on their profits diff --git a/contracts/Core/parameters/child/StakeManagerParams.sol b/contracts/Core/parameters/child/StakeManagerParams.sol index 8d86be70..36fa74e2 100644 --- a/contracts/Core/parameters/child/StakeManagerParams.sol +++ b/contracts/Core/parameters/child/StakeManagerParams.sol @@ -37,16 +37,12 @@ abstract contract StakeManagerParams is ACL, IStakeManagerParams, Constants { /// @notice slashing params being used if staker is slashed. Slash Penalty = bounty + burned + kept == 100% SlashNums public slashNums = SlashNums(500_000, 9_500_000, 0); /// @notice minimum amount of stake required to participate - uint256 public minStake = 20000 * (10**18); + uint256 public minStake = 20000 * (10 ** 18); /// @notice minimum amount of stake required to become a staker - uint256 public minSafeRazor = 10000 * (10**18); + uint256 public minSafeRazor = 10000 * (10 ** 18); /// @inheritdoc IStakeManagerParams - function setSlashParams( - uint32 _bounty, - uint32 _burn, - uint32 _keep - ) external override onlyRole(GOVERNANCE_ROLE) { + function setSlashParams(uint32 _bounty, uint32 _burn, uint32 _keep) external override onlyRole(GOVERNANCE_ROLE) { require(_bounty + _burn + _keep <= BASE_DENOMINATOR, "params sum exceeds denominator"); // slither-disable-next-line events-maths slashNums = SlashNums(_bounty, _burn, _keep); diff --git a/contracts/Core/parameters/child/VoteManagerParams.sol b/contracts/Core/parameters/child/VoteManagerParams.sol index cb05b868..8fd917d3 100644 --- a/contracts/Core/parameters/child/VoteManagerParams.sol +++ b/contracts/Core/parameters/child/VoteManagerParams.sol @@ -9,7 +9,7 @@ abstract contract VoteManagerParams is ACL, IVoteManagerParams, Constants { /// @notice maximum number of collections that can be assigned to the staker uint16 public toAssign = 3; /// @notice minimum amount of stake required to participate - uint256 public minStake = 20000 * (10**18); + uint256 public minStake = 20000 * (10 ** 18); /// @inheritdoc IVoteManagerParams function setMinStake(uint256 _minStake) external override onlyRole(GOVERNANCE_ROLE) { diff --git a/contracts/Core/parameters/interfaces/IStakeManagerParams.sol b/contracts/Core/parameters/interfaces/IStakeManagerParams.sol index 5270e24b..95a167da 100644 --- a/contracts/Core/parameters/interfaces/IStakeManagerParams.sol +++ b/contracts/Core/parameters/interfaces/IStakeManagerParams.sol @@ -9,11 +9,7 @@ interface IStakeManagerParams { * @param _burn updated percent value to be set for burn * @param _keep updated percent value to be set for keep */ - function setSlashParams( - uint32 _bounty, - uint32 _burn, - uint32 _keep - ) external; + function setSlashParams(uint32 _bounty, uint32 _burn, uint32 _keep) external; /** * @notice changing the number of epochs for which the RAZORs are locked after initiating withdraw diff --git a/contracts/tokenization/IStakedToken.sol b/contracts/tokenization/IStakedToken.sol index 1e07a9f5..2f562165 100644 --- a/contracts/tokenization/IStakedToken.sol +++ b/contracts/tokenization/IStakedToken.sol @@ -17,11 +17,7 @@ interface IStakedToken is IERC20 { * * - `account` cannot be the zero address. */ - function mint( - address account, - uint256 amount, - uint256 razorDeposited - ) external returns (bool); + function mint(address account, uint256 amount, uint256 razorDeposited) external returns (bool); /** * @dev Destroys `amount` tokens from `account`, reducing the diff --git a/contracts/tokenization/StakedToken.sol b/contracts/tokenization/StakedToken.sol index 65c43235..8069b223 100644 --- a/contracts/tokenization/StakedToken.sol +++ b/contracts/tokenization/StakedToken.sol @@ -36,11 +36,7 @@ contract StakedToken is ERC20, IStakedToken { } /// @inheritdoc IStakedToken - function mint( - address account, - uint256 amount, - uint256 _razorDeposited - ) external override onlyOwner returns (bool) { + function mint(address account, uint256 amount, uint256 _razorDeposited) external override onlyOwner returns (bool) { razorDeposited[account] = razorDeposited[account] + _razorDeposited; _mint(account, amount); return true; @@ -65,11 +61,7 @@ contract StakedToken is ERC20, IStakedToken { * @param to address where sRZR is being transferred to * @param amount amount sRZR being transferred */ - function _beforeTokenTransfer( - address from, - address to, - uint256 amount - ) internal virtual override { + function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual override { //mint : addition, would happen in case of delegate or stake //burn : subtraction, would happeen when staker calls withdraw //transfer : add and sub diff --git a/package.json b/package.json index 2ce82951..c0feafed 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@razor-network/contracts", - "version": "2.0.0", + "version": "2.0.1", "description": "These are the contracts for Razor network testnet", "author": "Razor Network", "private": false, diff --git a/scenarios/scenarios.js b/scenarios/scenarios.js index bd5a20f3..2151cb8a 100644 --- a/scenarios/scenarios.js +++ b/scenarios/scenarios.js @@ -1,3 +1,4 @@ +const { assert } = require('chai'); const { getState, adhocCommit, adhocReveal, getData, adhocPropose, } = require('../test/helpers/utils'); @@ -910,7 +911,6 @@ describe('Scenarios', async () => { const median = await calculateDisputesData(medianIndex, voteManager, stakeManager, - collectionManager, epoch); helper[medianIndex] = median.median; } @@ -974,7 +974,6 @@ describe('Scenarios', async () => { } = await calculateDisputesData(validActiveCollectionIndexToBeDisputed, voteManager, stakeManager, - collectionManager, epoch); await blockManager.connect(signers[4]).giveSorted(epoch, validActiveCollectionIndexToBeDisputed, sortedValues); diff --git a/test/AssignCollectionsRandomly.js b/test/AssignCollectionsRandomly.js index 0db76ce4..26f90786 100644 --- a/test/AssignCollectionsRandomly.js +++ b/test/AssignCollectionsRandomly.js @@ -135,11 +135,11 @@ describe('AssignCollectionsRandomly', function () { } = await calculateDisputesData(validLeafIdToBeDisputed, voteManager, stakeManager, - collectionManager, epoch); await blockManager.connect(signers[19]).giveSorted(epoch, validLeafIdToBeDisputed, sortedValues); const collectionIndexInBlock = await getCollectionIdPositionInBlock(epoch, await blockManager.sortedProposedBlockIds(epoch, 0), signers[19], blockManager, collectionManager); + await assertRevert(blockManager.connect(signers[19]).finalizeDispute(epoch, 0, collectionIndexInBlock), 'Block proposed with same medians'); await mineToNextState(); @@ -151,10 +151,10 @@ describe('AssignCollectionsRandomly', function () { /* /////////////////////////////////////////////////////////////// DELEGATOR ////////////////////////////////////////////////////////////// */ - const collectionName = 'c2'; + const collectionName = 'c0'; const hName = utils.solidityKeccak256(['string'], [collectionName]); const result1 = await delegator.getResult(hName); - assertBNEqual(result1[3], 300); + assertBNEqual(result1[3], 100); const result2 = await delegator.getResult(utils.solidityKeccak256(['string'], ['c1'])); assertBNEqual(result2[3], 0); @@ -194,7 +194,6 @@ describe('AssignCollectionsRandomly', function () { } = await calculateDisputesData(validLeafIdToBeDisputed, voteManager, stakeManager, - collectionManager, epoch); await blockManager.connect(signers[19]).giveSorted(epoch, validLeafIdToBeDisputed, sortedValues); let collectionIndexInBlock = await getCollectionIdPositionInBlock(epoch, await blockManager.sortedProposedBlockIds(epoch, 0), @@ -202,7 +201,7 @@ describe('AssignCollectionsRandomly', function () { await assertRevert(blockManager.connect(signers[19]).finalizeDispute(epoch, 0, collectionIndexInBlock), 'Block proposed with same medians'); // Give Sorted and FinaliseDispute on non-revealed asset - await blockManager.giveSorted(epoch, 0, [100]); + await blockManager.giveSorted(epoch, 3, [400]); collectionIndexInBlock = await getCollectionIdPositionInBlock(epoch, await blockManager.sortedProposedBlockIds(epoch, 0), signers[0], blockManager, collectionManager); await assertRevert(blockManager.finalizeDispute(epoch, 0, collectionIndexInBlock), 'Invalid dispute'); @@ -213,7 +212,7 @@ describe('AssignCollectionsRandomly', function () { await assertRevert(blockManager.disputeCollectionIdShouldBePresent(epoch, 0, 5), 'Dispute: ID present only'); await assertRevert(blockManager.disputeCollectionIdShouldBePresent(epoch, 0, 6), 'Dispute: ID present only'); await assertRevert(blockManager.disputeCollectionIdShouldBePresent(epoch, 0, 7), 'Dispute: ID present only'); - await assertRevert(blockManager.disputeCollectionIdShouldBePresent(epoch, 0, 1), 'Dispute: ID should be absent'); + await assertRevert(blockManager.disputeCollectionIdShouldBePresent(epoch, 0, 1), 'Dispute: ID present only'); await assertRevert(blockManager.disputeCollectionIdShouldBePresent(epoch, 0, 4), 'Dispute: ID should be absent'); await assertRevert(blockManager.disputeCollectionIdShouldBeAbsent(epoch, 0, 2, 0), 'Dispute: ID should be present'); @@ -221,7 +220,7 @@ describe('AssignCollectionsRandomly', function () { await assertRevert(blockManager.disputeCollectionIdShouldBeAbsent(epoch, 0, 5, 0), 'Dispute: ID should be present'); await assertRevert(blockManager.disputeCollectionIdShouldBeAbsent(epoch, 0, 6, 0), 'Dispute: ID should be present'); await assertRevert(blockManager.disputeCollectionIdShouldBeAbsent(epoch, 0, 7, 0), 'Dispute: ID should be present'); - await assertRevert(blockManager.disputeCollectionIdShouldBeAbsent(epoch, 0, 1, 0), 'Dispute: ID absent only'); + await assertRevert(blockManager.disputeCollectionIdShouldBeAbsent(epoch, 0, 1, 0), 'Dispute: ID should be present'); await assertRevert(blockManager.disputeCollectionIdShouldBeAbsent(epoch, 0, 4, 0), 'Dispute: ID absent only'); // the id itself doesnt exist await assertRevert(blockManager.disputeOnOrderOfIds(epoch, 0, 1, 0), 'index1 not greater than index0 0'); @@ -229,10 +228,10 @@ describe('AssignCollectionsRandomly', function () { }); it('Delegator should be able to fetch the result of non revealed asset', async () => { - const collectionName = 'c2'; + const collectionName = 'c0'; const hName = utils.solidityKeccak256(['string'], [collectionName]); const result = await delegator.getResult(hName); - assertBNEqual(result[3], 300); + assertBNEqual(result[3], 100); }); it('Staker Proposes revealed assets in-correctly', async () => { @@ -296,11 +295,11 @@ describe('AssignCollectionsRandomly', function () { await restoreSnapshot(snapshotId); snapshotId = await takeSnapshot(); // additional 2 - await adhocPropose(signers[1], [1, 2, 5, 6, 7], [100, 200, 500, 600, 700], stakeManager, blockManager, voteManager); + await adhocPropose(signers[1], [1, 2, 4, 5, 6, 7], [100, 200, 400, 500, 600, 700], stakeManager, blockManager, voteManager); await mineToNextState(); const epoch = await getEpoch(); - await blockManager.disputeCollectionIdShouldBeAbsent(epoch, 0, 1, 0); + await blockManager.disputeCollectionIdShouldBeAbsent(epoch, 0, 4, 2); const blockIndexToBeConfirmed = await blockManager.blockIndexToBeConfirmed(); const block = await blockManager.getProposedBlock(epoch, 0); expect(blockIndexToBeConfirmed).to.eq(-1); diff --git a/test/BlockManager.js b/test/BlockManager.js index 50d15ad3..f331d3cb 100644 --- a/test/BlockManager.js +++ b/test/BlockManager.js @@ -2,6 +2,7 @@ // @dev : above is a quick fix for this linting error // I couldnt understand what it meant, to solve it +const { assert, expect } = require('chai'); const { assertBNEqual, assertDeepEqual, @@ -34,7 +35,7 @@ const { const { utils } = ethers; const { - commit, reveal, propose, proposeWithDeviation, reset, calculateMedians, calculateInvalidMedians, getIdsRevealed, + commit, reveal, propose, proposeWithDeviation, reset, calculateMedians, calculateInvalidMedians, getIdsRevealed, getData, } = require('./helpers/InternalEngine'); describe('BlockManager', function () { @@ -278,7 +279,6 @@ describe('BlockManager', function () { } = await calculateDisputesData(validLeafIdToBeDisputed, voteManager, stakeManager, - collectionManager, epoch); await blockManager.connect(signers[19]).giveSorted(epoch, validLeafIdToBeDisputed, sortedValues); const numActiveCollections = await collectionManager.getNumActiveCollections(); @@ -409,7 +409,6 @@ describe('BlockManager', function () { const res1 = await calculateDisputesData(validLeafIdToBeDisputed, voteManager, stakeManager, - collectionManager, epoch); await blockManager.connect(signers[19]).giveSorted(epoch, validLeafIdToBeDisputed, res1.sortedValues); const firstDispute = await blockManager.disputes(epoch, signers[19].address); @@ -428,7 +427,6 @@ describe('BlockManager', function () { const res2 = await calculateDisputesData(validLeafIdToBeDisputed, voteManager, stakeManager, - collectionManager, epoch); await blockManager.connect(signers[15]).giveSorted(epoch, validLeafIdToBeDisputed, res2.sortedValues); @@ -550,10 +548,12 @@ describe('BlockManager', function () { // Staker 3 await reveal(signers[7], 20, voteManager, stakeManager); + + const data = await getData(signers[7]); // Propose await mineToNextState(); - validLeafIdToBeDisputed = toBigNumber('4'); + validLeafIdToBeDisputed = data.seqAllotedCollections[0]; await proposeWithDeviation(signers[6], 1, stakeManager, blockManager, voteManager, collectionManager); @@ -572,7 +572,6 @@ describe('BlockManager', function () { } = await calculateDisputesData(validLeafIdToBeDisputed, voteManager, stakeManager, - collectionManager, epoch); // Dispute in batches @@ -793,7 +792,6 @@ describe('BlockManager', function () { const res1 = await calculateDisputesData(validLeafIdToBeDisputed, voteManager, stakeManager, - collectionManager, epoch); await blockManager.connect(signers[10]).giveSorted(epoch, validLeafIdToBeDisputed, res1.sortedValues); @@ -1347,7 +1345,6 @@ describe('BlockManager', function () { const res = await calculateDisputesData(validLeafIdToBeDisputed, voteManager, stakeManager, - collectionManager, epoch); await blockManager.giveSorted(epoch, validLeafIdToBeDisputed, res.sortedValues); diff --git a/test/CollectionManager.js b/test/CollectionManager.js index 6d1702fc..cf60bc16 100644 --- a/test/CollectionManager.js +++ b/test/CollectionManager.js @@ -321,7 +321,7 @@ describe('CollectionManager', function () { const tolerance = 500; const depthArr = []; const expectedDepthArr = []; - for (let i = 4; i <= 102; i++) { + for (let i = 4; i <= 50; i++) { await collectionManager.createCollection(tolerance, power, 1, [1, 2], `Test Collection ${i}`); const numActiveCollections = await collectionManager.getNumActiveCollections(); const treeDepth = await collectionManager.getDepth(); diff --git a/test/RandomNoManager.js b/test/RandomNoManager.js index f2203f00..ee2ee04a 100644 --- a/test/RandomNoManager.js +++ b/test/RandomNoManager.js @@ -1,3 +1,4 @@ +const { assert } = require('chai'); const { assertBNEqual, mineToNextEpoch, @@ -166,7 +167,7 @@ describe('RandomNoManager', function () { // Get Random no : Generic From Epoch const randomNo3 = await randomNoManager.getGenericRandomNumber(epoch); const seed3 = await randomNoManager.secrets(epoch); - const salt3 = 0; + const salt3 = '0x0000000000000000000000000000000000000000000000000000000000000000'; const locallyCalculatedRandomNo3 = await prngHash(seed3, salt3); assertBNEqual(randomNo3, toBigNumber(locallyCalculatedRandomNo3)); assertBNNotEqual(randomNo3, randomNo); diff --git a/test/helpers/InternalEngine.js b/test/helpers/InternalEngine.js index e4df382f..041fb08f 100644 --- a/test/helpers/InternalEngine.js +++ b/test/helpers/InternalEngine.js @@ -230,6 +230,8 @@ const proposeWithDeviation = async (signer, deviation, stakeManager, blockManage mediansValues, iteration, biggestStakerId); + + return [idsRevealedThisEpoch, mediansValues]; }; const propose = async (signer, stakeManager, blockManager, voteManager, collectionManager) => { diff --git a/test/helpers/constants.js b/test/helpers/constants.js index a5d8be43..dc6d63cd 100644 --- a/test/helpers/constants.js +++ b/test/helpers/constants.js @@ -3,11 +3,11 @@ const { BigNumber } = ethers; const DEFAULT_ADMIN_ROLE_HASH = '0x0000000000000000000000000000000000000000000000000000000000000000'; const ONE_ETHER = BigNumber.from(10).pow(BigNumber.from(18)); -const EPOCH_LENGTH = BigNumber.from(1200); +const EPOCH_LENGTH = BigNumber.from(300); const BASE_DENOMINATOR = BigNumber.from(10000000); const NUM_BLOCKS = 10; const NUM_STATES = BigNumber.from(5); -const STATE_LENGTH = BigNumber.from(240); +const STATE_LENGTH = BigNumber.from(60); const GRACE_PERIOD = 0; const UNSTAKE_LOCK_PERIOD = 1; const WITHDRAW_LOCK_PERIOD = 1; diff --git a/test/helpers/utils.js b/test/helpers/utils.js index ce4f9d47..6adcecab 100644 --- a/test/helpers/utils.js +++ b/test/helpers/utils.js @@ -302,11 +302,12 @@ const adhocPropose = async (signer, ids, medians, stakeManager, blockManager, vo biggestStakerId); }; -const getCollectionIdPositionInBlock = async (epoch, blockId, signer, blockManager) => { +const getCollectionIdPositionInBlock = async (epoch, blockId, signer, blockManager, collectionManager) => { const { ids } = await blockManager.getProposedBlock(epoch, blockId); // console.log(ids); const dispute = await blockManager.disputes(epoch, signer.address); - const { collectionId } = dispute; + const { leafId } = dispute; + const collectionId = await collectionManager.getCollectionIdFromLeafId(leafId); let collectionIndexInBlock = 0; for (let i = 0; i < ids.length; i++) { if (ids[i] === collectionId) { collectionIndexInBlock = i; break; }