Skip to content

Commit

Permalink
Fix: publish assets on-chain (#654)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
whitneypurdum committed Sep 19, 2022
1 parent 664aed4 commit 2c0a860
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
47 changes: 46 additions & 1 deletion e2e/claims.service.e2e.ts
Expand Up @@ -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 = {
Expand Down Expand Up @@ -160,6 +161,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 @@ -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()
Expand Down Expand Up @@ -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]);

Expand Down Expand Up @@ -1304,7 +1350,6 @@ describe('Сlaim tests', () => {
const assetDID = `did:${Methods.Erc1056}:${
Chain.VOLTA
}:${await assetsService.registerAsset()}`;

mockGetCachedOwnedAssets.mockResolvedValueOnce([
{ document: { id: assetDID }, id: assetDID },
]);
Expand Down
4 changes: 2 additions & 2 deletions src/modules/claims/claims.service.ts
Expand Up @@ -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,
});
Expand Down

0 comments on commit 2c0a860

Please sign in to comment.