generated from PolymeshAssociation/typescript-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from PolymathNetwork/feat/MSDK-71-security-tok…
…en-entity Feat/msdk 71 security token entity
- Loading branch information
Showing
4 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Entity } from '~/base'; | ||
import { PolkadotMockFactory } from '~/testUtils/mocks'; | ||
|
||
import { SecurityToken } from '../'; | ||
|
||
describe('SecurityToken class', () => { | ||
const polkadotMockFactory = new PolkadotMockFactory(); | ||
|
||
polkadotMockFactory.initMocks({ mockContext: true }); | ||
|
||
afterEach(() => { | ||
polkadotMockFactory.reset(); | ||
}); | ||
|
||
afterAll(() => { | ||
polkadotMockFactory.cleanup(); | ||
}); | ||
|
||
test('should extend entity', () => { | ||
expect(SecurityToken.prototype instanceof Entity).toBe(true); | ||
}); | ||
|
||
describe('constructor', () => { | ||
test('should assign ticker to instance', () => { | ||
const ticker = 'test'; | ||
const context = polkadotMockFactory.getContextInstance(); | ||
const securityToken = new SecurityToken({ ticker }, context); | ||
|
||
expect(securityToken.ticker).toBe(ticker); | ||
}); | ||
}); | ||
|
||
describe('method: isUniqueIdentifiers', () => { | ||
test('should return true if the object conforms to the interface', () => { | ||
expect(SecurityToken.isUniqueIdentifiers({ ticker: 'someTicker' })).toBe(true); | ||
expect(SecurityToken.isUniqueIdentifiers({})).toBe(false); | ||
expect(SecurityToken.isUniqueIdentifiers({ ticker: 3 })).toBe(false); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Entity } from '~/base'; | ||
import { Context } from '~/context'; | ||
|
||
/** | ||
* Properties that uniquely identify a Security Token | ||
*/ | ||
export interface UniqueIdentifiers { | ||
/** | ||
* ticker of the security token | ||
*/ | ||
ticker: string; | ||
} | ||
|
||
/** | ||
* Class used to manage all the Security Token functionality | ||
*/ | ||
export class SecurityToken extends Entity<UniqueIdentifiers> { | ||
/** | ||
* @hidden | ||
* Check if a value is of type [[UniqueIdentifiers]] | ||
*/ | ||
public static isUniqueIdentifiers(identifier: unknown): identifier is UniqueIdentifiers { | ||
const { ticker } = identifier as UniqueIdentifiers; | ||
|
||
return typeof ticker === 'string'; | ||
} | ||
|
||
/** | ||
* ticker of the Security Token | ||
*/ | ||
public ticker: string; | ||
|
||
/** | ||
* @hidden | ||
*/ | ||
constructor(identifiers: UniqueIdentifiers, context: Context) { | ||
super(identifiers, context); | ||
|
||
const { ticker } = identifiers; | ||
|
||
this.ticker = ticker; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { Identity } from './Identity'; | ||
export { TickerReservation } from './TickerReservation'; | ||
export { SecurityToken } from './SecurityToken'; |