Skip to content

Commit

Permalink
Return latest segments gracePeriodInDays in CoverViewer
Browse files Browse the repository at this point in the history
  • Loading branch information
0xdewy authored and shark0der committed Oct 13, 2022
1 parent a621d8c commit 924e31f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
11 changes: 4 additions & 7 deletions contracts/modules/cover/CoverViewer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ contract CoverViewer {
uint8 coverAsset;
string coverAssetSymbol;
uint8 claimMethod;
uint16[] gracePeriodInDays;
uint16 gracePeriodInDays;
}

uint private constant CAPACITY_REDUCTION_DENOMINATOR = 10000;
Expand All @@ -48,7 +48,7 @@ contract CoverViewer {
uint coverStart;
uint coverEnd;
uint amountRemaining;
uint16[] memory gracePeriodInDays; // grace period for each segment
uint16 gracePeriodInDays; // grace period for each segment
CoverData memory coverData = cover().coverData(coverId);

{
Expand All @@ -58,15 +58,12 @@ contract CoverViewer {
if (segmentCount == 1) {
coverEnd = coverStart + firstSegment.period;
amountRemaining = firstSegment.amount;
gracePeriodInDays = firstSegment.gracePeriodInDays;
} else {
CoverSegment memory lastSegment = cover().coverSegments(coverId, segmentCount - 1);
coverEnd = lastSegment.start + lastSegment.period;
amountRemaining = lastSegment.amount;
}

for (uint i = 0; i < segmentCount; i++){
CoverSegment memory segment = cover().coverSegments(coverId, i);
gracePeriodInDays[i] = segment.gracePeriodInDays;
gracePeriodInDays = lastSegment.gracePeriodInDays;
}
}

Expand Down
12 changes: 9 additions & 3 deletions test/unit/CoverViewer/views.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { assert } = require('chai');
const { expect } = require('chai');
const { ethers } = require('hardhat');
const {
utils: { parseEther },
Expand All @@ -24,7 +24,13 @@ describe('views', function () {

const segments = await coverViewer.getCoverSegments(coverId);

assert.equal(segments.length, 1);
assert(segments[0].amount.toString(), coverSegment1.amount.toString());
expect(segments.length).to.be.equal(1);
expect(segments[0].amount.toString()).to.be.equal(coverSegment1.amount.toString());
expect(segments[0].start).to.be.equal(coverSegment1.start);
expect(segments[0].period).to.be.equal(coverSegment1.period);
expect(segments[0].gracePeriodInDays).to.be.equal(coverSegment1.gracePeriodInDays);
expect(segments[0].priceRatio).to.be.equal(coverSegment1.priceRatio);
expect(segments[0].expired).to.be.equal(false);
expect(segments[0].globalRewardsRatio).to.be.equal(coverSegment1.globalRewardsRatio);
});
});

0 comments on commit 924e31f

Please sign in to comment.