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: refactor PIA and CAA remove procedures
- Loading branch information
1 parent
08432ca
commit 89b291d
Showing
9 changed files
with
242 additions
and
192 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
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
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
208 changes: 120 additions & 88 deletions
208
src/api/procedures/__tests__/removePrimaryIssuanceAgent.ts
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,91 +1,123 @@ | ||
import { IdentityId, Ticker, TxTags } from 'polymesh-types/types'; | ||
import sinon from 'sinon'; | ||
|
||
import { | ||
getAuthorization, | ||
Params, | ||
prepareRemovePrimaryIssuanceAgent, | ||
} from '~/api/procedures/removePrimaryIssuanceAgent'; | ||
import { Context } 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('removePrimaryIssuanceAgent procedure', () => { | ||
test('dummy test', () => { | ||
expect(true).toBeTruthy(); | ||
let mockContext: Mocked<Context>; | ||
let stringToTickerStub: sinon.SinonStub; | ||
let stringToIdentityIdStub: sinon.SinonStub; | ||
let ticker: string; | ||
let did: string; | ||
let rawTicker: Ticker; | ||
let rawIdentityId: IdentityId; | ||
let addTransactionStub: sinon.SinonStub; | ||
|
||
beforeAll(() => { | ||
dsMockUtils.initMocks(); | ||
procedureMockUtils.initMocks(); | ||
entityMockUtils.initMocks(); | ||
stringToTickerStub = sinon.stub(utilsConversionModule, 'stringToTicker'); | ||
stringToIdentityIdStub = sinon.stub(utilsConversionModule, 'stringToIdentityId'); | ||
ticker = 'someTicker'; | ||
rawTicker = dsMockUtils.createMockTicker(ticker); | ||
did = 'someDid'; | ||
rawIdentityId = dsMockUtils.createMockIdentityId(did); | ||
}); | ||
}); | ||
|
||
// import { Ticker, TxTags } from 'polymesh-types/types'; | ||
// import sinon from 'sinon'; | ||
|
||
// import { | ||
// getAuthorization, | ||
// Params, | ||
// prepareRemovePrimaryIssuanceAgent, | ||
// } from '~/api/procedures/removePrimaryIssuanceAgent'; | ||
// import { Context } 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('removePrimaryIssuanceAgent procedure', () => { | ||
// let mockContext: Mocked<Context>; | ||
// let stringToTickerStub: sinon.SinonStub; | ||
// let ticker: string; | ||
// let rawTicker: Ticker; | ||
// let addTransactionStub: sinon.SinonStub; | ||
|
||
// beforeAll(() => { | ||
// dsMockUtils.initMocks(); | ||
// procedureMockUtils.initMocks(); | ||
// entityMockUtils.initMocks(); | ||
// stringToTickerStub = sinon.stub(utilsConversionModule, 'stringToTicker'); | ||
// ticker = 'someTicker'; | ||
// rawTicker = dsMockUtils.createMockTicker(ticker); | ||
// }); | ||
|
||
// beforeEach(() => { | ||
// mockContext = dsMockUtils.getContextInstance(); | ||
// stringToTickerStub.returns(rawTicker); | ||
// addTransactionStub = procedureMockUtils.getAddTransactionStub(); | ||
// }); | ||
|
||
// afterEach(() => { | ||
// entityMockUtils.reset(); | ||
// procedureMockUtils.reset(); | ||
// dsMockUtils.reset(); | ||
// }); | ||
|
||
// afterAll(() => { | ||
// entityMockUtils.cleanup(); | ||
// procedureMockUtils.cleanup(); | ||
// dsMockUtils.cleanup(); | ||
// }); | ||
|
||
// test('should add a remove primary issuance agent transaction to the queue', async () => { | ||
// const args = { | ||
// ticker, | ||
// }; | ||
|
||
// const transaction = dsMockUtils.createTxStub('asset', 'removePrimaryIssuanceAgent'); | ||
// const proc = procedureMockUtils.getInstance<Params, void>(mockContext); | ||
|
||
// await prepareRemovePrimaryIssuanceAgent.call(proc, args); | ||
|
||
// sinon.assert.calledWith(addTransactionStub, transaction, {}, rawTicker); | ||
// }); | ||
|
||
// describe('getAuthorization', () => { | ||
// test('should return the appropriate roles and permissions', () => { | ||
// const proc = procedureMockUtils.getInstance<Params, void>(mockContext); | ||
// const boundFunc = getAuthorization.bind(proc); | ||
// const args = { | ||
// ticker, | ||
// } as Params; | ||
|
||
// expect(boundFunc(args)).toEqual({ | ||
// identityRoles: [{ type: RoleType.TokenOwner, ticker }], | ||
// signerPermissions: { | ||
// transactions: [TxTags.asset.RemovePrimaryIssuanceAgent], | ||
// tokens: [entityMockUtils.getSecurityTokenInstance({ ticker })], | ||
// portfolios: [], | ||
// }, | ||
// }); | ||
// }); | ||
// }); | ||
// }); | ||
beforeEach(() => { | ||
mockContext = dsMockUtils.getContextInstance(); | ||
stringToTickerStub.returns(rawTicker); | ||
stringToIdentityIdStub.returns(rawIdentityId); | ||
addTransactionStub = procedureMockUtils.getAddTransactionStub(); | ||
}); | ||
|
||
afterEach(() => { | ||
entityMockUtils.reset(); | ||
procedureMockUtils.reset(); | ||
dsMockUtils.reset(); | ||
}); | ||
|
||
afterAll(() => { | ||
entityMockUtils.cleanup(); | ||
procedureMockUtils.cleanup(); | ||
dsMockUtils.cleanup(); | ||
}); | ||
|
||
test('should add a remove primary issuance agent transaction to the queue', async () => { | ||
const args = { | ||
ticker, | ||
}; | ||
|
||
entityMockUtils.configureMocks({ | ||
securityTokenOptions: { | ||
details: { | ||
primaryIssuanceAgents: [entityMockUtils.getIdentityInstance({ did })], | ||
}, | ||
}, | ||
}); | ||
|
||
const transaction = dsMockUtils.createTxStub('externalAgents', 'removeAgent'); | ||
const proc = procedureMockUtils.getInstance<Params, void>(mockContext); | ||
|
||
await prepareRemovePrimaryIssuanceAgent.call(proc, args); | ||
|
||
sinon.assert.calledWith(addTransactionStub, transaction, {}, rawTicker, rawIdentityId); | ||
}); | ||
|
||
test('should throw an error if Primary Issuance Agent list has more than one identity', async () => { | ||
const args = { | ||
ticker, | ||
}; | ||
|
||
entityMockUtils.configureMocks({ | ||
securityTokenOptions: { | ||
details: { | ||
primaryIssuanceAgents: [ | ||
entityMockUtils.getIdentityInstance({ did: 'did' }), | ||
entityMockUtils.getIdentityInstance({ did: 'otherDid' }), | ||
], | ||
}, | ||
}, | ||
}); | ||
|
||
const proc = procedureMockUtils.getInstance<Params, void>(mockContext); | ||
|
||
await expect(prepareRemovePrimaryIssuanceAgent.call(proc, args)).rejects.toThrow( | ||
'We can not perform this procedure with more than one Primary Issuance Agent involved' | ||
); | ||
}); | ||
|
||
describe('getAuthorization', () => { | ||
test('should return the appropriate roles and permissions', () => { | ||
const proc = procedureMockUtils.getInstance<Params, void>(mockContext); | ||
const boundFunc = getAuthorization.bind(proc); | ||
const args = { | ||
ticker, | ||
} as Params; | ||
|
||
expect(boundFunc(args)).toEqual({ | ||
identityRoles: [{ type: RoleType.TokenOwner, ticker }], | ||
signerPermissions: { | ||
transactions: [TxTags.asset.RemovePrimaryIssuanceAgent], | ||
tokens: [entityMockUtils.getSecurityTokenInstance({ ticker })], | ||
portfolios: [], | ||
}, | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.