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

Commit bc64077

Browse files
author
Victor Wiebe
committed
fix: replicate changes inside etherDividend for all createDividends
including test changes and changes to wrapper checkIsValidDividend
1 parent 1360109 commit bc64077

File tree

2 files changed

+108
-7
lines changed

2 files changed

+108
-7
lines changed

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

Lines changed: 70 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ describe('EtherDividendCheckpointWrapper', () => {
6565
when(mockedSecurityTokenOwnerMethod.callAsync()).thenResolve(expectedOwnerResult);
6666
when(mockedSecurityTokenContract.owner).thenReturn(instance(mockedSecurityTokenOwnerMethod));
6767

68+
const expectedTotalSupplyResult = new BigNumber(1000);
69+
const mockedSecurityTokenTotalSupplyMethod = mock(MockedCallMethod);
70+
when(mockedSecurityTokenTotalSupplyMethod.callAsync()).thenResolve(expectedTotalSupplyResult);
71+
when(mockedSecurityTokenContract.totalSupply).thenReturn(instance(mockedSecurityTokenTotalSupplyMethod));
72+
6873
// Mock web3 wrapper owner
6974
when(mockedWrapper.getAvailableAddressesAsync()).thenResolve([expectedOwnerResult]);
7075

@@ -115,10 +120,12 @@ describe('EtherDividendCheckpointWrapper', () => {
115120
).once();
116121
verify(mockedSecurityTokenOwnerMethod.callAsync()).once();
117122
verify(mockedSecurityTokenContract.owner).once();
118-
verify(mockedContract.securityToken).once();
119-
verify(mockedGetSecurityTokenAddressMethod.callAsync()).once();
120-
verify(mockedContractFactory.getSecurityTokenContract(expectedSecurityTokenAddress)).once();
123+
verify(mockedContract.securityToken).twice();
124+
verify(mockedGetSecurityTokenAddressMethod.callAsync()).twice();
125+
verify(mockedContractFactory.getSecurityTokenContract(expectedSecurityTokenAddress)).twice();
121126
verify(mockedWrapper.getAvailableAddressesAsync()).once();
127+
verify(mockedSecurityTokenTotalSupplyMethod.callAsync()).once();
128+
verify(mockedSecurityTokenContract.totalSupply).once();
122129
});
123130
});
124131

@@ -141,6 +148,13 @@ describe('EtherDividendCheckpointWrapper', () => {
141148
when(mockedSecurityTokenOwnerMethod.callAsync()).thenResolve(expectedOwnerResult);
142149
when(mockedSecurityTokenContract.owner).thenReturn(instance(mockedSecurityTokenOwnerMethod));
143150

151+
const expectedTotalSupplyResult = new BigNumber(1000);
152+
const mockedSecurityTokenTotalSupplyMethod = mock(MockedCallMethod);
153+
when(mockedSecurityTokenTotalSupplyMethod.callAsync(objectContaining(new BigNumber(checkpointId)))).thenResolve(
154+
expectedTotalSupplyResult,
155+
);
156+
when(mockedSecurityTokenContract.totalSupplyAt).thenReturn(instance(mockedSecurityTokenTotalSupplyMethod));
157+
144158
// Mock web3 wrapper owner
145159
when(mockedWrapper.getAvailableAddressesAsync()).thenResolve([expectedOwnerResult]);
146160

@@ -208,6 +222,8 @@ describe('EtherDividendCheckpointWrapper', () => {
208222
verify(mockedGetSecurityTokenAddressMethod.callAsync()).twice();
209223
verify(mockedContractFactory.getSecurityTokenContract(expectedSecurityTokenAddress)).twice();
210224
verify(mockedWrapper.getAvailableAddressesAsync()).once();
225+
verify(mockedSecurityTokenTotalSupplyMethod.callAsync(objectContaining(new BigNumber(checkpointId)))).once();
226+
verify(mockedSecurityTokenContract.totalSupplyAt).once();
211227
});
212228
});
213229

