diff --git a/contracts/Core/StakeManager.sol b/contracts/Core/StakeManager.sol index cad9f8d0..c8531f0c 100644 --- a/contracts/Core/StakeManager.sol +++ b/contracts/Core/StakeManager.sol @@ -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"); @@ -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); diff --git a/test/StakeManager.js b/test/StakeManager.js index 69a2f834..531927a1 100644 --- a/test/StakeManager.js +++ b/test/StakeManager.js @@ -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 () { @@ -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); @@ -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'); + }); }); });