Skip to content

Commit

Permalink
Merge branch 'develop' into DS-82-add-start-end-of-pool
Browse files Browse the repository at this point in the history
  • Loading branch information
hejkerooo committed Nov 30, 2021
2 parents 6060fb2 + ff91e59 commit df7e98c
Show file tree
Hide file tree
Showing 21 changed files with 89 additions and 111 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- uses: actions/checkout@v2
with:
fetch-depth: 0
token: ${{ secrets.SECRET_NAME }}
token: ${{ github.token }}
- uses: actions/setup-node@v2-beta
with:
node-version: "10.22.0"
Expand Down
7 changes: 7 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# [3.3.0-alpha.22](https://github.com/energywebfoundation/iam-client-lib/compare/v3.3.0-alpha.21...v3.3.0-alpha.22) (2021-11-26)


### Features

* **messaging:** disable nats messaging method for Node.js ([febabd2](https://github.com/energywebfoundation/iam-client-lib/commit/febabd295b1dbae2553fea4eef6b965504c67484))

# [3.3.0-alpha.21](https://github.com/energywebfoundation/iam-client-lib/compare/v3.3.0-alpha.20...v3.3.0-alpha.21) (2021-11-25)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

### constructor

**new ClaimsService**(`_signerService`, `_domainsService`, `_cacheClient`, `_didRegistry`, `_messagingService`)
**new ClaimsService**(`_signerService`, `_domainsService`, `_cacheClient`, `_didRegistry`)

#### Parameters

Expand All @@ -42,7 +42,6 @@
| `_domainsService` | [`DomainsService`](modules_domains_domains_service.DomainsService.md) |
| `_cacheClient` | [`CacheClient`](modules_cacheClient_cacheClient_service.CacheClient.md) |
| `_didRegistry` | [`DidRegistry`](modules_didRegistry_didRegistry_service.DidRegistry.md) |
| `_messagingService` | [`MessagingService`](modules_messaging_messaging_service.MessagingService.md) |

## Methods

Expand Down Expand Up @@ -356,7 +355,7 @@ ___

### create

`Static` **create**(`signerService`, `domainsService`, `cacheClient`, `didRegistry`, `messagingService`): `Promise`<[`ClaimsService`](modules_claims_claims_service.ClaimsService.md)\>
`Static` **create**(`signerService`, `domainsService`, `cacheClient`, `didRegistry`): `Promise`<[`ClaimsService`](modules_claims_claims_service.ClaimsService.md)\>

#### Parameters

Expand All @@ -366,7 +365,6 @@ ___
| `domainsService` | [`DomainsService`](modules_domains_domains_service.DomainsService.md) |
| `cacheClient` | [`CacheClient`](modules_cacheClient_cacheClient_service.CacheClient.md) |
| `didRegistry` | [`DidRegistry`](modules_didRegistry_didRegistry_service.DidRegistry.md) |
| `messagingService` | [`MessagingService`](modules_messaging_messaging_service.MessagingService.md) |

#### Returns

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,9 @@
### Enumeration members

- [Nats](modules_messaging_messaging_types.MessagingMethod.md#nats)
- [SmartContractStorage](modules_messaging_messaging_types.MessagingMethod.md#smartcontractstorage)
- [WebRTC](modules_messaging_messaging_types.MessagingMethod.md#webrtc)

## Enumeration members

### Nats

**Nats** = `"nats"`

___

### SmartContractStorage

**SmartContractStorage** = `"smartContractStorage"`

___

### WebRTC

**WebRTC** = `"webRTC"`
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,20 @@
### Properties

- [messagingMethod](config_messaging_config.MessagingConfig.md#messagingmethod)
- [natsEnvironmentName](config_messaging_config.MessagingConfig.md#natsenvironmentname)
- [natsServerUrl](config_messaging_config.MessagingConfig.md#natsserverurl)

## Properties

### messagingMethod

**messagingMethod**: [`MessagingMethod`](../enums/modules_messaging_messaging_types.MessagingMethod.md)
**messagingMethod**: [`Nats`](../enums/modules_messaging_messaging_types.MessagingMethod.md#nats)

___

### natsEnvironmentName

**natsEnvironmentName**: `string`

___

Expand Down
14 changes: 14 additions & 0 deletions docs/api/interfaces/modules_assets_assets_types.Asset.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,21 @@

### Properties

- [createdAt](modules_assets_assets_types.Asset.md#createdat)
- [document](modules_assets_assets_types.Asset.md#document)
- [id](modules_assets_assets_types.Asset.md#id)
- [offeredTo](modules_assets_assets_types.Asset.md#offeredto)
- [owner](modules_assets_assets_types.Asset.md#owner)
- [updatedAt](modules_assets_assets_types.Asset.md#updatedat)

## Properties

### createdAt

**createdAt**: `string`

___

### document

**document**: `IDIDDocument`
Expand All @@ -34,3 +42,9 @@ ___
### owner

**owner**: `string`

___

### updatedAt

**updatedAt**: `string`
7 changes: 0 additions & 7 deletions docs/api/modules/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
- [MessagingMethod](index.md#messagingmethod)
- [MessagingService](index.md#messagingservice)
- [MethodNotAvailableInNodeEnvError](index.md#methodnotavailableinnodeenverror)
- [NATS\_EXCHANGE\_TOPIC](index.md#nats_exchange_topic)
- [NODE\_FIELDS\_KEY](index.md#node_fields_key)
- [NamespaceType](index.md#namespacetype)
- [Order](index.md#order)
Expand Down Expand Up @@ -330,12 +329,6 @@ Re-exports: [MethodNotAvailableInNodeEnvError](../classes/errors_MethodNotAvaila

___

### NATS\_EXCHANGE\_TOPIC

Re-exports: [NATS\_EXCHANGE\_TOPIC](modules_messaging_messaging_types.md#nats_exchange_topic)

___

### NODE\_FIELDS\_KEY

Re-exports: [NODE\_FIELDS\_KEY](modules_domains_domains_types.md#node_fields_key)
Expand Down
7 changes: 0 additions & 7 deletions docs/api/modules/modules_messaging.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
- [IMessage](modules_messaging.md#imessage)
- [MessagingMethod](modules_messaging.md#messagingmethod)
- [MessagingService](modules_messaging.md#messagingservice)
- [NATS\_EXCHANGE\_TOPIC](modules_messaging.md#nats_exchange_topic)

## References

Expand All @@ -26,9 +25,3 @@ ___
### MessagingService

Re-exports: [MessagingService](../classes/modules_messaging_messaging_service.MessagingService.md)

___

### NATS\_EXCHANGE\_TOPIC

Re-exports: [NATS\_EXCHANGE\_TOPIC](modules_messaging_messaging_types.md#nats_exchange_topic)
10 changes: 0 additions & 10 deletions docs/api/modules/modules_messaging_messaging_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,3 @@
### Interfaces

- [IMessage](../interfaces/modules_messaging_messaging_types.IMessage.md)

### Variables

- [NATS\_EXCHANGE\_TOPIC](modules_messaging_messaging_types.md#nats_exchange_topic)

## Variables

### NATS\_EXCHANGE\_TOPIC

`Const` **NATS\_EXCHANGE\_TOPIC**: ``"claim.exchange"``
39 changes: 17 additions & 22 deletions e2e/claims.service.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,19 @@ import { Methods } from "@ew-did-registry/did";
import { addressOf } from "@ew-did-registry/did-ethr-resolver";
import { KeyTags } from "@ew-did-registry/did-resolver-interface";
import { ethers, providers, utils, Wallet } from "ethers";
import { JSONCodec } from "nats.ws";
import {
AssetsService,
chainConfigs,
ClaimsService,
DidRegistry,
DomainsService,
ERROR_MESSAGES,
initWithPrivateKeySigner,
MessagingService,
NATS_EXCHANGE_TOPIC,
ProviderType,
RegistrationTypes,
SignerService,
chainConfigs,
StakingService,
DidRegistry,
MessagingService,
} from "../src";
import { replenish, root, rpcUrl, setupENS } from "./utils/setup_contracts";
import { ClaimManager__factory } from "../ethers/factories/ClaimManager__factory";
Expand Down Expand Up @@ -73,6 +71,9 @@ const mockGetDidDocument = jest.fn().mockImplementation((did: string) => {
});
const mockGetAssetById = jest.fn();
const mockGetClaimsBySubject = jest.fn();
const mockRequestClaim = jest.fn();
const mockIssueClaim = jest.fn();
const mockRejectClaim = jest.fn();
jest.mock("../src/modules/cacheClient/cacheClient.service", () => {
return {
CacheClient: jest.fn().mockImplementation(() => {
Expand All @@ -83,23 +84,23 @@ jest.mock("../src/modules/cacheClient/cacheClient.service", () => {
getClaimsBySubject: mockGetClaimsBySubject,
init: jest.fn(),
login: jest.fn(),
requestClaim: mockRequestClaim,
issueClaim: mockIssueClaim,
rejectClaim: mockRejectClaim,
};
}),
};
});

const mockPublish = jest.fn();
MessagingService.create = (signerService: SignerService) => Promise.resolve(new MessagingService(signerService));
jest.mock("../src/modules/messaging/messaging.service", () => {
return {
MessagingService: jest.fn().mockImplementation(() => {
return { publish: mockPublish };
return { publish: jest.fn() };
}),
};
});

const jsonCodec = JSONCodec();

StakingService.create = jest.fn();

describe("Enrollment claim tests", () => {
Expand Down Expand Up @@ -155,16 +156,14 @@ describe("Enrollment claim tests", () => {
registrationTypes,
subject: subjectDID,
});
const [, encodedMsg] = mockPublish.mock.calls.pop();
const message = jsonCodec.decode(encodedMsg) as any;
const [, message] = mockRequestClaim.mock.calls.pop();

await signerService.connect(issueSigner, ProviderType.PrivateKey);
const issuerDID = signerService.did;
await claimsService.issueClaimRequest({ ...message });
const [requesterChannel, data] = mockPublish.mock.calls.pop();
expect(requesterChannel).toEqual(`${requesterDID}.${NATS_EXCHANGE_TOPIC}`);
const [, data] = mockIssueClaim.mock.calls.pop();

const { issuedToken, requester, claimIssuer, onChainProof, acceptedBy } = jsonCodec.decode(data) as any;
const { issuedToken, requester, claimIssuer, onChainProof, acceptedBy } = data;

if (registrationTypes.includes(RegistrationTypes.OffChain)) {
expect(issuedToken).not.toBeUndefined();
Expand Down Expand Up @@ -311,12 +310,8 @@ describe("Enrollment claim tests", () => {
claim: { claimType: `${roleName1}.${root}`, claimTypeVersion: 1, fields: [] },
registrationTypes,
});
const [, encodedMsg1] = mockPublish.mock.calls.pop();
const { id, subjectAgreement, token } = jsonCodec.decode(encodedMsg1) as {
id;
subjectAgreement;
token;
};
const [, message] = mockRequestClaim.mock.calls.pop();
const { id, subjectAgreement, token } = message;
const issuerFields: { key: string; value: string | number }[] = [
{
key: "document ID",
Expand All @@ -337,8 +332,8 @@ describe("Enrollment claim tests", () => {
issuerFields,
});

const [, encodedMsg2] = mockPublish.mock.calls.pop();
const { issuedToken } = jsonCodec.decode(encodedMsg2) as { issuedToken };
const [, msg2] = mockIssueClaim.mock.calls.pop();
const { issuedToken } = msg2 as { issuedToken };
const data = didRegistry.jwt.decode(issuedToken) as { claimData: { issuerFields } };
expect(data.claimData.issuerFields).toEqual(issuerFields);
});
Expand Down
10 changes: 6 additions & 4 deletions e2e/staking.pool.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { IRoleDefinition } from "@energyweb/iam-contracts";
import { Methods } from "@ew-did-registry/did";
import { KeyTags } from "@ew-did-registry/did-resolver-interface";

import { BigNumber, providers, utils, Wallet } from "ethers";
import { JSONCodec } from "nats.ws";
import {
DomainsService,
initWithPrivateKeySigner,
Expand Down Expand Up @@ -32,7 +32,6 @@ const orgOwnerDid = `did:${Methods.Erc1056}:${orgOwner.address}`;
const patron = Wallet.createRandom().connect(provider);
const patronDID = `did:${Methods.Erc1056}:${patron.address}`;

const jsonCodec = JSONCodec();
MessagingService.create = (signerService: SignerService) => Promise.resolve(new MessagingService(signerService));
const mockPublish = jest.fn();
jest.mock("../src/modules/messaging/messaging.service", () => {
Expand All @@ -48,6 +47,7 @@ const mockGetDidDocument = jest.fn().mockImplementation(({ did }: { did: string
return { publicKey: [{ id: `did:ethr:${did}-${KeyTags.OWNER}` }] };
});
const mockGetApplicationsByOrgNamespace = jest.fn();
const mockRequestClaim = jest.fn();

jest.mock("../src/modules/cacheClient/cacheClient.service", () => {
return {
Expand All @@ -58,6 +58,8 @@ jest.mock("../src/modules/cacheClient/cacheClient.service", () => {
getApplicationsByOrganization: mockGetApplicationsByOrgNamespace,
init: jest.fn(),
login: jest.fn(),
requestClaim: mockRequestClaim,
issueClaim: jest.fn(),
};
}),
};
Expand Down Expand Up @@ -122,8 +124,8 @@ describe("StakingPool tests", () => {
registrationTypes,
});

const [, encodedMsg] = mockPublish.mock.calls.pop();
const { id, subjectAgreement, token } = jsonCodec.decode(encodedMsg) as any;
const [, message] = mockRequestClaim.mock.calls.pop();
const { id, subjectAgreement, token } = message;

await signerService.connect(orgOwner, ProviderType.PrivateKey);
mockGetRoleDefinition.mockReturnValueOnce(data);
Expand Down
9 changes: 5 additions & 4 deletions e2e/staking.service.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { providers, Wallet } from "ethers";
import { JSONCodec } from "nats.ws";
import { IRoleDefinition } from "@energyweb/iam-contracts";
import { Methods } from "@ew-did-registry/did";
import { KeyTags } from "@ew-did-registry/did-resolver-interface";
Expand All @@ -26,7 +25,6 @@ const orgOwnerDid = `did:${Methods.Erc1056}:${orgOwner.address}`;
const patron = Wallet.createRandom().connect(provider);
const patronDID = `did:${Methods.Erc1056}:${patron.address}`;

const jsonCodec = JSONCodec();
MessagingService.create = (signerService: SignerService) => Promise.resolve(new MessagingService(signerService));
const mockPublish = jest.fn();
jest.mock("../src/modules/messaging/messaging.service", () => {
Expand All @@ -42,6 +40,7 @@ const mockGetDidDocument = jest.fn().mockImplementation(({ did }: { did: string
return { publicKey: [{ id: `did:ethr:${did}-${KeyTags.OWNER}` }] };
});
const mockGetApplicationsByOrgNamespace = jest.fn();
const mockRequestClaim = jest.fn();

jest.mock("../src/modules/cacheClient/cacheClient.service", () => {
return {
Expand All @@ -52,6 +51,8 @@ jest.mock("../src/modules/cacheClient/cacheClient.service", () => {
getApplicationsByOrganization: mockGetApplicationsByOrgNamespace,
init: jest.fn(),
login: jest.fn(),
requestClaim: mockRequestClaim,
issueClaim: jest.fn(),
};
}),
};
Expand Down Expand Up @@ -115,8 +116,8 @@ describe("Staking service tests", () => {
registrationTypes,
});

const [, encodedMsg] = mockPublish.mock.calls.pop();
const { id, subjectAgreement, token } = jsonCodec.decode(encodedMsg) as any;
const [, message] = mockRequestClaim.mock.calls.pop();
const { id, subjectAgreement, token } = message;

await signerService.connect(orgOwner, ProviderType.PrivateKey);
mockGetRoleDefinition.mockReturnValueOnce(data);
Expand Down
2 changes: 1 addition & 1 deletion jest.setup.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
jest.setTimeout(20000);
jest.setTimeout(40000);
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "iam-client-lib",
"version": "3.3.0-alpha.21",
"version": "3.3.0-alpha.22",
"description": "Library for Decentralized Identity and Access Management",
"main": "dist/index.js",
"module": "dist/index.esm.js",
Expand Down

0 comments on commit df7e98c

Please sign in to comment.