Allow slashing of stake
This commit is contained in:
parent
38fee6d83a
commit
50bab88447
|
@ -39,4 +39,8 @@ contract Stakes {
|
|||
require(locks[account] > 0, "Stake already unlocked");
|
||||
locks[account] -= 1;
|
||||
}
|
||||
|
||||
function _slash(address account, uint percentage) internal {
|
||||
stakes[account] = stakes[account] * (100 - percentage) / 100;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,4 +27,8 @@ contract TestStakes is Stakes {
|
|||
function unlockStake(address account) public {
|
||||
_unlockStake(account);
|
||||
}
|
||||
|
||||
function slash(address account, uint percentage) public {
|
||||
_slash(account, percentage);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,4 +68,11 @@ describe("Stakes", function () {
|
|||
await stakes.unlockStake(host.address)
|
||||
await expect(stakes.withdrawStake()).not.to.be.reverted
|
||||
})
|
||||
|
||||
it("slashes stake", async function () {
|
||||
await token.approve(stakes.address, 1000)
|
||||
await stakes.increaseStake(1000)
|
||||
await stakes.slash(host.address, 10)
|
||||
expect(await stakes.stake(host.address)).to.equal(900)
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue