Skip to content

Commit 4549f67

Browse files
author
Victor Wiebe
committed
feat: increase dividend distribution coverage
1 parent 6e5d897 commit 4549f67

File tree

2 files changed

+71
-2
lines changed

2 files changed

+71
-2
lines changed

src/procedures/__tests__/CreateErc20DividendDistribution.ts

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import * as tokenFactoryModule from '../../testUtils/MockedTokenFactoryObject';
1111
import { CreateErc20DividendDistribution } from '../../procedures/CreateErc20DividendDistribution';
1212
import { Procedure } from '~/procedures/Procedure';
1313
import { PolymathError } from '~/PolymathError';
14-
import { ErrorCode , ProcedureType } from '~/types';
14+
import { ErrorCode, ProcedureType } from '~/types';
1515
import { ApproveErc20 } from '../ApproveErc20';
1616
import * as securityTokenFactoryModule from '~/entities/factories/SecurityTokenFactory';
1717
import * as cappedStoFactoryModule from '~/entities/factories/CappedStoFactory';
@@ -27,7 +27,6 @@ import * as usdTieredStoFactoryModule from '~/entities/factories/UsdTieredStoFac
2727
import * as taxWithholdingFactoryModule from '~/entities/factories/TaxWithholdingFactory';
2828
import * as utilsModule from '~/utils';
2929

30-
3130
const params1 = {
3231
symbol: 'TEST1',
3332
name: 'Test Token 1',
@@ -199,6 +198,42 @@ describe('CreateErc20DividendDistribution', () => {
199198
expect(spyOnAddProcedure.withArgs(ApproveErc20).callCount).toBe(1);
200199
});
201200

201+
test('should send the transaction to CreateErc20DividendDistribution with taxWitholdings', async () => {
202+
target = new CreateErc20DividendDistribution(
203+
{
204+
symbol: params1.symbol,
205+
maturityDate: params1.maturityDate,
206+
expiryDate: params1.expiryDate,
207+
erc20Address: params1.erc20Address,
208+
amount: params1.amount,
209+
checkpointIndex: params1.checkpointIndex,
210+
name: params1.name,
211+
taxWithholdings: [
212+
{
213+
address: '0x5555555555555555555555555555555555555555',
214+
percentage: 50,
215+
},
216+
],
217+
},
218+
contextMock.getMockInstance()
219+
);
220+
const spyOnAddProcedure = sinon.spy(target, 'addProcedure');
221+
const spyOnAddTransaction = sinon.spy(target, 'addTransaction');
222+
// Real call
223+
await target.prepareTransactions();
224+
225+
// Verifications
226+
expect(
227+
spyOnAddTransaction.withArgs(erc20DividendsMock.getMockInstance().setWithholding).callCount
228+
).toBe(2);
229+
expect(
230+
spyOnAddTransaction.withArgs(
231+
erc20DividendsMock.getMockInstance().createDividendWithCheckpointAndExclusions
232+
).callCount
233+
).toBe(2);
234+
expect(spyOnAddProcedure.withArgs(ApproveErc20).callCount).toBe(1);
235+
});
236+
202237
test('should throw if there is no supplied valid security token', async () => {
203238
tokenFactoryMock.set(
204239
'getSecurityTokenInstanceFromTicker',

src/procedures/__tests__/CreateEtherDividendDistribution.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,40 @@ describe('CreateEtherDividendDistribution', () => {
182182
).toBe(1);
183183
});
184184

185+
test('should send the transaction to CreateEtherDividendDistribution with taxwithholdings', async () => {
186+
target = new CreateEtherDividendDistribution(
187+
{
188+
symbol: params1.symbol,
189+
maturityDate: params1.maturityDate,
190+
expiryDate: params1.expiryDate,
191+
amount: params1.amount,
192+
checkpointIndex: params1.checkpointIndex,
193+
name: params1.name,
194+
taxWithholdings: [
195+
{
196+
address: '0x5555555555555555555555555555555555555555',
197+
percentage: 50,
198+
},
199+
],
200+
},
201+
contextMock.getMockInstance()
202+
);
203+
204+
const spyOnAddTransaction = sinon.spy(target, 'addTransaction');
205+
// Real call
206+
await target.prepareTransactions();
207+
208+
// Verifications
209+
expect(
210+
spyOnAddTransaction.withArgs(etherDividendsMock.getMockInstance().setWithholding).callCount
211+
).toBe(2);
212+
expect(
213+
spyOnAddTransaction.withArgs(
214+
etherDividendsMock.getMockInstance().createDividendWithCheckpointAndExclusions
215+
).callCount
216+
).toBe(2);
217+
});
218+
185219
test('should throw if corresponding event is not fired', async () => {
186220
findEventsStub = ImportMock.mockFunction(utilsModule, 'findEvents', []);
187221

0 commit comments

Comments
 (0)