mirror of https://github.com/nucypher/nucypher.git
WorkLock: forbid refund before claiming tokens
parent
b6cfd57829
commit
232802dfb1
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue