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.
feat(external agents): create external agent base code
Also modified `DefaultTrustedClaimIssuer` BREAKING CHANGE: `DefaultTrustedClaimIssuer` now extends `Identity`. This means its `identity: Identity` property was removed. Since the class is now an extension of `Identity`, the did can be obtained via the `did` property
- Loading branch information
Showing
9 changed files
with
188 additions
and
22 deletions.
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,35 @@ | ||
import BigNumber from 'bignumber.js'; | ||
|
||
import { Context, Entity } from '~/internal'; | ||
|
||
export interface UniqueIdentifiers { | ||
id: BigNumber; | ||
} | ||
|
||
/** | ||
* Represents an external agent for a Security Token | ||
*/ | ||
export class AgentGroup extends Entity<UniqueIdentifiers> { | ||
/** | ||
* @hidden | ||
* Check if a value is of type [[UniqueIdentifiers]] | ||
*/ | ||
public static isUniqueIdentifiers(identifier: unknown): identifier is UniqueIdentifiers { | ||
const { id } = identifier as UniqueIdentifiers; | ||
|
||
return id instanceof BigNumber; | ||
} | ||
|
||
public id: BigNumber; | ||
|
||
/** | ||
* @hidden | ||
*/ | ||
public constructor(identifiers: UniqueIdentifiers, context: Context) { | ||
super(identifiers, context); | ||
|
||
const { id } = identifiers; | ||
|
||
this.id = id; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Context, Identity } from '~/internal'; | ||
|
||
export interface UniqueIdentifiers { | ||
did: string; | ||
ticker: string; | ||
} | ||
|
||
/** | ||
* Represents an external agent for a Security Token | ||
*/ | ||
export class ExternalAgent extends Identity { | ||
/** | ||
* @hidden | ||
* Check if a value is of type [[UniqueIdentifiers]] | ||
*/ | ||
public static isUniqueIdentifiers(identifier: unknown): identifier is UniqueIdentifiers { | ||
const { did, ticker } = identifier as UniqueIdentifiers; | ||
|
||
return typeof did === 'string' && typeof ticker === 'string'; | ||
} | ||
|
||
/** | ||
* ticker of the Security Token | ||
*/ | ||
public ticker: string; | ||
|
||
/** | ||
* @hidden | ||
*/ | ||
public 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { Namespace, SecurityToken } from '~/internal'; | ||
|
||
/** | ||
* Handles all Security Token External Agents related functionality | ||
*/ | ||
export class ExternalAgents extends Namespace<SecurityToken> {} |
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import BigNumber from 'bignumber.js'; | ||
|
||
import { AgentGroup, Context, Entity } from '~/internal'; | ||
import { dsMockUtils, entityMockUtils } from '~/testUtils/mocks'; | ||
|
||
describe('AgentGroup class', () => { | ||
let context: Context; | ||
|
||
beforeAll(() => { | ||
dsMockUtils.initMocks(); | ||
entityMockUtils.initMocks(); | ||
}); | ||
|
||
beforeEach(() => { | ||
context = dsMockUtils.getContextInstance(); | ||
}); | ||
|
||
afterEach(() => { | ||
dsMockUtils.reset(); | ||
entityMockUtils.reset(); | ||
}); | ||
|
||
afterAll(() => { | ||
dsMockUtils.cleanup(); | ||
entityMockUtils.cleanup(); | ||
}); | ||
|
||
test('should extend Entity', () => { | ||
expect(AgentGroup.prototype instanceof Entity).toBe(true); | ||
}); | ||
|
||
describe('constructor', () => { | ||
test('should assign id to instance', () => { | ||
const id = new BigNumber(1); | ||
const agentGroup = new AgentGroup({ id }, context); | ||
|
||
expect(agentGroup.id).toBe(id); | ||
}); | ||
}); | ||
|
||
describe('method: isUniqueIdentifiers', () => { | ||
test('should return true if the object conforms to the interface', () => { | ||
expect(AgentGroup.isUniqueIdentifiers({ id: new BigNumber(1) })).toBe(true); | ||
expect(AgentGroup.isUniqueIdentifiers({})).toBe(false); | ||
expect(AgentGroup.isUniqueIdentifiers({ id: 1 })).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
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,49 @@ | ||
import { Context, ExternalAgent, Identity } from '~/internal'; | ||
import { dsMockUtils, entityMockUtils } from '~/testUtils/mocks'; | ||
|
||
describe('ExternalAgent class', () => { | ||
let context: Context; | ||
|
||
beforeAll(() => { | ||
dsMockUtils.initMocks(); | ||
entityMockUtils.initMocks(); | ||
}); | ||
|
||
beforeEach(() => { | ||
context = dsMockUtils.getContextInstance(); | ||
}); | ||
|
||
afterEach(() => { | ||
dsMockUtils.reset(); | ||
entityMockUtils.reset(); | ||
}); | ||
|
||
afterAll(() => { | ||
dsMockUtils.cleanup(); | ||
entityMockUtils.cleanup(); | ||
}); | ||
|
||
test('should extend Identity', () => { | ||
expect(ExternalAgent.prototype instanceof Identity).toBe(true); | ||
}); | ||
|
||
describe('constructor', () => { | ||
test('should assign ticker and did to instance', () => { | ||
const did = 'someDid'; | ||
const ticker = 'SOMETICKER'; | ||
const externalAgent = new ExternalAgent({ did, ticker }, context); | ||
|
||
expect(externalAgent.ticker).toBe(ticker); | ||
expect(externalAgent.did).toEqual(did); | ||
}); | ||
}); | ||
|
||
describe('method: isUniqueIdentifiers', () => { | ||
test('should return true if the object conforms to the interface', () => { | ||
expect(ExternalAgent.isUniqueIdentifiers({ did: 'someDid', ticker: 'symbol' })).toBe(true); | ||
expect(ExternalAgent.isUniqueIdentifiers({})).toBe(false); | ||
expect(ExternalAgent.isUniqueIdentifiers({ did: 'someDid' })).toBe(false); | ||
expect(ExternalAgent.isUniqueIdentifiers({ did: 1 })).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