Last active
August 6, 2021 11:27
-
-
Save percybolmer/6912fd990c1fbbab575f1e0caf1f834a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it("reward stakes", async() => { | |
devToken = await DevToken.deployed(); | |
// Use a fresh Account, Mint 1000 Tokens to it | |
let staker = accounts[3]; | |
await devToken.mint(accounts[3],1000); | |
let initial_balance = await devToken.balanceOf(staker); | |
// Make a stake on 200, fast forward 20 hours, claim reward, amount should be Initial balanace +4 | |
await devToken.stake(200, {from: staker}); | |
await helper.advanceTimeAndBlock(3600*20); | |
let stakeSummary = await devToken.hasStake(staker); | |
let stake = stakeSummary.stakes[0]; | |
// Withdraw 100 from stake at index 0 | |
await devToken.withdrawStake(100, 0, { from: staker}); | |
// Balance of account holder should be updated by 104 tokens | |
let after_balance = await devToken.balanceOf(staker); | |
let expected = 1000-200+100+Number(stake.claimable); | |
assert.equal(after_balance.toNumber(), expected, "Failed to withdraw the stake correctly") | |
// Claiming them again should not return any rewards since we reset timer | |
try{ | |
await devToken.withdrawStake(100, 0 , {from:staker}); | |
}catch(error){ | |
assert.fail(error); | |
} | |
let second_balance = await devToken.balanceOf(staker); | |
// we should have gained 100 this time. | |
assert.equal(second_balance.toNumber(), after_balance.toNumber()+100, "Failed to reset timer second withdrawal reward") | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment