|
| 1 | +import { BigNumber } from '@polymeshassociation/polymesh-sdk'; |
| 2 | +import { TargetTreatment } from '@polymeshassociation/polymesh-sdk/types'; |
| 3 | +import { TestFactory } from '~/helpers'; |
| 4 | +import { RestClient } from '~/rest'; |
| 5 | +import { createAssetParams } from '~/rest/assets/params'; |
| 6 | +import { ProcessMode } from '~/rest/common'; |
| 7 | +import { Identity } from '~/rest/identities/interfaces'; |
| 8 | + |
| 9 | +const handles = ['issuer', 'recipient']; |
| 10 | +let factory: TestFactory; |
| 11 | + |
| 12 | +describe('Corporate Actions', () => { |
| 13 | + let restClient: RestClient; |
| 14 | + let signer: string; |
| 15 | + let issuer: Identity; |
| 16 | + let assetParams: ReturnType<typeof createAssetParams>; |
| 17 | + let assetId: string; |
| 18 | + |
| 19 | + beforeAll(async () => { |
| 20 | + factory = await TestFactory.create({ handles }); |
| 21 | + ({ restClient } = factory); |
| 22 | + issuer = factory.getSignerIdentity(handles[0]); |
| 23 | + |
| 24 | + signer = issuer.signer; |
| 25 | + |
| 26 | + assetParams = createAssetParams({ |
| 27 | + options: { processMode: ProcessMode.Submit, signer }, |
| 28 | + }); |
| 29 | + }); |
| 30 | + |
| 31 | + afterAll(async () => { |
| 32 | + await factory.close(); |
| 33 | + }); |
| 34 | + |
| 35 | + it('should create and fetch the Asset', async () => { |
| 36 | + assetId = await restClient.assets.createAndGetAssetId(assetParams); |
| 37 | + |
| 38 | + const asset = await restClient.assets.getAsset(assetId); |
| 39 | + |
| 40 | + expect(asset).toMatchObject({ |
| 41 | + name: assetParams.name, |
| 42 | + assetType: assetParams.assetType, |
| 43 | + }); |
| 44 | + |
| 45 | + await restClient.compliance.pauseRequirements(assetId, { |
| 46 | + options: { processMode: ProcessMode.Submit, signer }, |
| 47 | + }); |
| 48 | + }); |
| 49 | + |
| 50 | + it('should get the corporate actions default config', async () => { |
| 51 | + const result = await restClient.corporateActions.getCorporateActionsDefaultConfig(assetId); |
| 52 | + |
| 53 | + expect(result).toEqual( |
| 54 | + expect.objectContaining({ |
| 55 | + targets: { |
| 56 | + identities: [], |
| 57 | + treatment: TargetTreatment.Exclude, |
| 58 | + }, |
| 59 | + defaultTaxWithholding: '0', |
| 60 | + taxWithholdings: [], |
| 61 | + }) |
| 62 | + ); |
| 63 | + }); |
| 64 | + |
| 65 | + it('should modify the corporate actions default config', async () => { |
| 66 | + await restClient.corporateActions.modifyCorporateActionsDefaultConfig(assetId, { |
| 67 | + options: { processMode: ProcessMode.Submit, signer }, |
| 68 | + defaultTaxWithholding: new BigNumber(100), |
| 69 | + targets: undefined, |
| 70 | + taxWithholdings: undefined, |
| 71 | + }); |
| 72 | + |
| 73 | + const result = await restClient.corporateActions.getCorporateActionsDefaultConfig(assetId); |
| 74 | + |
| 75 | + expect(result).toEqual( |
| 76 | + expect.objectContaining({ |
| 77 | + targets: { |
| 78 | + identities: [], |
| 79 | + treatment: TargetTreatment.Exclude, |
| 80 | + }, |
| 81 | + defaultTaxWithholding: '100', |
| 82 | + taxWithholdings: [], |
| 83 | + }) |
| 84 | + ); |
| 85 | + }); |
| 86 | +}); |
0 commit comments