Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jon cancel withdraw request #29

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions contracts/RenPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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

/**
Expand Down
28 changes: 28 additions & 0 deletions tests/ren_pool/test_withdraw_cancellation.py
Original file line number Diff line number Diff line change
@@ -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