From 015195539a37d30212a8be9ed1935181303a8653 Mon Sep 17 00:00:00 2001 From: Andrew Dmytrenko Date: Wed, 14 Sep 2022 17:33:04 +0300 Subject: [PATCH 1/2] added prettier config, formatted files --- .prettierrc | 28 ++++ contracts/LockedCreation.sol | 53 +++++-- contracts/LockedDealV2.sol | 20 +-- contracts/LockedManageable.sol | 46 +++++- contracts/LockedPoolz.sol | 9 +- package.json | 4 +- test/1_TrustSwap.js | 25 ++-- test/2_CreatePool.js | 89 +++++++---- test/3_FailCreatePool.js | 124 +++++++++++---- test/4_Access.js | 116 +++++++++----- test/5_Managable.js | 24 +-- test/6_Events.js | 266 +++++++++++++++++---------------- 12 files changed, 519 insertions(+), 285 deletions(-) create mode 100644 .prettierrc diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..1751f01 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,28 @@ +{ + "overrides": [ + { + "files": "*.sol", + "options": { + "printWidth": 80, + "tabWidth": 4, + "useTabs": false, + "singleQuote": false, + "bracketSpacing": false, + "explicitTypes": "always" + } + }, + { + "files": "*.js", + "options": { + "printWidth": 120, + "useTabs": false, + "tabWidth": 4, + "semi": false, + "singleQuote": false, + "trailingComma": "none", + "bracketSpacing": true, + "bracketSameLine": true + } + } + ] +} diff --git a/contracts/LockedCreation.sol b/contracts/LockedCreation.sol index 945251b..fcba66a 100644 --- a/contracts/LockedCreation.sol +++ b/contracts/LockedCreation.sol @@ -11,9 +11,12 @@ contract LockedCreation is LockedPoolz { uint256 _FinishTime, //Until what time the pool will end uint256 _StartAmount, //Total amount of the tokens to sell in the pool address _Owner // Who the tokens belong to - ) external payable notZeroAddress(_Owner) returns(uint256) { + ) external payable notZeroAddress(_Owner) returns (uint256) { TransferInToken(_Token, msg.sender, _StartAmount); - if(WhiteList_Address != address(0) && !(isUserWithoutFee(msg.sender) || isTokenWithoutFee(_Token))){ + if ( + WhiteList_Address != address(0) && + !(isUserWithoutFee(msg.sender) || isTokenWithoutFee(_Token)) + ) { PayFee(Fee); } CreatePool(_Token, _StartTime, _FinishTime, _StartAmount, _Owner); @@ -25,7 +28,9 @@ contract LockedCreation is LockedPoolz { uint256[] calldata _FinishTime, uint256[] calldata _StartAmount, address[] calldata _Owner - ) external payable + ) + external + payable isGreaterThanZero(_Owner.length) isBelowLimit(_Owner.length) { @@ -33,12 +38,21 @@ contract LockedCreation is LockedPoolz { require(_StartTime.length == _FinishTime.length, "Date Array Invalid"); require(_Owner.length == _StartAmount.length, "Amount Array Invalid"); TransferInToken(_Token, msg.sender, Array.getArraySum(_StartAmount)); - if(WhiteList_Address != address(0) && !(isUserWithoutFee(msg.sender) || isTokenWithoutFee(_Token))){ + if ( + WhiteList_Address != address(0) && + !(isUserWithoutFee(msg.sender) || isTokenWithoutFee(_Token)) + ) { PayFee(Fee * _Owner.length); } uint256 firstPoolId = Index; - for(uint i=0 ; i < _Owner.length; i++){ - CreatePool(_Token, _StartTime[i], _FinishTime[i], _StartAmount[i], _Owner[i]); + for (uint256 i = 0; i < _Owner.length; i++) { + CreatePool( + _Token, + _StartTime[i], + _FinishTime[i], + _StartAmount[i], + _Owner[i] + ); } uint256 lastPoolId = Index - 1; emit MassPoolsCreated(firstPoolId, lastPoolId); @@ -51,20 +65,35 @@ contract LockedCreation is LockedPoolz { uint256[] calldata _FinishTime, uint256[] calldata _StartAmount, address[] calldata _Owner - ) external payable + ) + external + payable isGreaterThanZero(_StartTime.length) isBelowLimit(_Owner.length * _FinishTime.length) { require(_Owner.length == _StartAmount.length, "Amount Array Invalid"); require(_FinishTime.length == _StartTime.length, "Date Array Invalid"); - TransferInToken(_Token, msg.sender, Array.getArraySum(_StartAmount) * _FinishTime.length); + TransferInToken( + _Token, + msg.sender, + Array.getArraySum(_StartAmount) * _FinishTime.length + ); uint256 firstPoolId = Index; - if(WhiteList_Address != address(0) && !(isUserWithoutFee(msg.sender) || isTokenWithoutFee(_Token))){ + if ( + WhiteList_Address != address(0) && + !(isUserWithoutFee(msg.sender) || isTokenWithoutFee(_Token)) + ) { PayFee(Fee * _Owner.length * _FinishTime.length); } - for(uint i=0 ; i < _FinishTime.length ; i++){ - for(uint j=0 ; j < _Owner.length ; j++){ - CreatePool(_Token, _StartTime[i], _FinishTime[i], _StartAmount[j], _Owner[j]); + for (uint256 i = 0; i < _FinishTime.length; i++) { + for (uint256 j = 0; j < _Owner.length; j++) { + CreatePool( + _Token, + _StartTime[i], + _FinishTime[i], + _StartAmount[j], + _Owner[j] + ); } } uint256 lastPoolId = Index - 1; diff --git a/contracts/LockedDealV2.sol b/contracts/LockedDealV2.sol index 56c6572..18f303e 100644 --- a/contracts/LockedDealV2.sol +++ b/contracts/LockedDealV2.sol @@ -4,15 +4,21 @@ pragma solidity ^0.8.0; import "./LockedPoolzData.sol"; contract LockedDealV2 is LockedPoolzData { - function getWithdrawableAmount(uint256 _PoolId) public view isPoolValid(_PoolId) returns(uint256){ + function getWithdrawableAmount(uint256 _PoolId) + public + view + isPoolValid(_PoolId) + returns (uint256) + { Pool storage pool = AllPoolz[_PoolId]; - if(block.timestamp < pool.StartTime) return 0; - if(pool.FinishTime < block.timestamp) return pool.StartAmount - pool.DebitedAmount; + if (block.timestamp < pool.StartTime) return 0; + if (pool.FinishTime < block.timestamp) + return pool.StartAmount - pool.DebitedAmount; uint256 totalPoolDuration = pool.FinishTime - pool.StartTime; uint256 timePassed = block.timestamp - pool.StartTime; uint256 timePassedPermille = timePassed * 1000; uint256 ratioPermille = timePassedPermille / totalPoolDuration; - uint256 debitableAmount = pool.StartAmount * ratioPermille/ 1000; + uint256 debitableAmount = (pool.StartAmount * ratioPermille) / 1000; return debitableAmount - pool.DebitedAmount; } @@ -28,11 +34,7 @@ contract LockedDealV2 is LockedPoolzData { uint256 tokenAmount = getWithdrawableAmount(_PoolId); uint256 tempDebitAmount = tokenAmount + pool.DebitedAmount; pool.DebitedAmount = tempDebitAmount; - TransferToken( - pool.Token, - pool.Owner, - tokenAmount - ); + TransferToken(pool.Token, pool.Owner, tokenAmount); emit TokenWithdrawn(_PoolId, pool.Owner, tokenAmount); return true; } diff --git a/contracts/LockedManageable.sol b/contracts/LockedManageable.sol index 101e3c7..88fa9ba 100644 --- a/contracts/LockedManageable.sol +++ b/contracts/LockedManageable.sol @@ -6,7 +6,11 @@ import "poolz-helper-v2/contracts/FeeBaseHelper.sol"; import "./LockedDealEvents.sol"; import "./LockedDealModifiers.sol"; -contract LockedManageable is FeeBaseHelper, LockedDealEvents, LockedDealModifiers { +contract LockedManageable is + FeeBaseHelper, + LockedDealEvents, + LockedDealModifiers +{ constructor() { maxTransactionLimit = 400; isTokenFilterOn = false; // disable token filter whitelist @@ -32,19 +36,45 @@ contract LockedManageable is FeeBaseHelper, LockedDealEvents, LockedDealModifier isTokenFilterOn = !isTokenFilterOn; } - function isTokenWithoutFee(address _tokenAddress) notZeroAddress(WhiteList_Address) public view returns(bool) { - return IWhiteList(WhiteList_Address).Check(_tokenAddress, TokenFeeWhiteListId) > 0; + function isTokenWithoutFee(address _tokenAddress) + public + view + notZeroAddress(WhiteList_Address) + returns (bool) + { + return + IWhiteList(WhiteList_Address).Check( + _tokenAddress, + TokenFeeWhiteListId + ) > 0; } - function isTokenWhiteListed(address _tokenAddress) public view returns(bool) { - return !isTokenFilterOn || IWhiteList(WhiteList_Address).Check(_tokenAddress, TokenFilterWhiteListId) > 0; + function isTokenWhiteListed(address _tokenAddress) + public + view + returns (bool) + { + return + !isTokenFilterOn || + IWhiteList(WhiteList_Address).Check( + _tokenAddress, + TokenFilterWhiteListId + ) > + 0; } - function isUserWithoutFee(address _UserAddress) notZeroAddress(WhiteList_Address) public view returns(bool) { - return IWhiteList(WhiteList_Address).Check(_UserAddress, UserWhiteListId) > 0; + function isUserWithoutFee(address _UserAddress) + public + view + notZeroAddress(WhiteList_Address) + returns (bool) + { + return + IWhiteList(WhiteList_Address).Check(_UserAddress, UserWhiteListId) > + 0; } - function setMaxTransactionLimit(uint256 _newLimit) external onlyOwner{ + function setMaxTransactionLimit(uint256 _newLimit) external onlyOwner { maxTransactionLimit = _newLimit; } } diff --git a/contracts/LockedPoolz.sol b/contracts/LockedPoolz.sol index 25504d5..47b57c9 100644 --- a/contracts/LockedPoolz.sol +++ b/contracts/LockedPoolz.sol @@ -46,7 +46,14 @@ contract LockedPoolz is LockedManageable { "StartTime is greater than FinishTime" ); //register the pool - AllPoolz[Index] = Pool(_StartTime, _FinishTime, _StartAmount, 0, _Owner, _Token); + AllPoolz[Index] = Pool( + _StartTime, + _FinishTime, + _StartAmount, + 0, + _Owner, + _Token + ); MyPoolz[_Owner].push(Index); emit NewPoolCreated( Index, diff --git a/package.json b/package.json index a77b75b..69d8611 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "test": "test" }, "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "prettier": "prettier --write contracts/*.sol && prettier --write test/" }, "author": "Ashwin Arora", "license": "MIT", @@ -27,6 +27,8 @@ "chai-as-promised": "^7.1.1", "chai-bignumber": "^2.0.2", "ganache-cli": "^6.12.2", + "prettier": "^2.7.1", + "prettier-plugin-solidity": "^1.0.0-dev.23", "poolz-helper-v2": "^2.0.16", "truffle-plugin-verify": "^0.5.26" } diff --git a/test/1_TrustSwap.js b/test/1_TrustSwap.js index 793c296..5b22e46 100644 --- a/test/1_TrustSwap.js +++ b/test/1_TrustSwap.js @@ -1,21 +1,22 @@ const LockedDealV2 = artifacts.require("LockedDealV2") const TestToken = artifacts.require("ERC20Token") -const { assert } = require('chai') -const constants = require('@openzeppelin/test-helpers/src/constants.js'); +const { assert } = require("chai") +const constants = require("@openzeppelin/test-helpers/src/constants.js") -contract('LockedDealV2', (accounts) => { +contract("LockedDealV2", (accounts) => { let instance, Token - const allow = 1, owner = accounts[2] + const allow = 1, + owner = accounts[2] const date = new Date() before(async () => { instance = await LockedDealV2.deployed() - Token = await TestToken.new('TestToken', 'TEST') + Token = await TestToken.new("TestToken", "TEST") }) - it('Lock 1 test token for account2 from acount 0', async () => { + it("Lock 1 test token for account2 from acount 0", async () => { await Token.approve(instance.address, constants.MAX_UINT256) - date.setDate(date.getDate() + 1) // add a day + date.setDate(date.getDate() + 1) // add a day const startTime = Math.floor(date.getTime() / 1000) const finishTime = startTime + 60 * 60 * 24 * 30 await instance.CreateNewPool(Token.address, startTime, finishTime, allow, owner) @@ -23,14 +24,14 @@ contract('LockedDealV2', (accounts) => { assert.equal(mypoolz.length, 1) }) - it('fail on withdraw from account 2', async () => { + it("fail on withdraw from account 2", async () => { let took = await instance.WithdrawToken.call(0) assert.isFalse(took) }) - it('open new pool for account 1 ', async () => { + it("open new pool for account 1 ", async () => { const date = new Date() - date.setDate(date.getDate() - 1) // sub a day + date.setDate(date.getDate() - 1) // sub a day const startTime = Math.floor(date.getTime() / 1000) const finishTime = startTime + 60 * 60 * 24 * 30 await instance.CreateNewPool(Token.address, startTime, finishTime, allow, accounts[1]) @@ -38,8 +39,8 @@ contract('LockedDealV2', (accounts) => { assert.equal(mypoolz.length, 1) }) - it('withdraw from account 1', async () => { + it("withdraw from account 1", async () => { let took = await instance.WithdrawToken.call(1) assert.isTrue(took) }) -}) \ No newline at end of file +}) diff --git a/test/2_CreatePool.js b/test/2_CreatePool.js index 8a22317..95553df 100644 --- a/test/2_CreatePool.js +++ b/test/2_CreatePool.js @@ -1,34 +1,37 @@ const LockedDealV2 = artifacts.require("LockedDealV2") const TestToken = artifacts.require("ERC20Token") -const { assert } = require('chai') -const constants = require('@openzeppelin/test-helpers/src/constants.js'); +const { assert } = require("chai") +const constants = require("@openzeppelin/test-helpers/src/constants.js") -contract('Create Pool', accounts => { +contract("Create Pool", (accounts) => { let instance, Token let invalidToken, poolId let startTime, finishTime - const owner = accounts[1], fromAddress = accounts[0] + const owner = accounts[1], + fromAddress = accounts[0] const allow = 100 before(async () => { instance = await LockedDealV2.new() - Token = await TestToken.new('TestToken', 'TEST') - invalidToken = await TestToken.new('InvalidToken', 'TEST') + Token = await TestToken.new("TestToken", "TEST") + invalidToken = await TestToken.new("InvalidToken", "TEST") }) - it('should create a single new pool', async () => { + it("should create a single new pool", async () => { await Token.approve(instance.address, constants.MAX_UINT256, { from: fromAddress }) let date = new Date() date.setDate(date.getDate() + 1) startTime = Math.floor(date.getTime() / 1000) finishTime = startTime + 60 * 60 * 24 * 30 - const tx = await instance.CreateNewPool(Token.address, startTime, finishTime, allow, owner, { from: fromAddress }) + const tx = await instance.CreateNewPool(Token.address, startTime, finishTime, allow, owner, { + from: fromAddress + }) poolId = tx.logs[1].args.PoolId const result = await instance.AllPoolz(poolId, { from: owner }) assert.equal(result[4], owner) }) - it('should create pools in mass', async () => { + it("should create pools in mass", async () => { const allow = 100 const numberOfPools = 5 let date = new Date() @@ -49,22 +52,29 @@ contract('Create Pool', accounts => { finishTimeStamps.push(future - 7200) const startAmounts = [allow, allow, allow, allow, allow] const owners = [accounts[9], accounts[8], accounts[7], accounts[6], accounts[5]] - const tx = await instance.CreateMassPools(Token.address, startTimeStamps, finishTimeStamps, startAmounts, owners, { from: fromAddress }) + const tx = await instance.CreateMassPools( + Token.address, + startTimeStamps, + finishTimeStamps, + startAmounts, + owners, + { from: fromAddress } + ) const firstPoolId = tx.logs[tx.logs.length - 1].args.FirstPoolId.toString() const lastPoolId = tx.logs[tx.logs.length - 1].args.LastPoolId.toString() const pids = [] - tx.logs.forEach(element => { - if (element.event === 'NewPoolCreated') { + tx.logs.forEach((element) => { + if (element.event === "NewPoolCreated") { pids.push(element.args.PoolId.toString()) } - }); - assert.equal(firstPoolId, '1') + }) + assert.equal(firstPoolId, "1") assert.equal(lastPoolId, numberOfPools.toString()) assert.equal(pids.length, numberOfPools) assert.equal(pids.length, lastPoolId - firstPoolId + 1) }) - it('should create pools with respect to finish time', async () => { + it("should create pools with respect to finish time", async () => { const allow = 100 const numberOfOwners = 3 const numberOfTimestamps = 6 @@ -72,34 +82,43 @@ contract('Create Pool', accounts => { date.setDate(date.getDate() + 1) let future = Math.floor(date.getTime() / 1000) const startTimeStamps = [] - for (let i = 1; i <= numberOfTimestamps; i++) { // generating array of length 5 + for (let i = 1; i <= numberOfTimestamps; i++) { + // generating array of length 5 startTimeStamps.push(future + 3600 * i) } future = future + 60 * 60 * 24 * 30 const finishTimeStamps = [] - for (let i = 1; i <= numberOfTimestamps; i++) { // generating array of length 5 + for (let i = 1; i <= numberOfTimestamps; i++) { + // generating array of length 5 finishTimeStamps.push(future + 3600 * i) } const startAmounts = [allow, allow, allow] const owners = [accounts[9], accounts[8], accounts[7]] // const result = await instance.CreatePoolsWrtTime.call(Token.address, startTimeStamps, startAmounts, owners, {from: fromAddress}) - const tx = await instance.CreatePoolsWrtTime(Token.address, startTimeStamps, finishTimeStamps, startAmounts, owners, { from: fromAddress }) + const tx = await instance.CreatePoolsWrtTime( + Token.address, + startTimeStamps, + finishTimeStamps, + startAmounts, + owners, + { from: fromAddress } + ) const firstPoolId = tx.logs[tx.logs.length - 1].args.FirstPoolId.toString() const lastPoolId = tx.logs[tx.logs.length - 1].args.LastPoolId.toString() const pids = [] - tx.logs.forEach(element => { - if (element.event === 'NewPoolCreated') { + tx.logs.forEach((element) => { + if (element.event === "NewPoolCreated") { pids.push(element.args.PoolId.toString()) } - }); - assert.equal(firstPoolId, '6') + }) + assert.equal(firstPoolId, "6") assert.equal(lastPoolId, (numberOfOwners * numberOfTimestamps + parseInt(firstPoolId) - 1).toString()) assert.equal(pids.length, numberOfOwners * numberOfTimestamps) assert.equal(pids.length, lastPoolId - firstPoolId + 1) poolId = lastPoolId }) - it('should get all my pools ids by token', async () => { + it("should get all my pools ids by token", async () => { let result = await instance.GetMyPoolsIdByToken(accounts[1], [Token.address], { from: accounts[1] }) assert.equal(result.toString(), [0]) @@ -109,10 +128,14 @@ contract('Create Pool', accounts => { result = await instance.GetMyPoolsIdByToken(accounts[8], [Token.address], { from: accounts[8] }) assert.equal(result.toString(), [2, 7, 10, 13, 16, 19, 22]) - result = await instance.GetMyPoolsIdByToken(accounts[9], [Token.address, invalidToken.address], { from: accounts[9] }) + result = await instance.GetMyPoolsIdByToken(accounts[9], [Token.address, invalidToken.address], { + from: accounts[9] + }) assert.equal(result.toString(), [1, 6, 9, 12, 15, 18, 21]) - result = await instance.GetMyPoolsIdByToken(accounts[6], [Token.address, invalidToken.address], { from: accounts[6] }) + result = await instance.GetMyPoolsIdByToken(accounts[6], [Token.address, invalidToken.address], { + from: accounts[6] + }) assert.equal(result.toString(), [4]) result = await instance.GetMyPoolsIdByToken(accounts[5], [Token.address], { from: accounts[5] }) @@ -122,7 +145,7 @@ contract('Create Pool', accounts => { assert.equal(result.toString(), []) }) - it('should get pools data by ids', async () => { + it("should get pools data by ids", async () => { const result = await instance.GetPoolsData([0], { from: accounts[1] }) assert.equal(1, result.length) assert.equal(startTime, result[0].StartTime) @@ -132,8 +155,8 @@ contract('Create Pool', accounts => { assert.equal(accounts[1], result[0].Owner) assert.equal(Token.address, result[0].Token) }) - - it('should transfer locked pool', async () => { + + it("should transfer locked pool", async () => { const owner = accounts[7] const newOwner = accounts[2] const result = await instance.PoolTransfer(poolId, newOwner, { from: owner }) @@ -142,17 +165,17 @@ contract('Create Pool', accounts => { assert.equal(result.logs[result.logs.length - 1].args.OldOwner.toString(), owner) assert.equal(result.logs[result.logs.length - 1].args.NewOwner.toString(), newOwner.toString()) }) - - it('should get my pools data by token', async () => { + + it("should get my pools data by token", async () => { const owner = accounts[4] - const result = await instance.GetMyPoolDataByToken(owner, [Token.address], {from: owner}) + const result = await instance.GetMyPoolDataByToken(owner, [Token.address], { from: owner }) assert.equal(result.length, 0) let date = new Date() date.setDate(date.getDate() + 1) startTime = Math.floor(date.getTime() / 1000) finishTime = startTime + 60 * 60 * 24 * 30 await instance.CreateNewPool(Token.address, startTime, finishTime, allow, owner) - const data = await instance.GetMyPoolDataByToken(owner, [Token.address], {from: owner}) + const data = await instance.GetMyPoolDataByToken(owner, [Token.address], { from: owner }) assert.equal(1, data.length) assert.equal(startTime, data[0].StartTime) assert.equal(finishTime, data[0].FinishTime) @@ -161,4 +184,4 @@ contract('Create Pool', accounts => { assert.equal(owner, data[0].Owner) assert.equal(Token.address, data[0].Token) }) -}) \ No newline at end of file +}) diff --git a/test/3_FailCreatePool.js b/test/3_FailCreatePool.js index f5c6f5c..66e9624 100644 --- a/test/3_FailCreatePool.js +++ b/test/3_FailCreatePool.js @@ -1,17 +1,19 @@ const LockedDealV2 = artifacts.require("LockedDealV2") const TestToken = artifacts.require("ERC20Token") -const truffleAssert = require('truffle-assertions') -const constants = require('@openzeppelin/test-helpers/src/constants.js'); +const truffleAssert = require("truffle-assertions") +const constants = require("@openzeppelin/test-helpers/src/constants.js") -contract('Fail Create Pool', accounts => { - let instance, Token, fromAddress = accounts[0] +contract("Fail Create Pool", (accounts) => { + let instance, + Token, + fromAddress = accounts[0] let date, future, startTime, finishTime const allow = 100 const owner = accounts[6] before(async () => { instance = await LockedDealV2.new() - Token = await TestToken.new('TestToken', 'TEST') + Token = await TestToken.new("TestToken", "TEST") date = new Date() date.setDate(date.getDate() + 1) future = Math.floor(date.getTime() / 1000) @@ -19,56 +21,121 @@ contract('Fail Create Pool', accounts => { finishTime = future + 60 * 60 * 24 * 30 }) - it('Fail to Create Pool when approval is not given', async () => { - await truffleAssert.reverts(instance.CreateNewPool(Token.address, startTime, finishTime, allow, fromAddress, { from: fromAddress }), "no allowance") + it("Fail to Create Pool when approval is not given", async () => { + await truffleAssert.reverts( + instance.CreateNewPool(Token.address, startTime, finishTime, allow, fromAddress, { from: fromAddress }), + "no allowance" + ) }) - it('Failed to get data when pool does not exist', async () => { + it("Failed to get data when pool does not exist", async () => { await truffleAssert.reverts(instance.GetPoolsData([55], { from: accounts[1] }), "Pool does not exist") }) - it('Fail to Create Pool when StartTime is greater than FinishTime', async () => { + it("Fail to Create Pool when StartTime is greater than FinishTime", async () => { date = new Date() date.setDate(date.getDate() + 1) startTime = Math.floor(date.getTime() / 1000) finishTime = startTime - 1 await Token.approve(instance.address, constants.MAX_UINT256, { from: fromAddress }) - await truffleAssert.reverts(instance.CreateNewPool(Token.address, startTime, finishTime, allow, fromAddress, { from: fromAddress }), "StartTime is greater than FinishTime") + await truffleAssert.reverts( + instance.CreateNewPool(Token.address, startTime, finishTime, allow, fromAddress, { from: fromAddress }), + "StartTime is greater than FinishTime" + ) }) - it('Fail to Create Mass Pool when array length not equal', async () => { + it("Fail to Create Mass Pool when array length not equal", async () => { await truffleAssert.reverts( - instance.CreateMassPools(Token.address, [startTime,startTime], [finishTime,finishTime], [allow, allow], [accounts[0]], { from: fromAddress }), "Date Array Invalid") + instance.CreateMassPools( + Token.address, + [startTime, startTime], + [finishTime, finishTime], + [allow, allow], + [accounts[0]], + { from: fromAddress } + ), + "Date Array Invalid" + ) await truffleAssert.reverts( - instance.CreateMassPools(Token.address, [startTime], [finishTime, finishTime], [allow, allow], [accounts[0], accounts[1]], { from: fromAddress }), "Date Array Invalid") + instance.CreateMassPools( + Token.address, + [startTime], + [finishTime, finishTime], + [allow, allow], + [accounts[0], accounts[1]], + { from: fromAddress } + ), + "Date Array Invalid" + ) await truffleAssert.reverts( - instance.CreateMassPools(Token.address, [startTime, startTime], [finishTime, finishTime], [allow], [accounts[0], accounts[1]], { from: fromAddress }), "Amount Array Invalid") + instance.CreateMassPools( + Token.address, + [startTime, startTime], + [finishTime, finishTime], + [allow], + [accounts[0], accounts[1]], + { from: fromAddress } + ), + "Amount Array Invalid" + ) }) - it('Fail to Create Wrt Time Pool when array length not equal', async () => { + it("Fail to Create Wrt Time Pool when array length not equal", async () => { await truffleAssert.reverts( - instance.CreatePoolsWrtTime(Token.address, [startTime, startTime], [finishTime, finishTime], [allow], [accounts[0], accounts[1]], { from: fromAddress }), "Amount Array Invalid") + instance.CreatePoolsWrtTime( + Token.address, + [startTime, startTime], + [finishTime, finishTime], + [allow], + [accounts[0], accounts[1]], + { from: fromAddress } + ), + "Amount Array Invalid" + ) await truffleAssert.reverts( - instance.CreatePoolsWrtTime(Token.address, [startTime], [finishTime, finishTime], [allow, allow], [accounts[0], accounts[1]], { from: fromAddress }), "Date Array Invalid") + instance.CreatePoolsWrtTime( + Token.address, + [startTime], + [finishTime, finishTime], + [allow, allow], + [accounts[0], accounts[1]], + { from: fromAddress } + ), + "Date Array Invalid" + ) }) - it('Fail to Create Pool when Time array length is Zero', async () => { - await truffleAssert.reverts(instance.CreatePoolsWrtTime(Token.address, [], [], [100], [accounts[6]], { from: fromAddress }), "Array length should be greater than zero") + it("Fail to Create Pool when Time array length is Zero", async () => { + await truffleAssert.reverts( + instance.CreatePoolsWrtTime(Token.address, [], [], [100], [accounts[6]], { from: fromAddress }), + "Array length should be greater than zero" + ) }) - it('Fail to Create Pool when maxTransactionLimit is exceeded', async () => { - let ownerArray = [], startArray = [], finishArray = [], amountArray = [] + it("Fail to Create Pool when maxTransactionLimit is exceeded", async () => { + let ownerArray = [], + startArray = [], + finishArray = [], + amountArray = [] for (let i = 0; i < 401; i++) { ownerArray.push(owner) startArray.push(future) finishArray.push(future + 60 * 60 * 24) amountArray.push(allow) } - await truffleAssert.reverts(instance.CreateMassPools(Token.address, startArray, finishArray, amountArray, ownerArray, { from: fromAddress }), "Max array length limit exceeded") + await truffleAssert.reverts( + instance.CreateMassPools(Token.address, startArray, finishArray, amountArray, ownerArray, { + from: fromAddress + }), + "Max array length limit exceeded" + ) }) - it('Fail to Create Pool wrt Time when max limit is exceeded', async () => { - let ownerArray = [], startTime = [], finishTime = [], amountArray = [] + it("Fail to Create Pool wrt Time when max limit is exceeded", async () => { + let ownerArray = [], + startTime = [], + finishTime = [], + amountArray = [] for (let i = 0; i < 41; i++) { ownerArray.push(owner) amountArray.push(allow) @@ -77,6 +144,11 @@ contract('Fail Create Pool', accounts => { startTime.push(future + i * 3600) finishTime.push(future + i * 3600 + 60 * 60) } - await truffleAssert.reverts(instance.CreatePoolsWrtTime(Token.address, startTime, finishTime, amountArray, ownerArray, { from: fromAddress }), "Max array length limit exceeded") + await truffleAssert.reverts( + instance.CreatePoolsWrtTime(Token.address, startTime, finishTime, amountArray, ownerArray, { + from: fromAddress + }), + "Max array length limit exceeded" + ) }) -}) \ No newline at end of file +}) diff --git a/test/4_Access.js b/test/4_Access.js index c2a4c43..cb20dee 100644 --- a/test/4_Access.js +++ b/test/4_Access.js @@ -1,16 +1,21 @@ const LockedDealV2 = artifacts.require("LockedDealV2") const TestToken = artifacts.require("ERC20Token") -const { assert } = require('chai') -const timeMachine = require('ganache-time-traveler') -const truffleAssert = require('truffle-assertions') -const constants = require('@openzeppelin/test-helpers/src/constants.js'); - -contract('Access to Locked Deal', accounts => { - let instance, Token, fromAddress = accounts[0], owner = accounts[9], poolId, allow = 100 +const { assert } = require("chai") +const timeMachine = require("ganache-time-traveler") +const truffleAssert = require("truffle-assertions") +const constants = require("@openzeppelin/test-helpers/src/constants.js") + +contract("Access to Locked Deal", (accounts) => { + let instance, + Token, + fromAddress = accounts[0], + owner = accounts[9], + poolId, + allow = 100 before(async () => { instance = await LockedDealV2.new() - Token = await TestToken.new('TestToken', 'TEST') + Token = await TestToken.new("TestToken", "TEST") await Token.approve(instance.address, constants.MAX_UINT256, { from: fromAddress }) let date = new Date() date.setDate(date.getDate() + 1) @@ -22,11 +27,13 @@ contract('Access to Locked Deal', accounts => { date.setDate(date.getDate() + 1) startTime = Math.floor(date.getTime() / 1000) finishTime = startTime + 60 * 60 * 24 * 30 - const tx = await instance.CreateNewPool(Token.address, startTime, finishTime, allow, owner, { from: fromAddress }) + const tx = await instance.CreateNewPool(Token.address, startTime, finishTime, allow, owner, { + from: fromAddress + }) poolId = tx.logs[1].args.PoolId }) - it('Pool Transfer', async () => { + it("Pool Transfer", async () => { const newOwner = accounts[8] poolId = 1 await instance.PoolTransfer(poolId, newOwner, { from: owner }) @@ -38,7 +45,7 @@ contract('Access to Locked Deal', accounts => { owner = newOwner }) - it('Split Pool Amount with owner address', async () => { + it("Split Pool Amount with owner address", async () => { const amount = 25 allow = allow - amount // const tx = await instance.SplitPoolAmount.call(poolId, amount, owner, {from: owner}) @@ -53,7 +60,7 @@ contract('Access to Locked Deal', accounts => { assert.equal(newPool[2], amount) }) - it('Split Pool Amount with new address', async () => { + it("Split Pool Amount with new address", async () => { const amount = 25 allow = allow - amount const approvedAddress = accounts[7] @@ -65,7 +72,7 @@ contract('Access to Locked Deal', accounts => { assert.equal(newPool[2], amount) }) - it('returns new pool id', async () => { + it("returns new pool id", async () => { const amount = 10 allow = allow - amount const pid = await instance.SplitPoolAmount.call(poolId, amount, owner, { from: owner }) @@ -73,15 +80,16 @@ contract('Access to Locked Deal', accounts => { assert.equal(pid.toString(), tx.logs[0].args.PoolId.toString()) }) - describe('Giving approval and splitting pool', () => { - const approvalAmount = 10, spender = accounts[1] + describe("Giving approval and splitting pool", () => { + const approvalAmount = 10, + spender = accounts[1] // it('print all data', async () => { // const data = await instance.AllPoolz(poolId, {from: owner}) // console.log(data[1].toString()) // }) - it('giving approval', async () => { + it("giving approval", async () => { await instance.ApproveAllowance(poolId, approvalAmount, spender, { from: owner }) const amount = await instance.Allowance(poolId, spender) const dataOwner = await instance.AllPoolz(poolId, { from: owner }) @@ -90,7 +98,7 @@ contract('Access to Locked Deal', accounts => { assert.deepEqual(dataOwner, dataSpender) }) - it('spliting pool from approved address', async () => { + it("spliting pool from approved address", async () => { const newOwner = accounts[2] const tx = await instance.SplitPoolAmountFrom(poolId, approvalAmount, newOwner, { from: spender }) const newPoolId = tx.logs[0].args.PoolId @@ -99,55 +107,82 @@ contract('Access to Locked Deal', accounts => { }) }) - describe('Fail Tests', () => { - it('Fail to transfer ownership when called from wrong address', async () => { - await truffleAssert.reverts(instance.PoolTransfer(poolId, accounts[5], { from: fromAddress }), "You are not Pool Owner") - await truffleAssert.reverts(instance.PoolTransfer(poolId, accounts[8], { from: accounts[8] }), "Can't be the same owner") + describe("Fail Tests", () => { + it("Fail to transfer ownership when called from wrong address", async () => { + await truffleAssert.reverts( + instance.PoolTransfer(poolId, accounts[5], { from: fromAddress }), + "You are not Pool Owner" + ) + await truffleAssert.reverts( + instance.PoolTransfer(poolId, accounts[8], { from: accounts[8] }), + "Can't be the same owner" + ) }) - it('Fail to transfer ownership when past finish time', async () =>{ + it("Fail to transfer ownership when past finish time", async () => { let date = new Date() date.setDate(date.getDate() + 1) let startTime = Math.floor(date.getTime() / 1000) let finishTime = startTime + 60 * 60 * 24 * 30 - const tx = await instance.CreateNewPool(Token.address, startTime, finishTime, allow, owner, { from: fromAddress }) + const tx = await instance.CreateNewPool(Token.address, startTime, finishTime, allow, owner, { + from: fromAddress + }) poolId = tx.logs[1].args.PoolId await timeMachine.advanceBlockAndSetTime(finishTime + 1) - await truffleAssert.reverts(instance.PoolTransfer(poolId, accounts[0], { from: owner }), "Can't create with past finish time") + await truffleAssert.reverts( + instance.PoolTransfer(poolId, accounts[0], { from: owner }), + "Can't create with past finish time" + ) await timeMachine.advanceBlockAndSetTime(Math.floor(Date.now() / 1000)) - }) + }) - it('Fail to Create Pool with 0 address owner', async () => { + it("Fail to Create Pool with 0 address owner", async () => { const allow = 100 let date = new Date() date.setDate(date.getDate() + 1) const startTime = Math.floor(date.getTime() / 1000) const finishTime = startTime + 60 * 60 * 24 - await truffleAssert.reverts(instance.CreateNewPool(Token.address, startTime, finishTime, allow, constants.ZERO_ADDRESS, { from: fromAddress }), "Zero Address is not allowed") + await truffleAssert.reverts( + instance.CreateNewPool(Token.address, startTime, finishTime, allow, constants.ZERO_ADDRESS, { + from: fromAddress + }), + "Zero Address is not allowed" + ) }) - it('Fail to transfer ownership to 0 address', async () => { - await truffleAssert.reverts(instance.PoolTransfer(poolId, constants.ZERO_ADDRESS, { from: owner }), "Zero Address is not allowed") + it("Fail to transfer ownership to 0 address", async () => { + await truffleAssert.reverts( + instance.PoolTransfer(poolId, constants.ZERO_ADDRESS, { from: owner }), + "Zero Address is not allowed" + ) }) - it('Fail to split pool when balance is not enough', async () => { + it("Fail to split pool when balance is not enough", async () => { const data = await instance.AllPoolz(poolId, { from: owner }) const amount = data[1] + 1 - await truffleAssert.reverts(instance.SplitPoolAmount(poolId, amount, owner, { from: owner }), "Not Enough Amount Balance") + await truffleAssert.reverts( + instance.SplitPoolAmount(poolId, amount, owner, { from: owner }), + "Not Enough Amount Balance" + ) }) - - it('Not enough Allowance when split pool amount', async () => { + it("Not enough Allowance when split pool amount", async () => { const approvalAmount = 100 - await truffleAssert.reverts(instance.SplitPoolAmountFrom(poolId, approvalAmount, accounts[2], { from: owner }), "Not enough Allowance") + await truffleAssert.reverts( + instance.SplitPoolAmountFrom(poolId, approvalAmount, accounts[2], { from: owner }), + "Not enough Allowance" + ) }) - it('Fail to execute when Pool ID is invalid', async () => { + it("Fail to execute when Pool ID is invalid", async () => { const invalidId = 99 - await truffleAssert.reverts(instance.PoolTransfer(invalidId, accounts[5], { from: owner }), "Pool does not exist") + await truffleAssert.reverts( + instance.PoolTransfer(invalidId, accounts[5], { from: owner }), + "Pool does not exist" + ) }) - it('Failed to split pool after withdrawing', async () => { + it("Failed to split pool after withdrawing", async () => { const date = new Date() date.setDate(date.getDate() + 1) const startTime = Math.floor(date.getTime() / 1000) @@ -156,8 +191,11 @@ contract('Access to Locked Deal', accounts => { await instance.WithdrawToken(poolId) const data = await instance.AllPoolz(poolId, { from: owner }) const amount = data[3] - await truffleAssert.reverts(instance.SplitPoolAmount(poolId, amount, owner, { from: owner }), "Pool is Unlocked") + await truffleAssert.reverts( + instance.SplitPoolAmount(poolId, amount, owner, { from: owner }), + "Pool is Unlocked" + ) await timeMachine.advanceBlockAndSetTime(Math.floor(Date.now() / 1000)) }) }) -}) \ No newline at end of file +}) diff --git a/test/5_Managable.js b/test/5_Managable.js index ada3dcd..58b4809 100644 --- a/test/5_Managable.js +++ b/test/5_Managable.js @@ -1,8 +1,8 @@ const LockedDealV2 = artifacts.require("LockedDealV2") const TestToken = artifacts.require("ERC20Token") -const { assert } = require('chai') +const { assert } = require("chai") -contract('Managable', accounts => { +contract("Managable", (accounts) => { let instance, ownerAddress let testToken @@ -10,61 +10,61 @@ contract('Managable', accounts => { instance = await LockedDealV2.new() const owner = await instance.owner() ownerAddress = owner.toString() - testToken = await TestToken.new("test", 'tst') + testToken = await TestToken.new("test", "tst") }) - it('should set whitelist address', async () => { + it("should set whitelist address", async () => { const whiteListAddress = accounts[9] await instance.setWhiteListAddress(whiteListAddress, { from: ownerAddress }) const address = await instance.WhiteList_Address() assert.equal(whiteListAddress, address) }) - it('should set WhiteListId', async () => { + it("should set WhiteListId", async () => { const whiteListId = 1 await instance.setTokenFeeWhiteListId(whiteListId, { from: ownerAddress }) const id = await instance.TokenFeeWhiteListId() assert.equal(whiteListId, id) }) - it('should swap token filter', async () => { + it("should swap token filter", async () => { const currentFilter = await instance.isTokenFilterOn() await instance.swapTokenFilter({ from: ownerAddress }) const newFilter = await instance.isTokenFilterOn() assert.equal(currentFilter, !newFilter) }) - it('should set max transaction limit', async () => { + it("should set max transaction limit", async () => { const newLimit = 300 await instance.setMaxTransactionLimit(newLimit, { from: ownerAddress }) const limit = await instance.maxTransactionLimit() assert.equal(newLimit, limit) }) - it('should set fee', async () => { + it("should set fee", async () => { const newFee = 30 await instance.SetFeeAmount(newFee, { from: ownerAddress }) const fee = await instance.Fee() assert.equal(newFee, fee) }) - it('should set POZ token', async () => { + it("should set POZ token", async () => { await instance.SetFeeToken(testToken.address, { from: ownerAddress }) const FeeToken = await instance.FeeToken() assert.equal(FeeToken, testToken.address) }) - it('should set token filter whitelist id', async () =>{ + it("should set token filter whitelist id", async () => { const whiteListId = 2 await instance.setTokenFilterWhiteListId(whiteListId, { from: ownerAddress }) const id = await instance.TokenFilterWhiteListId() assert.equal(whiteListId, id) }) - it('should set token filter whitelist id', async () =>{ + it("should set token filter whitelist id", async () => { const whiteListId = 3 await instance.setUserWhiteListId(whiteListId, { from: ownerAddress }) const id = await instance.UserWhiteListId() assert.equal(whiteListId, id) }) -}) \ No newline at end of file +}) diff --git a/test/6_Events.js b/test/6_Events.js index c4de09f..8a06e64 100644 --- a/test/6_Events.js +++ b/test/6_Events.js @@ -1,137 +1,139 @@ -const LockedDealV2 = artifacts.require("LockedDealV2"); -const TestToken = artifacts.require("ERC20Token"); -const truffleAssert = require('truffle-assertions'); -const constants = require('@openzeppelin/test-helpers/src/constants.js'); +const LockedDealV2 = artifacts.require("LockedDealV2") +const TestToken = artifacts.require("ERC20Token") +const truffleAssert = require("truffle-assertions") +const constants = require("@openzeppelin/test-helpers/src/constants.js") -contract('Pools - events', (accounts) => { - let lockedDeal; - let testToken; +contract("Pools - events", (accounts) => { + let lockedDeal + let testToken - let fromAddress = accounts[0]; - let owner = accounts[9]; + let fromAddress = accounts[0] + let owner = accounts[9] - let poolId; - let allow = 100; - let result; - - before(async () => { - lockedDeal = await LockedDealV2.new(); - testToken = await TestToken.new("test", 'tst'); - await testToken.approve(lockedDeal.address, constants.MAX_UINT256, { from: fromAddress }); - }); - - describe('TokenWithdrawn event is emitted', async () => { - - before(async () => { - let date = new Date(); - date.setDate(date.getDate() - 1); - const startTime = Math.floor(date.getTime() / 1000); - const finishTime = startTime + 60 * 60 * 24 - - const tx = await lockedDeal.CreateNewPool(testToken.address, startTime, finishTime, allow, owner, { from: fromAddress }); - poolId = tx.logs[1].args.PoolId; - }); - - it('TokenWithdrawn event is emitted', async () => { - result = await lockedDeal.WithdrawToken(poolId.toNumber()); - // Check event - truffleAssert.eventEmitted(result, 'TokenWithdrawn'); - }); - - }); - - describe('NewPoolCreated event is emitted', async () => { - - before(async () => { - let date = new Date(); - date.setDate(date.getDate() + 1); - - const startTime = Math.floor(date.getTime() / 1000); - const finishTime = startTime + 60 * 60 * 24 - const owner = accounts[1]; - const tx = await lockedDeal.CreateNewPool(testToken.address, startTime, finishTime, allow, owner, { from: fromAddress }); - - result = tx; - }); - - it('NewPoolCreated event is emitted', async () => { - // Check event - truffleAssert.eventEmitted(result, 'NewPoolCreated'); - }); - - }); - - describe('Pool transfer event is emitted', async () => { + let poolId + let allow = 100 + let result before(async () => { - let date = new Date(); - date.setDate(date.getDate() + 1); - - let startTime = Math.floor(date.getTime() / 1000); - let finishTime = startTime + 60 * 60 * 24 - await lockedDeal.CreateNewPool(testToken.address, startTime, finishTime, allow, owner, { from: fromAddress }); - date.setDate(date.getDate() + 1); - startTime = Math.floor(date.getTime() / 1000); - finishTime = startTime + 60 * 60 * 24 - const tx = await lockedDeal.CreateNewPool(testToken.address, startTime, finishTime, allow, owner, { from: fromAddress }); - poolId = tx.logs[1].args.PoolId; - }); - - it('Pool transfer event is emitted', async () => { - const newOwner = accounts[8]; - - result = await lockedDeal.PoolTransfer(poolId, newOwner, { from: owner }); - // Check event - truffleAssert.eventEmitted(result, 'PoolTransferred'); - }); - - }); - - describe('PoolApproval event is emitted', async () => { - - const approvalAmount = 10; - const spender = accounts[1]; - - before(async () => { - let date = new Date(); - date.setDate(date.getDate() + 1); - - const startTime = Math.floor(date.getTime() / 1000); - const finishTime = startTime + 60 * 60 * 24 - const tx = await lockedDeal.CreateNewPool(testToken.address, startTime, finishTime, allow, owner, { from: fromAddress }); - poolId = tx.logs[1].args.PoolId; - }); - - it('PoolApproval event is emitted', async () => { - result = await lockedDeal.ApproveAllowance(poolId, approvalAmount, spender, { from: owner }); - // Check event - truffleAssert.eventEmitted(result, 'PoolApproval'); - }); - - }); - - describe('PoolSplit event is emitted', async () => { - const amount = 10; - - before(async () => { - allow -= amount; - - let date = new Date(); - date.setDate(date.getDate() + 1); - - const startTime = Math.floor(date.getTime() / 1000); - const finishTime = startTime + 60 * 60 * 24 - - const tx = await lockedDeal.CreateNewPool(testToken.address, startTime, finishTime, allow, owner, { from: fromAddress }); - poolId = tx.logs[1].args.PoolId; - }); - - it('PoolSplit event is emitted', async () => { - result = await lockedDeal.SplitPoolAmount(poolId, amount, owner, { from: owner }); - // Check event - truffleAssert.eventEmitted(result, 'PoolSplit'); - }); - - }); - -}); \ No newline at end of file + lockedDeal = await LockedDealV2.new() + testToken = await TestToken.new("test", "tst") + await testToken.approve(lockedDeal.address, constants.MAX_UINT256, { from: fromAddress }) + }) + + describe("TokenWithdrawn event is emitted", async () => { + before(async () => { + let date = new Date() + date.setDate(date.getDate() - 1) + const startTime = Math.floor(date.getTime() / 1000) + const finishTime = startTime + 60 * 60 * 24 + + const tx = await lockedDeal.CreateNewPool(testToken.address, startTime, finishTime, allow, owner, { + from: fromAddress + }) + poolId = tx.logs[1].args.PoolId + }) + + it("TokenWithdrawn event is emitted", async () => { + result = await lockedDeal.WithdrawToken(poolId.toNumber()) + // Check event + truffleAssert.eventEmitted(result, "TokenWithdrawn") + }) + }) + + describe("NewPoolCreated event is emitted", async () => { + before(async () => { + let date = new Date() + date.setDate(date.getDate() + 1) + + const startTime = Math.floor(date.getTime() / 1000) + const finishTime = startTime + 60 * 60 * 24 + const owner = accounts[1] + const tx = await lockedDeal.CreateNewPool(testToken.address, startTime, finishTime, allow, owner, { + from: fromAddress + }) + + result = tx + }) + + it("NewPoolCreated event is emitted", async () => { + // Check event + truffleAssert.eventEmitted(result, "NewPoolCreated") + }) + }) + + describe("Pool transfer event is emitted", async () => { + before(async () => { + let date = new Date() + date.setDate(date.getDate() + 1) + + let startTime = Math.floor(date.getTime() / 1000) + let finishTime = startTime + 60 * 60 * 24 + await lockedDeal.CreateNewPool(testToken.address, startTime, finishTime, allow, owner, { + from: fromAddress + }) + date.setDate(date.getDate() + 1) + startTime = Math.floor(date.getTime() / 1000) + finishTime = startTime + 60 * 60 * 24 + const tx = await lockedDeal.CreateNewPool(testToken.address, startTime, finishTime, allow, owner, { + from: fromAddress + }) + poolId = tx.logs[1].args.PoolId + }) + + it("Pool transfer event is emitted", async () => { + const newOwner = accounts[8] + + result = await lockedDeal.PoolTransfer(poolId, newOwner, { from: owner }) + // Check event + truffleAssert.eventEmitted(result, "PoolTransferred") + }) + }) + + describe("PoolApproval event is emitted", async () => { + const approvalAmount = 10 + const spender = accounts[1] + + before(async () => { + let date = new Date() + date.setDate(date.getDate() + 1) + + const startTime = Math.floor(date.getTime() / 1000) + const finishTime = startTime + 60 * 60 * 24 + const tx = await lockedDeal.CreateNewPool(testToken.address, startTime, finishTime, allow, owner, { + from: fromAddress + }) + poolId = tx.logs[1].args.PoolId + }) + + it("PoolApproval event is emitted", async () => { + result = await lockedDeal.ApproveAllowance(poolId, approvalAmount, spender, { from: owner }) + // Check event + truffleAssert.eventEmitted(result, "PoolApproval") + }) + }) + + describe("PoolSplit event is emitted", async () => { + const amount = 10 + + before(async () => { + allow -= amount + + let date = new Date() + date.setDate(date.getDate() + 1) + + const startTime = Math.floor(date.getTime() / 1000) + const finishTime = startTime + 60 * 60 * 24 + + const tx = await lockedDeal.CreateNewPool(testToken.address, startTime, finishTime, allow, owner, { + from: fromAddress + }) + poolId = tx.logs[1].args.PoolId + }) + + it("PoolSplit event is emitted", async () => { + result = await lockedDeal.SplitPoolAmount(poolId, amount, owner, { from: owner }) + // Check event + truffleAssert.eventEmitted(result, "PoolSplit") + }) + }) +}) From 82f0630a6aec04e6fda82c442eaa31ffb6cc1a8a Mon Sep 17 00:00:00 2001 From: Andrew Dmytrenko Date: Wed, 21 Sep 2022 09:51:13 +0300 Subject: [PATCH 2/2] formatt files --- contracts/ERC20Token.sol | 2 +- test/4_Access.js | 14 +++++++------- test/7_Withdraw.js | 14 +++++++------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/contracts/ERC20Token.sol b/contracts/ERC20Token.sol index c919adf..a3c0c8f 100644 --- a/contracts/ERC20Token.sol +++ b/contracts/ERC20Token.sol @@ -1,4 +1,4 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import "poolz-helper-v2/contracts/token/ERC20Token.sol"; \ No newline at end of file +import "poolz-helper-v2/contracts/token/ERC20Token.sol"; diff --git a/test/4_Access.js b/test/4_Access.js index 7c0f22d..136f9e7 100644 --- a/test/4_Access.js +++ b/test/4_Access.js @@ -45,12 +45,14 @@ contract("Access to Locked Deal", (accounts) => { owner = newOwner }) - it('should get pool transfer status', async () => { + it("should get pool transfer status", async () => { let date = new Date() date.setDate(date.getDate() + 1) let startTime = Math.floor(date.getTime() / 1000) let finishTime = startTime + 60 * 60 * 24 * 30 - const tx = await instance.CreateNewPool(Token.address, startTime, finishTime, allow, owner, { from: fromAddress }) + const tx = await instance.CreateNewPool(Token.address, startTime, finishTime, allow, owner, { + from: fromAddress + }) poolId = tx.logs[1].args.PoolId await timeMachine.advanceBlockAndSetTime(finishTime) const status = await instance.isTransferPoolActive(poolId) @@ -61,7 +63,7 @@ contract("Access to Locked Deal", (accounts) => { await timeMachine.advanceBlockAndSetTime(Math.floor(Date.now() / 1000)) }) - it('Split Pool Amount with owner address', async () => { + it("Split Pool Amount with owner address", async () => { let date = new Date() date.setDate(date.getDate() + 1) let startTime = Math.floor(date.getTime() / 1000) @@ -140,8 +142,8 @@ contract("Access to Locked Deal", (accounts) => { "Can't be the same owner" ) }) - - it('Fail to Create Pool with 0 address owner', async () => { + + it("Fail to Create Pool with 0 address owner", async () => { const allow = 100 let date = new Date() date.setDate(date.getDate() + 1) @@ -202,7 +204,5 @@ contract("Access to Locked Deal", (accounts) => { ) await timeMachine.advanceBlockAndSetTime(Math.floor(Date.now() / 1000)) }) - - }) }) diff --git a/test/7_Withdraw.js b/test/7_Withdraw.js index 5038e86..e323e84 100644 --- a/test/7_Withdraw.js +++ b/test/7_Withdraw.js @@ -1,8 +1,8 @@ const LockedDealV2 = artifacts.require("LockedDealV2") const TestToken = artifacts.require("ERC20Token") -const { assert } = require('chai') -const timeMachine = require('ganache-time-traveler') -const constants = require('@openzeppelin/test-helpers/src/constants.js'); +const { assert } = require("chai") +const timeMachine = require("ganache-time-traveler") +const constants = require("@openzeppelin/test-helpers/src/constants.js") const BigNumber = require("bignumber.js") contract("Withdraw", (accounts) => { @@ -18,7 +18,7 @@ contract("Withdraw", (accounts) => { await Token.approve(instance.address, constants.MAX_UINT256, { from: fromAddress }) }) - it('should create a single new pool', async () => { + it("should create a single new pool", async () => { const date = new Date() const startTime = Math.floor(date.getTime() / 1000) date.setDate(date.getDate() + 2) @@ -50,7 +50,7 @@ contract("Withdraw", (accounts) => { assert.equal(expectedResult, result.toString(), "check return value") }) - it('finish time < now', async () => { + it("finish time < now", async () => { const date = new Date() const startTime = Math.floor(date.getTime() / 1000) date.setDate(date.getDate() + 1) @@ -79,7 +79,7 @@ contract("Withdraw", (accounts) => { assert.equal("0", result.toString(), "check debited amount") }) - it('Withdraw tokens', async () => { + it("Withdraw tokens", async () => { const date = new Date() date.setDate(date.getDate() - 1) const startTime = Math.floor(date.getTime() / 1000) @@ -196,7 +196,7 @@ contract("Withdraw", (accounts) => { const date = new Date() const startTime = Math.floor(date.getTime() / 1000) const finishTime = startTime + 120 // add two minutes - const halfTime = finishTime - 60 // 1 min after start time + const halfTime = finishTime - 60 // 1 min after start time let tx = await instance.CreateNewPool(Token.address, startTime, finishTime, allow, owner, { from: fromAddress })