Skip to content

Commit

Permalink
Increased coverage on stake manager and removed two require statement…
Browse files Browse the repository at this point in the history
…s from stakeManager.sol (#353)

* Added test case to increase coverage on stake manager and removed require statemenet from stakemanager file

* Changed the name of test cases as mentioned in conversations
  • Loading branch information
GauravJain9 authored Aug 26, 2021
1 parent ac97f68 commit 414e85b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
2 changes: 0 additions & 2 deletions contracts/Core/StakeManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ contract StakeManager is Initializable, ACL, StakeStorage, StateManager, Pause {
uint256 amount
) external initialized checkEpochAndState(State.Commit, epoch, parameters.epochLength()) whenNotPaused {
require(stakers[stakerId].acceptDelegation, "Delegetion not accpected");
require(stakers[stakerId].tokenAddress != address(0x0000000000000000000000000000000000000000), "Staker has not staked yet");
// Step 1: Razor Token Transfer : Amount
require(razor.transferFrom(msg.sender, address(this), amount), "RZR token transfer failed");

Expand Down Expand Up @@ -244,7 +243,6 @@ contract StakeManager is Initializable, ACL, StakeStorage, StateManager, Pause {
function resetLock(uint32 stakerId) external initialized whenNotPaused {
// Lock should be expired if you want to reset
require(locks[msg.sender][stakers[stakerId].tokenAddress].amount != 0, "Existing Lock doesnt exist");
require(stakers[stakerId].id != 0, "staker.id = 0");

Structs.Staker storage staker = stakers[stakerId];
IStakedToken sToken = IStakedToken(stakers[stakerId].tokenAddress);
Expand Down
41 changes: 40 additions & 1 deletion test/StakeManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ describe('StakeManager', function () {
await razor.transfer(signers[7].address, stake1);
await razor.transfer(signers[8].address, stake1);
await razor.transfer(signers[9].address, stake1);
await razor.transfer(signers[12].address, stake1);
});

it('should not allow non admin to pause', async function () {
Expand Down Expand Up @@ -273,7 +274,7 @@ describe('StakeManager', function () {
await assertRevert(tx, 'Existing Lock doesnt exist');
});

it('Staker should not be able to unstake more than his stoken balance', async function () {
it('Staker should not be able to unstake more than his sRZR balance', async function () {
const epoch = await getEpoch();
const stakerIdAcc1 = await stakeManager.stakerIds(signers[1].address);
const staker = await stakeManager.getStaker(stakerIdAcc1);
Expand Down Expand Up @@ -1222,5 +1223,43 @@ describe('StakeManager', function () {
const tx = stakeManager.connect(signers[3]).withdraw(epoch, stakerIdacc3);
await assertRevert(tx, 'Nonpositive Stake');
});

it('Stakers should not be able to withdraw if their current sRZR balance is less than the locked amount', async function () {
let epoch = await getEpoch();
await razor.connect(signers[12]).approve(stakeManager.address, tokenAmount('420000'));
await stakeManager.connect(signers[12]).stake(epoch, tokenAmount('420000'));
const stakerId = await stakeManager.stakerIds(signers[12].address);
const staker = await stakeManager.stakers(stakerId);
const sToken = await stakedToken.attach(staker.tokenAddress);
await stakeManager.connect(signers[12]).unstake(epoch, stakerId, tokenAmount('420000'));
await sToken.connect(signers[12]).transfer(signers[10].address, tokenAmount('20000'));
for (let i = 0; i < WITHDRAW_LOCK_PERIOD; i++) {
await mineToNextEpoch();
}
epoch = await getEpoch();
const tx = stakeManager.connect(signers[12]).withdraw(epoch, stakerId);
await assertRevert(tx, 'locked amount lost');
await stakeManager.connect(signers[12]).resetLock(stakerId);
});

it('ResetLock should fail, if stakers sRZR balance is less than the amount to be penalized', async function () {
let epoch = await getEpoch();
let stakerId = await stakeManager.stakerIds(signers[12].address);
let staker = await stakeManager.stakers(stakerId);
let sToken = await stakedToken.attach(staker.tokenAddress);
let amount = await sToken.balanceOf(staker._address);
await stakeManager.connect(signers[12]).unstake(epoch, stakerId, amount);
await sToken.connect(signers[12]).transfer(signers[10].address, amount);
for (let i = 0; i < WITHDRAW_LOCK_PERIOD + 1; i++) {
await mineToNextEpoch();
}
epoch = await getEpoch();
stakerId = await stakeManager.stakerIds(signers[12].address);
staker = await stakeManager.stakers(stakerId);
sToken = await stakedToken.attach(staker.tokenAddress);
amount = await sToken.balanceOf(staker._address);
const tx = stakeManager.connect(signers[12]).resetLock(stakerId);
await assertRevert(tx, 'ERC20: burn amount exceeds balance');
});
});
});

0 comments on commit 414e85b

Please sign in to comment.