Skip to content

Commit fc7539c

Browse files
authored
#39 - updates DDay based claim error handling (#40)
* updates DDay based claim error handling * fixes DDay contract test * deploys updates to kovan testnet
1 parent d3e47f1 commit fc7539c

File tree

5 files changed

+11
-62
lines changed

5 files changed

+11
-62
lines changed

contracts/components/Claims.sol

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ contract Claims {
235235
) internal dDayBasedClaim(_safeId, data) {
236236
claimsCount += 1;
237237

238-
if (block.timestamp >= data.dDay) {
238+
require(block.timestamp >= data.dDay, "Cannot create claim before DDay");
239239
claims[claimsCount] = Types.Claim({
240240
id: claimsCount,
241241
claimedBy: msg.sender,
@@ -244,16 +244,6 @@ contract Claims {
244244
evidenceGroupId: 0,
245245
status: Types.ClaimStatus.Passed
246246
});
247-
} else if (block.timestamp < data.dDay) {
248-
claims[claimsCount] = Types.Claim({
249-
id: claimsCount,
250-
claimedBy: msg.sender,
251-
claimType: Types.ClaimType.DDayBased,
252-
metaEvidenceId: 0,
253-
evidenceGroupId: 0,
254-
status: Types.ClaimStatus.Failed
255-
});
256-
}
257247

258248
emit CreateClaim(_safeId,claimsCount, block.timestamp);
259249
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@safient/contracts",
3-
"version": "0.1.16-alpha",
3+
"version": "0.1.17-alpha",
44
"description": "JavaScript SDK to manage and interact with the safe claims on Safient protocol.",
55
"keywords": [
66
"Web3",

src/utils/networks.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"chainId": 42,
2525
"addresses": {
2626
"AutoAppealableArbitrator": "0xf54D6b97749ECD28F9EbF836Ed9cE0C387a2f0A1",
27-
"SafientMain": "0xF88915c8762aB973b64086221cDFd20Ec104F732"
27+
"SafientMain": "0x1690F123657760C1a4998f10E5908F1c53e7eFc2"
2828
}
2929
},
3030
"ropsten": {

test-sdk/claims.js

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -331,14 +331,7 @@ describe('safientMain', async () => {
331331
await safientMainCreator.createSafe(beneficiaryAddress, safeId[3], Types.ClaimType.DDayBased, 0, 6, '', '');
332332

333333
// create a claim - before D-Day (claim should fail)
334-
const tx1 = await safientMainBeneficiary.createClaim(safeId[3], '');
335-
const txReceipt1 = await tx1.wait();
336-
const claimId1 = txReceipt1.events[0].args[1];
337-
const claimID1 = parseInt(claimId1._hex);
338-
339-
// check claim status (DDayBased)
340-
const safeId4ClaimResult1 = await safientMainAccountX.getClaimStatus(safeId[3], claimID1);
341-
expect(safeId4ClaimResult1).to.equal(2); // claim got Failed (before D-Day)
334+
await expect(safientMainBeneficiary.createClaim(safeId[3], '')).to.be.rejectedWith(Error);;
342335

343336
// mine a new block after 6 seconds
344337
const mineNewBlock = new Promise((resolve, reject) => {
@@ -374,14 +367,7 @@ describe('safientMain', async () => {
374367
await safientMainCreator.createSafe(beneficiaryAddress, safeId[4], Types.ClaimType.DDayBased, 0, now + 6, '', '');
375368

376369
// create a claim - before D-Day (6 seconds) (claim should fail)
377-
const tx1 = await safientMainBeneficiary.createClaim(safeId[4], '');
378-
const txReceipt1 = await tx1.wait();
379-
const claimId1 = txReceipt1.events[0].args[1];
380-
const claimID1 = parseInt(claimId1._hex);
381-
382-
// check claim status (DDayBased)
383-
const safeId4ClaimResult1 = await safientMainAccountX.getClaimStatus(safeId[4], claimID1);
384-
expect(safeId4ClaimResult1).to.equal(2); // claim got Failed (before D-Day)
370+
await expect(safientMainBeneficiary.createClaim(safeId[4], '')).to.be.rejectedWith(Error);;
385371

386372
latestBlockNumber = await ethers.provider.getBlockNumber();
387373
latestBlock = await ethers.provider.getBlock(latestBlockNumber);
@@ -399,14 +385,7 @@ describe('safientMain', async () => {
399385
const result1 = await mineNewBlock1;
400386

401387
// create a claim - before D-Day (12 seconds) (claim should fail)
402-
const tx2 = await safientMainBeneficiary.createClaim(safeId[4], '');
403-
const txReceipt2 = await tx2.wait();
404-
const claimId2 = txReceipt2.events[0].args[1];
405-
const claimID2 = parseInt(claimId2._hex);
406-
407-
// check claim status (DDayBased)
408-
const safeId4ClaimResult2 = await safientMainAccountX.getClaimStatus(safeId[4], claimID2);
409-
expect(safeId4ClaimResult2).to.equal(2); // claim got Failed (before D-Day)
388+
await expect(safientMainBeneficiary.createClaim(safeId[4], '')).to.be.rejectedWith(Error);
410389

411390
// mine a new block after 2 seconds
412391
const mineNewBlock2 = new Promise((resolve, reject) => {

test/claims.js

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -334,16 +334,10 @@ describe('SafientMain', async () => {
334334
''
335335
);
336336

337+
337338
// create a claim - before D-Day (claim should fail)
338-
const tx1 = await safientMain.connect(beneficiary).createClaim(safeId4, '');
339-
const txReceipt1 = await tx1.wait();
340-
const claimId1 = txReceipt1.events[0].args[1];
341-
const claimID1 = parseInt(claimId1._hex);
342-
343-
// check claim status (DDayBased)
344-
const safeId4ClaimResult1 = await safientMain.connect(accountX).getClaimStatus(safeId4, claimID1);
345-
expect(safeId4ClaimResult1).to.equal(2); // claim got Failed (before D-Day)
346-
339+
await expect(safientMain.connect(beneficiary).createClaim(safeId4, '')).to.be.revertedWith('Cannot create claim before DDay');
340+
347341
// mine a new block after 6 seconds
348342
const mineNewBlock = new Promise((resolve, reject) => {
349343
setTimeout(() => {
@@ -389,14 +383,7 @@ describe('SafientMain', async () => {
389383
);
390384

391385
// create a claim - before D-Day (6 seconds) (claim should fail)
392-
const tx1 = await safientMain.connect(beneficiary).createClaim(safeId5, '');
393-
const txReceipt1 = await tx1.wait();
394-
const claimId1 = txReceipt1.events[0].args[1];
395-
const claimID1 = parseInt(claimId1._hex);
396-
397-
// check claim status (DDayBased)
398-
const safeId5ClaimResult1 = await safientMain.connect(accountX).getClaimStatus(safeId5, claimID1);
399-
expect(safeId5ClaimResult1).to.equal(2); // claim got Failed (before D-Day)
386+
await expect(safientMain.connect(beneficiary).createClaim(safeId5, '')).to.be.revertedWith('Cannot create claim before DDay');
400387

401388
latestBlockNumber = await ethers.provider.getBlockNumber();
402389
latestBlock = await ethers.provider.getBlock(latestBlockNumber);
@@ -414,14 +401,7 @@ describe('SafientMain', async () => {
414401
const result1 = await mineNewBlock1;
415402

416403
// create a claim - before D-Day (12 seconds) (claim should fail)
417-
const tx2 = await safientMain.connect(beneficiary).createClaim(safeId5, '');
418-
const txReceipt2 = await tx2.wait();
419-
const claimId2 = txReceipt2.events[0].args[1];
420-
const claimID2 = parseInt(claimId2._hex);
421-
422-
// check claim status (DDayBased)
423-
const safeId5ClaimResult2 = await safientMain.connect(accountX).getClaimStatus(safeId5, claimID2);
424-
expect(safeId5ClaimResult2).to.equal(2); // claim got Failed (before D-Day)
404+
await expect(safientMain.connect(beneficiary).createClaim(safeId5, '')).to.be.revertedWith('Cannot create claim before DDay');
425405

426406
// mine a new block after 4 seconds
427407
const mineNewBlock2 = new Promise((resolve, reject) => {

0 commit comments

Comments
 (0)