Skip to content

Commit

Permalink
Merge pull request #26 from PolymeshAssociation/master-into-alpha
Browse files Browse the repository at this point in the history
Master into alpha
  • Loading branch information
polymath-eric committed May 2, 2024
2 parents a526420 + 8001f0d commit 783cdae
Show file tree
Hide file tree
Showing 28 changed files with 457 additions and 160 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

## Polymesh version

This release is compatible with Polymesh v6.x.x and Polymesh Private v1.x.x
This release is compatible with Polymesh v6.0, v6.1, v6.2 and Polymesh Private v1.0

<!--- End of section --->

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
"@polkadot/api": "10.9.1",
"@polkadot/util": "12.4.2",
"@polkadot/util-crypto": "12.4.2",
"@polymeshassociation/polymesh-sdk": "24.1.0",
"@polymeshassociation/polymesh-sdk": "24.2.1",
"bignumber.js": "9.0.1",
"bluebird": "^3.7.2",
"cross-fetch": "^4.0.0",
Expand Down
6 changes: 0 additions & 6 deletions scripts/consts.js

This file was deleted.

73 changes: 41 additions & 32 deletions scripts/updateReadme.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
/* eslint-disable @typescript-eslint/naming-convention */
const W3CWebSocket = require('websocket').w3cwebsocket;
const WebSocketAsPromised = require('websocket-as-promised');
/* eslint-enable @typescript-eslint/naming-convention */
/* eslint-disable */

const fs = require('fs');
const path = require('path');
const replace = require('replace-in-file');
const { NODE_URL, WS_PORT } = require('./consts');
const versionRegex = /This release is compatible with Polymesh v(.*) and Polymesh Private .*/;
const ppVersionRegex = /This release is compatible with Polymesh v.* and Polymesh Private v(.*)/;

const versionRegex = /This release is compatible with Polymesh v(\d+\.\d+\.\d+)/;
const getSupportedNodeVersion = path => {
const constantsFile = fs.readFileSync(path, {
encoding: 'utf8',
});

const regex = /export const SUPPORTED_NODE_VERSION_RANGE = '([^']+)';/g;

const match = regex.exec(constantsFile);

return match[1];
};

