Skip to content

Commit

Permalink
Add gracePeriodInDays to assertCoverFields test helper
Browse files Browse the repository at this point in the history
  • Loading branch information
0xdewy committed Oct 10, 2022
1 parent 14cd864 commit 8fee40e
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 8 deletions.
46 changes: 41 additions & 5 deletions test/unit/Cover/buyCover.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const { bnEqual } = require('../utils').helpers;
const { parseEther } = ethers.utils;
const { AddressZero } = ethers.constants;
const { BigNumber } = ethers;
const gracePeriodInDays = 120;

describe('buyCover', function () {
it('should purchase new cover using 1 staking pool', async function () {
Expand Down Expand Up @@ -66,7 +67,14 @@ describe('buyCover', function () {

const expectedCoverId = '0';

await assertCoverFields(cover, expectedCoverId, { productId, coverAsset, period, amount, targetPriceRatio });
await assertCoverFields(cover, expectedCoverId, {
productId,
coverAsset,
period,
amount,
targetPriceRatio,
gracePeriodInDays,
});
});

it('should purchase new cover using 2 staking pools', async function () {
Expand Down Expand Up @@ -142,7 +150,14 @@ describe('buyCover', function () {

const expectedCoverId = '0';

await assertCoverFields(cover, expectedCoverId, { productId, coverAsset, period, amount, targetPriceRatio });
await assertCoverFields(cover, expectedCoverId, {
productId,
coverAsset,
period,
amount,
targetPriceRatio,
gracePeriodInDays,
});
});

it('should purchase new cover using NXM with commission', async function () {
Expand Down Expand Up @@ -218,7 +233,14 @@ describe('buyCover', function () {

const expectedCoverId = '0';

await assertCoverFields(cover, expectedCoverId, { productId, coverAsset, period, amount, targetPriceRatio });
await assertCoverFields(cover, expectedCoverId, {
productId,
coverAsset,
period,
amount,
targetPriceRatio,
gracePeriodInDays,
});
});

it('should purchase new cover using DAI with commission', async function () {
Expand Down Expand Up @@ -299,7 +321,14 @@ describe('buyCover', function () {

const expectedCoverId = '0';

await assertCoverFields(cover, expectedCoverId, { productId, coverAsset, period, amount, targetPriceRatio });
await assertCoverFields(cover, expectedCoverId, {
productId,
coverAsset,
period,
amount,
targetPriceRatio,
gracePeriodInDays,
});
});

it('should purchase new cover using USDC with commission', async function () {
Expand Down Expand Up @@ -381,7 +410,14 @@ describe('buyCover', function () {

const expectedCoverId = '0';

await assertCoverFields(cover, expectedCoverId, { productId, coverAsset, period, amount, targetPriceRatio });
await assertCoverFields(cover, expectedCoverId, {
productId,
coverAsset,
period,
amount,
targetPriceRatio,
gracePeriodInDays,
});
});

it('should revert for unavailable product', async function () {
Expand Down
6 changes: 6 additions & 0 deletions test/unit/Cover/editCover.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const { parseEther } = ethers.utils;
const { AddressZero } = ethers.constants;

const { assertCoverFields, buyCoverOnOnePool, MAX_COVER_PERIOD } = require('./helpers');
const gracePeriodInDays = 120;

describe('editCover', function () {
const coverBuyFixture = {
Expand Down Expand Up @@ -70,6 +71,7 @@ describe('editCover', function () {
period,
amount: increasedAmount,
targetPriceRatio,
gracePeriodInDays,
segmentId: '1',
});
});
Expand Down Expand Up @@ -122,6 +124,7 @@ describe('editCover', function () {
period: increasedPeriod,
amount,
targetPriceRatio,
gracePeriodInDays,
segmentId: '1',
});
});
Expand Down Expand Up @@ -177,6 +180,7 @@ describe('editCover', function () {
period: increasedPeriod,
amount: increasedAmount,
targetPriceRatio,
gracePeriodInDays,
segmentId: '1',
});
});
Expand Down Expand Up @@ -232,6 +236,7 @@ describe('editCover', function () {
period: increasedPeriod,
amount: decreasedAmount,
targetPriceRatio,
gracePeriodInDays,
segmentId: '1',
});
});
Expand Down Expand Up @@ -278,6 +283,7 @@ describe('editCover', function () {
period,
amount: increasedAmount,
targetPriceRatio,
gracePeriodInDays,
segmentId: '1',
});
});
Expand Down
4 changes: 2 additions & 2 deletions test/unit/Cover/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ async function createStakingPool(cover, productId, capacity, targetPrice, active
async function assertCoverFields(
cover,
coverId,
{ productId, coverAsset, period, amount, targetPriceRatio, segmentId = '0', amountPaidOut = '0' },
{ productId, coverAsset, period, amount, targetPriceRatio, gracePeriodInDays, segmentId = '0', amountPaidOut = '0' },
) {
const storedCoverData = await cover.coverData(coverId);

const segment = await cover.coverSegments(coverId, segmentId);

assert.equal(storedCoverData.productId, productId);
assert.equal(storedCoverData.coverAsset, coverAsset);
bnEqual(storedCoverData.amountPaidOut, amountPaidOut);
assert.equal(segment.gracePeriodInDays, gracePeriodInDays);
assert.equal(segment.period, period);
assert.equal(segment.amount.toString(), amount.toString());
bnEqual(segment.priceRatio, targetPriceRatio);
Expand Down
4 changes: 3 additions & 1 deletion test/unit/Cover/performStakeBurn.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ const { assertCoverFields, buyCoverOnOnePool } = require('./helpers');
const { bnEqual } = require('../utils').helpers;

const { parseEther } = ethers.utils;
const gracePeriodInDays = 120;

describe('performStakeBurn', function () {
describe.only('performStakeBurn', function () {
const coverBuyFixture = {
productId: 0,
coverAsset: 0, // ETH
Expand Down Expand Up @@ -51,6 +52,7 @@ describe('performStakeBurn', function () {
period,
amount: remainingAmount,
targetPriceRatio,
gracePeriodInDays,
segmentId,
amountPaidOut: burnAmount,
});
Expand Down

0 comments on commit 8fee40e

Please sign in to comment.