-
Notifications
You must be signed in to change notification settings - Fork 0
Added cancelWithdrawRequest and tests #51
base: master
Are you sure you want to change the base?
Changes from all commits
a3ce027
30a846e
805d132
4c1ed16
488ebbe
1a183d5
120f773
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm hesitating if we need the first 2 lines or not. Also, It'd be nice to add tests for this piece of code as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll add the tests, as for the lines sender is used two times in the function so making it a variable makes sence in my opinion. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean, not sure if we need the require statement here. |
||
delete withdrawRequests[sender]; | ||
} | ||
// TODO: getWithdrawRequests | ||
|
||
/** | ||
|
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}) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could use |
||
# 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the third todo is automatically implemented when we test if the amount is positive, what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if I follow. What I was trying to say is: in case we have this situation
_target doesn't have an associated withdrawRequest
then the code should revert. I think your code implements this situation.Now, what I was referring was to add an actual test to the test suit to cover this case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh right, I thought you meant checking it in the smart contract, my bad.
Will definitely implement the test yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will do this in a later PR since it is not related to cancelWithdrawRequest