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

Commit 1d2d6d1

Browse files
author
Victor Wiebe
committed
fix: check currentCheckpoint is lower than params checkpoint, ST
1 parent adb93df commit 1d2d6d1

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/contract_wrappers/tokens/__tests__/security_token_wrapper.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,14 @@ describe('SecurityTokenWrapper', () => {
714714
checkpointId: 1,
715715
};
716716

717+
const expectedCheckpointIdResult = new BigNumber(2);
718+
// Mocked method
719+
const mockedCheckpointIdMethod = mock(MockedCallMethod);
720+
// Stub the method
721+
when(mockedContract.currentCheckpointId).thenReturn(instance(mockedCheckpointIdMethod));
722+
// Stub the request
723+
when(mockedCheckpointIdMethod.callAsync()).thenResolve(expectedCheckpointIdResult);
724+
717725
const expectedDecimalsResult = new BigNumber(18);
718726
const mockedDecimalsMethod = mock(MockedCallMethod);
719727
when(mockedContract.decimals).thenReturn(instance(mockedDecimalsMethod));
@@ -737,6 +745,8 @@ describe('SecurityTokenWrapper', () => {
737745
verify(mockedMethod.callAsync(objectContaining(numberToBigNumber(mockedParams.checkpointId)))).once();
738746
verify(mockedContract.decimals).once();
739747
verify(mockedDecimalsMethod.callAsync()).once();
748+
verify(mockedContract.currentCheckpointId).once();
749+
verify(mockedCheckpointIdMethod.callAsync()).once();
740750
});
741751
});
742752

@@ -750,6 +760,14 @@ describe('SecurityTokenWrapper', () => {
750760
checkpointId: 1,
751761
};
752762

763+
const expectedCheckpointIdResult = new BigNumber(2);
764+
// Mocked method
765+
const mockedCheckpointIdMethod = mock(MockedCallMethod);
766+
// Stub the method
767+
when(mockedContract.currentCheckpointId).thenReturn(instance(mockedCheckpointIdMethod));
768+
// Stub the request
769+
when(mockedCheckpointIdMethod.callAsync()).thenResolve(expectedCheckpointIdResult);
770+
753771
const expectedDecimalsResult = new BigNumber(18);
754772
const mockedDecimalsMethod = mock(MockedCallMethod);
755773
when(mockedContract.decimals).thenReturn(instance(mockedDecimalsMethod));
@@ -775,6 +793,8 @@ describe('SecurityTokenWrapper', () => {
775793
).once();
776794
verify(mockedContract.decimals).once();
777795
verify(mockedDecimalsMethod.callAsync()).once();
796+
verify(mockedContract.currentCheckpointId).once();
797+
verify(mockedCheckpointIdMethod.callAsync()).once();
778798
});
779799
});
780800

src/contract_wrappers/tokens/security_token_wrapper.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1337,6 +1337,10 @@ export default class SecurityTokenWrapper extends ERC20TokenWrapper {
13371337
};
13381338

13391339
public totalSupplyAt = async (params: CheckpointIdParams) => {
1340+
assert.assert(
1341+
(await this.currentCheckpointId()).isGreaterThanOrEqualTo(params.checkpointId),
1342+
'Checkpoint id must be less than or equal to currentCheckpoint',
1343+
);
13401344
return weiToValue(
13411345
await (await this.contract).totalSupplyAt.callAsync(numberToBigNumber(params.checkpointId)),
13421346
await this.decimals(),
@@ -1345,6 +1349,10 @@ export default class SecurityTokenWrapper extends ERC20TokenWrapper {
13451349

13461350
public balanceOfAt = async (params: BalanceOfAtParams) => {
13471351
assert.isETHAddressHex('investor', params.investor);
1352+
assert.assert(
1353+
(await this.currentCheckpointId()).isGreaterThanOrEqualTo(params.checkpointId),
1354+
'Checkpoint id must be less than or equal to currentCheckpoint',
1355+
);
13481356
return weiToValue(
13491357
await (await this.contract).balanceOfAt.callAsync(params.investor, numberToBigNumber(params.checkpointId)),
13501358
await this.decimals(),
@@ -1632,7 +1640,7 @@ export default class SecurityTokenWrapper extends ERC20TokenWrapper {
16321640

16331641
public removeDocument = async (params: DocumentParams) => {
16341642
await this.checkOnlyOwner(params.txData);
1635-
const document = await this.getDocument({name: params.name});
1643+
const document = await this.getDocument({ name: params.name });
16361644
assert.assert(document.documentUri.length !== 0, 'Document does not exist');
16371645
return (await this.contract).removeDocument.sendTransactionAsync(
16381646
stringToBytes32(params.name),

0 commit comments

Comments
 (0)