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

Commit c89039d

Browse files
author
Victor Wiebe
committed
fix: 🐛 assert document exists before removeDocument (ST)
1 parent c798255 commit c89039d

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ import {
4141
weiToValue,
4242
stringArrayToBytes32Array,
4343
bytes32ArrayToStringArray,
44-
bigNumberToDate, parsePartitionBytes32Value,
44+
bigNumberToDate,
45+
parsePartitionBytes32Value,
4546
} from '../../../utils/convert';
4647
import { MockedCallMethod, MockedSendMethod, getMockedPolyResponse } from '../../../test_utils/mocked_methods';
4748

@@ -4838,6 +4839,20 @@ describe('SecurityTokenWrapper', () => {
48384839
test.todo('should fail if name is 0 length');
48394840
test.todo('should fail if uri is 0 length');
48404841
test('should send the transaction to removeDocument', async () => {
4842+
const documentUri = 'Uri';
4843+
const documentHash = stringToBytes32('Hash');
4844+
const documentTime = new Date(2030, 1);
4845+
const expectedGetDocumentResult = [documentUri, documentHash, dateToBigNumber(documentTime)];
4846+
// Mocked method
4847+
const mockedGetDocumentParams = { name: 'Name' };
4848+
const mockedGetDocumentMethod = mock(MockedCallMethod);
4849+
// Stub the method
4850+
when(mockedContract.getDocument).thenReturn(instance(mockedGetDocumentMethod));
4851+
// Stub the request
4852+
when(
4853+
mockedGetDocumentMethod.callAsync(objectContaining(stringToBytes32(mockedGetDocumentParams.name))),
4854+
).thenResolve(expectedGetDocumentResult);
4855+
48414856
// Mocked parameters
48424857
const mockedParams = {
48434858
name: 'Name',
@@ -4887,6 +4902,8 @@ describe('SecurityTokenWrapper', () => {
48874902
verify(mockedContract.owner).once();
48884903
verify(mockedOwnerMethod.callAsync()).once();
48894904
verify(mockedWrapper.getAvailableAddressesAsync()).once();
4905+
verify(mockedContract.getDocument).once();
4906+
verify(mockedGetDocumentMethod.callAsync(objectContaining(stringToBytes32(mockedGetDocumentParams.name)))).once();
48904907
});
48914908
});
48924909

src/contract_wrappers/tokens/security_token_wrapper.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,8 +1615,8 @@ export default class SecurityTokenWrapper extends ERC20TokenWrapper {
16151615
};
16161616

16171617
public setDocument = async (params: SetDocumentParams) => {
1618-
assert.assert(params.name.length > 0, 'Bad name');
1619-
assert.assert(params.uri.length > 0, 'Bad uri');
1618+
assert.assert(params.name.length > 0, 'Bad name, cannot be empty');
1619+
assert.assert(params.uri.length > 0, 'Bad uri, cannot be empty');
16201620
await this.checkOnlyOwner(params.txData);
16211621
return (await this.contract).setDocument.sendTransactionAsync(
16221622
stringToBytes32(params.name),
@@ -1629,6 +1629,8 @@ export default class SecurityTokenWrapper extends ERC20TokenWrapper {
16291629

16301630
public removeDocument = async (params: DocumentParams) => {
16311631
await this.checkOnlyOwner(params.txData);
1632+
const document = await this.getDocument({name: params.name});
1633+
assert.assert(document.documentUri.length !== 0, 'Document does not exist');
16321634
return (await this.contract).removeDocument.sendTransactionAsync(
16331635
stringToBytes32(params.name),
16341636
params.txData,

0 commit comments

Comments
 (0)