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

Commit 263bbdc

Browse files
author
Victor Wiebe
committed
fix: partitions refactorings
add Locked partition type, add new parse partitons, use in tests
1 parent ecb7947 commit 263bbdc

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import {
4141
weiToValue,
4242
stringArrayToBytes32Array,
4343
bytes32ArrayToStringArray,
44-
bigNumberToDate,
44+
bigNumberToDate, parsePartitionBytes32Value,
4545
} from '../../../utils/convert';
4646
import { MockedCallMethod, MockedSendMethod, getMockedPolyResponse } from '../../../test_utils/mocked_methods';
4747

@@ -148,7 +148,7 @@ describe('SecurityTokenWrapper', () => {
148148

149149
describe('partitionsOf', () => {
150150
test('should call to partitionsOf', async () => {
151-
const expectedResult = stringArrayToBytes32Array(['UNDEFINED', 'UNLOCKED']);
151+
const expectedResult = stringArrayToBytes32Array(['0', 'UNLOCKED', 'LOCKED']);
152152
const mockedParams = {
153153
partition: 'UNLOCKED',
154154
operator: '0x5555555555555555555555555555555555555555',
@@ -164,7 +164,7 @@ describe('SecurityTokenWrapper', () => {
164164
// Real call
165165
const result = await target.partitionsOf(mockedParams);
166166
// Result expectation
167-
expect(result).toEqual(bytes32ArrayToStringArray(expectedResult));
167+
expect(result).toEqual(expectedResult.map(parsePartitionBytes32Value));
168168
// Verifications
169169
verify(mockedContract.partitionsOf).once();
170170
verify(mockedMethod.callAsync(mockedParams.tokenHolder)).once();

src/contract_wrappers/tokens/security_token_wrapper.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ import {
7878
bytes32ToString,
7979
dateToBigNumber,
8080
numberToBigNumber,
81+
parsePartitionBytes32Value,
8182
stringToBytes32,
8283
valueArrayToWeiArray,
8384
valueToWei,
@@ -912,8 +913,8 @@ export default class SecurityTokenWrapper extends ERC20TokenWrapper {
912913

913914
public partitionsOf = async (params: PartitionsOfParams): Promise<Partition[]> => {
914915
const partitions = await (await this.contract).partitionsOf.callAsync(params.tokenHolder);
915-
return bytes32ArrayToStringArray(partitions).map(element => {
916-
return element === Partition.Unlocked ? Partition.Unlocked : Partition.Undefined;
916+
return partitions.map(element => {
917+
return parsePartitionBytes32Value(element);
917918
});
918919
};
919920

@@ -1610,7 +1611,7 @@ export default class SecurityTokenWrapper extends ERC20TokenWrapper {
16101611
const typedResult: CanTransferByPartitionData = {
16111612
statusCode: result[0],
16121613
reasonCode: bytes32ToString(result[1]),
1613-
partition: bytes32ToString(result[2]) === Partition.Unlocked ? Partition.Unlocked : Partition.Undefined,
1614+
partition: parsePartitionBytes32Value(result[2]),
16141615
};
16151616
return typedResult;
16161617
};

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ export enum Feature {
119119

120120
export enum Partition {
121121
Unlocked = 'UNLOCKED',
122+
Locked = 'LOCKED',
122123
Undefined = 'UNDEFINED',
123124
}
124125

src/utils/convert.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ethers } from 'ethers';
22
import { BigNumber } from '@0x/utils';
3+
import { Partition } from '../types';
34

45
const BASE = new BigNumber(10);
56

@@ -81,3 +82,15 @@ export function packVersion(major: string, minor: string, patch: string) {
8182
export function stringToKeccak256(value: string) {
8283
return ethers.utils.keccak256(value);
8384
}
85+
export function parsePartitionBytes32Value(value: string): Partition {
86+
switch (bytes32ToString(value)) {
87+
case 'UNLOCKED':
88+
return Partition.Unlocked;
89+
case 'LOCKED':
90+
return Partition.Locked;
91+
case '0':
92+
return Partition.Undefined;
93+
default:
94+
throw new Error('Partition not recognized');
95+
}
96+
}

0 commit comments

Comments
 (0)