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: allow setting a CA's checkpoint to null
This was made possible by refactoring the CA classes into a base abstract class and two implementations, allowing `CorporateAction` and `DividendDistribution` to have separate signatures for `modifyCheckpoint` BREAKING CHANGE: change the type of `ModifyCheckpointParams.checkpoint` to `Checkpoint | CheckpointSchedule | Date | null`
- Loading branch information
Showing
12 changed files
with
233 additions
and
61 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,64 @@ | ||
import BigNumber from 'bignumber.js'; | ||
|
||
import { CorporateActionBase } from '~/api/entities/CorporateActionBase'; | ||
import { Context, modifyCaCheckpoint, ModifyCaCheckpointParams } from '~/internal'; | ||
import { | ||
CorporateActionKind, | ||
CorporateActionTargets, | ||
ProcedureMethod, | ||
TaxWithholding, | ||
} from '~/types'; | ||
import { HumanReadableType } from '~/types/utils'; | ||
import { createProcedureMethod } from '~/utils/internal'; | ||
|
||
export interface UniqueIdentifiers { | ||
id: BigNumber; | ||
ticker: string; | ||
} | ||
|
||
export interface HumanReadable { | ||
id: string; | ||
ticker: string; | ||
declarationDate: string; | ||
description: string; | ||
targets: HumanReadableType<CorporateActionTargets>; | ||
defaultTaxWithholding: string; | ||
taxWithholdings: HumanReadableType<TaxWithholding[]>; | ||
} | ||
|
||
export interface Params { | ||
kind: CorporateActionKind; | ||
declarationDate: Date; | ||
description: string; | ||
targets: CorporateActionTargets; | ||
defaultTaxWithholding: BigNumber; | ||
taxWithholdings: TaxWithholding[]; | ||
} | ||
|
||
/** | ||
* Represents an action initiated by the issuer of a Security Token which may affect the positions of | ||
* the Tokenholders | ||
*/ | ||
export class CorporateAction extends CorporateActionBase { | ||
/** | ||
* @hidden | ||
*/ | ||
public constructor(args: UniqueIdentifiers & Params, context: Context) { | ||
super(args, context); | ||
|
||
this.modifyCheckpoint = createProcedureMethod( | ||
{ | ||
getProcedureAndArgs: modifyCaCheckpointArgs => [ | ||
modifyCaCheckpoint, | ||
{ corporateAction: this, ...modifyCaCheckpointArgs }, | ||
], | ||
}, | ||
context | ||
); | ||
} | ||
|
||
/** | ||
* Modify the Corporate Action's Checkpoint | ||
*/ | ||
public modifyCheckpoint: ProcedureMethod<ModifyCaCheckpointParams, void>; | ||
} |
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
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import BigNumber from 'bignumber.js'; | ||
|
||
import { Context, CorporateAction, CorporateActionBase, TransactionQueue } from '~/internal'; | ||
import { dsMockUtils, entityMockUtils, procedureMockUtils } from '~/testUtils/mocks'; | ||
import { | ||
CorporateActionKind, | ||
CorporateActionTargets, | ||
TargetTreatment, | ||
TaxWithholding, | ||
} from '~/types'; | ||
|
||
jest.mock( | ||
'~/api/entities/Checkpoint', | ||
require('~/testUtils/mocks/entities').mockCheckpointModule('~/api/entities/Checkpoint') | ||
); | ||
jest.mock( | ||
'~/api/entities/CheckpointSchedule', | ||
require('~/testUtils/mocks/entities').mockCheckpointScheduleModule( | ||
'~/api/entities/CheckpointSchedule' | ||
) | ||
); | ||
jest.mock( | ||
'~/base/Procedure', | ||
require('~/testUtils/mocks/procedure').mockProcedureModule('~/base/Procedure') | ||
); | ||
|
||
describe('CorporateAction class', () => { | ||
let context: Context; | ||
let id: BigNumber; | ||
let ticker: string; | ||
let declarationDate: Date; | ||
let kind: CorporateActionKind; | ||
let description: string; | ||
let targets: CorporateActionTargets; | ||
let defaultTaxWithholding: BigNumber; | ||
let taxWithholdings: TaxWithholding[]; | ||
|
||
let corporateAction: CorporateAction; | ||
|
||
beforeAll(() => { | ||
dsMockUtils.initMocks(); | ||
entityMockUtils.initMocks(); | ||
procedureMockUtils.initMocks(); | ||
}); | ||
|
||
beforeEach(() => { | ||
context = dsMockUtils.getContextInstance(); | ||
|
||
id = new BigNumber(1); | ||
ticker = 'SOME_TICKER'; | ||
declarationDate = new Date('10/14/1987 UTC'); | ||
kind = CorporateActionKind.UnpredictableBenefit; | ||
description = 'someDescription'; | ||
targets = { | ||
identities: [], | ||
treatment: TargetTreatment.Exclude, | ||
}; | ||
defaultTaxWithholding = new BigNumber(10); | ||
taxWithholdings = []; | ||
|
||
corporateAction = new CorporateAction( | ||
{ | ||
id, | ||
ticker, | ||
kind, | ||
declarationDate, | ||
description, | ||
targets, | ||
defaultTaxWithholding, | ||
taxWithholdings, | ||
}, | ||
context | ||
); | ||
}); | ||
|
||
afterEach(() => { | ||
dsMockUtils.reset(); | ||
entityMockUtils.reset(); | ||
procedureMockUtils.reset(); | ||
}); | ||
|
||
afterAll(() => { | ||
dsMockUtils.cleanup(); | ||
entityMockUtils.cleanup(); | ||
procedureMockUtils.cleanup(); | ||
}); | ||
|
||
test('should extend CorporateActionBase', () => { | ||
expect(CorporateAction.prototype instanceof CorporateActionBase).toBe(true); | ||
}); | ||
|
||
describe('method: modifyCheckpoint', () => { | ||
test('should prepare the procedure and return the resulting transaction queue', async () => { | ||
const expectedQueue = ('someQueue' as unknown) as TransactionQueue<void>; | ||
const args = { | ||
checkpoint: new Date(), | ||
}; | ||
|
||
procedureMockUtils | ||
.getPrepareStub() | ||
.withArgs({ args: { corporateAction, ...args }, transformer: undefined }, context) | ||
.resolves(expectedQueue); | ||
|
||
const queue = await corporateAction.modifyCheckpoint(args); | ||
|
||
expect(queue).toBe(expectedQueue); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.