Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: publish assets on-chain #654

Merged
merged 12 commits into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

### Properties

- [claimData](modules_claims.CreateClaimRequestOptions.md#claimdata)
- [claim](modules_claims.CreateClaimRequestOptions.md#claim)
- [registrationTypes](modules_claims.CreateClaimRequestOptions.md#registrationtypes)
- [subject](modules_claims.CreateClaimRequestOptions.md#subject)

## Properties

### claimData
### claim

• **claimData**: `ClaimData`
• **claim**: `ClaimData`

Claim request params

Expand Down
47 changes: 46 additions & 1 deletion e2e/claims.service.e2e.ts
Original file line number Diff line number Diff line change
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({
whitneypurdum marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -1301,7 +1347,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
Original file line number Diff line number Diff line change
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,
whitneypurdum marked this conversation as resolved.
Show resolved Hide resolved
subject,
role: claimType,
version: +claimTypeVersion,
});
Expand Down