@@ -230,6 +246,24 @@ describe('EtherDividendCheckpointWrapper', () => {
230246
when(mockedSecurityTokenOwnerMethod.callAsync()).thenResolve(expectedOwnerResult);
231247
when(mockedSecurityTokenContract.owner).thenReturn(instance(mockedSecurityTokenOwnerMethod));
232248

249+
const excluded = ['0x9999999999999999999999999999999999999999', '0x8888888888888888888888888888888888888888'];
250+
const expectedTotalSupplyResult = new BigNumber(1000);
251+
const mockedSecurityTokenTotalSupplyMethod = mock(MockedCallMethod);
252+
when(mockedSecurityTokenTotalSupplyMethod.callAsync(objectContaining(new BigNumber(checkpointId)))).thenResolve(
253+
expectedTotalSupplyResult,
254+
);
255+
when(mockedSecurityTokenContract.totalSupplyAt).thenReturn(instance(mockedSecurityTokenTotalSupplyMethod));
256+
257+
const expectedSecurityTokenBalanceOfResult = new BigNumber(10);
258+
const mockedSecurityTokenBalanceOfMethod = mock(MockedCallMethod);
259+
function whenBalanceOf(addr: string) {
260+
when(
261+
mockedSecurityTokenBalanceOfMethod.callAsync(addr, objectContaining(new BigNumber(checkpointId))),
262+
).thenResolve(expectedSecurityTokenBalanceOfResult);
263+
}
264+
when(mockedSecurityTokenContract.balanceOfAt).thenReturn(instance(mockedSecurityTokenBalanceOfMethod));
265+
excluded.map(whenBalanceOf);
266+
233267
// Mock web3 wrapper owner
234268
when(mockedWrapper.getAvailableAddressesAsync()).thenResolve([expectedOwnerResult]);
235269

@@ -300,6 +334,15 @@ describe('EtherDividendCheckpointWrapper', () => {
300334
verify(mockedGetSecurityTokenAddressMethod.callAsync()).twice();
301335
verify(mockedContractFactory.getSecurityTokenContract(expectedSecurityTokenAddress)).twice();
302336
verify(mockedWrapper.getAvailableAddressesAsync()).once();
337+
verify(mockedSecurityTokenTotalSupplyMethod.callAsync(objectContaining(new BigNumber(checkpointId)))).once();
338+
verify(mockedSecurityTokenContract.totalSupplyAt).once();
339+
function verifyBalanceOf(addr: string) {
340+
verify(
341+
mockedSecurityTokenBalanceOfMethod.callAsync(addr, objectContaining(new BigNumber(checkpointId))),
342+
).once();
343+
}
344+
excluded.map(verifyBalanceOf);
345+
verify(mockedSecurityTokenContract.balanceOfAt).times(excluded.length);
303346
});
304347
});
305348

@@ -321,6 +364,20 @@ describe('EtherDividendCheckpointWrapper', () => {
321364
when(mockedSecurityTokenOwnerMethod.callAsync()).thenResolve(expectedOwnerResult);
322365
when(mockedSecurityTokenContract.owner).thenReturn(instance(mockedSecurityTokenOwnerMethod));
323366

367+
const excluded = ['0x9999999999999999999999999999999999999999', '0x8888888888888888888888888888888888888888'];
368+
const expectedTotalSupplyResult = new BigNumber(1000);
369+
const mockedSecurityTokenTotalSupplyMethod = mock(MockedCallMethod);
370+
when(mockedSecurityTokenTotalSupplyMethod.callAsync()).thenResolve(expectedTotalSupplyResult);
371+
when(mockedSecurityTokenContract.totalSupply).thenReturn(instance(mockedSecurityTokenTotalSupplyMethod));
372+
373+
const expectedSecurityTokenBalanceOfResult = new BigNumber(10);
374+
const mockedSecurityTokenBalanceOfMethod = mock(MockedCallMethod);
375+
function whenBalanceOf(addr: string) {
376+
when(mockedSecurityTokenBalanceOfMethod.callAsync(addr)).thenResolve(expectedSecurityTokenBalanceOfResult);
377+
}
378+
when(mockedSecurityTokenContract.balanceOf).thenReturn(instance(mockedSecurityTokenBalanceOfMethod));
379+
excluded.map(whenBalanceOf);
380+
324381
// Mock web3 wrapper owner
325382
when(mockedWrapper.getAvailableAddressesAsync()).thenResolve([expectedOwnerResult]);
326383

@@ -374,10 +431,17 @@ describe('EtherDividendCheckpointWrapper', () => {
374431
).once();
375432
verify(mockedSecurityTokenOwnerMethod.callAsync()).once();
376433
verify(mockedSecurityTokenContract.owner).once();
377-
verify(mockedContract.securityToken).once();
378-
verify(mockedGetSecurityTokenAddressMethod.callAsync()).once();
379-
verify(mockedContractFactory.getSecurityTokenContract(expectedSecurityTokenAddress)).once();
434+
verify(mockedContract.securityToken).twice();
435+
verify(mockedGetSecurityTokenAddressMethod.callAsync()).twice();
436+
verify(mockedContractFactory.getSecurityTokenContract(expectedSecurityTokenAddress)).twice();
380437
verify(mockedWrapper.getAvailableAddressesAsync()).once();
438+
verify(mockedSecurityTokenTotalSupplyMethod.callAsync()).once();
439+
verify(mockedSecurityTokenContract.totalSupply).once();
440+
function verifyBalanceOf(addr: string) {
441+
verify(mockedSecurityTokenBalanceOfMethod.callAsync(addr)).once();
442+
}
443+
verify(mockedSecurityTokenContract.balanceOf).times(excluded.length);
444+
excluded.map(verifyBalanceOf);
381445
});
382446
});
383447

