Skip to content

Commit af93b93

Browse files
test: 💍 add corporate actions config tests
1 parent 8e98347 commit af93b93

File tree

6 files changed

+168
-0
lines changed

6 files changed

+168
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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+
});

tests/src/rest/client.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Assets } from '~/rest/assets';
55
import { Claims } from '~/rest/claims/client';
66
import { TxBase } from '~/rest/common';
77
import { Compliance } from '~/rest/compliance';
8+
import { CorporateActions } from '~/rest/corporate-actions';
89
import { Identities } from '~/rest/identities';
910
import { Network } from '~/rest/network';
1011
import { Nfts } from '~/rest/nfts';
@@ -28,6 +29,7 @@ export class RestClient {
2829
public claims: Claims;
2930
public network: Network;
3031
public checkpoints: Checkpoints;
32+
public corporateActions: CorporateActions;
3133

3234
constructor(public baseUrl: string) {
3335
this.accounts = new Accounts(this);
@@ -42,6 +44,7 @@ export class RestClient {
4244
this.claims = new Claims(this);
4345
this.network = new Network(this);
4446
this.checkpoints = new Checkpoints(this);
47+
this.corporateActions = new CorporateActions(this);
4548
}
4649

4750
public async get<T = unknown>(path: string): Promise<T> {
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { BigNumber } from '@polymeshassociation/polymesh-sdk';
2+
import { RestClient } from '~/rest/client';
3+
import { TxBase } from '~/rest/common';
4+
import { PostResult } from '~/rest/interfaces';
5+
import { setAssetDocumentParams } from '../assets';
6+
import {
7+
corporateActionDefaultConfigParams,
8+
CorporateActionTargets,
9+
CorporateActionTaxWithHoldings,
10+
} from './params';
11+
12+
export class CorporateActions {
13+
constructor(private readonly client: RestClient) {}
14+
15+
public async getCorporateActionsDefaultConfig(
16+
ticker: string
17+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
18+
): Promise<{
19+
targets: CorporateActionTargets;
20+
defaultTaxWithholding: string;
21+
taxWithholdings: CorporateActionTaxWithHoldings[];
22+
}> {
23+
return this.client.get(`/assets/${ticker}/corporate-actions/default-config`);
24+
}
25+
26+
public async modifyCorporateActionsDefaultConfig(
27+
ticker: string,
28+
params: ReturnType<typeof corporateActionDefaultConfigParams>
29+
): Promise<PostResult> {
30+
return this.client.post(`/assets/${ticker}/corporate-actions/default-config/modify`, params);
31+
}
32+
33+
public async deleteCorporateActions(
34+
ticker: string,
35+
id: BigNumber,
36+
txBase: TxBase
37+
): Promise<PostResult> {
38+
return this.client.post(`/assets/${ticker}/corporate-actions/${id}/delete`, { ...txBase });
39+
}
40+
41+
public async linkDocuments(
42+
asset: string,
43+
id: BigNumber,
44+
params: ReturnType<typeof setAssetDocumentParams>
45+
): Promise<PostResult> {
46+
return this.client.post(`assets/${asset}/corporate-actions/${id}/documents/link`, params);
47+
}
48+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './client';
2+
export * from './params';
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { BigNumber } from '@polymeshassociation/polymesh-sdk';
2+
import { TargetTreatment } from '@polymeshassociation/polymesh-sdk/types';
3+
import { TxBase, TxExtras } from '../common';
4+
5+
export type CorporateActionTargets = {
6+
identities: string[];
7+
treatment: TargetTreatment;
8+
};
9+
10+
export type CorporateActionTaxWithHoldings = {
11+
identity: string;
12+
percentage: BigNumber;
13+
};
14+
15+
export const corporateActionDefaultConfigParams = (
16+
base: TxBase,
17+
defaultTaxWithholding?: BigNumber,
18+
targets?: CorporateActionTargets,
19+
taxWithholdings?: CorporateActionTaxWithHoldings[],
20+
extras: TxExtras = {}
21+
) =>
22+
({
23+
targets,
24+
defaultTaxWithholding,
25+
taxWithholdings,
26+
...extras,
27+
...base,
28+
} as const);

tests/src/sdk/assets/controllerTransfer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export const fungibleAssetControllerTransfer = async (
3131

3232
const transferTx = await sdk.settlements.addInstruction({
3333
legs: [{ asset, from: identity, to: targetDid, amount: new BigNumber(1000) }],
34+
venueId: undefined,
3435
});
3536
const instruction = await transferTx.run();
3637
assert(transferTx.isSuccess);

0 commit comments

Comments
 (0)