Skip to content

Commit

Permalink
Task/harvest tests (#176)
Browse files Browse the repository at this point in the history
* Add harvest tests

* Add slither config
  • Loading branch information
antoncoding authored Aug 19, 2020
1 parent d056d53 commit 597fa31
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 1 deletion.
3 changes: 3 additions & 0 deletions slither.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"filter_paths": "packages|mocks|tests|echidna"
}
97 changes: 96 additions & 1 deletion test/optionsContract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ const truffleAssert = require('truffle-assertions');
import Reverter from './utils/reverter';

import {checkVault} from './utils/helper';
const {time, expectEvent, expectRevert} = require('@openzeppelin/test-helpers');
const {
time,
expectEvent,
expectRevert,
BN
} = require('@openzeppelin/test-helpers');

const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';

Expand Down Expand Up @@ -756,5 +761,95 @@ contract('OptionsContract', accounts => {
'Options contract expired'
);
});
describe('#harvest', () => {
const amount = '100000000';
let otoken: OptionsContractInstance;
let bonusToken: Erc20MintableInstance;
before('contract setup', async () => {
const now = (await time.latest()).toNumber();
expiry = now + time.duration.days(30).toNumber();
windowSize = expiry;
otoken = await OptionsContract.new(
weth.address,
-'18',
dai.address,
-'18',
-'17',
'90',
-'18',
usdc.address,
expiry,
oracle.address,
windowSize,
{from: creatorAddress}
);
bonusToken = await MintableToken.new();

await bonusToken.mint(otoken.address, amount);
});

it('should revert trying to harvest collateral token', async () => {
weth.mint(otoken.address, amount);
await expectRevert(
otoken.harvest(weth.address, amount, {
from: creatorAddress
}),
"Owner can't harvest this token"
);
});

it('should revert trying to harvest underlying token', async () => {
dai.mint(otoken.address, amount);
await expectRevert(
otoken.harvest(dai.address, amount, {
from: creatorAddress
}),
"Owner can't harvest this token"
);
});

it('should revert trying to harvest strike token', async () => {
usdc.mint(otoken.address, amount);
await expectRevert(
otoken.harvest(usdc.address, amount, {
from: creatorAddress
}),
"Owner can't harvest this token"
);
});

it('should revert when someone esle than owner call harvest', async () => {
await expectRevert(
otoken.harvest(bonusToken.address, amount, {
from: firstOwnerAddress
}),
'Ownable: caller is not the owner.'
);
});

it('should remove bonus token from the contract', async () => {
const contractBalanceBefore = await bonusToken.balanceOf(
otoken.address
);
const ownerBalanceBefore = await bonusToken.balanceOf(creatorAddress);

await otoken.harvest(bonusToken.address, amount, {
from: creatorAddress
});

const contractBalanceAfter = await bonusToken.balanceOf(otoken.address);
const ownerBalanceAfter = await bonusToken.balanceOf(creatorAddress);

assert.equal(
contractBalanceBefore.toString(),
contractBalanceAfter.add(new BN(amount)).toString()
);

assert.equal(
ownerBalanceAfter.toString(),
ownerBalanceBefore.add(new BN(amount)).toString()
);
});
});
});
});

0 comments on commit 597fa31

Please sign in to comment.