|
| 1 | +import { TestFactory } from '~/helpers'; |
| 2 | +import { RestClient } from '~/rest'; |
| 3 | +import { createAssetParams } from '~/rest/assets/params'; |
| 4 | +import { ProcessMode } from '~/rest/common'; |
| 5 | +import { Identity } from '~/rest/identities/interfaces'; |
| 6 | +import { RestSuccessResult } from '~/rest/interfaces'; |
| 7 | +import { fungibleInstructionParams } from '~/rest/settlements/params'; |
| 8 | + |
| 9 | +import { expectBasicTxInfo } from '../utils'; |
| 10 | +import { |
| 11 | + createDividendDistributionParams, |
| 12 | + claimDividendDistributionParams, |
| 13 | + payDividendDistributionParams, |
| 14 | + reclaimDividendDistributionParams, |
| 15 | + modifyDistributionCheckpointParams, |
| 16 | +} from '~/rest/corporate-actions/params'; |
| 17 | + |
| 18 | +const handles = ['issuer', 'holder']; |
| 19 | +let factory: TestFactory; |
| 20 | + |
| 21 | +describe('Dividend Distributions', () => { |
| 22 | + let restClient: RestClient; |
| 23 | + let signer: string; |
| 24 | + let issuer: Identity; |
| 25 | + let holder: Identity; |
| 26 | + let assetParams: ReturnType<typeof createAssetParams>; |
| 27 | + let assetId: string; |
| 28 | + let distributionId: string; |
| 29 | + |
| 30 | + beforeAll(async () => { |
| 31 | + factory = await TestFactory.create({ handles }); |
| 32 | + ({ restClient } = factory); |
| 33 | + issuer = factory.getSignerIdentity(handles[0]); |
| 34 | + holder = factory.getSignerIdentity(handles[1]); |
| 35 | + signer = issuer.signer; |
| 36 | + |
| 37 | + assetParams = createAssetParams({ |
| 38 | + options: { processMode: ProcessMode.Submit, signer }, |
| 39 | + }); |
| 40 | + }); |
| 41 | + |
| 42 | + afterAll(async () => { |
| 43 | + await factory.close(); |
| 44 | + }); |
| 45 | + |
| 46 | + it('should create and fetch the Asset', async () => { |
| 47 | + assetId = await restClient.assets.createAndGetAssetId(assetParams); |
| 48 | + }); |
| 49 | + |
| 50 | + it('should transfer part of the Asset to the holder', async () => { |
| 51 | + const params = fungibleInstructionParams(assetId, issuer.did, holder.did, { |
| 52 | + options: { processMode: ProcessMode.Submit, signer }, |
| 53 | + }); |
| 54 | + const txData = await restClient.settlements.createDirectInstruction(params); |
| 55 | + expect((txData as RestSuccessResult).instruction).toBeDefined(); |
| 56 | + |
| 57 | + const affirmTxData = await restClient.settlements.affirmInstruction( |
| 58 | + // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 59 | + (txData as any).instruction, |
| 60 | + { options: { processMode: ProcessMode.Submit, signer: holder.signer } } |
| 61 | + ); |
| 62 | + |
| 63 | + expect(affirmTxData).toMatchObject({ |
| 64 | + transactions: expect.arrayContaining([ |
| 65 | + { |
| 66 | + transactionTag: 'settlement.affirmInstructionWithCount', |
| 67 | + type: 'single', |
| 68 | + ...expectBasicTxInfo, |
| 69 | + }, |
| 70 | + ]), |
| 71 | + }); |
| 72 | + }); |
| 73 | + |
| 74 | + it('should have no dividend distributions', async () => { |
| 75 | + const distributions = await restClient.corporateActions.getDividendDistributions(assetId); |
| 76 | + |
| 77 | + expect(distributions.results.length).toEqual(0); |
| 78 | + }); |
| 79 | + |
| 80 | + it('should create a dividend distribution', async () => { |
| 81 | + const params = createDividendDistributionParams({ |
| 82 | + options: { processMode: ProcessMode.Submit, signer }, |
| 83 | + }); |
| 84 | + const result = await restClient.corporateActions.configureDividendDistribution(assetId, params); |
| 85 | + expect(result).toMatchObject({ |
| 86 | + transactions: expect.arrayContaining([ |
| 87 | + { |
| 88 | + transactionTag: 'corporateAction.configureDividendDistribution', |
| 89 | + type: 'single', |
| 90 | + ...expectBasicTxInfo, |
| 91 | + }, |
| 92 | + ]), |
| 93 | + }); |
| 94 | + expect(result.dividendDistribution).toBeDefined(); |
| 95 | + expect(result.dividendDistribution.id).toBeDefined(); |
| 96 | + distributionId = result.dividendDistribution.id as string; |
| 97 | + }); |
| 98 | + |
| 99 | + it('should fetch the dividend distribution', async () => { |
| 100 | + const result = await restClient.corporateActions.getDividendDistribution( |
| 101 | + assetId, |
| 102 | + distributionId |
| 103 | + ); |
| 104 | + expect(result).toBeDefined(); |
| 105 | + expect(result.id).toBe(distributionId); |
| 106 | + expect(result.asset).toBe(assetId); |
| 107 | + }); |
| 108 | + |
| 109 | + it('should pay the dividend distribution', async () => { |
| 110 | + const params = payDividendDistributionParams( |
| 111 | + { |
| 112 | + options: { processMode: ProcessMode.Submit, signer }, |
| 113 | + }, |
| 114 | + undefined, |
| 115 | + [holder.did] |
| 116 | + ); |
| 117 | + const result = await restClient.corporateActions.payDividendDistribution( |
| 118 | + assetId, |
| 119 | + distributionId, |
| 120 | + params |
| 121 | + ); |
| 122 | + expect(result).toMatchObject({ |
| 123 | + transactions: expect.arrayContaining([ |
| 124 | + { |
| 125 | + transactionTag: 'corporateAction.payDividendDistribution', |
| 126 | + type: 'single', |
| 127 | + ...expectBasicTxInfo, |
| 128 | + }, |
| 129 | + ]), |
| 130 | + }); |
| 131 | + }); |
| 132 | + |
| 133 | + it('holder should be able to get pending distributions', async () => { |
| 134 | + const distributions = await restClient.identities.pendingDividendDistributions(holder.did); |
| 135 | + expect(distributions.results.length).toEqual(1); |
| 136 | + expect(distributions.results[0].id).toBe(distributionId); |
| 137 | + }); |
| 138 | + |
| 139 | + it('holder should be able to claim the distribution', async () => { |
| 140 | + const params = claimDividendDistributionParams({ |
| 141 | + options: { processMode: ProcessMode.Submit, signer }, |
| 142 | + }); |
| 143 | + |
| 144 | + const result = await restClient.corporateActions.claimDividendDistribution( |
| 145 | + assetId, |
| 146 | + distributionId, |
| 147 | + params |
| 148 | + ); |
| 149 | + expect(result).toMatchObject({ |
| 150 | + transactions: expect.arrayContaining([ |
| 151 | + { |
| 152 | + transactionTag: 'corporateAction.claimDividendDistribution', |
| 153 | + type: 'single', |
| 154 | + ...expectBasicTxInfo, |
| 155 | + }, |
| 156 | + ]), |
| 157 | + }); |
| 158 | + }); |
| 159 | + |
| 160 | + it('should reclaim the distribution', async () => { |
| 161 | + const params = reclaimDividendDistributionParams({ |
| 162 | + options: { processMode: ProcessMode.Submit, signer }, |
| 163 | + }); |
| 164 | + const result = await restClient.corporateActions.reclaimDividendDistributionFunds( |
| 165 | + assetId, |
| 166 | + distributionId, |
| 167 | + params |
| 168 | + ); |
| 169 | + expect(result).toMatchObject({ |
| 170 | + transactions: expect.arrayContaining([ |
| 171 | + { |
| 172 | + transactionTag: 'corporateAction.reclaimDividendDistributionFunds', |
| 173 | + type: 'single', |
| 174 | + ...expectBasicTxInfo, |
| 175 | + }, |
| 176 | + ]), |
| 177 | + }); |
| 178 | + }); |
| 179 | + |
| 180 | + it('should be able to get payment history', async () => { |
| 181 | + const result = await restClient.corporateActions.paymentHistory(assetId, distributionId); |
| 182 | + expect(result).toMatchObject({ |
| 183 | + results: expect.arrayContaining([ |
| 184 | + { |
| 185 | + transactionTag: 'corporateAction.paymentHistory', |
| 186 | + type: 'single', |
| 187 | + ...expectBasicTxInfo, |
| 188 | + }, |
| 189 | + ]), |
| 190 | + total: 1, |
| 191 | + }); |
| 192 | + }); |
| 193 | + |
| 194 | + it('should be able to create another dividend distribution', async () => { |
| 195 | + const params = createDividendDistributionParams({ |
| 196 | + options: { processMode: ProcessMode.Submit, signer }, |
| 197 | + }); |
| 198 | + const result = await restClient.corporateActions.configureDividendDistribution(assetId, params); |
| 199 | + expect(result).toMatchObject({ |
| 200 | + transactions: expect.arrayContaining([ |
| 201 | + { |
| 202 | + transactionTag: 'corporateAction.configureDividendDistribution', |
| 203 | + type: 'single', |
| 204 | + ...expectBasicTxInfo, |
| 205 | + }, |
| 206 | + ]), |
| 207 | + }); |
| 208 | + |
| 209 | + distributionId = result.dividendDistribution.id as string; |
| 210 | + }); |
| 211 | + |
| 212 | + it('should be able to modify the checkpoint', async () => { |
| 213 | + const params = modifyDistributionCheckpointParams( |
| 214 | + { |
| 215 | + options: { processMode: ProcessMode.Submit, signer }, |
| 216 | + }, |
| 217 | + undefined, |
| 218 | + { type: 'Existing', id: '1' } |
| 219 | + ); |
| 220 | + const result = await restClient.corporateActions.modifyDistributionCheckpoint( |
| 221 | + assetId, |
| 222 | + distributionId, |
| 223 | + params |
| 224 | + ); |
| 225 | + expect(result).toMatchObject({ |
| 226 | + transactions: expect.arrayContaining([ |
| 227 | + { |
| 228 | + transactionTag: 'corporateAction.modifyDistributionCheckpoint', |
| 229 | + type: 'single', |
| 230 | + ...expectBasicTxInfo, |
| 231 | + }, |
| 232 | + ]), |
| 233 | + }); |
| 234 | + }); |
| 235 | +}); |
0 commit comments