Skip to content

Commit

Permalink
feat: 🎸 update to 6.0
Browse files Browse the repository at this point in the history
updates to be compatible with 6.0 chains

BREAKING CHANGE: 🧨 Checkpoint Schedules specify dates explictly, reschedule instruction
removed - use executeManually instead, InvestorUniquness claim types
removed
  • Loading branch information
polymath-eric committed Jul 31, 2023
1 parent 83d2c79 commit fcffc4b
Show file tree
Hide file tree
Showing 29 changed files with 227 additions and 813 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

A REST API wrapper for the Polymesh blockchain.

This version is compatible with chain versions 5.2.x
This version is compatible with chain versions 6.0.x

## Setup

Expand Down
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@
"@nestjs/schedule": "^2.2.0",
"@nestjs/swagger": "^6.2.1",
"@nestjs/typeorm": "^9.0.1",
"@polymeshassociation/fireblocks-signing-manager": "^1.0.3",
"@polymeshassociation/hashicorp-vault-signing-manager": "^1.1.6",
"@polymeshassociation/local-signing-manager": "^1.3.0",
"@polymeshassociation/polymesh-sdk": "20.1.0",
"@polymeshassociation/signing-manager-types": "^1.2.1",
"@polymeshassociation/fireblocks-signing-manager": "^2.1.0",
"@polymeshassociation/hashicorp-vault-signing-manager": "^2.1.0",
"@polymeshassociation/local-signing-manager": "^2.1.0",
"@polymeshassociation/polymesh-sdk": "21.0.0-alpha.9",
"@polymeshassociation/signing-manager-types": "^2.1.0",
"class-transformer": "0.5.1",
"class-validator": "^0.14.0",
"joi": "17.4.0",
Expand Down Expand Up @@ -106,6 +106,7 @@
"prettier": "2.3.1",
"prettier-eslint": "12.0.0",
"prettier-eslint-cli": "5.0.1",
"react": "^18.2.0",
"semantic-release": "^19.0.5",
"supertest": "6.1.3",
"ts-jest": "26.5.4",
Expand Down
18 changes: 3 additions & 15 deletions src/checkpoints/checkpoints.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Test, TestingModule } from '@nestjs/testing';
import { BigNumber } from '@polymeshassociation/polymesh-sdk';
import { CalendarUnit } from '@polymeshassociation/polymesh-sdk/types';

