Skip to content

Commit

Permalink
Merge pull request #45 from The-Poolz/issue-44
Browse files Browse the repository at this point in the history
added MultiWithdraw tests
  • Loading branch information
Lomet authored Nov 8, 2022
2 parents 5ad95fe + 467536c commit c1959bf
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 1 deletion.
4 changes: 4 additions & 0 deletions bin/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ cp -a ./node_modules/poolz-multi-sender/contracts/. ./contracts/MultiSender

cp -a ./node_modules/poolz-delay-vault/contracts/. ./contracts/DelayVault

cp -a ./node_modules/poolz-multi-withdraw/contracts/. ./contracts/MultiWithdraw

cp -a ./node_modules/poolz-back/test/General/. ./test/01_PoolzBack

cp -a ./node_modules/poolz-whitelist/test/. ./test/02_WhiteList
Expand All @@ -45,5 +47,7 @@ cp -a ./node_modules/poolz-flex-staking/test/. ./test/FlexStaking
cp -a ./node_modules/poolz-multi-sender/test/. ./test/MultiSender

cp -a ./node_modules/poolz-delay-vault/test/. ./test/DelayVault

cp -a ./node_modules/poolz-multi-withdraw/test/. ./test/MultiWithdraw
#temporary fix for naming error of TestToken in Benefit tests
#sed -i 's/"TestToken"/"Token"/g' test/4_Benefit/test.js
28 changes: 28 additions & 0 deletions contracts/MultiWithdraw/MultiManageable.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "poolz-helper-v2/contracts/GovManager.sol";

contract MultiManageable is GovManager {
constructor() {
maxTransactionLimit = 500;
}

address public LockedDealAddress;
uint256 public maxTransactionLimit;

function setLockedDealAddress(address _LockedDealAddress)
public
onlyOwnerOrGov
{
require(
LockedDealAddress != _LockedDealAddress,
"Can't set the same LockedDeal address"
);
LockedDealAddress = _LockedDealAddress;
}

function setMaxTransactionLimit(uint256 _newLimit) external onlyOwnerOrGov {
maxTransactionLimit = _newLimit;
}
}
32 changes: 32 additions & 0 deletions contracts/MultiWithdraw/MultiWithdraw.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "./MultiManageable.sol";
import "poolz-helper-v2/contracts/interfaces/ILockedDealV2.sol";

/// @author The-Poolz contracts team
contract MultiWithdraw is MultiManageable {
event TokensWithdrawn(uint256[] PoolsIds, uint256 Length);

modifier notZeroAddress(address _LockedDeal) {
require(
_LockedDeal != address(0x0),
"LockedDeal can't be zero address"
);
_;
}

function MultiWithdrawTokens(uint256[] memory _poolIds)
public
notZeroAddress(LockedDealAddress)
{
require(
maxTransactionLimit >= _poolIds.length,
"Max array length limit exceeded"
);
for (uint256 i = 0; i < _poolIds.length; i++) {
ILockedDealV2(LockedDealAddress).WithdrawToken(_poolIds[i]);
}
emit TokensWithdrawn(_poolIds, _poolIds.length);
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"poolz-whitelist-converter": "^1.0.2",
"uniswap-v2-test": "^1.0.2",
"poolz-multi-sender": "1.0.2",
"poolz-delay-vault": "1.0.2"
"poolz-delay-vault": "1.0.2",
"poolz-multi-withdraw": "1.0.0"
},
"devDependencies": {
"@openzeppelin/test-helpers": "^0.5.15",
Expand Down
63 changes: 63 additions & 0 deletions test/18_MultiWithdraw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
const MultiWithdraw = artifacts.require("MultiWithdraw")
const LockedDealV2 = artifacts.require("LockedDealV2")
const TestToken = artifacts.require("ERC20Token")
const timeMachine = require("ganache-time-traveler")
const { assert } = require("chai")
const truffleAssert = require("truffle-assertions")
const constants = require("@openzeppelin/test-helpers/src/constants.js")

contract("MultiWithdraw", (accounts) => {
let multiWithdraw, lockedDealV2, token
const allow = '100', amount = '100000'
const owners = [accounts[9], accounts[8], accounts[7], accounts[6], accounts[5]]
let lastPoolId, finishTime

before(async () => {
multiWithdraw = await MultiWithdraw.new()
lockedDealV2 = await LockedDealV2.new()
token = await TestToken.new('TestToken', 'TEST')
})

it('should create mass pools', async () => {
const numberOfPools = 5
await token.approve(lockedDealV2.address, allow * numberOfPools)
let date = new Date()
date.setDate(date.getDate())
let future = Math.floor(date.getTime() / 1000)
const startTimeStamps = []
for(let i = 0; i < owners.length; i++)
startTimeStamps.push(future)
finishTime = future = future + 60 * 60 * 24 * 30
const finishTimeStamps = []
for(let i = 0; i < owners.length; i++)
finishTimeStamps.push(future)
const startAmounts = [allow, allow, allow, allow, allow]
const tx = await lockedDealV2.CreateMassPools(token.address, startTimeStamps, finishTimeStamps, startAmounts, owners, { value: amount * numberOfPools })
lastPoolId = tx.logs[tx.logs.length - 1].args.LastPoolId.toString()
})

it("should mass withdraw", async () => {
await multiWithdraw.setLockedDealAddress(lockedDealV2.address)
let poolIds = []
for(let i = 0; i <= lastPoolId; i++)
poolIds.push(i.toString())
let oldBalances = []
for(let i = 0; i < owners.length; i++) {
oldBalances.push((await token.balanceOf(owners[i])))
}
await timeMachine.advanceBlockAndSetTime(finishTime)
await multiWithdraw.MultiWithdrawTokens(poolIds)
let balances = []
for(let i = 0; i < owners.length; i++) {
balances.push((await token.balanceOf(owners[i])))
}
for(let i = 0; i < owners.length; i++) {
assert.equal(balances[i].toString(), allow.toString())
assert.notEqual(balances[i].toString(), oldBalances[i].toString())
}
})

after(async () => {
await timeMachine.advanceBlockAndSetTime(Math.floor(Date.now() / 1000))
})
})

0 comments on commit c1959bf

Please sign in to comment.