Skip to content

Commit b4b7626

Browse files
authored
Merge pull request #107 from PolymathNetwork/chore/DA-364
chore: 🤖 Bump SDK version to 15.0.0-alpha.10
2 parents 6cef460 + 8a9b7b2 commit b4b7626

11 files changed

+47
-123
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"@nestjs/swagger": "^5.2.1",
3434
"@polymathnetwork/hashicorp-vault-signing-manager": "^1.1.0",
3535
"@polymathnetwork/local-signing-manager": "^1.0.5",
36-
"@polymathnetwork/polymesh-sdk": "15.0.0-alpha.6",
36+
"@polymathnetwork/polymesh-sdk": "15.0.0-alpha.10",
3737
"@polymathnetwork/signing-manager-types": "^1.0.3",
3838
"class-transformer": "0.5.1",
3939
"class-validator": "^0.13.2",

src/accounts/accounts.util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function createPermissionsModel(permissions: Permissions): PermissionsMod
1414
let assetPermissions: AssetPermissionsModel | null;
1515
if (assets) {
1616
const { type, values } = assets;
17-
assetPermissions = new AssetPermissionsModel({ type, values: values.map(v => v.toJson()) });
17+
assetPermissions = new AssetPermissionsModel({ type, values: values.map(v => v.toHuman()) });
1818
} else {
1919
assetPermissions = null;
2020
}

