diff --git a/contracts/components/Claims.sol b/contracts/components/Claims.sol index 9f96e66..8b7232d 100644 --- a/contracts/components/Claims.sol +++ b/contracts/components/Claims.sol @@ -235,7 +235,7 @@ contract Claims { ) internal dDayBasedClaim(_safeId, data) { claimsCount += 1; - if (block.timestamp >= data.dDay) { + require(block.timestamp >= data.dDay, "Cannot create claim before DDay"); claims[claimsCount] = Types.Claim({ id: claimsCount, claimedBy: msg.sender, @@ -244,16 +244,6 @@ contract Claims { evidenceGroupId: 0, status: Types.ClaimStatus.Passed }); - } else if (block.timestamp < data.dDay) { - claims[claimsCount] = Types.Claim({ - id: claimsCount, - claimedBy: msg.sender, - claimType: Types.ClaimType.DDayBased, - metaEvidenceId: 0, - evidenceGroupId: 0, - status: Types.ClaimStatus.Failed - }); - } emit CreateClaim(_safeId,claimsCount, block.timestamp); } diff --git a/package.json b/package.json index b0c3624..4822fbd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@safient/contracts", - "version": "0.1.16-alpha", + "version": "0.1.17-alpha", "description": "JavaScript SDK to manage and interact with the safe claims on Safient protocol.", "keywords": [ "Web3", diff --git a/src/utils/networks.json b/src/utils/networks.json index 4c7b654..757e1ca 100644 --- a/src/utils/networks.json +++ b/src/utils/networks.json @@ -24,7 +24,7 @@ "chainId": 42, "addresses": { "AutoAppealableArbitrator": "0xf54D6b97749ECD28F9EbF836Ed9cE0C387a2f0A1", - "SafientMain": "0xF88915c8762aB973b64086221cDFd20Ec104F732" + "SafientMain": "0x1690F123657760C1a4998f10E5908F1c53e7eFc2" } }, "ropsten": { diff --git a/test-sdk/claims.js b/test-sdk/claims.js index b460563..63b70e3 100644 --- a/test-sdk/claims.js +++ b/test-sdk/claims.js @@ -331,14 +331,7 @@ describe('safientMain', async () => { await safientMainCreator.createSafe(beneficiaryAddress, safeId[3], Types.ClaimType.DDayBased, 0, 6, '', ''); // create a claim - before D-Day (claim should fail) - const tx1 = await safientMainBeneficiary.createClaim(safeId[3], ''); - const txReceipt1 = await tx1.wait(); - const claimId1 = txReceipt1.events[0].args[1]; - const claimID1 = parseInt(claimId1._hex); - - // check claim status (DDayBased) - const safeId4ClaimResult1 = await safientMainAccountX.getClaimStatus(safeId[3], claimID1); - expect(safeId4ClaimResult1).to.equal(2); // claim got Failed (before D-Day) + await expect(safientMainBeneficiary.createClaim(safeId[3], '')).to.be.rejectedWith(Error);; // mine a new block after 6 seconds const mineNewBlock = new Promise((resolve, reject) => { @@ -374,14 +367,7 @@ describe('safientMain', async () => { await safientMainCreator.createSafe(beneficiaryAddress, safeId[4], Types.ClaimType.DDayBased, 0, now + 6, '', ''); // create a claim - before D-Day (6 seconds) (claim should fail) - const tx1 = await safientMainBeneficiary.createClaim(safeId[4], ''); - const txReceipt1 = await tx1.wait(); - const claimId1 = txReceipt1.events[0].args[1]; - const claimID1 = parseInt(claimId1._hex); - - // check claim status (DDayBased) - const safeId4ClaimResult1 = await safientMainAccountX.getClaimStatus(safeId[4], claimID1); - expect(safeId4ClaimResult1).to.equal(2); // claim got Failed (before D-Day) + await expect(safientMainBeneficiary.createClaim(safeId[4], '')).to.be.rejectedWith(Error);; latestBlockNumber = await ethers.provider.getBlockNumber(); latestBlock = await ethers.provider.getBlock(latestBlockNumber); @@ -399,14 +385,7 @@ describe('safientMain', async () => { const result1 = await mineNewBlock1; // create a claim - before D-Day (12 seconds) (claim should fail) - const tx2 = await safientMainBeneficiary.createClaim(safeId[4], ''); - const txReceipt2 = await tx2.wait(); - const claimId2 = txReceipt2.events[0].args[1]; - const claimID2 = parseInt(claimId2._hex); - - // check claim status (DDayBased) - const safeId4ClaimResult2 = await safientMainAccountX.getClaimStatus(safeId[4], claimID2); - expect(safeId4ClaimResult2).to.equal(2); // claim got Failed (before D-Day) + await expect(safientMainBeneficiary.createClaim(safeId[4], '')).to.be.rejectedWith(Error); // mine a new block after 2 seconds const mineNewBlock2 = new Promise((resolve, reject) => { diff --git a/test/claims.js b/test/claims.js index 40959c3..5675c52 100644 --- a/test/claims.js +++ b/test/claims.js @@ -334,16 +334,10 @@ describe('SafientMain', async () => { '' ); + // create a claim - before D-Day (claim should fail) - const tx1 = await safientMain.connect(beneficiary).createClaim(safeId4, ''); - const txReceipt1 = await tx1.wait(); - const claimId1 = txReceipt1.events[0].args[1]; - const claimID1 = parseInt(claimId1._hex); - - // check claim status (DDayBased) - const safeId4ClaimResult1 = await safientMain.connect(accountX).getClaimStatus(safeId4, claimID1); - expect(safeId4ClaimResult1).to.equal(2); // claim got Failed (before D-Day) - + await expect(safientMain.connect(beneficiary).createClaim(safeId4, '')).to.be.revertedWith('Cannot create claim before DDay'); + // mine a new block after 6 seconds const mineNewBlock = new Promise((resolve, reject) => { setTimeout(() => { @@ -389,14 +383,7 @@ describe('SafientMain', async () => { ); // create a claim - before D-Day (6 seconds) (claim should fail) - const tx1 = await safientMain.connect(beneficiary).createClaim(safeId5, ''); - const txReceipt1 = await tx1.wait(); - const claimId1 = txReceipt1.events[0].args[1]; - const claimID1 = parseInt(claimId1._hex); - - // check claim status (DDayBased) - const safeId5ClaimResult1 = await safientMain.connect(accountX).getClaimStatus(safeId5, claimID1); - expect(safeId5ClaimResult1).to.equal(2); // claim got Failed (before D-Day) + await expect(safientMain.connect(beneficiary).createClaim(safeId5, '')).to.be.revertedWith('Cannot create claim before DDay'); latestBlockNumber = await ethers.provider.getBlockNumber(); latestBlock = await ethers.provider.getBlock(latestBlockNumber); @@ -414,14 +401,7 @@ describe('SafientMain', async () => { const result1 = await mineNewBlock1; // create a claim - before D-Day (12 seconds) (claim should fail) - const tx2 = await safientMain.connect(beneficiary).createClaim(safeId5, ''); - const txReceipt2 = await tx2.wait(); - const claimId2 = txReceipt2.events[0].args[1]; - const claimID2 = parseInt(claimId2._hex); - - // check claim status (DDayBased) - const safeId5ClaimResult2 = await safientMain.connect(accountX).getClaimStatus(safeId5, claimID2); - expect(safeId5ClaimResult2).to.equal(2); // claim got Failed (before D-Day) + await expect(safientMain.connect(beneficiary).createClaim(safeId5, '')).to.be.revertedWith('Cannot create claim before DDay'); // mine a new block after 4 seconds const mineNewBlock2 = new Promise((resolve, reject) => {