diff --git a/contracts/RenPool.sol b/contracts/RenPool.sol index df3eff7..7f521e1 100644 --- a/contracts/RenPool.sol +++ b/contracts/RenPool.sol @@ -178,8 +178,8 @@ contract RenPool { function fulfillWithdrawRequest(address _target) external { address sender = msg.sender; uint amount = withdrawRequests[_target]; - // ^ This could not be defined plus make sure amount > 0 - // TODO: make sure user cannot fullfil his own request + require(amount > 0, "Amount has to be positive"); + require(sender != _target, "Sender cannot be yourself"); // TODO: add test for when _target doesn't have an associated withdrawRequest require(isLocked == true, "Pool is not locked"); @@ -201,7 +201,13 @@ contract RenPool { // TODO emit event } - // TODO: cancelWithdrawRequest + function cancelWithdrawRequest() external { + address sender = msg.sender; + // Strictly positive so that we are sure not to have error in case the withdraw request doesn't exist for example + require(withdrawRequests[sender] > 0, "No withdraw request"); + + delete withdrawRequests[sender]; + } // TODO: getWithdrawRequests /** diff --git a/tests/ren_pool/test_withdraw_cancellation.py b/tests/ren_pool/test_withdraw_cancellation.py new file mode 100644 index 0000000..687bad6 --- /dev/null +++ b/tests/ren_pool/test_withdraw_cancellation.py @@ -0,0 +1,28 @@ +from brownie.test import given, strategy +from brownie import accounts +import pytest +import constants as C + +@pytest.mark.parametrize('user', accounts[0:3]) # [owner, nodeOperator, user] +@given( + amount=strategy('uint256', min_value = 1, max_value = C.POOL_BOND), +) +def test_ren_pool_withdraw_cancellation(ren_pool, ren_token, user, amount, owner): + """ + Test withdraw cancellation happy path. + """ + # Owner locks pool (could be any other user) + ren_token.approve(ren_pool, C.POOL_BOND, {'from': owner}) + ren_pool.deposit(C.POOL_BOND, {'from': owner}) + + # The pool is locked. We can now request withdraw + ren_pool.requestWithdraw(amount, {'from': user}) + + # Make sure the withdraw request exists + assert ren_pool.withdrawRequests(user) == amount + + # Delete the withdraw request + ren_pool.cancelWithdrawRequest({'from': user}) + + # Make sure the withdraw request does not exist anymore + assert ren_pool.withdrawRequests(user) == None