From 2c0a860c7e11b9fb833ddbed71e2adf51229987b Mon Sep 17 00:00:00 2001 From: Whitney Purdum Date: Mon, 19 Sep 2022 10:03:14 -0400 Subject: [PATCH] Fix: publish assets on-chain (#654) * fix(infura): replace config with ipfs daemon for initUser methods * fix: update agreer for subjectAgreementCheck * fix: update test to register asset * fix: always use subject for subjectAgreement * fix: remove mock for getting assets * fix: remove unused asset wallet * fix: use subject --- e2e/claims.service.e2e.ts | 47 +++++++++++++++++++++++++++- src/modules/claims/claims.service.ts | 4 +-- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/e2e/claims.service.e2e.ts b/e2e/claims.service.e2e.ts index 2c87e6d6..f99c7028 100644 --- a/e2e/claims.service.e2e.ts +++ b/e2e/claims.service.e2e.ts @@ -73,6 +73,7 @@ const vcExpired = 'vcExpired'; const electrician = 'electrician'; const projectElectrician = 'projectElectrician'; const projectInstaller = 'projectInstaller'; +const roleForAsset = 'roleForAsset'; const namespace = root; const version = 1; const baseRoleDef = { @@ -160,6 +161,11 @@ const roles: Record = { roleName: projectInstaller, issuer: { issuerType: 'DID', did: [staticIssuerDID] }, }, + [`${roleForAsset}.${root}`]: { + ...baseRoleDef, + roleName: roleForAsset, + issuer: { issuerType: 'DID', did: [rootOwnerDID] }, + }, }; const mockGetRoleDefinition = jest .fn() @@ -337,6 +343,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() @@ -948,6 +960,40 @@ describe('Сlaim tests', () => { ).toBe(true); }); + test('should be able to issue without request and publish onchain for owned asset', async () => { + await signerService.connect(rootOwner, ProviderType.PrivateKey); + const claimType = `${roleForAsset}.${root}`; + const assetDID = `did:${Methods.Erc1056}:${ + Chain.VOLTA + }:${await assetsService.registerAsset()}`; + + const claim = await issueWithoutRequest(rootOwner, { + subjectDID: assetDID, + claimType, + registrationTypes, + }); + expect(claim.onChainProof).toHaveLength(132); + const mockedClaim = { + claimType, + isApproved: true, + onChainProof: claim.onChainProof, + claimTypeVersion: version, + acceptedBy: claim.acceptedBy, + subject: assetDID, + }; + mockGetClaimsBySubject + .mockReset() + .mockImplementationOnce(() => [mockedClaim]); + + await claimsService.publishPublicClaim({ + claim: { claimType }, + registrationTypes, + }); + expect( + await claimsService.hasOnChainRole(assetDID, claimType, version) + ).toBe(true); + }); + test('should be able to issue without publishing onchain', async () => { mockGetClaimsBySubject.mockImplementationOnce(() => [role1Claim]); @@ -1304,7 +1350,6 @@ describe('Сlaim tests', () => { const assetDID = `did:${Methods.Erc1056}:${ Chain.VOLTA }:${await assetsService.registerAsset()}`; - mockGetCachedOwnedAssets.mockResolvedValueOnce([ { document: { id: assetDID }, id: assetDID }, ]); diff --git a/src/modules/claims/claims.service.ts b/src/modules/claims/claims.service.ts index 5bced296..ff576cba 100644 --- a/src/modules/claims/claims.service.ts +++ b/src/modules/claims/claims.service.ts @@ -545,9 +545,9 @@ export class ClaimsService { return; } - if (!subjectAgreement && subject === this._signerService.did) { + if (!subjectAgreement) { subjectAgreement = await this.approveRolePublishing({ - subject: this._signerService.did, + subject, role: claimType, version: +claimTypeVersion, });