From c7adfea761c3a21e035b841a1bf65564e0e95522 Mon Sep 17 00:00:00 2001 From: Franklin Richards Date: Mon, 26 Jul 2021 16:11:40 +0530 Subject: [PATCH 1/6] Minor comment added to LockedSOV Contract --- contracts/LockedFund.sol | 1 + 1 file changed, 1 insertion(+) diff --git a/contracts/LockedFund.sol b/contracts/LockedFund.sol index d8fb0bc..54e3653 100644 --- a/contracts/LockedFund.sol +++ b/contracts/LockedFund.sol @@ -324,6 +324,7 @@ contract LockedFund is ILockedFund { */ function withdrawAndStakeTokens(address _receiverAddress) external { _withdrawWaitedUnlockedBalance(msg.sender, _receiverAddress); + // TODO: Withdraw Unlocked Balances as well. _createVestingAndStake(msg.sender); } From 5b29d9d3c07660fc09545880f3f86ee2e2321372 Mon Sep 17 00:00:00 2001 From: Franklin Richards Date: Mon, 26 Jul 2021 18:36:14 +0530 Subject: [PATCH 2/6] Utils updated --- tests/utils.js | 52 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 6 deletions(-) diff --git a/tests/utils.js b/tests/utils.js index f3c8bc8..187e921 100644 --- a/tests/utils.js +++ b/tests/utils.js @@ -42,7 +42,12 @@ async function currentTimestamp() { } /** * Function to create staking and vesting details. - */ + * + * @param creator The address which creates all those staking and vesting addresses. + * @param token The token address. + * + * @return [staking, vestingLogic, vestingRegistry] The objects of staking, vesting logics and vesting registry. +*/ async function createStakeAndVest(creator, token) { // Creating the Staking Instance. stakingLogic = await StakingLogic.new(token.address, { from: creator }); @@ -154,11 +159,11 @@ async function checkStatus( * @return [Token Balance, Vested Balance, Locked Balance, Waited Unlocked Balance, Unlocked Balance]. */ async function getTokenBalances(addr, tokenContract, lockedFundContract) { - let tokenBal = await tokenContract.balanceOf(addr); - let vestedBal = await lockedFundContract.getVestedBalance(addr); - let lockedBal = await lockedFundContract.getLockedBalance(addr); - let waitedUnlockedBal = await lockedFundContract.getWaitedUnlockedBalance(addr); - let unlockedBal = await lockedFundContract.getUnlockedBalance(addr); + let tokenBal = (await tokenContract.balanceOf(addr)).toNumber(); + let vestedBal = (await lockedFundContract.getVestedBalance(addr)).toNumber(); + let lockedBal = (await lockedFundContract.getLockedBalance(addr)).toNumber(); + let waitedUnlockedBal = (await lockedFundContract.getWaitedUnlockedBalance(addr)).toNumber(); + let unlockedBal = (await lockedFundContract.getUnlockedBalance(addr)).toNumber(); return [tokenBal, vestedBal, lockedBal, waitedUnlockedBal, unlockedBal]; } @@ -180,6 +185,23 @@ async function userMintAndApprove(tokenContract, userAddr, toApprove) { /** * Checks Tier Details. + * + * @param _originsBase The origins contract object. + * @param _tierCount The tier count. + * @param _minAmount The minimum tier deposit amount. + * @param _maxAmount The maximum tier deposit amount. + * @param _remainingTokens The remamining tokens in the tier for sale. + * @param _saleStartTS The sale start timestamp for the tier. + * @param _saleEnd The sale end timestamp for the tier. + * @param _unlockedBP The unlocked amount specified in basis point. + * @param _vestOrLockCliff The cliff for vesting or locking tokens. + * @param _vestOrLockDuration The duration for vesting or locking tokens. + * @param _depositRate The deposit rate for the particular tier. + * @param _depositToken The deposit token for the particular tier (if deposit type as token). + * @param _depositType The deposit type (RBTC or Token). + * @param _verificationType The verification type for the tier. + * @param _saleEndDurationOrTS The sale end duration specified as duration or timestamp. + * @param _transferType The transfer type for the tier. */ async function checkTier( _originsBase, @@ -221,6 +243,23 @@ async function checkTier( assert(tierPartB._transferType.eq(new BN(_transferType)), "Transfer Type is not correctly set."); } +/** + * Function to create a locked fund contract. + * + * @param waitedTS The time after which waited unlock will be unlocked. + * @param token The token address. + * @param vestingRegistry The vesting registry address. + * @param adminList The admin list for locked fund. + * @param creator The address used to create the locked fund. + * + * @return lockedFund contract object. + */ +async function createLockedFund(waitedTS, token, vestingRegistry, adminList, creator) { + lockedFund = await LockedFund.new(waitedTS, token.address, vestingRegistry.address, adminList, { from: creator }); + + return lockedFund; +} + // Contract Artifacts const Token = artifacts.require("Token"); const LockedFund = artifacts.require("LockedFund"); @@ -250,6 +289,7 @@ module.exports = { getTokenBalances, userMintAndApprove, checkTier, + createLockedFund, // Contract Artifacts Token, LockedFund, From be5fce357eb0bc1a35491fdb57e1d2772cc0417e Mon Sep 17 00:00:00 2001 From: Franklin Richards Date: Mon, 26 Jul 2021 18:36:59 +0530 Subject: [PATCH 3/6] LockedFund Tests Refactored --- tests/LockedFund/admin.test.js | 8 +- tests/LockedFund/creator.test.js | 5 +- tests/LockedFund/state.test.js | 189 +++++++++++++++++-------------- tests/LockedFund/user.test.js | 9 +- 4 files changed, 112 insertions(+), 99 deletions(-) diff --git a/tests/LockedFund/admin.test.js b/tests/LockedFund/admin.test.js index 1c3152d..8076b4f 100644 --- a/tests/LockedFund/admin.test.js +++ b/tests/LockedFund/admin.test.js @@ -6,9 +6,9 @@ const { randomValue, currentTimestamp, createStakeAndVest, + createLockedFund, // Contract Artifacts Token, - LockedFund, VestingRegistry, } = require("../utils"); @@ -32,11 +32,9 @@ contract("LockedFund (Admin Functions)", (accounts) => { // Creating the Staking and Vesting [staking, vestingLogic, vestingRegistry] = await createStakeAndVest(creator, token); - }); - beforeEach("Creating New Locked Fund Contract Instance.", async () => { // Creating the instance of LockedFund Contract. - lockedFund = await LockedFund.new(waitedTS, token.address, vestingRegistry.address, [admin], { from: creator }); + lockedFund = await createLockedFund(waitedTS, token, vestingRegistry, [admin], creator); // Adding lockedFund as an admin in the Vesting Registry. await vestingRegistry.addAdmin(lockedFund.address, { from: creator }); @@ -51,12 +49,10 @@ contract("LockedFund (Admin Functions)", (accounts) => { }); it("Admin should not be able to add another admin more than once.", async () => { - await lockedFund.addAdmin(newAdmin, { from: admin }); await expectRevert(lockedFund.addAdmin(newAdmin, { from: admin }), "LockedFund: Address is already admin."); }); it("Admin should be able to remove an admin.", async () => { - await lockedFund.addAdmin(newAdmin, { from: admin }); await lockedFund.removeAdmin(newAdmin, { from: admin }); }); diff --git a/tests/LockedFund/creator.test.js b/tests/LockedFund/creator.test.js index 2614c27..42c1189 100644 --- a/tests/LockedFund/creator.test.js +++ b/tests/LockedFund/creator.test.js @@ -6,6 +6,7 @@ const { randomValue, currentTimestamp, createStakeAndVest, + createLockedFund, // Contract Artifacts Token, LockedFund, @@ -32,11 +33,9 @@ contract("LockedFund (Creator Functions)", (accounts) => { // Creating the Staking and Vesting [staking, vestingLogic, vestingRegistry] = await createStakeAndVest(creator, token); - }); - beforeEach("Creating New Locked Fund Contract Instance.", async () => { // Creating the instance of LockedFund Contract. - lockedFund = await LockedFund.new(waitedTS, token.address, vestingRegistry.address, [admin], { from: creator }); + lockedFund = await createLockedFund(waitedTS, token, vestingRegistry, [admin], creator); // Adding lockedFund as an admin in the Vesting Registry. await vestingRegistry.addAdmin(lockedFund.address, { from: creator }); diff --git a/tests/LockedFund/state.test.js b/tests/LockedFund/state.test.js index d9b1d0a..7170049 100644 --- a/tests/LockedFund/state.test.js +++ b/tests/LockedFund/state.test.js @@ -7,9 +7,9 @@ const { createStakeAndVest, checkStatus, getTokenBalances, + createLockedFund, // Contract Artifacts Token, - LockedFund, VestingFactory, VestingRegistry, } = require("../utils"); @@ -43,11 +43,9 @@ contract("LockedFund (State Change)", (accounts) => { // Creating the Staking and Vesting [staking, vestingLogic, vestingRegistry] = await createStakeAndVest(creator, token); - }); - beforeEach("Creating New Locked Fund Contract Instance.", async () => { // Creating the instance of LockedFund Contract. - lockedFund = await LockedFund.new(waitedTS, token.address, vestingRegistry.address, [admin], { from: creator }); + lockedFund = await createLockedFund(waitedTS, token, vestingRegistry, [admin], creator); // Adding lockedFund as an admin in the Vesting Registry. await vestingRegistry.addAdmin(lockedFund.address, { from: creator }); @@ -73,7 +71,6 @@ contract("LockedFund (State Change)", (accounts) => { }); it("Admin should be able to remove an admin.", async () => { - await lockedFund.addAdmin(newAdmin, { from: admin }); await checkStatus( lockedFund, [1, 1, 0, 0, 1, 1, 1, 1, 1, 1], @@ -131,14 +128,17 @@ contract("LockedFund (State Change)", (accounts) => { zero, false ); + await lockedFund.changeVestingRegistry(vestingRegistry.address, { from: admin }); }); it("Admin should be able to change the waited timestamp.", async () => { let value = randomValue(); let newWaitedTS = waitedTS + value; - await lockedFund.changeWaitedTS(newWaitedTS, { from: admin }); + // Creating the instance of LockedFund Contract. + newLockedFund = await createLockedFund(waitedTS, token, vestingRegistry, [admin], creator); + await newLockedFund.changeWaitedTS(newWaitedTS, { from: admin }); await checkStatus( - lockedFund, + newLockedFund, [1, 1, 0, 0, 1, 1, 1, 1, 1, 1], userOne, newWaitedTS, @@ -177,6 +177,7 @@ contract("LockedFund (State Change)", (accounts) => { }); it("Admin should be able to deposit using depositVested() and unlock as immediate.", async () => { + let [tokenBal, vestedBal, lockedBal, waitedUnlockedBal, unlockedBal] = await getTokenBalances(userOne, token, lockedFund); let value = randomValue(); token.mint(admin, value, { from: creator }); token.approve(lockedFund.address, value, { from: admin }); @@ -190,15 +191,16 @@ contract("LockedFund (State Change)", (accounts) => { cliff, duration, vestingRegistry.address, - Math.ceil(value / 2), - zero, - zero, - Math.floor(value / 2), + Math.ceil(value / 2) + vestedBal, + zero + lockedBal, + zero + waitedUnlockedBal, + Math.floor(value / 2) + unlockedBal, false ); }); it("Admin should be able to deposit using depositVested() and unlock as none.", async () => { + let [tokenBal, vestedBal, lockedBal, waitedUnlockedBal, unlockedBal] = await getTokenBalances(userOne, token, lockedFund); let value = randomValue(); token.mint(admin, value, { from: creator }); token.approve(lockedFund.address, value, { from: admin }); @@ -212,15 +214,16 @@ contract("LockedFund (State Change)", (accounts) => { cliff, duration, vestingRegistry.address, - value, - zero, - zero, - zero, + value + vestedBal, + zero + lockedBal, + zero + waitedUnlockedBal, + zero + unlockedBal, false ); }); it("Admin should be able to deposit using depositLocked().", async () => { + let [tokenBal, vestedBal, lockedBal, waitedUnlockedBal, unlockedBal] = await getTokenBalances(userOne, token, lockedFund); let value = randomValue(); token.mint(admin, value, { from: creator }); token.approve(lockedFund.address, value, { from: admin }); @@ -229,6 +232,7 @@ contract("LockedFund (State Change)", (accounts) => { }); it("Admin should be able to deposit using depositWaitedUnlocked() with non zero basis point.", async () => { + let [tokenBal, vestedBal, lockedBal, waitedUnlockedBal, unlockedBal] = await getTokenBalances(userOne, token, lockedFund); let value = randomValue(); token.mint(admin, value, { from: creator }); token.approve(lockedFund.address, value, { from: admin }); @@ -239,18 +243,19 @@ contract("LockedFund (State Change)", (accounts) => { userOne, waitedTS, token.address, - zero, - zero, + cliff, + duration, vestingRegistry.address, - zero, - zero, - Math.ceil(value / 2), - Math.floor(value / 2), + zero + vestedBal, + zero + lockedBal, + Math.ceil(value / 2) + waitedUnlockedBal, + Math.floor(value / 2) + unlockedBal, false ); }); it("Admin should be able to deposit using depositWaitedUnlocked() with zero basis point.", async () => { + let [tokenBal, vestedBal, lockedBal, waitedUnlockedBal, unlockedBal] = await getTokenBalances(userOne, token, lockedFund); let value = randomValue(); token.mint(admin, value, { from: creator }); token.approve(lockedFund.address, value, { from: admin }); @@ -261,18 +266,19 @@ contract("LockedFund (State Change)", (accounts) => { userOne, waitedTS, token.address, - zero, - zero, + cliff, + duration, vestingRegistry.address, - zero, - zero, - value, - zero, + zero + vestedBal, + zero + lockedBal, + value + waitedUnlockedBal, + zero + unlockedBal, false ); }); it("User should be able to withdraw waited unlocked balance using withdrawWaitedUnlockedBalance().", async () => { + let [tokenBal, vestedBal, lockedBal, waitedUnlockedBal, unlockedBal] = await getTokenBalances(userOne, token, lockedFund); let value = randomValue(); token.mint(admin, value, { from: creator }); token.approve(lockedFund.address, value, { from: admin }); @@ -286,13 +292,13 @@ contract("LockedFund (State Change)", (accounts) => { cliff, duration, vestingRegistry.address, - Math.ceil(value / 2), - zero, - Math.floor(value / 2), - zero, + Math.ceil(value / 2) + vestedBal, + zero + lockedBal, + Math.floor(value / 2) + waitedUnlockedBal, + zero + unlockedBal, false ); - let oldBalances = await getTokenBalances(userOne, token, lockedFund); + [oldTokenBal, vestedBal, lockedBal, waitedUnlockedBal, unlockedBal] = await getTokenBalances(userOne, token, lockedFund); await lockedFund.withdrawWaitedUnlockedBalance(zeroAddress, { from: userOne }); await checkStatus( lockedFund, @@ -303,17 +309,18 @@ contract("LockedFund (State Change)", (accounts) => { cliff, duration, vestingRegistry.address, - Math.ceil(value / 2), - zero, - zero, + zero + vestedBal, + zero + lockedBal, zero, + zero + unlockedBal, false ); - let newBalances = await getTokenBalances(userOne, token, lockedFund); - assert.strictEqual(newBalances[0].toNumber(), oldBalances[0].toNumber() + Math.floor(value / 2), "Token Balance not matching."); + [newTokenBal,,,,] = await getTokenBalances(userOne, token, lockedFund); + assert.strictEqual(newTokenBal, oldTokenBal + waitedUnlockedBal, "Token Balance not matching."); }); it("User should be able to withdraw waited unlocked balance to any wallet using withdrawWaitedUnlockedBalance().", async () => { + let [tokenBal, vestedBal, lockedBal, waitedUnlockedBal, unlockedBal] = await getTokenBalances(userOne, token, lockedFund); let value = randomValue(); token.mint(admin, value, { from: creator }); token.approve(lockedFund.address, value, { from: admin }); @@ -327,13 +334,13 @@ contract("LockedFund (State Change)", (accounts) => { cliff, duration, vestingRegistry.address, - Math.ceil(value / 2), - zero, - Math.floor(value / 2), - zero, + Math.ceil(value / 2) + vestedBal, + zero + lockedBal, + Math.floor(value / 2) + waitedUnlockedBal, + zero + unlockedBal, false ); - let oldBalances = await getTokenBalances(userTwo, token, lockedFund); + [oldTokenBal,,,,] = await getTokenBalances(userTwo, token, lockedFund); await lockedFund.withdrawWaitedUnlockedBalance(userTwo, { from: userOne }); await checkStatus( lockedFund, @@ -344,17 +351,18 @@ contract("LockedFund (State Change)", (accounts) => { cliff, duration, vestingRegistry.address, - Math.ceil(value / 2), - zero, - zero, + Math.ceil(value / 2) + vestedBal, + zero + lockedBal, zero, + zero + unlockedBal, false ); - let newBalances = await getTokenBalances(userTwo, token, lockedFund); - assert.strictEqual(newBalances[0].toNumber(), oldBalances[0].toNumber() + Math.floor(value / 2), "Token Balance not matching."); + [newTokenBal,,,,] = await getTokenBalances(userTwo, token, lockedFund); + assert.strictEqual(newTokenBal, oldTokenBal + Math.floor(value / 2), "Token Balance not matching."); }); it("User should be able to create vesting and stake vested balance using createVestingAndStake().", async () => { + let [tokenBal, vestedBal, lockedBal, waitedUnlockedBal, unlockedBal] = await getTokenBalances(userOne, token, lockedFund); let value = randomValue(); token.mint(admin, value, { from: creator }); token.approve(lockedFund.address, value, { from: admin }); @@ -368,12 +376,13 @@ contract("LockedFund (State Change)", (accounts) => { cliff, duration, vestingRegistry.address, - value, - zero, - zero, - zero, + value + vestedBal, + zero + lockedBal, + zero + waitedUnlockedBal, + zero + unlockedBal, false ); + [oldTokenBal, vestedBal, lockedBal, waitedUnlockedBal, unlockedBal] = await getTokenBalances(userOne, token, lockedFund); await lockedFund.createVestingAndStake({ from: userOne }); await checkStatus( lockedFund, @@ -385,14 +394,15 @@ contract("LockedFund (State Change)", (accounts) => { duration, vestingRegistry.address, zero, - zero, - zero, - zero, + zero + lockedBal, + zero + waitedUnlockedBal, + zero + unlockedBal, false ); }); it("User should be able to create vesting using createVesting().", async () => { + let [tokenBal, vestedBal, lockedBal, waitedUnlockedBal, unlockedBal] = await getTokenBalances(userOne, token, lockedFund); let value = randomValue(); token.mint(admin, value, { from: creator }); token.approve(lockedFund.address, value, { from: admin }); @@ -406,12 +416,13 @@ contract("LockedFund (State Change)", (accounts) => { cliff, duration, vestingRegistry.address, - value, - zero, - zero, - zero, + value + vestedBal, + zero + lockedBal, + zero + waitedUnlockedBal, + zero + unlockedBal, false ); + [oldTokenBal, vestedBal, lockedBal, waitedUnlockedBal, unlockedBal] = await getTokenBalances(userOne, token, lockedFund); await lockedFund.createVesting({ from: userOne }); await checkStatus( lockedFund, @@ -422,15 +433,16 @@ contract("LockedFund (State Change)", (accounts) => { cliff, duration, vestingRegistry.address, - value, - zero, - zero, - zero, + zero + vestedBal, + zero + lockedBal, + zero + waitedUnlockedBal, + zero + unlockedBal, false ); }); it("User should be able to stake vested balance using stakeTokens().", async () => { + let [tokenBal, vestedBal, lockedBal, waitedUnlockedBal, unlockedBal] = await getTokenBalances(userOne, token, lockedFund); let value = randomValue(); token.mint(admin, value, { from: creator }); token.approve(lockedFund.address, value, { from: admin }); @@ -444,12 +456,13 @@ contract("LockedFund (State Change)", (accounts) => { cliff, duration, vestingRegistry.address, - value, - zero, - zero, - zero, + value + vestedBal, + zero + lockedBal, + zero + waitedUnlockedBal, + zero + unlockedBal, false ); + [oldTokenBal, vestedBal, lockedBal, waitedUnlockedBal, unlockedBal] = await getTokenBalances(userOne, token, lockedFund); await lockedFund.stakeTokens({ from: userOne }); await checkStatus( lockedFund, @@ -461,9 +474,9 @@ contract("LockedFund (State Change)", (accounts) => { duration, vestingRegistry.address, zero, - zero, - zero, - zero, + zero + lockedBal, + zero + waitedUnlockedBal, + zero + unlockedBal, false ); }); @@ -480,6 +493,7 @@ contract("LockedFund (State Change)", (accounts) => { vestingFactory.transferOwnership(newVestingRegistry.address); await newVestingRegistry.addAdmin(lockedFund.address); await lockedFund.changeVestingRegistry(newVestingRegistry.address, { from: admin }); + let [tokenBal, vestedBal, lockedBal, waitedUnlockedBal, unlockedBal] = await getTokenBalances(userOne, token, lockedFund); let value = randomValue(); token.mint(admin, value, { from: creator }); token.approve(lockedFund.address, value, { from: admin }); @@ -493,13 +507,13 @@ contract("LockedFund (State Change)", (accounts) => { cliff, duration, newVestingRegistry.address, - Math.ceil(value / 2), - zero, - Math.floor(value / 2), - zero, + Math.ceil(value / 2) + vestedBal, + zero + lockedBal, + Math.floor(value / 2) + waitedUnlockedBal, + zero + unlockedBal, false ); - let oldBalances = await getTokenBalances(userOne, token, lockedFund); + [oldTokenBal, vestedBal, lockedBal, waitedUnlockedBal, unlockedBal] = await getTokenBalances(userOne, token, lockedFund); await lockedFund.withdrawAndStakeTokens(zeroAddress, { from: userOne }); await checkStatus( lockedFund, @@ -511,13 +525,13 @@ contract("LockedFund (State Change)", (accounts) => { duration, newVestingRegistry.address, zero, + zero + lockedBal, zero, - zero, - zero, + zero + unlockedBal, false ); - let newBalances = await getTokenBalances(userOne, token, lockedFund); - assert.strictEqual(newBalances[0].toNumber(), oldBalances[0].toNumber() + Math.floor(value / 2), "Token Balance not matching."); + [newTokenBal, vestedBal, lockedBal, waitedUnlockedBal, unlockedBal] = await getTokenBalances(userOne, token, lockedFund); + assert.strictEqual(newTokenBal, oldTokenBal + Math.floor(value / 2), "Token Balance not matching."); }); it("User should be able to withdraw waited unlocked balance to any wallet, create vesting and stake vested balance using withdrawAndStakeTokens().", async () => { @@ -532,6 +546,7 @@ contract("LockedFund (State Change)", (accounts) => { vestingFactory.transferOwnership(newVestingRegistry.address); await newVestingRegistry.addAdmin(lockedFund.address); await lockedFund.changeVestingRegistry(newVestingRegistry.address, { from: admin }); + let [tokenBal, vestedBal, lockedBal, waitedUnlockedBal, unlockedBal] = await getTokenBalances(userOne, token, lockedFund); let value = randomValue(); token.mint(admin, value, { from: creator }); token.approve(lockedFund.address, value, { from: admin }); @@ -545,13 +560,13 @@ contract("LockedFund (State Change)", (accounts) => { cliff, duration, newVestingRegistry.address, - Math.ceil(value / 2), - zero, - Math.floor(value / 2), - zero, + Math.ceil(value / 2) + vestedBal, + zero + lockedBal, + Math.floor(value / 2) + waitedUnlockedBal, + zero + unlockedBal, false ); - let oldBalances = await getTokenBalances(userTwo, token, lockedFund); + [oldTokenBal,,,,] = await getTokenBalances(userTwo, token, lockedFund); await lockedFund.withdrawAndStakeTokens(userTwo, { from: userOne }); await checkStatus( lockedFund, @@ -563,13 +578,13 @@ contract("LockedFund (State Change)", (accounts) => { duration, newVestingRegistry.address, zero, + zero + lockedBal, zero, - zero, - zero, + zero + unlockedBal, false ); - let newBalances = await getTokenBalances(userTwo, token, lockedFund); - assert.strictEqual(newBalances[0].toNumber(), oldBalances[0].toNumber() + Math.floor(value / 2), "Token Balance not matching."); + [newTokenBal,,,,] = await getTokenBalances(userTwo, token, lockedFund); + assert.strictEqual(newTokenBal, oldTokenBal + Math.floor(value / 2), "Token Balance not matching."); }); it("Admin should be able to get the cliff and duration of a user.", async () => { diff --git a/tests/LockedFund/user.test.js b/tests/LockedFund/user.test.js index 248acd7..e542005 100644 --- a/tests/LockedFund/user.test.js +++ b/tests/LockedFund/user.test.js @@ -6,6 +6,7 @@ const { randomValue, currentTimestamp, createStakeAndVest, + createLockedFund, // Contract Artifacts Token, LockedFund, @@ -32,11 +33,9 @@ contract("LockedFund (User Functions)", (accounts) => { // Creating the Staking and Vesting [staking, vestingLogic, vestingRegistry] = await createStakeAndVest(creator, token); - }); - beforeEach("Creating New Locked Fund Contract Instance.", async () => { // Creating the instance of LockedFund Contract. - lockedFund = await LockedFund.new(waitedTS, token.address, vestingRegistry.address, [admin], { from: creator }); + lockedFund = await createLockedFund(waitedTS, token, vestingRegistry, [admin], creator); // Adding lockedFund as an admin in the Vesting Registry. await vestingRegistry.addAdmin(lockedFund.address, { from: creator }); @@ -150,6 +149,10 @@ contract("LockedFund (User Functions)", (accounts) => { }); it("User should be able to withdraw waited unlocked balance, create vesting and stake vested balance using withdrawAndStakeTokens().", async () => { + // Creating the instance of LockedFund Contract. + lockedFund = await createLockedFund(waitedTS, token, vestingRegistry, [admin], creator); + // Adding lockedFund as an admin in the Vesting Registry. + await vestingRegistry.addAdmin(lockedFund.address, { from: creator }); let value = randomValue(); token.mint(admin, value, { from: creator }); token.approve(lockedFund.address, value, { from: admin }); From 3e693f503f4e6caa4ae8621b9fc22e33fd578dc2 Mon Sep 17 00:00:00 2001 From: Franklin Richards Date: Mon, 26 Jul 2021 18:37:12 +0530 Subject: [PATCH 4/6] README Updated --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index c6ef046..42e89b4 100644 --- a/README.md +++ b/README.md @@ -132,3 +132,4 @@ Please make sure to read the README mentioned in the scripts folder before runni - Total unique wallets participated in all tiers. Currently only unique wallets participated in a each tier is counted, which is not the same as unique wallets participated in all tiers combined. New storage structure will be required. - Tests related to other type of sales to be added. - Reduce the reason string text size, or use a numbering system with errors in mainly LockedFund and OriginsBase. +- `saleEndDurationOrTS` in OriginsBase has little upside for storing and might be removable in the future. From 63698dafc05bf14f6d3aa58d10155e759af6f170 Mon Sep 17 00:00:00 2001 From: Franklin Richards Date: Mon, 26 Jul 2021 18:37:46 +0530 Subject: [PATCH 5/6] Formatting Done on Tests --- tests/LockedFund/state.test.js | 10 +++++----- tests/utils.js | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/LockedFund/state.test.js b/tests/LockedFund/state.test.js index 7170049..1df5d01 100644 --- a/tests/LockedFund/state.test.js +++ b/tests/LockedFund/state.test.js @@ -315,7 +315,7 @@ contract("LockedFund (State Change)", (accounts) => { zero + unlockedBal, false ); - [newTokenBal,,,,] = await getTokenBalances(userOne, token, lockedFund); + [newTokenBal, , , ,] = await getTokenBalances(userOne, token, lockedFund); assert.strictEqual(newTokenBal, oldTokenBal + waitedUnlockedBal, "Token Balance not matching."); }); @@ -340,7 +340,7 @@ contract("LockedFund (State Change)", (accounts) => { zero + unlockedBal, false ); - [oldTokenBal,,,,] = await getTokenBalances(userTwo, token, lockedFund); + [oldTokenBal, , , ,] = await getTokenBalances(userTwo, token, lockedFund); await lockedFund.withdrawWaitedUnlockedBalance(userTwo, { from: userOne }); await checkStatus( lockedFund, @@ -357,7 +357,7 @@ contract("LockedFund (State Change)", (accounts) => { zero + unlockedBal, false ); - [newTokenBal,,,,] = await getTokenBalances(userTwo, token, lockedFund); + [newTokenBal, , , ,] = await getTokenBalances(userTwo, token, lockedFund); assert.strictEqual(newTokenBal, oldTokenBal + Math.floor(value / 2), "Token Balance not matching."); }); @@ -566,7 +566,7 @@ contract("LockedFund (State Change)", (accounts) => { zero + unlockedBal, false ); - [oldTokenBal,,,,] = await getTokenBalances(userTwo, token, lockedFund); + [oldTokenBal, , , ,] = await getTokenBalances(userTwo, token, lockedFund); await lockedFund.withdrawAndStakeTokens(userTwo, { from: userOne }); await checkStatus( lockedFund, @@ -583,7 +583,7 @@ contract("LockedFund (State Change)", (accounts) => { zero + unlockedBal, false ); - [newTokenBal,,,,] = await getTokenBalances(userTwo, token, lockedFund); + [newTokenBal, , , ,] = await getTokenBalances(userTwo, token, lockedFund); assert.strictEqual(newTokenBal, oldTokenBal + Math.floor(value / 2), "Token Balance not matching."); }); diff --git a/tests/utils.js b/tests/utils.js index 187e921..9ff4258 100644 --- a/tests/utils.js +++ b/tests/utils.js @@ -42,12 +42,12 @@ async function currentTimestamp() { } /** * Function to create staking and vesting details. - * + * * @param creator The address which creates all those staking and vesting addresses. * @param token The token address. - * + * * @return [staking, vestingLogic, vestingRegistry] The objects of staking, vesting logics and vesting registry. -*/ + */ async function createStakeAndVest(creator, token) { // Creating the Staking Instance. stakingLogic = await StakingLogic.new(token.address, { from: creator }); @@ -185,7 +185,7 @@ async function userMintAndApprove(tokenContract, userAddr, toApprove) { /** * Checks Tier Details. - * + * * @param _originsBase The origins contract object. * @param _tierCount The tier count. * @param _minAmount The minimum tier deposit amount. @@ -245,13 +245,13 @@ async function checkTier( /** * Function to create a locked fund contract. - * + * * @param waitedTS The time after which waited unlock will be unlocked. * @param token The token address. * @param vestingRegistry The vesting registry address. * @param adminList The admin list for locked fund. * @param creator The address used to create the locked fund. - * + * * @return lockedFund contract object. */ async function createLockedFund(waitedTS, token, vestingRegistry, adminList, creator) { From 0bcb94019d14340157f98d51052db3fe645d8904 Mon Sep 17 00:00:00 2001 From: Franklin Richards Date: Mon, 26 Jul 2021 18:39:26 +0530 Subject: [PATCH 6/6] Tests Refactoring --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 83b6481..721110f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "origins-launchpad", - "version": "1.2.8", + "version": "1.2.9", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 0b9ca17..0806ecc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "origins-launchpad", - "version": "1.2.8", + "version": "1.2.9", "description": "The smart contracts for the Origins Platform", "keywords": [ "Origins",