Skip to content
This repository was archived by the owner on Jul 6, 2022. It is now read-only.

Commit 8c9ed5e

Browse files
author
Victor Wiebe
committed
fix: dividend changes fo excluded and checkpoint id
Updating first test with checkpoint and exclusions
1 parent 7f455b5 commit 8c9ed5e

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

src/contract_wrappers/modules/checkpoint/__tests__/erc20_dividend_checkpoint_wrapper.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,24 @@ describe('ERC20DividendCheckpointWrapper', () => {
315315
when(mockedSecurityTokenOwnerMethod.callAsync()).thenResolve(expectedOwnerResult);
316316
when(mockedSecurityTokenContract.owner).thenReturn(instance(mockedSecurityTokenOwnerMethod));
317317

318+
const excluded = ['0x9999999999999999999999999999999999999999', '0x8888888888888888888888888888888888888888'];
319+
const expectedTotalSupplyResult = new BigNumber(1000);
320+
const mockedSecurityTokenTotalSupplyMethod = mock(MockedCallMethod);
321+
when(mockedSecurityTokenTotalSupplyMethod.callAsync(objectContaining(new BigNumber(checkpointId)))).thenResolve(
322+
expectedTotalSupplyResult,
323+
);
324+
when(mockedSecurityTokenContract.totalSupplyAt).thenReturn(instance(mockedSecurityTokenTotalSupplyMethod));
325+
326+
const expectedSecurityTokenBalanceOfResult = new BigNumber(10);
327+
const mockedSecurityTokenBalanceOfMethod = mock(MockedCallMethod);
328+
function whenBalanceOf (addr: string){
329+
when(
330+
mockedSecurityTokenBalanceOfMethod.callAsync(addr, objectContaining(new BigNumber(checkpointId))),
331+
).thenResolve(expectedSecurityTokenBalanceOfResult);
332+
when(mockedSecurityTokenContract.balanceOfAt).thenReturn(instance(mockedSecurityTokenBalanceOfMethod));
333+
}
334+
excluded.map(whenBalanceOf);
335+
318336
const expectedBalanceOfResult = new BigNumber(100);
319337
const mockedBalanceOfAddressMethod = mock(MockedCallMethod);
320338
when(mockedERC20DetailedContract.balanceOf).thenReturn(instance(mockedBalanceOfAddressMethod));
@@ -411,6 +429,15 @@ describe('ERC20DividendCheckpointWrapper', () => {
411429
verify(mockedContractFactory.getERC20DetailedContract(token)).twice();
412430
verify(mockedERC20DetailedContract.decimals).once();
413431
verify(mockedDecimalsMethod.callAsync()).once();
432+
verify(mockedSecurityTokenTotalSupplyMethod.callAsync(objectContaining(new BigNumber(checkpointId)))).once();
433+
verify(mockedSecurityTokenContract.totalSupplyAt).once();
434+
function verifyBalanceOf (addr: string){
435+
verify(
436+
mockedSecurityTokenBalanceOfMethod.callAsync(addr, objectContaining(new BigNumber(checkpointId))),
437+
).once();
438+
}
439+
excluded.map(verifyBalanceOf);
440+
verify(mockedSecurityTokenContract.balanceOfAt).times(excluded.length);
414441
});
415442
});
416443

src/contract_wrappers/modules/checkpoint/erc20_dividend_checkpoint_wrapper.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,9 @@ export default class ERC20DividendCheckpointWrapper extends DividendCheckpointWr
359359
assert.assert(expiry > maturity, 'Expiry before maturity');
360360
assert.isFutureDate(expiry, 'Expiry in past');
361361
assert.isBigNumberGreaterThanZero(amount, 'No dividend sent');
362+
const stContract = await this.securityTokenContract();
362363
if (checkpointId !== undefined) {
363-
const currentCheckpointId = await (await this.securityTokenContract()).currentCheckpointId.callAsync();
364+
const currentCheckpointId = await stContract.currentCheckpointId.callAsync();
364365
assert.assert(checkpointId < new BigNumber(currentCheckpointId).toNumber(), 'Invalid checkpoint');
365366
}
366367
assert.isNonZeroETHAddressHex('token', token);
@@ -371,5 +372,44 @@ export default class ERC20DividendCheckpointWrapper extends DividendCheckpointWr
371372
const erc20TokenAllowance = await erc20Detailed.allowance.callAsync(callerAddress, token);
372373
assert.assert(erc20TokenAllowance.isGreaterThanOrEqualTo(amount), 'Your allowance is less than dividend amount');
373374
assert.assert(erc20TokenBalance.isGreaterThanOrEqualTo(amount), 'Your balance is less than dividend amount');
375+
376+
function checkExcludedAssertions(addr: string) {
377+
assert.isNonZeroETHAddressHex('Excluded Address', addr);
378+
}
379+
380+
if (excluded) {
381+
excluded.map(checkExcludedAssertions);
382+
assert.areThereDuplicatedStrings('Excluded Addresses', excluded);
383+
}
384+
let currentSupply;
385+
let excludedSupply = new BigNumber(0);
386+
if (checkpointId) {
387+
currentSupply = await stContract.totalSupplyAt.callAsync(new BigNumber(checkpointId));
388+
if (excluded) {
389+
const promises = [];
390+
for (let i = 0; i < excluded.length; i += 1) {
391+
excludedSupply = excludedSupply.plus(
392+
promises.push(stContract.balanceOfAt.callAsync(excluded[i], new BigNumber(checkpointId))),
393+
);
394+
}
395+
excludedSupply = BigNumber.sum.apply(null, await Promise.all(promises));
396+
}
397+
} else {
398+
currentSupply = await stContract.totalSupply.callAsync();
399+
if (excluded) {
400+
const promises = [];
401+
for (let i = 0; i < excluded.length; i += 1) {
402+
excludedSupply = excludedSupply.plus(
403+
promises.push(stContract.balanceOf.callAsync(excluded[i])),
404+
);
405+
}
406+
excludedSupply = BigNumber.sum.apply(null, await Promise.all(promises));
407+
}
408+
}
409+
assert.assert(!currentSupply.isZero(), 'Invalid supply, must be greater than 0');
410+
assert.assert(
411+
currentSupply.isGreaterThan(excludedSupply),
412+
'Invalid supply, current supply must be greater than excluded supply',
413+
);
374414
};
375415
}

0 commit comments

Comments
 (0)