Skip to content

Instantly share code, notes, and snippets.

@percybolmer
Last active August 6, 2021 11:27
Show Gist options
  • Save percybolmer/6912fd990c1fbbab575f1e0caf1f834a to your computer and use it in GitHub Desktop.
Save percybolmer/6912fd990c1fbbab575f1e0caf1f834a to your computer and use it in GitHub Desktop.
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