import { IdentityBalanceModel } from '~/assets/models/identity-balance.model';
import { CheckpointsController } from '~/checkpoints/checkpoints.controller';
Expand Down Expand Up @@ -131,12 +130,7 @@ describe('CheckpointsController', () => {
{
schedule: {
id: new BigNumber(1),
period: {
unit: CalendarUnit.Month,
amount: new BigNumber(3),
},
start: mockDate,
complexity: new BigNumber(4),
pendingPoints: [mockDate],
expiryDate: null,
},
details: {
Expand All @@ -154,12 +148,7 @@ describe('CheckpointsController', () => {
{
id: new BigNumber(1),
ticker: 'TICKER',
period: {
unit: CalendarUnit.Month,
amount: new BigNumber(3),
},
start: mockDate,
complexity: new BigNumber(4),
pendingPoints: [mockDate],
expiryDate: null,
remainingCheckpoints: new BigNumber(1),
nextCheckpointDate: mockDate,
Expand Down Expand Up @@ -215,8 +204,7 @@ describe('CheckpointsController', () => {
const body = {
signer: 'signer',
start: mockDate,
period: { unit: CalendarUnit.Month, amount: new BigNumber(3) },
repetitions: new BigNumber(2),
points: [],
};

const result = await controller.createSchedule({ ticker: 'TICKER' }, body);
Expand Down
20 changes: 7 additions & 13 deletions src/checkpoints/checkpoints.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,11 @@ export class CheckpointsController {
const schedules = await this.checkpointsService.findSchedulesByTicker(ticker);
return new ResultsModel({
results: schedules.map(
({ schedule: { id, period, start, complexity, expiryDate }, details }) =>
({ schedule: { id, pendingPoints, expiryDate }, details }) =>
new CheckpointScheduleModel({
id,
ticker,
period,
start,
complexity,
pendingPoints,
expiryDate,
...details,
})
Expand Down Expand Up @@ -234,24 +232,22 @@ export class CheckpointsController {
@Param() { ticker, id }: CheckpointScheduleParamsDto
): Promise<CheckpointScheduleModel> {
const {
schedule: { period, start, complexity, expiryDate },
schedule: { pendingPoints, expiryDate },
details,
} = await this.checkpointsService.findScheduleById(ticker, id);

return new CheckpointScheduleModel({
id,
period,
start,
ticker,
complexity,
pendingPoints,
expiryDate,
...details,
});
}

@ApiOperation({
summary: 'Create Schedule',
description: 'This endpoint will create a Schedule that creates Checkpoints periodically',
description: 'This endpoint will create a Schedule that creates future Checkpoints',
})
@ApiParam({
name: 'ticker',
Expand Down Expand Up @@ -279,18 +275,16 @@ export class CheckpointsController {
details,
}) => {
const {
schedule: { id, period, start, complexity, expiryDate },
schedule: { id, expiryDate, pendingPoints },
details: scheduleDetails,
} = await this.checkpointsService.findScheduleById(ticker, createdScheduleId);

return new CreatedCheckpointScheduleModel({
schedule: new CheckpointScheduleModel({
id,
ticker,
period,
start,
complexity,
expiryDate,
pendingPoints,
...scheduleDetails,
}),
transactions,
Expand Down
14 changes: 3 additions & 11 deletions src/checkpoints/checkpoints.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const mockIsPolymeshTransaction = jest.fn();

import { Test, TestingModule } from '@nestjs/testing';
import { BigNumber } from '@polymeshassociation/polymesh-sdk';
import { CalendarUnit, TxTags } from '@polymeshassociation/polymesh-sdk/types';
import { TxTags } from '@polymeshassociation/polymesh-sdk/types';

import { AssetsService } from '~/assets/assets.service';
import { CheckpointsService } from '~/checkpoints/checkpoints.service';
Expand Down Expand Up @@ -133,10 +133,6 @@ describe('CheckpointsService', () => {
{
schedule: {
id: new BigNumber(1),
period: {
unit: CalendarUnit.Month,
amount: new BigNumber(3),
},
start: new Date(),
complexity: new BigNumber(4),
expiryDate: null,
Expand Down Expand Up @@ -266,9 +262,7 @@ describe('CheckpointsService', () => {
const mockDate = new Date();
const params = {
signer,
start: mockDate,
period: { unit: CalendarUnit.Month, amount: new BigNumber(3) },
repetitions: new BigNumber(2),
points: [mockDate],
};

const result = await service.createScheduleByTicker('TICKER', params);
Expand All @@ -279,9 +273,7 @@ describe('CheckpointsService', () => {
expect(mockTransactionsService.submit).toHaveBeenCalledWith(
mockAsset.checkpoints.schedules.create,
{
start: mockDate,
period: { unit: CalendarUnit.Month, amount: new BigNumber(3) },
repetitions: new BigNumber(2),
points: [mockDate],
},
{
signer,
Expand Down
29 changes: 0 additions & 29 deletions src/checkpoints/dto/calendar-period.dto.ts

This file was deleted.

41 changes: 6 additions & 35 deletions src/checkpoints/dto/create-checkpoint-schedule.dto.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,19 @@
/* istanbul ignore file */

import { ApiProperty } from '@nestjs/swagger';
import { BigNumber } from '@polymeshassociation/polymesh-sdk';
import { Type } from 'class-transformer';
import { IsDate, IsOptional, ValidateNested } from 'class-validator';
import { IsArray } from 'class-validator';

import { CalendarPeriodDto } from '~/checkpoints/dto/calendar-period.dto';
import { ToBigNumber } from '~/common/decorators/transformation';
import { IsBigNumber } from '~/common/decorators/validation';
import { TransactionBaseDto } from '~/common/dto/transaction-base-dto';

export class CreateCheckpointScheduleDto extends TransactionBaseDto {
@ApiProperty({
description:
'Date from which the Schedule will start creating Checkpoints. A null value means the first Checkpoint will be created immediately',
description: 'An array of dates for when to make Checkpoints',
type: 'string',
example: new Date('05/23/2021').toISOString(),
nullable: true,
isArray: true,
example: [new Date('03/23/2030').toISOString(), new Date('03/23/2031').toISOString()],
})
@IsOptional()
@IsDate()
@IsArray()
@Type(() => Date)
readonly start: Date | null;

@ApiProperty({
description:
'Periodic interval between Checkpoints. For example, a period of 2 weeks means that a Checkpoint will be created every 2 weeks. A null value means this Schedule creates a single Checkpoint and then expires',
type: CalendarPeriodDto,
nullable: true,
})
@IsOptional()
@ValidateNested()
@Type(() => CalendarPeriodDto)
readonly period: CalendarPeriodDto | null;

@ApiProperty({
description:
'Number of Checkpoints that should be created by this Schedule. A null or 0 value means infinite Checkpoints (the Schedule never expires)',
type: 'string',
example: '12',
nullable: true,
})
@IsOptional()
@IsBigNumber()
@ToBigNumber()
readonly repetitions: BigNumber | null;
readonly points: Date[];
}
25 changes: 0 additions & 25 deletions src/checkpoints/models/calendar-period.model.ts

This file was deleted.

37 changes: 11 additions & 26 deletions src/checkpoints/models/checkpoint-schedule.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import { ApiProperty } from '@nestjs/swagger';
import { BigNumber } from '@polymeshassociation/polymesh-sdk';
import { Type } from 'class-transformer';

import { CalendarPeriodModel } from '~/checkpoints/models/calendar-period.model';
import { FromBigNumber } from '~/common/decorators/transformation';

export class CheckpointScheduleModel {
Expand All @@ -23,39 +21,26 @@ export class CheckpointScheduleModel {
})
readonly ticker: string;

@ApiProperty({
description: 'Date at which first Checkpoint was created',
type: 'string',
example: new Date('10/14/1987').toISOString(),
})
readonly start: Date;
// @ApiProperty({
// description: 'Date at which first Checkpoint was created',
// type: 'string',
// example: new Date('10/14/1987').toISOString(),
// })
// readonly start: Date;

@ApiProperty({
description:
'Date at which the last Checkpoint will be created with this Schedule. A null value means that this Schedule never expires',
description: 'Date at which the last Checkpoint will be created',
type: 'string',
nullable: true,
example: new Date('10/14/1987').toISOString(),
})
readonly expiryDate: Date | null;
readonly expiryDate: Date;

@ApiProperty({
description:
'Period in which this Schedule creates a Checkpoint. A null value means this Schedule creates a single Checkpoint and then expires',
nullable: true,
type: CalendarPeriodModel,
})
@Type(() => CalendarPeriodModel)
readonly period: CalendarPeriodModel | null;

@ApiProperty({
description:
'Abstract measure of the complexity of this Schedule. Shorter periods translate into more complexity',
description: 'Dates at which checkpoints will be created',
type: 'string',
example: '1',
example: new Date('10/14/1987').toISOString(),
})
@FromBigNumber()
readonly complexity: BigNumber;
readonly pendingPoints: Date[];

@ApiProperty({
description: 'Number of Checkpoints left to be created by the Schedule',
Expand Down
20 changes: 1 addition & 19 deletions src/claims/claims.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DeepMocked } from '@golevelup/ts-jest';
import { Test } from '@nestjs/testing';
import { ClaimType, ScopeType } from '@polymeshassociation/polymesh-sdk/types';
import { ClaimType } from '@polymeshassociation/polymesh-sdk/types';

import { ClaimsController } from '~/claims/claims.controller';
import { ClaimsService } from '~/claims/claims.service';
Expand Down Expand Up @@ -76,22 +76,4 @@ describe('ClaimsController', () => {
expect(result).toEqual({ ...txResult, results: undefined });
});
});

describe('addInvestorUniqueness', () => {
it('should call addInvestorUniqueness method and return transaction data', async () => {
mockClaimsService.addInvestorUniqueness.mockResolvedValue({ ...txResult, result: undefined });
const mockArgs = {
scope: { type: ScopeType.Identity, value: did },
cddId: '0x1',
proof: 'proof',
scopeId: 'id',
signer,
};
const result = await controller.addInvestorUniqueness(mockArgs);

expect(mockClaimsService.addInvestorUniqueness).toHaveBeenCalledWith(mockArgs);

expect(result).toEqual({ ...txResult, results: undefined });
});
});
});
Loading

0 comments on commit fcffc4b

Please sign in to comment.