Skip to content

Commit

Permalink
fix: update agreer for subjectAgreementCheck
Browse files Browse the repository at this point in the history
  • Loading branch information
whitneypurdum committed Sep 12, 2022
1 parent 17042ec commit 9a818a3
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 5 deletions.
48 changes: 47 additions & 1 deletion e2e/claims.service.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ const projectInstallerCandidate = Wallet.createRandom().connect(provider);
const projectInstallerCandidateDID = `did:${Methods.Erc1056}:${Chain.VOLTA}:${projectInstallerCandidate.address}`;
const rootOwner = Wallet.createRandom().connect(provider);
const rootOwnerDID = `did:${Methods.Erc1056}:${Chain.VOLTA}:${rootOwner.address}`;
const myAsset = Wallet.createRandom().connect(provider);
const myAssetDid = `did:${Methods.Erc1056}:${Chain.VOLTA}:${myAsset.address}`;
const roleName1 = 'myrole1';
const roleName2 = 'myrole2';
const roleName3 = 'myrole3';
Expand All @@ -73,6 +75,7 @@ const vcExpired = 'vcExpired';
const electrician = 'electrician';
const projectElectrician = 'projectElectrician';
const projectInstaller = 'projectInstaller';
const roleForAsset = 'roleForAsset';
const namespace = root;
const version = 1;
const baseRoleDef = {
Expand Down Expand Up @@ -160,6 +163,11 @@ const roles: Record<string, IRoleDefinitionV2> = {
roleName: projectInstaller,
issuer: { issuerType: 'DID', did: [staticIssuerDID] },
},
[`${roleForAsset}.${root}`]: {
...baseRoleDef,
roleName: roleForAsset,
issuer: { issuerType: 'DID', did: [rootOwnerDID] },
},
};
const mockGetRoleDefinition = jest
.fn()
Expand Down Expand Up @@ -244,6 +252,7 @@ describe('Сlaim tests', () => {
await replenish(await rootOwner.getAddress());
await replenish(await dynamicIssuer.getAddress());
await replenish(await projectInstallerCandidate.getAddress());
await replenish(await myAsset.getAddress());

await setupENS(await rootOwner.getAddress());
let connectToCacheServer;
Expand Down Expand Up @@ -337,6 +346,12 @@ describe('Сlaim tests', () => {
data: roles[`${projectInstaller}.${root}`],
returnSteps: false,
});
await domainsService.createRole({
roleName: roleForAsset,
namespace,
data: roles[`${roleForAsset}.${root}`],
returnSteps: false,
});

({ didRegistry, claimsService } = await connectToDidRegistry(
await spawnIpfsDaemon()
Expand Down Expand Up @@ -495,7 +510,8 @@ describe('Сlaim tests', () => {
requestorFields,
});

expirationTimestamp && expect(exp).toEqual(Math.floor(expirationTimestamp / 1000));
expirationTimestamp &&
expect(exp).toEqual(Math.floor(expirationTimestamp / 1000));

expect(claimData).not.toContain({
fields: [{ key: 'temperature', value: 36 }],
Expand Down Expand Up @@ -947,6 +963,36 @@ describe('Сlaim tests', () => {
).toBe(true);
});

test('should be able to issue without request and publish onchain when signer is not subject (i.e. for asset)', async () => {
const claimType = `${roleForAsset}.${root}`;
const claim = await issueWithoutRequest(rootOwner, {
subjectDID: myAssetDid,
claimType,
registrationTypes,
});
expect(claim.onChainProof).toHaveLength(132);
await signerService.connect(rootOwner, ProviderType.PrivateKey);
const mockedClaim = {
claimType,
isApproved: true,
onChainProof: claim.onChainProof,
claimTypeVersion: version,
acceptedBy: claim.acceptedBy,
subject: myAssetDid,
};
mockGetClaimsBySubject
.mockReset()
.mockImplementationOnce(() => [mockedClaim]);

await claimsService.publishPublicClaim({
claim: { claimType },
registrationTypes,
});
expect(
await claimsService.hasOnChainRole(rootOwnerDID, claimType, version)
).toBe(true);
});

test('should be able to issue without publishing onchain', async () => {
mockGetClaimsBySubject.mockImplementationOnce(() => [role1Claim]);

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions src/modules/claims/claims.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -545,12 +545,16 @@ export class ClaimsService {
return;
}

if (!subjectAgreement && subject === this._signerService.did) {
if (!subjectAgreement) {
// If the signer is the subject, use the signer DID. If the signer is not the subject, use the subject DID:
const subjectAgreer =
subject === this._signerService.did ? this._signerService.did : subject;
subjectAgreement = await this.approveRolePublishing({
subject: this._signerService.did,
subject: subjectAgreer,
role: claimType,
version: +claimTypeVersion,
});
// }
}

const expiry = expirationTimestamp || eternityTimestamp;
Expand Down

0 comments on commit 9a818a3

Please sign in to comment.