From a3ce0276b2e52987c2f3ff82830c7e5fd01a1685 Mon Sep 17 00:00:00 2001 From: Jonathan Stefanov <38321403+JonathanStefanov@users.noreply.github.com> Date: Fri, 17 Sep 2021 19:29:23 +0200 Subject: [PATCH 1/7] Added cancelWithdrawRequest and tests --- contracts/RenPool.sol | 7 ++++- tests/ren_pool/test_withdraw_cancellation.py | 30 ++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 tests/ren_pool/test_withdraw_cancellation.py diff --git a/contracts/RenPool.sol b/contracts/RenPool.sol index df3eff7..480872a 100644 --- a/contracts/RenPool.sol +++ b/contracts/RenPool.sol @@ -201,7 +201,12 @@ contract RenPool { // TODO emit event } - // TODO: cancelWithdrawRequest + function cancelWithdrawRequest() external { + address sender = msg.sender; + 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..c169f32 --- /dev/null +++ b/tests/ren_pool/test_withdraw_cancellation.py @@ -0,0 +1,30 @@ +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. + """ + user_init_balance = ren_token.balanceOf(user) + + # 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': owner}) + + # Make sure the withdraw request exists + assert ren_pool.withdrawRequests(owner) == amount + + # Delete the withdraw request + ren_pool.cancelWithdrawRequest({'from': owner}) + + # Make sure the withdraw request does not exist anymore + assert ren_pool.withdrawRequests(owner) != amount From 30a846ef451880886b53f69393f16a01b4bb910a Mon Sep 17 00:00:00 2001 From: Jonathan Stefanov <38321403+JonathanStefanov@users.noreply.github.com> Date: Sat, 18 Sep 2021 20:43:19 +0200 Subject: [PATCH 2/7] Added requirements for fulfillWithdrawRequest function --- contracts/RenPool.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/RenPool.sol b/contracts/RenPool.sol index 480872a..6804757 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"); From 805d1321d06e9024f59076d4f5a476033c693317 Mon Sep 17 00:00:00 2001 From: Jonathan Stefanov Date: Sun, 10 Oct 2021 21:50:03 +0200 Subject: [PATCH 3/7] Corrections --- env | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 env diff --git a/env b/env new file mode 100644 index 0000000..f0c1c88 --- /dev/null +++ b/env @@ -0,0 +1,5 @@ +DEFAULT_NETWORK=mainnet-fork +WEB3_INFURA_PROJECT_ID=291119dc87d5477d88eb44697c14b685 +WALLET_PRIVATE_KEY=f08fb5d1dbc23535ae411b83ffc3276dbf4b258435170bcb16882f3fcaa15a0d +WALLET_MNEMONIC=rough truck super garlic swim bronze april phrase maid marine roof label +WALLET_PASSWORD=12345678 From 4c1ed1689bb6351479dbaff1e9480c5c2d12db48 Mon Sep 17 00:00:00 2001 From: Jonathan Stefanov Date: Sun, 10 Oct 2021 21:54:52 +0200 Subject: [PATCH 4/7] Revert "Added requirements for fulfillWithdrawRequest function" This reverts commit 30a846ef451880886b53f69393f16a01b4bb910a. --- contracts/RenPool.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/RenPool.sol b/contracts/RenPool.sol index 6804757..480872a 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]; - require(amount > 0, "Amount has to be positive"); - require(sender != _target, "Sender cannot be yourself"); + // ^ This could not be defined plus make sure amount > 0 + // TODO: make sure user cannot fullfil his own request // TODO: add test for when _target doesn't have an associated withdrawRequest require(isLocked == true, "Pool is not locked"); From 488ebbeb9fda1140dbd3c7cb07d1935269e72613 Mon Sep 17 00:00:00 2001 From: Jonathan Stefanov Date: Sun, 10 Oct 2021 22:04:32 +0200 Subject: [PATCH 5/7] Second correction --- tests/ren_pool/test_withdraw_cancellation.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/ren_pool/test_withdraw_cancellation.py b/tests/ren_pool/test_withdraw_cancellation.py index c169f32..687bad6 100644 --- a/tests/ren_pool/test_withdraw_cancellation.py +++ b/tests/ren_pool/test_withdraw_cancellation.py @@ -11,20 +11,18 @@ def test_ren_pool_withdraw_cancellation(ren_pool, ren_token, user, amount, owner """ Test withdraw cancellation happy path. """ - user_init_balance = ren_token.balanceOf(user) - # 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': owner}) + ren_pool.requestWithdraw(amount, {'from': user}) # Make sure the withdraw request exists - assert ren_pool.withdrawRequests(owner) == amount + assert ren_pool.withdrawRequests(user) == amount # Delete the withdraw request - ren_pool.cancelWithdrawRequest({'from': owner}) + ren_pool.cancelWithdrawRequest({'from': user}) # Make sure the withdraw request does not exist anymore - assert ren_pool.withdrawRequests(owner) != amount + assert ren_pool.withdrawRequests(user) == None From 1a183d5c555b965053a5488c3e5c91569a1180ad Mon Sep 17 00:00:00 2001 From: Jonathan Stefanov Date: Sun, 10 Oct 2021 22:06:08 +0200 Subject: [PATCH 6/7] Changed require in cancelWithdrawRequest method --- contracts/RenPool.sol | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/contracts/RenPool.sol b/contracts/RenPool.sol index 480872a..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"); @@ -203,7 +203,8 @@ contract RenPool { function cancelWithdrawRequest() external { address sender = msg.sender; - require(withdrawRequests[sender] >= 0, "No withdraw request"); + // 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]; } From 120f77349bcd1c388a3023f961845e1f9167c138 Mon Sep 17 00:00:00 2001 From: Jonathan Stefanov <38321403+JonathanStefanov@users.noreply.github.com> Date: Wed, 13 Oct 2021 17:00:41 +0200 Subject: [PATCH 7/7] Delete env --- env | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 env diff --git a/env b/env deleted file mode 100644 index f0c1c88..0000000 --- a/env +++ /dev/null @@ -1,5 +0,0 @@ -DEFAULT_NETWORK=mainnet-fork -WEB3_INFURA_PROJECT_ID=291119dc87d5477d88eb44697c14b685 -WALLET_PRIVATE_KEY=f08fb5d1dbc23535ae411b83ffc3276dbf4b258435170bcb16882f3fcaa15a0d -WALLET_MNEMONIC=rough truck super garlic swim bronze april phrase maid marine roof label -WALLET_PASSWORD=12345678