Skip to content

Commit

Permalink
added failure tests (#94)
Browse files Browse the repository at this point in the history
* added failure tests

* small test fix
  • Loading branch information
YouStillAlive authored Sep 2, 2022
1 parent d240ff1 commit 71c2d4b
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 12 deletions.
42 changes: 32 additions & 10 deletions test/3_FailCreatePool.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ 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()
Expand All @@ -21,17 +22,43 @@ contract('Fail Create Pool', accounts => {
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 () => {
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 () => {
date = new Date()
date.setDate(date.getDate() + 1)
startTime = Math.floor(date.getTime() / 1000)
finishTime = startTime - 1
await Token.approve(instance.address, allow, { from: fromAddress })
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 () => {
await Token.approve(instance.address, allow * 2, { from: fromAddress })
await truffleAssert.reverts(
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")
await truffleAssert.reverts(
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 () => {
await Token.approve(instance.address, allow * 2, { from: fromAddress })
await truffleAssert.reverts(
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")
})

it('Fail to Create Pool when Time array length is Zero', async () => {
await Token.approve(instance.address, 100, { from: fromAddress })
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 () => {
const allow = 1
const owner = accounts[6]
let date = new Date()
date.setDate(date.getDate() + 1)
const future = Math.floor(date.getTime() / 1000)
let ownerArray = [], startArray = [], finishArray = [], amountArray = []
await Token.approve(instance.address, allow * 401, { from: fromAddress })
for (let i = 0; i < 401; i++) {
Expand All @@ -44,11 +71,6 @@ contract('Fail Create Pool', accounts => {
})

it('Fail to Create Pool wrt Time when max limit is exceeded', async () => {
const allow = 1
const owner = accounts[6]
let date = new Date()
date.setDate(date.getDate() + 1)
const future = Math.floor(date.getTime() / 1000)
let ownerArray = [], startTime = [], finishTime = [], amountArray = []
await Token.approve(instance.address, allow * 410, { from: fromAddress })
for (let i = 0; i < 41; i++) {
Expand Down
34 changes: 32 additions & 2 deletions test/4_Access.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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');

Expand Down Expand Up @@ -97,15 +98,28 @@ contract('Access to Locked Deal', accounts => {
const newPoolId = tx.logs[0].args.PoolId
const data = await instance.AllPoolz(newPoolId, { from: newOwner })
assert.equal(approvalAmount, data[2])

})
})

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 () =>{
let date = new Date()
date.setDate(date.getDate() + 1)
let startTime = Math.floor(date.getTime() / 1000)
let finishTime = startTime + 60 * 60 * 24 * 30
await Token.approve(instance.address, allow, { 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 timeMachine.advanceBlockAndSetTime(Math.floor(Date.now() / 1000))
})

it('Fail to Create Pool with 0 address owner', async () => {
const allow = 100
let date = new Date()
Expand All @@ -125,9 +139,25 @@ contract('Access to Locked Deal', accounts => {
await truffleAssert.reverts(instance.SplitPoolAmount(poolId, amount, owner, { from: owner }), "Not Enough Amount Balance")
})

it('Fail to split pool when Pool is unlocked', async () => {
const date = new Date()
date.setDate(date.getDate() + 1)
const startTime = Math.floor(date.getTime() / 1000)
const finishTime = startTime + 60 * 60 * 24 * 30
await timeMachine.advanceBlockAndSetTime(finishTime + 1)
const data = await instance.AllPoolz(poolId, { from: owner })
const amount = data[1] + 1
await truffleAssert.reverts(instance.SplitPoolAmount(poolId, amount, owner, { from: owner }), "Pool is Unlocked")
await timeMachine.advanceBlockAndSetTime(Math.floor(Date.now() / 1000))
})

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")
})

it('Fail to execute when Pool ID is invalid', async () => {
await truffleAssert.reverts(instance.PoolTransfer(99, accounts[5], { from: owner }), "Pool does not exist")
})
})

})

0 comments on commit 71c2d4b

Please sign in to comment.