Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save percybolmer/85d308e202493f33e4b408d917c48d8d to your computer and use it in GitHub Desktop.
Save percybolmer/85d308e202493f33e4b408d917c48d8d to your computer and use it in GitHub Desktop.
it("calculate rewards", async() => {
devToken = await DevToken.deployed();
let owner = accounts[0];
// Owner has 1 stake at this time, its the index 1 with 100 Tokens staked
// So lets fast forward time by 20 Hours and see if we gain 2% reward
const newBlock = await helper.advanceTimeAndBlock(3600*20);
let reward = await devToken.calculateTotalAvailableRewards(owner);
assert.equal(reward.toNumber(), 100*0.02, "Reward should be 2 after staking for twenty hours with 100")
// Make a new Stake for 1000, fast forward 20 hours again, and make sure total stake reward is 24 (20+4)
// Remember that the first 100 has been staked for 40 hours now, so its 4 in rewards.
await devToken.stake(1000, {from: owner});
await helper.advanceTimeAndBlock(3600*20);
let stakes = await devToken.hasStake(owner);
let second_reward = await devToken.calculateTotalAvailableRewards(owner);
assert.equal(second_reward.toNumber(), (100*0.04)+(1000*0.02), "Staking reward for the two bets should sum up to 24 tokens");
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment