Skip to content

Commit

Permalink
Merge pull request #38 from PolymathNetwork/feat/MSDK-38-create-secur…
Browse files Browse the repository at this point in the history
…ity-token

MSDK-38: create security token (MSDK-101)
  • Loading branch information
VictorVicente authored Mar 18, 2020
2 parents 5d87d8b + d963d29 commit 1bef876
Show file tree
Hide file tree
Showing 17 changed files with 958 additions and 57 deletions.
13 changes: 5 additions & 8 deletions src/Polymesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,12 @@ export class Polymesh {
}

/**
* Get the POLY balance of the current account
* Get the POLYX balance of the current account
*/
public async getIdentityBalance(): Promise<BigNumber> {
public getIdentityBalance(): Promise<BigNumber> {
const { currentIdentity } = this.context;
if (currentIdentity) {
const balance = await currentIdentity.getPolyXBalance();
return balance;
return currentIdentity.getPolyXBalance();
} else {
throw new PolymeshError({
code: ErrorCode.FatalError,
Expand All @@ -99,7 +98,7 @@ export class Polymesh {
}

/**
* Get the free POLY balance of an account
* Get the free POLYX balance of an account
*
* @param args.accountId - defaults to the current account
*/
Expand All @@ -115,9 +114,7 @@ export class Polymesh {
*
* @param args.ticker - ticker symbol to reserve
*/
public async reserveTicker(
args: ReserveTickerParams
): Promise<TransactionQueue<TickerReservation>> {
public reserveTicker(args: ReserveTickerParams): Promise<TransactionQueue<TickerReservation>> {
return reserveTicker.prepare(args, this.context);
}

Expand Down
8 changes: 4 additions & 4 deletions src/__tests__/Polymesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ describe('Polymesh Class', () => {
nodeUrl: 'wss://some.url',
});

return expect(polymesh.getIdentityBalance()).rejects.toThrow(
return expect(() => polymesh.getIdentityBalance()).toThrow(
'The current account does not have an associated identity'
);
});

test("should return the identity's POLY balance", async () => {
test("should return the identity's POLYX balance", async () => {
const fakeBalance = new BigNumber(20);
polkadotMockUtils.initMocks({ contextOptions: { withSeed: true, balance: fakeBalance } });

Expand All @@ -137,7 +137,7 @@ describe('Polymesh Class', () => {
});

describe('method: getAccountBalance', () => {
test('should return the free POLY balance of the current account', async () => {
test('should return the free POLYX balance of the current account', async () => {
const fakeBalance = new BigNumber(100);
polkadotMockUtils.initMocks({ contextOptions: { balance: fakeBalance } });

Expand All @@ -149,7 +149,7 @@ describe('Polymesh Class', () => {
expect(result).toEqual(fakeBalance);
});

test('should return the free POLY balance of the supplied account', async () => {
test('should return the free POLYX balance of the supplied account', async () => {
const fakeBalance = new BigNumber(100);
polkadotMockUtils.initMocks({ contextOptions: { balance: fakeBalance } });

Expand Down
34 changes: 33 additions & 1 deletion src/api/entities/TickerReservation/__tests__/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { Callback, Codec } from '@polkadot/types/types';
import BigNumber from 'bignumber.js';
import { Ticker } from 'polymesh-types/types';
import sinon from 'sinon';

import { SecurityToken } from '~/api/entities/SecurityToken';
import { reserveTicker } from '~/api/procedures';
import { createSecurityToken } from '~/api/procedures/createSecurityToken';
import { Entity, TransactionQueue } from '~/base';
import { polkadotMockUtils } from '~/testUtils/mocks';
import { TickerReservationStatus } from '~/types';
import { KnownTokenIdentifierType, KnownTokenType, TickerReservationStatus } from '~/types';

import { TickerReservation } from '../';

Expand Down Expand Up @@ -203,4 +206,33 @@ describe('TickerReservation class', () => {
expect(queue).toBe(expectedQueue);
});
});

describe('method: createToken', () => {
test('should prepare the procedure with the correct arguments and context, and return the resulting transaction queue', async () => {
const ticker = 'TEST';
const context = polkadotMockUtils.getContextInstance();
const tickerReservation = new TickerReservation({ ticker }, context);

const args = {
ticker,
name: 'TEST',
totalSupply: new BigNumber(100),
isDivisible: true,
tokenType: KnownTokenType.Equity,
tokenIdentifiers: [{ type: KnownTokenIdentifierType.Isin, value: '12345' }],
fundingRound: 'Series A',
};

const expectedQueue = ('someQueue' as unknown) as TransactionQueue<SecurityToken>;

sinon
.stub(createSecurityToken, 'prepare')
.withArgs(args, context)
.resolves(expectedQueue);

const queue = await tickerReservation.createToken(args);

expect(queue).toBe(expectedQueue);
});
});
});
21 changes: 20 additions & 1 deletion src/api/entities/TickerReservation/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { Identity } from '~/api/entities/Identity';
import { SecurityToken } from '~/api/entities/SecurityToken';
import { reserveTicker } from '~/api/procedures';
import {
createSecurityToken,
CreateSecurityTokenParams,
} from '~/api/procedures/createSecurityToken';
import { Entity, TransactionQueue } from '~/base';
import { Context } from '~/context';
import { identityIdToString, momentToDate } from '~/utils';
Expand Down Expand Up @@ -99,7 +104,7 @@ export class TickerReservation extends Entity<UniqueIdentifiers> {
* Extend the reservation time period of the ticker for 60 days from now
* to later use it in the creation of a Security Token.
*/
public async extend(): Promise<TransactionQueue<TickerReservation>> {
public extend(): Promise<TransactionQueue<TickerReservation>> {
const { ticker, context } = this;
const extendPeriod = true;
return reserveTicker.prepare(
Expand All @@ -110,4 +115,18 @@ export class TickerReservation extends Entity<UniqueIdentifiers> {
context
);
}

/**
* Create a Security Token using the reserved ticker
*
* @param args.totalSupply - amount of tokens that will be minted on creation
* @param args.isDivisible - whether a single token can be divided into decimal parts
* @param args.tokenType - type of security that the token represents (i.e. Equity, Debt, Commodity, etc)
* @param args.tokenIdentifiers - domestic or international alphanumeric security identifiers for the token (ISIN, CUSIP, etc)
* @param args.fundingRound - (optional) funding round in which the token currently is (Series A, Series B, etc)
*/
public createToken(args: CreateSecurityTokenParams): Promise<TransactionQueue<SecurityToken>> {
const { ticker, context } = this;
return createSecurityToken.prepare({ ticker, ...args }, context);
}
}
2 changes: 1 addition & 1 deletion src/api/entities/__tests__/Identity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('Identity class', () => {
});

describe('method: getPolyXBalance', () => {
test("should return the identity's POLY balance", async () => {
test("should return the identity's POLYX balance", async () => {
const fakeBalance = new BigNumber(100);
polkadotMockUtils
.createQueryStub('balances', 'identityBalance')
Expand Down
Loading

0 comments on commit 1bef876

Please sign in to comment.