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/client.ts b/tests/src/rest/client.ts index 18617f4..7f1b078 100644 --- a/tests/src/rest/client.ts +++ b/tests/src/rest/client.ts @@ -5,6 +5,7 @@ import { Assets } from '~/rest/assets'; import { Claims } from '~/rest/claims/client'; import { TxBase } from '~/rest/common'; import { Compliance } from '~/rest/compliance'; +import { CorporateActions } from '~/rest/corporate-actions'; import { Identities } from '~/rest/identities'; import { Network } from '~/rest/network'; import { Nfts } from '~/rest/nfts'; @@ -28,6 +29,7 @@ export class RestClient { public claims: Claims; public network: Network; public checkpoints: Checkpoints; + public corporateActions: CorporateActions; constructor(public baseUrl: string) { this.accounts = new Accounts(this); @@ -42,6 +44,7 @@ export class RestClient { this.claims = new Claims(this); this.network = new Network(this); this.checkpoints = new Checkpoints(this); + this.corporateActions = new CorporateActions(this); } public async get(path: string): Promise { diff --git a/tests/src/rest/corporate-actions/client.ts b/tests/src/rest/corporate-actions/client.ts new file mode 100644 index 0000000..c11df86 --- /dev/null +++ b/tests/src/rest/corporate-actions/client.ts @@ -0,0 +1,48 @@ +import { BigNumber } from '@polymeshassociation/polymesh-sdk'; +import { RestClient } from '~/rest/client'; +import { TxBase } from '~/rest/common'; +import { PostResult } from '~/rest/interfaces'; +import { setAssetDocumentParams } from '../assets'; +import { + corporateActionDefaultConfigParams, + CorporateActionTargets, + CorporateActionTaxWithHoldings, +} from './params'; + +export class CorporateActions { + constructor(private readonly client: RestClient) {} + + 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/index.ts b/tests/src/rest/corporate-actions/index.ts new file mode 100644 index 0000000..36fefdc --- /dev/null +++ b/tests/src/rest/corporate-actions/index.ts @@ -0,0 +1,2 @@ +export * from './client'; +export * from './params'; diff --git a/tests/src/rest/corporate-actions/params.ts b/tests/src/rest/corporate-actions/params.ts new file mode 100644 index 0000000..548a487 --- /dev/null +++ b/tests/src/rest/corporate-actions/params.ts @@ -0,0 +1,28 @@ +import { BigNumber } from '@polymeshassociation/polymesh-sdk'; +import { TargetTreatment } from '@polymeshassociation/polymesh-sdk/types'; +import { TxBase, TxExtras } from '../common'; + +export type CorporateActionTargets = { + identities: string[]; + treatment: TargetTreatment; +}; + +export type CorporateActionTaxWithHoldings = { + identity: string; + percentage: BigNumber; +}; + +export const corporateActionDefaultConfigParams = ( + base: TxBase, + defaultTaxWithholding?: BigNumber, + targets?: CorporateActionTargets, + taxWithholdings?: CorporateActionTaxWithHoldings[], + extras: TxExtras = {} +) => + ({ + targets, + defaultTaxWithholding, + taxWithholdings, + ...extras, + ...base, + } as const); diff --git a/tests/src/sdk/assets/controllerTransfer.ts b/tests/src/sdk/assets/controllerTransfer.ts index 542cc8d..fe20909 100644 --- a/tests/src/sdk/assets/controllerTransfer.ts +++ b/tests/src/sdk/assets/controllerTransfer.ts @@ -31,6 +31,7 @@ export const fungibleAssetControllerTransfer = async ( const transferTx = await sdk.settlements.addInstruction({ legs: [{ asset, from: identity, to: targetDid, amount: new BigNumber(1000) }], + venueId: undefined, }); const instruction = await transferTx.run(); assert(transferTx.isSuccess);