From 1ac0d8e1a7889d8d42394973f99157dde7881991 Mon Sep 17 00:00:00 2001 From: Prashant Bajpai <34747455+prashantasdeveloper@users.noreply.github.com> Date: Wed, 17 Sep 2025 21:37:15 +0530 Subject: [PATCH] =?UTF-8?q?test:=20=F0=9F=92=8D=20add=20corporate=20action?= =?UTF-8?q?s=20config=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/src/__tests__/rest/checkpoints/base.ts | 2 +- .../__tests__/rest/corporate-actions/base.ts | 86 +++++++++++++++++++ tests/src/rest/corporate-actions/client.ts | 43 +++++++++- tests/src/rest/corporate-actions/params.ts | 25 ++++++ 4 files changed, 154 insertions(+), 2 deletions(-) create mode 100644 tests/src/__tests__/rest/corporate-actions/base.ts diff --git a/tests/src/__tests__/rest/checkpoints/base.ts b/tests/src/__tests__/rest/checkpoints/base.ts index 3170c49..0482dfb 100644 --- a/tests/src/__tests__/rest/checkpoints/base.ts +++ b/tests/src/__tests__/rest/checkpoints/base.ts @@ -44,7 +44,7 @@ describe('Checkpoints Controller', () => { }, { name: 'Test Checkpoint Asset', - initialSupply: '1000000', // 1M tokens + initialSupply: '100', // 1M tokens } ); diff --git a/tests/src/__tests__/rest/corporate-actions/base.ts b/tests/src/__tests__/rest/corporate-actions/base.ts new file mode 100644 index 0000000..f42163a --- /dev/null +++ b/tests/src/__tests__/rest/corporate-actions/base.ts @@ -0,0 +1,86 @@ +import { BigNumber } from '@polymeshassociation/polymesh-sdk'; +import { TargetTreatment } from '@polymeshassociation/polymesh-sdk/types'; +import { TestFactory } from '~/helpers'; +import { RestClient } from '~/rest'; +import { createAssetParams } from '~/rest/assets/params'; +import { ProcessMode } from '~/rest/common'; +import { Identity } from '~/rest/identities/interfaces'; + +const handles = ['issuer', 'recipient']; +let factory: TestFactory; + +describe('Corporate Actions', () => { + let restClient: RestClient; + let signer: string; + let issuer: Identity; + let assetParams: ReturnType; + let assetId: string; + + beforeAll(async () => { + factory = await TestFactory.create({ handles }); + ({ restClient } = factory); + issuer = factory.getSignerIdentity(handles[0]); + + signer = issuer.signer; + + assetParams = createAssetParams({ + options: { processMode: ProcessMode.Submit, signer }, + }); + }); + + afterAll(async () => { + await factory.close(); + }); + + it('should create and fetch the Asset', async () => { + assetId = await restClient.assets.createAndGetAssetId(assetParams); + + const asset = await restClient.assets.getAsset(assetId); + + expect(asset).toMatchObject({ + name: assetParams.name, + assetType: assetParams.assetType, + }); + + await restClient.compliance.pauseRequirements(assetId, { + options: { processMode: ProcessMode.Submit, signer }, + }); + }); + + it('should get the corporate actions default config', async () => { + const result = await restClient.corporateActions.getCorporateActionsDefaultConfig(assetId); + + expect(result).toEqual( + expect.objectContaining({ + targets: { + identities: [], + treatment: TargetTreatment.Exclude, + }, + defaultTaxWithholding: '0', + taxWithholdings: [], + }) + ); + }); + + it('should modify the corporate actions default config', async () => { + await restClient.corporateActions.modifyCorporateActionsDefaultConfig(assetId, { + options: { processMode: ProcessMode.Submit, signer }, + defaultTaxWithholding: new BigNumber(100), + targets: undefined, + taxWithholdings: undefined, + }); + + const result = await restClient.corporateActions.getCorporateActionsDefaultConfig(assetId); + + expect(result).toEqual( + expect.objectContaining({ + targets: { + identities: [], + treatment: TargetTreatment.Exclude, + }, + defaultTaxWithholding: '100', + taxWithholdings: [], + }) + ); + }); +}); diff --git a/tests/src/rest/corporate-actions/client.ts b/tests/src/rest/corporate-actions/client.ts index 3c44800..dcb9400 100644 --- a/tests/src/rest/corporate-actions/client.ts +++ b/tests/src/rest/corporate-actions/client.ts @@ -1,15 +1,22 @@ +import { BigNumber } from '@polymeshassociation/polymesh-sdk'; + import { RestClient } from '~/rest/client'; +import { TxBase } from '~/rest/common'; import { PostResult, RestSuccessResult, ResultSet } from '~/rest/interfaces'; +import { setAssetDocumentParams } from '../assets'; import { claimDividendDistributionParams, + corporateActionDefaultConfigParams, + CorporateActionTargets, + CorporateActionTaxWithHoldings, createDividendDistributionParams, payDividendDistributionParams, reclaimDividendDistributionParams, } from './params'; export class CorporateActions { - constructor(private client: RestClient) {} + constructor(private readonly client: RestClient) {} // NOTE: Only endpoints verified against docs should live here @@ -92,4 +99,38 @@ export class CorporateActions { `/assets/${asset}/corporate-actions/dividend-distributions/${id}/payment-history` ); } + + public async getCorporateActionsDefaultConfig( + ticker: string + // eslint-disable-next-line @typescript-eslint/no-explicit-any + ): Promise<{ + targets: CorporateActionTargets; + defaultTaxWithholding: string; + taxWithholdings: CorporateActionTaxWithHoldings[]; + }> { + return this.client.get(`/assets/${ticker}/corporate-actions/default-config`); + } + + public async modifyCorporateActionsDefaultConfig( + ticker: string, + params: ReturnType + ): Promise { + return this.client.post(`/assets/${ticker}/corporate-actions/default-config/modify`, params); + } + + public async deleteCorporateActions( + ticker: string, + id: BigNumber, + txBase: TxBase + ): Promise { + return this.client.post(`/assets/${ticker}/corporate-actions/${id}/delete`, { ...txBase }); + } + + public async linkDocuments( + asset: string, + id: BigNumber, + params: ReturnType + ): Promise { + return this.client.post(`assets/${asset}/corporate-actions/${id}/documents/link`, params); + } } diff --git a/tests/src/rest/corporate-actions/params.ts b/tests/src/rest/corporate-actions/params.ts index 007be9b..77ef5f2 100644 --- a/tests/src/rest/corporate-actions/params.ts +++ b/tests/src/rest/corporate-actions/params.ts @@ -61,3 +61,28 @@ export const modifyDistributionCheckpointParams = ( ...base, checkpoint, } as const); + +export type CorporateActionTargets = { + identities: string[]; + treatment: TargetTreatment; +}; + +export type CorporateActionTaxWithHoldings = { + identity: string; + percentage: BigNumber; +}; + +export const corporateActionDefaultConfigParams = ( + base: TxBase, + defaultTaxWithholding?: BigNumber | undefined, + targets?: CorporateActionTargets | undefined, + taxWithholdings?: CorporateActionTaxWithHoldings[] | undefined, + extras: TxExtras = {} +) => + ({ + targets, + defaultTaxWithholding, + taxWithholdings, + ...extras, + ...base, + } as const);