/**
* Replace the version number in the README
Expand All @@ -15,29 +25,28 @@ const createReplacementVersion = newVersion => (text, prevVersion) => {
return text.replace(prevVersion, newVersion);
};

// eslint-disable-next-line @typescript-eslint/no-floating-promises
(async () => {
const wsp = new WebSocketAsPromised(`ws://${NODE_URL}:${WS_PORT}`, {
createWebSocket: url => new W3CWebSocket(url),
packMessage: data => JSON.stringify(data),
unpackMessage: data => JSON.parse(data.toString()),
attachRequestId: (data, requestId) => Object.assign({ id: requestId }, data),
extractRequestId: data => data && data.id,
});

await wsp.open();

const { result: version } = await wsp.sendRequest({
jsonrpc: '2.0',
method: 'system_version',
params: [],
});

replace.sync({
files: 'README.md',
from: versionRegex,
to: createReplacementVersion(version),
});

process.exit(0);
})();
const supportedNodeVersionString = supportedNodeVersion =>
supportedNodeVersion
.split('||')
.map(version => version.trim())
.join(', v');

const {
SUPPORTED_NODE_VERSION_RANGE: supportedNodeVersionForPolymesh,
} = require('@polymeshassociation/polymesh-sdk/utils/constants');

replace.sync({
files: 'README.md',
from: versionRegex,
to: createReplacementVersion(supportedNodeVersionString(supportedNodeVersionForPolymesh)),
});

const supportedNodeVersionForPolymeshPrivate = getSupportedNodeVersion(
path.resolve('src', 'utils', 'constants.ts')
);

replace.sync({
files: 'README.md',
from: ppVersionRegex,
to: createReplacementVersion(supportedNodeVersionString(supportedNodeVersionForPolymeshPrivate)),
});
3 changes: 1 addition & 2 deletions sdk-docs-typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"src/generated/types.ts",
"src/types/index.ts",
"src/types/utils",
"src/utils/index.ts",
"src/entities/types.ts",
"src/base"
],
"entryPointStrategy": "expand",
Expand All @@ -19,7 +19,6 @@
"src/base/Context.ts",
"src/base/Procedure.ts",
"**/sandbox.ts",
"src/api/entities/types.ts",
"src/api/entities/Namespace.ts",
"src/types/internal.ts",
"src/utils/**",
Expand Down
3 changes: 1 addition & 2 deletions src/api/client/Polymesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ import {
import { SigningManager } from '@polymeshassociation/signing-manager-types';

import { ConfidentialAccounts } from '~/api/client/ConfidentialAccounts';
import { ConfidentialAssets } from '~/api/client/ConfidentialAssets';
import { ConfidentialSettlements } from '~/api/client/ConfidentialSettlements';
import schema from '~/polkadot/schema';

import { ConfidentialAssets } from './ConfidentialAssets';

export interface ConnectParams {
/**
* The websocket URL for the Polymesh node to connect to
Expand Down
4 changes: 1 addition & 3 deletions src/api/entities/ConfidentialAsset/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { EventIdEnum } from '@polymeshassociation/polymesh-sdk/middleware/types';
import { Identity } from '@polymeshassociation/polymesh-sdk/types';
import BigNumber from 'bignumber.js';

import { ConfidentialVenue } from '~/internal';
import { ConfidentialAccount } from '~/types';
import { ConfidentialAccount, ConfidentialVenue, Identity } from '~/internal';

export interface ConfidentialAssetDetails {
owner: Identity;
Expand Down
158 changes: 158 additions & 0 deletions src/api/entities/Identity/__tests__/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
import { u64 } from '@polkadot/types';
import { PolymeshPrimitivesIdentityId } from '@polkadot/types/lookup';
import BigNumber from 'bignumber.js';
import { when } from 'jest-when';

import { Context, Entity, Identity } from '~/internal';
import { dsMockUtils, entityMockUtils, procedureMockUtils } from '~/testUtils/mocks';
import { MockContext } from '~/testUtils/mocks/dataSources';
import { ConfidentialLegParty } from '~/types';
import { tuple } from '~/types/utils';
import * as utilsConversionModule from '~/utils/conversion';

jest.mock(
'~/api/entities/ConfidentialAsset',
require('~/testUtils/mocks/entities').mockConfidentialAssetModule(
'~/api/entities/ConfidentialAsset'
)
);

jest.mock(
'~/api/entities/ConfidentialVenue',
require('~/testUtils/mocks/entities').mockConfidentialVenueModule(
'~/api/entities/ConfidentialVenue'
)
);

describe('Identity class', () => {
let context: MockContext;
let stringToIdentityIdSpy: jest.SpyInstance<PolymeshPrimitivesIdentityId, [string, Context]>;
let u64ToBigNumberSpy: jest.SpyInstance<BigNumber, [u64]>;

beforeAll(() => {
dsMockUtils.initMocks();
entityMockUtils.initMocks();
procedureMockUtils.initMocks();
stringToIdentityIdSpy = jest.spyOn(utilsConversionModule, 'stringToIdentityId');
u64ToBigNumberSpy = jest.spyOn(utilsConversionModule, 'u64ToBigNumber');
});

beforeEach(() => {
context = dsMockUtils.getContextInstance({
middlewareEnabled: true,
});
});

afterEach(() => {
dsMockUtils.reset();
entityMockUtils.reset();
procedureMockUtils.reset();
});

afterAll(() => {
dsMockUtils.cleanup();
procedureMockUtils.cleanup();
});

it('should extend Entity', () => {
expect(Identity.prototype instanceof Entity).toBe(true);
});

describe('constructor', () => {
it('should assign did to instance', () => {
const did = 'abc';
const identity = new Identity({ did }, context);

expect(identity.did).toBe(did);
});
});

describe('method: isUniqueIdentifiers', () => {
it('should return true if the object conforms to the interface', () => {
expect(Identity.isUniqueIdentifiers({ did: 'someDid' })).toBe(true);
expect(Identity.isUniqueIdentifiers({})).toBe(false);
expect(Identity.isUniqueIdentifiers({ did: 3 })).toBe(false);
});
});

describe('method: getInvolvedConfidentialTransactions', () => {
const transactionId = new BigNumber(1);
const legId = new BigNumber(2);

it('should return the transactions with the identity affirmation status', async () => {
dsMockUtils.createQueryMock('confidentialAsset', 'userAffirmations', {
entries: [
tuple(
[
dsMockUtils.createMockIdentityId('someDid'),
[
dsMockUtils.createMockConfidentialTransactionId(transactionId),
dsMockUtils.createMockConfidentialTransactionLegId(legId),
dsMockUtils.createMockConfidentialLegParty('Sender'),
],
],
dsMockUtils.createMockOption(dsMockUtils.createMockBool(false))
),
],
});

const identity = new Identity({ did: 'someDid' }, context);

const result = await identity.getInvolvedConfidentialTransactions();

expect(result).toEqual({
data: expect.arrayContaining([
expect.objectContaining({
affirmed: false,
legId: new BigNumber(2),
role: ConfidentialLegParty.Sender,
transaction: expect.objectContaining({ id: transactionId }),
}),
]),
next: null,
});
});
});

describe('method: getConfidentialVenues', () => {
let did: string;
let confidentialVenueId: BigNumber;

let rawDid: PolymeshPrimitivesIdentityId;
let rawConfidentialVenueId: u64;

beforeAll(() => {
did = 'someDid';
confidentialVenueId = new BigNumber(5);

rawDid = dsMockUtils.createMockIdentityId(did);
rawConfidentialVenueId = dsMockUtils.createMockU64(confidentialVenueId);
});

beforeEach(() => {
when(stringToIdentityIdSpy).calledWith(did, context).mockReturnValue(rawDid);
});

afterAll(() => {
jest.restoreAllMocks();
});

it('should return a list of Confidential Venues', async () => {
when(u64ToBigNumberSpy)
.calledWith(rawConfidentialVenueId)
.mockReturnValue(confidentialVenueId);

const mock = dsMockUtils.createQueryMock('confidentialAsset', 'identityVenues');
const mockStorageKey = { args: [rawDid, rawConfidentialVenueId] };

mock.keys = jest.fn().mockResolvedValue([mockStorageKey]);

const identity = new Identity({ did }, context);

const result = await identity.getConfidentialVenues();
expect(result).toEqual(
expect.arrayContaining([expect.objectContaining({ id: confidentialVenueId })])
);
});
});
});

0 comments on commit 783cdae

Please sign in to comment.