WorkLock: forbid refund before claiming tokens

pull/1803/head
vzotova 2020-03-25 11:59:51 +03:00
parent b6cfd57829
commit 232802dfb1
2 changed files with 8 additions and 1 deletions

View File

@ -523,10 +523,11 @@ contract WorkLock {
* @notice Refund ETH for the completed work
*/
function refund() external returns (uint256 refundETH) {
WorkInfo storage info = workInfo[msg.sender];
require(info.claimed, "Tokens must be claimed before refund");
refundETH = getAvailableRefund(msg.sender);
require(refundETH > 0, "Nothing to refund: there is no ETH to refund or no completed work");
WorkInfo storage info = workInfo[msg.sender];
if (refundETH == info.depositedETH) {
escrow.setWorkMeasurement(msg.sender, false);
}

View File

@ -590,6 +590,12 @@ def test_worklock(testerchain, token_economics, deploy_contract, token, escrow,
tx = escrow.functions.setCompletedWork(staker2, staker2_remaining_work // 2).transact()
testerchain.wait_for_receipt(tx)
assert not worklock.functions.workInfo(staker2).call()[2]
# Can't refund before claim even with completed work
with pytest.raises((TransactionFailed, ValueError)):
tx = worklock.functions.refund().transact({'from': staker2, 'gas_price': 0})
testerchain.wait_for_receipt(tx)
tx = worklock.functions.claim().transact({'from': staker2, 'gas_price': 0})
testerchain.wait_for_receipt(tx)
assert worklock.functions.getAvailableRefund(staker2).call() == 0