-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from The-Poolz/issue-44
added MultiWithdraw tests
- Loading branch information
Showing
5 changed files
with
129 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
}) | ||
}) |