Allow slashing of stake

This commit is contained in:
Mark Spanbroek 2021-11-04 13:16:11 +01:00
parent 38fee6d83a
commit 50bab88447
3 changed files with 15 additions and 0 deletions

View File

@ -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;
}
}

View File

@ -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);
}
}

View File

@ -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)
})
})