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(checkpoints): add
checkpoints.create
to the Security Token Entity
Also upgraded the SDK to use Polymesh 2.5
- Loading branch information
Showing
20 changed files
with
631 additions
and
420 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
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,27 @@ | ||
import { Context, createCheckpoint, Namespace, SecurityToken } from '~/internal'; | ||
import { ProcedureMethod } from '~/types/internal'; | ||
import { createProcedureMethod } from '~/utils/internal'; | ||
|
||
/** | ||
* Handles all Security Token Checkpoints related functionality | ||
*/ | ||
export class Checkpoints extends Namespace<SecurityToken> { | ||
/** | ||
* @hidden | ||
*/ | ||
constructor(parent: SecurityToken, context: Context) { | ||
super(parent, context); | ||
|
||
const { ticker } = parent; | ||
|
||
this.create = createProcedureMethod(() => [createCheckpoint, { ticker }], context); | ||
} | ||
|
||
/** | ||
* Create a snapshot of Security Token holders and their respective balances at this moment | ||
* | ||
* @note required role: | ||
* - Security Token Owner | ||
*/ | ||
public create: ProcedureMethod<void, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { Ticker, TxTags } from 'polymesh-types/types'; | ||
import sinon from 'sinon'; | ||
|
||
import { | ||
getAuthorization, | ||
Params, | ||
prepareCreateCheckpoint, | ||
} from '~/api/procedures/createCheckpoint'; | ||
import { Context, SecurityToken } from '~/internal'; | ||
import { dsMockUtils, entityMockUtils, procedureMockUtils } from '~/testUtils/mocks'; | ||
import { Mocked } from '~/testUtils/types'; | ||
import { RoleType } from '~/types'; | ||
import * as utilsConversionModule from '~/utils/conversion'; | ||
|
||
jest.mock( | ||
'~/api/entities/SecurityToken', | ||
require('~/testUtils/mocks/entities').mockSecurityTokenModule('~/api/entities/SecurityToken') | ||
); | ||
|
||
describe('createCheckpoint procedure', () => { | ||
let mockContext: Mocked<Context>; | ||
let stringToTickerStub: sinon.SinonStub<[string, Context], Ticker>; | ||
let ticker: string; | ||
let rawTicker: Ticker; | ||
|
||
beforeAll(() => { | ||
dsMockUtils.initMocks(); | ||
procedureMockUtils.initMocks(); | ||
entityMockUtils.initMocks(); | ||
stringToTickerStub = sinon.stub(utilsConversionModule, 'stringToTicker'); | ||
ticker = 'SOME_TICKER'; | ||
rawTicker = dsMockUtils.createMockTicker(ticker); | ||
}); | ||
|
||
let addTransactionStub: sinon.SinonStub; | ||
|
||
beforeEach(() => { | ||
addTransactionStub = procedureMockUtils.getAddTransactionStub(); | ||
mockContext = dsMockUtils.getContextInstance(); | ||
stringToTickerStub.withArgs(ticker, mockContext).returns(rawTicker); | ||
}); | ||
|
||
afterEach(() => { | ||
entityMockUtils.reset(); | ||
procedureMockUtils.reset(); | ||
dsMockUtils.reset(); | ||
}); | ||
|
||
afterAll(() => { | ||
entityMockUtils.cleanup(); | ||
procedureMockUtils.cleanup(); | ||
dsMockUtils.cleanup(); | ||
}); | ||
|
||
test('should add a create checkpoint transaction to the queue', async () => { | ||
const proc = procedureMockUtils.getInstance<Params, SecurityToken>(mockContext); | ||
|
||
const transaction = dsMockUtils.createTxStub('checkpoint', 'createCheckpoint'); | ||
|
||
const result = await prepareCreateCheckpoint.call(proc, { | ||
ticker, | ||
}); | ||
|
||
sinon.assert.calledWith(addTransactionStub, transaction, {}, rawTicker); | ||
|
||
expect(ticker).toBe(result.ticker); | ||
}); | ||
|
||
describe('getAuthorization', () => { | ||
test('should return the appropriate roles and permissions', () => { | ||
const proc = procedureMockUtils.getInstance<Params, SecurityToken>(mockContext); | ||
const boundFunc = getAuthorization.bind(proc); | ||
|
||
const token = entityMockUtils.getSecurityTokenInstance({ ticker }); | ||
const identityRoles = [{ type: RoleType.TokenOwner, ticker }]; | ||
|
||
expect(boundFunc({ ticker })).toEqual({ | ||
identityRoles, | ||
signerPermissions: { | ||
transactions: [TxTags.checkpoint.CreateCheckpoint], | ||
tokens: [token], | ||
portfolios: [], | ||
}, | ||
}); | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.