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

Commit 29f9f11

Browse files
author
Victor Wiebe
committed
feat: add changeSTVersionBounds and associated tests
1 parent 9447529 commit 29f9f11

File tree

3 files changed

+117
-12
lines changed

3 files changed

+117
-12
lines changed

src/contract_wrappers/modules/__tests__/module_factory_wrapper.test.ts

Lines changed: 81 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
} from '../../../utils/convert';
1818
import ModuleFactoryWrapper from '../module_factory_wrapper';
1919
import ContractWrapper from '../../contract_wrapper';
20-
import { FULL_DECIMALS, ModuleType } from '../../../types';
20+
import {BoundType, FULL_DECIMALS, ModuleType} from '../../../types';
2121

2222
describe('ModuleFactoryWrapper', () => {
2323
let target: ModuleFactoryWrapper;
@@ -486,11 +486,11 @@ describe('ModuleFactoryWrapper', () => {
486486
when(mockedContract.changeTags).thenReturn(instance(mockedMethod));
487487
// Stub the request
488488
when(
489-
mockedMethod.sendTransactionAsync(
490-
objectContaining(stringArrayToBytes32Array(mockedParams.tags)),
491-
mockedParams.txData,
492-
mockedParams.safetyFactor,
493-
),
489+
mockedMethod.sendTransactionAsync(
490+
objectContaining(stringArrayToBytes32Array(mockedParams.tags)),
491+
mockedParams.txData,
492+
mockedParams.safetyFactor,
493+
),
494494
).thenResolve(expectedResult);
495495

496496
// Owner Address expected
@@ -514,13 +514,82 @@ describe('ModuleFactoryWrapper', () => {
514514
verify(mockedOwnerMethod.callAsync()).once();
515515
verify(mockedContract.changeTags).once();
516516
verify(
517-
mockedMethod.sendTransactionAsync(
518-
objectContaining(stringArrayToBytes32Array(mockedParams.tags)),
519-
mockedParams.txData,
520-
mockedParams.safetyFactor,
521-
),
517+
mockedMethod.sendTransactionAsync(
518+
objectContaining(stringArrayToBytes32Array(mockedParams.tags)),
519+
mockedParams.txData,
520+
mockedParams.safetyFactor,
521+
),
522+
).once();
523+
verify(mockedWrapper.getAvailableAddressesAsync()).once();
524+
});
525+
});
526+
527+
describe('ChangeSTVersionBounds', () => {
528+
test.todo('should fail as there is an invalid bound type used');
529+
test.todo('should fail as tags array length is not 3');
530+
test('should send the transaction to changeSTVersionBounds', async () => {
531+
// Mocked parameters
532+
const mockedParams = {
533+
boundType: BoundType.LowerBound,
534+
newVersion: [2, 3, 4],
535+
txData: {},
536+
safetyFactor: 10,
537+
};
538+
const expectedResult = getMockedPolyResponse();
539+
// Mocked method
540+
const mockedMethod = mock(MockedSendMethod);
541+
// Stub the method
542+
when(mockedContract.changeSTVersionBounds).thenReturn(instance(mockedMethod));
543+
// Stub the request
544+
when(
545+
mockedMethod.sendTransactionAsync(
546+
mockedParams.boundType,
547+
mockedParams.newVersion,
548+
mockedParams.txData,
549+
mockedParams.safetyFactor,
550+
),
551+
).thenResolve(expectedResult);
552+
553+
// Owner Address expected
554+
const expectedOwnerResult = '0x5555555555555555555555555555555555555555';
555+
// Mocked method
556+
const mockedOwnerMethod = mock(MockedCallMethod);
557+
// Stub the method
558+
when(mockedContract.owner).thenReturn(instance(mockedOwnerMethod));
559+
// Stub the request
560+
when(mockedOwnerMethod.callAsync()).thenResolve(expectedOwnerResult);
561+
// Mock web3 wrapper owner
562+
when(mockedWrapper.getAvailableAddressesAsync()).thenResolve([expectedOwnerResult]);
563+
564+
// Address expected
565+
const expectedLowerSTVersionBoundsResult = [new BigNumber(1), new BigNumber(2), new BigNumber(3)];
566+
// Mocked method
567+
const mockedLowerSTVersionBoundsMethod = mock(MockedCallMethod);
568+
// Stub the method
569+
when(mockedContract.getLowerSTVersionBounds).thenReturn(instance(mockedLowerSTVersionBoundsMethod));
570+
// Stub the request
571+
when(mockedLowerSTVersionBoundsMethod.callAsync()).thenResolve(expectedLowerSTVersionBoundsResult);
572+
573+
// Real call
574+
const result = await target.changeSTVersionBounds(mockedParams);
575+
576+
// Result expectation
577+
expect(result).toBe(expectedResult);
578+
// Verifications
579+
verify(mockedContract.owner).once();
580+
verify(mockedOwnerMethod.callAsync()).once();
581+
verify(mockedContract.changeSTVersionBounds).once();
582+
verify(
583+
mockedMethod.sendTransactionAsync(
584+
mockedParams.boundType,
585+
mockedParams.newVersion,
586+
mockedParams.txData,
587+
mockedParams.safetyFactor,
588+
),
522589
).once();
523590
verify(mockedWrapper.getAvailableAddressesAsync()).once();
591+
verify(mockedContract.getLowerSTVersionBounds).once();
592+
verify(mockedLowerSTVersionBoundsMethod.callAsync()).once();
524593
});
525594
});
526595

@@ -569,7 +638,7 @@ describe('ModuleFactoryWrapper', () => {
569638
describe('getLowerSTVersionBounds', () => {
570639
test('should get LowerSTVersionBounds', async () => {
571640
// Address expected
572-
const expectedResult = [new BigNumber(1), new BigNumber(2)];
641+
const expectedResult = [new BigNumber(1), new BigNumber(2), new BigNumber(3)];
573642
// Mocked method
574643
const mockedMethod = mock(MockedCallMethod);
575644
// Stub the method

src/contract_wrappers/modules/module_factory_wrapper.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ interface ChangeTagsParams extends TxParams {
102102
tags: string[];
103103
}
104104

105+
interface ChangeSTVersionBoundsParams extends TxParams {
106+
boundType: BoundType;
107+
newVersion: number[];
108+
}
109+
105110
/**
106111
* This class includes the functionality related to interacting with the ModuleFactory contract.
107112
*/
@@ -252,6 +257,32 @@ export default class ModuleFactoryWrapper extends ContractWrapper {
252257
);
253258
};
254259

260+
/**
261+
* Change the ST VersionBounds
262+
*/
263+
public changeSTVersionBounds = async (params: ChangeSTVersionBoundsParams) => {
264+
await this.checkOnlyOwner(params.txData);
265+
assert.assert(
266+
params.boundType === BoundType.LowerBound || params.boundType === BoundType.UpperBound,
267+
'Invalid bound type',
268+
);
269+
assert.assert(params.newVersion.length === 3, 'Invalid version, number array must have 3 elements');
270+
const currentBound = BoundType.LowerBound === params.boundType ? await this.getLowerSTVersionBounds() : await this.getUpperSTVersionBounds();
271+
for (let i = 0; i < 3; i += 1) {
272+
if (params.boundType === BoundType.LowerBound) {
273+
assert.assert(currentBound[i].isLessThanOrEqualTo(params.newVersion[i]), 'New Lower ST Bounds must be less than or equal to current');
274+
} else {
275+
assert.assert(currentBound[i].isGreaterThanOrEqualTo(params.newVersion[i]), 'New Upper ST Bounds must be greater than or equal to current');
276+
}
277+
}
278+
return (await this.contract).changeSTVersionBounds.sendTransactionAsync(
279+
params.boundType,
280+
params.newVersion,
281+
params.txData,
282+
params.safetyFactor,
283+
);
284+
};
285+
255286
/**
256287
* Get setup cost
257288
*/

src/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ export enum Partition {
132132
Undefined = 'UNDEFINED',
133133
}
134134

135+
export enum BoundType {
136+
LowerBound = 'lowerBound',
137+
UpperBound = 'upperBound',
138+
}
139+
135140
export enum PolymathContract {
136141
PolyToken = 'PolyToken',
137142
ModuleRegistry = 'ModuleRegistry',

0 commit comments

Comments
 (0)