Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions tests/src/__tests__/rest/corporate-actions/base.ts
Original file line number Diff line number Diff line change
@@ -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<typeof createAssetParams>;
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: [],
})
);
});
});
3 changes: 3 additions & 0 deletions tests/src/rest/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
Expand All @@ -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<T = unknown>(path: string): Promise<T> {
Expand Down
48 changes: 48 additions & 0 deletions tests/src/rest/corporate-actions/client.ts
Original file line number Diff line number Diff line change
@@ -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<typeof corporateActionDefaultConfigParams>
): Promise<PostResult> {
return this.client.post(`/assets/${ticker}/corporate-actions/default-config/modify`, params);
}

public async deleteCorporateActions(
ticker: string,
id: BigNumber,
txBase: TxBase
): Promise<PostResult> {
return this.client.post(`/assets/${ticker}/corporate-actions/${id}/delete`, { ...txBase });
}

public async linkDocuments(
asset: string,
id: BigNumber,
params: ReturnType<typeof setAssetDocumentParams>
): Promise<PostResult> {
return this.client.post(`assets/${asset}/corporate-actions/${id}/documents/link`, params);
}
}
2 changes: 2 additions & 0 deletions tests/src/rest/corporate-actions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './client';
export * from './params';
28 changes: 28 additions & 0 deletions tests/src/rest/corporate-actions/params.ts
Original file line number Diff line number Diff line change
@@ -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);
1 change: 1 addition & 0 deletions tests/src/sdk/assets/controllerTransfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down