Last active
May 9, 2021 11:48
-
-
Save percybolmer/e3f5f6b114c6a8eaf0ac798720176026 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("cant withdraw bigger amount than current stake", async() => { | |
devToken = await DevToken.deployed(); | |
let owner = accounts[0]; | |
// Try withdrawing 200 from first stake | |
try { | |
await devToken.removeStake(200, 0, {from:owner}); | |
}catch(error){ | |
assert.equal(error.reason, "Cannot withdraw more than you have staked", "Failed to notice a too big withdrawal from stake"); | |
} | |
}); | |
it("withdraw 50 from a stake", async() => { | |
devToken = await DevToken.deployed(); | |
let owner = accounts[0]; | |
let withdraw_amount = 50; | |
// Try withdrawing 50 from first stake | |
await devToken.removeStake(withdraw_amount, 0, {from:owner}); | |
// Grab a new summary to see if the total amount has changed | |
let summary = await devToken.hasStake(owner); | |
assert.equal(summary.total_amount, 200-withdraw_amount, "The total staking amount should be 150"); | |
// Itterate all stakes and verify their amount aswell. | |
let stake_amount = summary.stakes[0].amount; | |
assert.equal(stake_amount, 100-withdraw_amount, "Wrong Amount in first stake after withdrawal"); | |
}); | |
it("remove stake if empty", async() => { | |
devToken = await DevToken.deployed(); | |
let owner = accounts[0]; | |
let withdraw_amount = 50; | |
// Try withdrawing 50 from first stake AGAIN, this should empty the first stake | |
await devToken.removeStake(withdraw_amount, 0, {from:owner}); | |
// Grab a new summary to see if the total amount has changed | |
let summary = await devToken.hasStake(owner); | |
assert.equal(summary.stakes[0].user, "0x0000000000000000000000000000000000000000", "Failed to remove stake when it was empty"); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment