Skip to content

Commit

Permalink
#41 - Auto claim status sync in safe data (#42)
Browse files Browse the repository at this point in the history
* adds automatic offchain and onchain claim status sync

* updates package version
  • Loading branch information
yathishram authored Jan 18, 2022
1 parent d7ec54c commit 74eb8c5
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 40 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@safient/core",
"version": "0.1.8-alpha",
"version": "0.1.9-alpha",
"description": "JavaScript SDK to manage safes and interact with Safient protocol.",
"keywords": [
"Web3",
Expand Down
22 changes: 17 additions & 5 deletions src/SafientCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,9 +465,15 @@ export class SafientCore {
try {
const result: Safe = await getSafeData(safeId);
// TODO: Need to move the different function
// if(result.decSafeKeyShards.length >=2 && result.stage !== SafeStages.CLAIMED){
// result.stage = SafeStages.RECOVERED
// }
if(result.stage === SafeStages.CLAIMING){
const claimStatus = await this.getClaimStatus(safeId, result.claims[result.claims.length - 1].disputeId)
result.claims[result.claims.length - 1].claimStatus = claimStatus
if(claimStatus === ClaimStages.PASSED){
result.stage = SafeStages.RECOVERING
}else{
result.stage = SafeStages.ACTIVE
}
}
return new SafientResponse({data: result});
} catch (err) {
throw new SafientResponse({error: Errors.SafeNotFound})
Expand Down Expand Up @@ -633,7 +639,9 @@ export class SafientCore {
const indexValue = safe.guardians.indexOf(did);
let recoveryStatus: boolean = false;
// internal function
if (safe.stage === SafeStages.RECOVERING) {
const res = await this.syncStage(safeId)

if (res.data === true && safe.stage === SafeStages.RECOVERING) {
const decShard: DecShard = await this.connection.idx?.ceramic.did?.decryptDagJWE(
safe.encSafeKeyShards[indexValue].data
) as DecShard;
Expand Down Expand Up @@ -739,7 +747,11 @@ export class SafientCore {
await this.updateStage(safeId, ClaimStages.PASSED, SafeStages.CLAIMED);
result = JSON.parse(safeData.toString());
return new SafientResponse({data: result.data})
} else {
}else if(safeData !== undefined && safe.stage === SafeStages.CLAIMED){
result = JSON.parse(safeData.toString());
return new SafientResponse({data: result.data})
}
else {
throw new SafientResponse({error: Errors.StageNotUpdated})
}
}
Expand Down
8 changes: 4 additions & 4 deletions test/scenario1.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,10 @@ describe('Scenario 1 - Creating safe offChain', async () => {
expect(result.data).to.equal(true);
});

it('Should update the stage on threadDB', async () => {
const result = await beneficiarySc.syncStage(safeId);
expect(result.data).to.equal(true);
});
// it('Should update the stage on threadDB', async () => {
// const result = await beneficiarySc.syncStage(safeId);
// expect(result.data).to.equal(true);
// });

it('Should initiate recovery by guardian 1', async () => {
const data = await guardianOneSc.reconstructSafe(safeId, guardianOne.data.did);
Expand Down
16 changes: 8 additions & 8 deletions test/scenario2.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,10 @@ describe('Scenario 2 - Creating safe onChain and Failing the dispute', async ()
expect(result.data).to.equal(true);
});

it('Should update the stage on threadDB', async () => {
const result = await beneficiarySc.syncStage(safeId);
expect(result.data).to.equal(true);
});
// it('Should update the stage on threadDB', async () => {
// const result = await beneficiarySc.syncStage(safeId);
// expect(result.data).to.equal(true);
// });

it('Should try to create Claim 2', async () => {
const file = {
Expand All @@ -264,10 +264,10 @@ describe('Scenario 2 - Creating safe onChain and Failing the dispute', async ()
expect(result.data).to.equal(true);
});

it('Should update the stage on threadDB', async () => {
const result = await beneficiarySc.syncStage(safeId);
expect(result.data).to.equal(true);
});
// it('Should update the stage on threadDB', async () => {
// const result = await beneficiarySc.syncStage(safeId);
// expect(result.data).to.equal(true);
// });

it('Should initiate recovery by guardian 1', async () => {
const data = await guardianOneSc.reconstructSafe(safeId, guardianOne.data.did);
Expand Down
12 changes: 6 additions & 6 deletions test/scenario3.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,12 @@ describe('Scenario 3 - Creating safe onChain and Passed the dispute', async () =
});
});

describe('Sync safe stage', async () => {
it('Updates the safe stage on threadDB according to the ruling', async () => {
const result = await beneficiarySc.syncStage(safeId);
expect(result.data).to.equal(true);
});
});
// describe('Sync safe stage', async () => {
// it('Updates the safe stage on threadDB according to the ruling', async () => {
// const result = await beneficiarySc.syncStage(safeId);
// expect(result.data).to.equal(true);
// });
// });

describe('Guardian recovery', async () => {
it('Recovery done by guardian 1', async () => {
Expand Down
8 changes: 4 additions & 4 deletions test/scenario4.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,10 @@ describe('Scenario 4 - Creating signal based Safe', async () => {
expect(disputeId.data).to.be.a('number');
});

it('Should update the stage on threadDB', async () => {
const result = await beneficiarySc.syncStage(safeId);
expect(result.data).to.equal(true);
});
// it('Should update the stage on threadDB', async () => {
// const result = await beneficiarySc.syncStage(safeId);
// expect(result.data).to.equal(true);
// });

it('Should initiate recovery by guardian 1', async () => {
const data = await guardianOneSc.reconstructSafe(safeId, guardianOne.data.did);
Expand Down
8 changes: 4 additions & 4 deletions test/scenario5.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,10 @@ describe('Scenario 5 - Creating signal based Safe', async () => {
expect(result.data.status).to.equal(1);
});

it('Should update the stage on threadDB', async () => {
const result = await beneficiarySc.syncStage(safeId);
expect(result.data).to.equal(true);
});
// it('Should update the stage on threadDB', async () => {
// const result = await beneficiarySc.syncStage(safeId);
// expect(result.data).to.equal(true);
// });

it('Should try recovery by guardian 1', async () => {
const data = await guardianOneSc.reconstructSafe(safeId, guardianOne.data.did);
Expand Down
8 changes: 4 additions & 4 deletions test/scenario6.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,10 @@ describe('Scenario 6 - Creating DDay based Safe', async () => {
expect(claimResult).to.equal(1); // claim got Passed (after D-Day)
});

it('Should update the stage on threadDB', async () => {
const result = await beneficiarySc.syncStage(safeId);
expect(result.data).to.equal(true);
});
// it('Should update the stage on threadDB', async () => {
// const result = await beneficiarySc.syncStage(safeId);
// expect(result.data).to.equal(true);
// });

it('Should initiate recovery by guardian 1', async () => {
const data = await guardianOneSc.reconstructSafe(safeId, guardianOne.data.did);
Expand Down
8 changes: 4 additions & 4 deletions test/unitTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,10 @@ describe('Unit test', async () => {
expect(result.data).to.equal(true);
});

it('Should update the stage on threadDB', async () => {
const result = await beneficiarySc.syncStage(safeId);
expect(result.data).to.equal(true);
});
// it('Should update the stage on threadDB', async () => {
// const result = await beneficiarySc.syncStage(safeId);
// expect(result.data).to.equal(true);
// });

// //Step 4: Recover Safes

Expand Down

0 comments on commit 74eb8c5

Please sign in to comment.