src/common/decorators/transformation.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export function ToBigNumber() {
2020
* Entity -> POJO
2121
*/
2222
export function FromEntity() {
23-
return applyDecorators(Transform(({ value }: { value: Entity<unknown> }) => value?.toJson()));
23+
return applyDecorators(Transform(({ value }: { value: Entity<unknown> }) => value?.toHuman()));
2424
}
2525

2626
/**
@@ -31,7 +31,7 @@ export function FromMaybeEntityArray() {
3131
Transform(({ value }: { value: unknown[] }) =>
3232
value.map(val => {
3333
if (isEntity(val)) {
34-
return val.toJson();
34+
return val.toHuman();
3535
}
3636

3737
return val;
@@ -44,16 +44,16 @@ export function FromMaybeEntityArray() {
4444
* or serialize the value if it is an SDK Entity in
4545
*/
4646
export function FromEntityObject() {
47-
return applyDecorators(Transform(({ value }: { value: unknown }) => toJsonObject(value)));
47+
return applyDecorators(Transform(({ value }: { value: unknown }) => toHumanObject(value)));
4848
}
4949

50-
function toJsonObject(obj: unknown): unknown {
50+
function toHumanObject(obj: unknown): unknown {
5151
if (isEntity(obj)) {
52-
return obj.toJson();
52+
return obj.toHuman();
5353
}
5454

5555
if (Array.isArray(obj)) {
56-
return obj.map(toJsonObject);
56+
return obj.map(toHumanObject);
5757
}
5858

5959
if (obj instanceof BigNumber && !obj.isNaN()) {
@@ -62,7 +62,7 @@ function toJsonObject(obj: unknown): unknown {
6262

6363
if (obj && typeof obj === 'object') {
6464
// eslint-disable-next-line @typescript-eslint/no-explicit-any
65-
return mapValues(obj as any, val => toJsonObject(val));
65+
return mapValues(obj as any, val => toHumanObject(val));
6666
}
6767
return obj;
6868
}

src/common/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
export interface Entity<Serialized> {
44
uuid: string;
55

6-
toJson(): Serialized;
6+
toHuman(): Serialized;
77
}
88

99
// eslint-disable-next-line @typescript-eslint/ban-types, @typescript-eslint/no-explicit-any

src/portfolios/portfolios.util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export async function createPortfolioModel(
6060
export function createPortfolioIdentifierModel(
6161
portfolio: DefaultPortfolio | NumberedPortfolio
6262
): PortfolioIdentifierModel {
63-
return new PortfolioIdentifierModel(portfolio.toJson());
63+
return new PortfolioIdentifierModel(portfolio.toHuman());
6464
}
6565

6666
export function toPortfolioId(id: BigNumber): BigNumber | undefined {

src/test-utils/mocks.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export class MockAsset {
140140
issue: jest.fn(),
141141
};
142142

143-
public toJson = jest.fn().mockImplementation(() => this.ticker);
143+
public toHuman = jest.fn().mockImplementation(() => this.ticker);
144144
}
145145

146146
export class MockInstruction {
@@ -193,7 +193,7 @@ export class MockPortfolio {
193193
public isCustodiedBy = jest.fn();
194194
public getCustodian = jest.fn();
195195
public moveFunds = jest.fn();
196-
public toJson = jest.fn().mockImplementation(() => {
196+
public toHuman = jest.fn().mockImplementation(() => {
197197
return {
198198
id: '1',
199199
did: '0x06'.padEnd(66, '0'),

src/ticker-reservations/ticker-reservations.controller.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,25 @@ describe('TickerReservationsController', () => {
4343
});
4444
});
4545

46+
describe('getDetails', () => {
47+
it('should call the service and return the details', async () => {
48+
const mockDetails = {
49+
owner: '0x6000',
50+
expiryDate: null,
51+
status: TickerReservationStatus.AssetCreated,
52+
};
53+
const mockTickerReservation = new MockTickerReservation();
54+
mockTickerReservation.details.mockResolvedValue(mockDetails);
55+
mockTickerReservationsService.findOne.mockResolvedValue(mockTickerReservation);
56+
57+
const ticker = 'SOME_TICKER';
58+
const result = await controller.getDetails({ ticker });
59+
60+
expect(result).toEqual(mockDetails);
61+
expect(mockTickerReservationsService.findOne).toHaveBeenCalledWith(ticker);
62+
});
63+
});
64+
4665
describe('transferOwnership', () => {
4766
it('should call the service and return the results', async () => {
4867
const mockAuthorization = new MockAuthorizationRequest();

src/ticker-reservations/ticker-reservations.controller.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { Body, Controller, Get, Param, Post } from '@nestjs/common';
22
import {
33
ApiCreatedResponse,
4-
ApiGoneResponse,
5-
ApiNotFoundResponse,
64
ApiOkResponse,
75
ApiOperation,
86
ApiParam,
@@ -60,12 +58,6 @@ export class TickerReservationsController {
6058
description: 'Details of the ticker reservation',
6159
type: TickerReservationModel,
6260
})
63-
@ApiNotFoundResponse({
64-
description: 'The ticker has not been reserved',
65-
})
66-
@ApiGoneResponse({
67-
description: 'Asset has already been created',
68-
})
6961
@Get(':ticker')
7062
public async getDetails(@Param() { ticker }: TickerParamsDto): Promise<TickerReservationModel> {
7163
const tickerReservation = await this.tickerReservationsService.findOne(ticker);

src/ticker-reservations/ticker-reservations.service.spec.ts

Lines changed: 6 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
const mockIsPolymeshError = jest.fn();
33
const mockIsPolymeshTransaction = jest.fn();
44

5-
import { GoneException, NotFoundException } from '@nestjs/common';
65
import { Test, TestingModule } from '@nestjs/testing';
76
import { BigNumber } from '@polymathnetwork/polymesh-sdk';
8-
import { ErrorCode, TxTags } from '@polymathnetwork/polymesh-sdk/types';
7+
import { TxTags } from '@polymathnetwork/polymesh-sdk/types';
98

109
import { TransactionType } from '~/common/types';
1110
import { POLYMESH_API } from '~/polymesh/polymesh.consts';
@@ -64,74 +63,12 @@ describe('TickerReservationsService', () => {
6463
});
6564

6665
describe('findOne', () => {
67-
describe('if the reservation does not exist', () => {
68-
it('should throw a NotFoundException', async () => {
69-
const mockError = {
70-
message: 'There is no reservation for',
71-
code: ErrorCode.UnmetPrerequisite,
72-
};
73-
mockPolymeshApi.assets.getTickerReservation.mockImplementation(() => {
74-
throw mockError;
75-
});
76-
77-
mockIsPolymeshError.mockReturnValue(true);
78-
79-
let error;
80-
try {
81-
await service.findOne('TICKER');
82-
} catch (err) {
83-
error = err;
84-
}
85-
86-
expect(error).toBeInstanceOf(NotFoundException);
87-
});
88-
});
89-
describe('if the asset has already been created', () => {
90-
it('should throw a GoneException', async () => {
91-
const mockError = {
92-
code: ErrorCode.UnmetPrerequisite,
93-
message: 'TICKER Asset has been created',
94-
};
95-
mockPolymeshApi.assets.getTickerReservation.mockImplementation(() => {
96-
throw mockError;
97-
});
98-
99-
mockIsPolymeshError.mockReturnValue(true);
100-
101-
let error;
102-
try {
103-
await service.findOne('TICKER');
104-
} catch (err) {
105-
error = err;
106-
}
107-
108-
expect(error).toBeInstanceOf(GoneException);
109-
});
110-
});
111-
describe('if there is a different error', () => {
112-
it('should pass the error along the chain', async () => {
113-
const expectedError = new Error('Something else');
114-
mockPolymeshApi.assets.getTickerReservation.mockImplementation(() => {
115-
throw expectedError;
116-
});
117-
mockIsPolymeshError.mockReturnValue(true);
118-
let error;
119-
try {
120-
await service.findOne('TICKER');
121-
} catch (err) {
122-
error = err;
123-
}
124-
expect(error).toBe(expectedError);
125-
});
126-
});
127-
describe('otherwise', () => {
128-
it('should return the reservation', async () => {
129-
const mockTickerReservation = new MockTickerReservation();
130-
mockPolymeshApi.assets.getTickerReservation.mockResolvedValue(mockTickerReservation);
66+
it('should return the reservation', async () => {
67+
const mockTickerReservation = new MockTickerReservation();
68+
mockPolymeshApi.assets.getTickerReservation.mockResolvedValue(mockTickerReservation);
13169

132-
const result = await service.findOne('TICKER');
133-
expect(result).toEqual(mockTickerReservation);
134-
});
70+
const result = await service.findOne('TICKER');
71+
expect(result).toEqual(mockTickerReservation);
13572
});
13673
});
13774

src/ticker-reservations/ticker-reservations.service.ts

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
import { GoneException, Injectable, NotFoundException } from '@nestjs/common';
2-
import {
3-
AuthorizationRequest,
4-
ErrorCode,
5-
TickerReservation,
6-
} from '@polymathnetwork/polymesh-sdk/types';
7-
import { isPolymeshError } from '@polymathnetwork/polymesh-sdk/utils';
1+
import { Injectable } from '@nestjs/common';
2+
import { AuthorizationRequest, TickerReservation } from '@polymathnetwork/polymesh-sdk/types';
83

94
import { TransferOwnershipDto } from '~/common/dto/transfer-ownership.dto';
105
import { processQueue, QueueResult } from '~/common/utils';
@@ -19,28 +14,9 @@ export class TickerReservationsService {
1914
) {}
2015

2116
public async findOne(ticker: string): Promise<TickerReservation> {
22-
try {
23-
return await this.polymeshService.polymeshApi.assets.getTickerReservation({
24-
ticker,
25-
});
26-
} catch (err: unknown) {
27-
if (isPolymeshError(err)) {
28-
const { code, message } = err;
29-
if (
30-
code === ErrorCode.UnmetPrerequisite &&
31-
message.startsWith('There is no reservation for')
32-
) {
33-
throw new NotFoundException(`There is no reservation for "${ticker}"`);
34-
} else if (
35-
code === ErrorCode.UnmetPrerequisite &&
36-
message.endsWith('Asset has been created')
37-
) {
38-
throw new GoneException(`Asset "${ticker}" has already been created`);
39-
}
40-
}
41-
42-
throw err;
43-
}
17+
return this.polymeshService.polymeshApi.assets.getTickerReservation({
18+
ticker,
19+
});
4420
}
4521

4622
public async reserve(ticker: string, signer: string): Promise<QueueResult<TickerReservation>> {

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,10 +1457,10 @@
14571457
dependencies:
14581458
"@polymathnetwork/signing-manager-types" "^1.0.3"
14591459

1460-
"@polymathnetwork/[email protected].6":
1461-
version "15.0.0-alpha.6"
1462-
resolved "https://registry.yarnpkg.com/@polymathnetwork/polymesh-sdk/-/polymesh-sdk-15.0.0-alpha.6.tgz#9f2747f3222f4ffc10708a67fadc8f9aadcd6720"
1463-
integrity sha512-MV8MjtGGcXBP1ykVRRvxZvZXqW7D9Fq0VOnJBSo1yopFajdOxW91m5Wae00XD0facUzArkfXvl+UuZpV0KtV+w==
1460+
"@polymathnetwork/[email protected].10":
1461+
version "15.0.0-alpha.10"
1462+
resolved "https://registry.yarnpkg.com/@polymathnetwork/polymesh-sdk/-/polymesh-sdk-15.0.0-alpha.10.tgz#d5f9998945fcc1015b66395e9a860cdf8a16be52"
1463+
integrity sha512-XzYH6r9aWvyhoCSQbbCEETK/OPrp5cadDNiDzOsYCJ/ie4pV7u6K/RiVWpzAw3+QS4sMTMUjzyNshYenFVh5Rg==
14641464
dependencies:
14651465
"@polkadot/api" "8.1.1"
14661466
"@polkadot/util" "9.0.1"

0 commit comments

Comments
 (0)