-
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?
Conversation
// ^ 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 |
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
// ^ 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 |
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
function cancelWithdrawRequest() external { | ||
address sender = msg.sender; | ||
require(withdrawRequests[sender] >= 0, "No withdraw request"); | ||
|
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'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 comment
The 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.
I could also use msg.sender too of course
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 mean, not sure if we need the require statement here.
Test withdraw cancellation happy path. | ||
""" | ||
user_init_balance = ren_token.balanceOf(user) | ||
|
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.
this variable is not being used
# 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 comment
The reason will be displayed to describe this comment to others. Learn more.
We could use user
instead of owner to be more generic
ren_pool.cancelWithdrawRequest({'from': owner}) | ||
|
||
# Make sure the withdraw request does not exist anymore | ||
assert ren_pool.withdrawRequests(owner) != amount |
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 would say assert ren_pool.withdrawRequests(owner) == Null
or something along those lines to reflect the non existence of the withdrawRequest. Well, actually, I'm not sure the request gets destroyed or is set back to zero (?)
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.
It is set to zero I believe, I'll make some tests and rectify this
No description provided.