src/contract_wrappers/modules/checkpoint/ether_dividend_checkpoint_wrapper.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,10 +398,47 @@ export default class EtherDividendCheckpointWrapper extends DividendCheckpointWr
398398
assert.assert(expiry > maturity, 'Expiry before maturity');
399399
assert.isFutureDate(expiry, 'Expiry in past');
400400
assert.isBigNumberGreaterThanZero(value, 'No dividend sent');
401+
const stContract = await this.securityTokenContract();
401402
if (checkpointId !== undefined) {
402-
const currentCheckpointId = await (await this.securityTokenContract()).currentCheckpointId.callAsync();
403+
const currentCheckpointId = await stContract.currentCheckpointId.callAsync();
403404
assert.assert(checkpointId < new BigNumber(currentCheckpointId).toNumber(), 'Invalid checkpoint');
404405
}
405406
assert.assert(name.length > 0, 'The name can not be empty');
407+
408+
function checkExcludedAssertions(addr: string) {
409+
assert.isNonZeroETHAddressHex('Excluded Address', addr);
410+
}
411+
if (excluded) {
412+
excluded.map(checkExcludedAssertions);
413+
assert.areThereDuplicatedStrings('Excluded Addresses', excluded);
414+
}
415+
let currentSupply;
416+
let excludedSupply = new BigNumber(0);
417+
if (checkpointId) {
418+
currentSupply = await stContract.totalSupplyAt.callAsync(new BigNumber(checkpointId));
419+
if (excluded) {
420+
const promises = [];
421+
for (let i = 0; i < excluded.length; i += 1) {
422+
excludedSupply = excludedSupply.plus(
423+
promises.push(stContract.balanceOfAt.callAsync(excluded[i], new BigNumber(checkpointId))),
424+
);
425+
}
426+
excludedSupply = BigNumber.sum.apply(null, await Promise.all(promises));
427+
}
428+
} else {
429+
currentSupply = await stContract.totalSupply.callAsync();
430+
if (excluded) {
431+
const promises = [];
432+
for (let i = 0; i < excluded.length; i += 1) {
433+
excludedSupply = excludedSupply.plus(promises.push(stContract.balanceOf.callAsync(excluded[i])));
434+
}
435+
excludedSupply = BigNumber.sum.apply(null, await Promise.all(promises));
436+
}
437+
}
438+
assert.assert(!currentSupply.isZero(), 'Invalid supply, must be greater than 0');
439+
assert.assert(
440+
currentSupply.isGreaterThan(excludedSupply),
441+
'Invalid supply, current supply must be greater than excluded supply',
442+
);
406443
};
407444
}

0 commit comments

Comments
 (0)