Skip to content

Commit

Permalink
feat: add dti to asset identifier enum. MSDK-287
Browse files Browse the repository at this point in the history
  • Loading branch information
shuffledex committed Sep 24, 2020
1 parent fc2e4a8 commit fb3bd93
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 20 deletions.
11 changes: 10 additions & 1 deletion src/api/entities/SecurityToken/__tests__/index.ts
Expand Up @@ -239,9 +239,11 @@ describe('SecurityToken class', () => {
let isinValue: string;
let cusipValue: string;
let cinsValue: string;
let dtiValue: string;
let isinMock: AssetIdentifier;
let cusipMock: AssetIdentifier;
let cinsMock: AssetIdentifier;
let dtiMock: AssetIdentifier;
let tokenIdentifiers: TokenIdentifier[];

let rawIdentifiers: [IdentifierType, AssetIdentifier][];
Expand All @@ -259,9 +261,11 @@ describe('SecurityToken class', () => {
isinValue = 'FAKE ISIN';
cusipValue = 'FAKE CUSIP';
cinsValue = 'FAKE CINS';
dtiValue = 'FAKE DTI';
isinMock = dsMockUtils.createMockAssetIdentifier(isinValue);
cusipMock = dsMockUtils.createMockAssetIdentifier(cusipValue);
cinsMock = dsMockUtils.createMockAssetIdentifier(cinsValue);
dtiMock = dsMockUtils.createMockAssetIdentifier(dtiValue);
tokenIdentifiers = [
{
type: TokenIdentifierType.Isin,
Expand All @@ -275,6 +279,10 @@ describe('SecurityToken class', () => {
type: TokenIdentifierType.Cins,
value: cinsValue,
},
{
type: TokenIdentifierType.Dti,
value: dtiValue,
},
];

rawIdentifiers = tokenIdentifiers.map(({ type, value }) =>
Expand Down Expand Up @@ -309,14 +317,15 @@ describe('SecurityToken class', () => {

test('should return the list of token identifiers for a security token', async () => {
dsMockUtils.createQueryStub('asset', 'identifiers', {
multi: [isinMock, cusipMock, cinsMock],
multi: [isinMock, cusipMock, cinsMock, dtiMock],
});

const result = await securityToken.getIdentifiers();

expect(result[0].value).toBe(isinValue);
expect(result[1].value).toBe(cusipValue);
expect(result[2].value).toBe(cinsValue);
expect(result[3].value).toBe(dtiValue);
});

test('should allow subscription', async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/testUtils/mocks/dataSources.ts
Expand Up @@ -1443,7 +1443,7 @@ export const createMockAuthIdentifier = (authIdentifier?: {
* NOTE: `isEmpty` will be set to true if no value is passed
*/
export const createMockIdentifierType = (
identifierType?: 'Isin' | 'Cusip' | 'Cins'
identifierType?: 'Isin' | 'Cusip' | 'Cins' | 'Dti'
): IdentifierType => {
return createMockEnum(identifierType) as IdentifierType;
};
Expand Down
1 change: 1 addition & 0 deletions src/types/index.ts
Expand Up @@ -129,6 +129,7 @@ export enum TokenIdentifierType {
Isin = 'Isin',
Cusip = 'Cusip',
Cins = 'Cins',
Dti = 'Dti',
}

// NOTE: query.asset.identifiers doesn’t support custom identifier types properly for now
Expand Down
6 changes: 6 additions & 0 deletions src/utils/__tests__/index.ts
Expand Up @@ -881,6 +881,12 @@ describe('tokenIdentifierTypeToIdentifierType and identifierTypeToString', () =>

result = identifierTypeToString(identifierType);
expect(result).toEqual(fakeResult);

fakeResult = TokenIdentifierType.Dti;
identifierType = dsMockUtils.createMockIdentifierType(fakeResult);

result = identifierTypeToString(identifierType);
expect(result).toEqual(fakeResult);
});
});

Expand Down
22 changes: 4 additions & 18 deletions src/utils/index.ts
Expand Up @@ -35,7 +35,6 @@ import {
FundingRoundName,
IdentifierType,
IdentityId,
IssueAssetItem,
Permission as MeshPermission,
PosRatio,
ProposalState as MeshProposalState,
Expand Down Expand Up @@ -70,7 +69,6 @@ import {
IdentityWithClaims,
isMultiClaimCondition,
isSingleClaimCondition,
IssuanceData,
KnownTokenType,
MultiClaimCondition,
NextKey,
Expand Down Expand Up @@ -636,8 +634,11 @@ export function identifierTypeToString(type: IdentifierType): string {
if (type.isIsin) {
return TokenIdentifierType.Isin;
}
if (type.isCins) {
return TokenIdentifierType.Cins;
}

return TokenIdentifierType.Cins;
return TokenIdentifierType.Dti;
}

/**
Expand Down Expand Up @@ -1105,21 +1106,6 @@ export function textToString(value: Text): string {
return value.toString();
}

/**
* @hidden
*/
export function issuanceDataToIssueAssetItem(
issuanceData: IssuanceData,
context: Context
): IssueAssetItem {
const { identity, amount } = issuanceData;
return context.polymeshApi.createType('IssueAssetItem', {
// eslint-disable-next-line @typescript-eslint/camelcase
identity_did: stringToIdentityId(signerToString(identity), context),
value: numberToBalance(amount, context),
});
}

/**
* @hidden
*/
Expand Down

0 comments on commit fb3bd93

Please sign in to comment.