|
1 | 1 | // ModuleFactoryWrapper test
|
2 |
| -import { mock, instance, reset, when, verify } from 'ts-mockito'; |
| 2 | +import {mock, instance, reset, when, verify, objectContaining} from 'ts-mockito'; |
3 | 3 | import {
|
4 | 4 | ModuleFactoryContract,
|
5 | 5 | BigNumber,
|
6 | 6 | Web3Wrapper,
|
7 | 7 | EtherDividendCheckpointEvents,
|
8 | 8 | } from '@polymathnetwork/abi-wrappers';
|
9 |
| -import { MockedCallMethod, MockedSendMethod } from '../../../test_utils/mocked_methods'; |
| 9 | +import {getMockedPolyResponse, MockedCallMethod, MockedSendMethod} from '../../../test_utils/mocked_methods'; |
10 | 10 | import ContractFactory from '../../../factories/contractFactory';
|
11 |
| -import { bytes32ToString, stringToBytes32, weiToValue } from '../../../utils/convert'; |
| 11 | +import { |
| 12 | + bytes32ToString, |
| 13 | + parseModuleTypeValue, |
| 14 | + stringArrayToBytes32Array, |
| 15 | + stringToBytes32, |
| 16 | + weiToValue |
| 17 | +} from '../../../utils/convert'; |
12 | 18 | import ModuleFactoryWrapper from '../module_factory_wrapper';
|
13 | 19 | import ContractWrapper from '../../contract_wrapper';
|
14 |
| -import { FULL_DECIMALS } from '../../../types'; |
| 20 | +import {FULL_DECIMALS, ModuleType} from '../../../types'; |
15 | 21 |
|
16 | 22 | describe('ModuleFactoryWrapper', () => {
|
17 | 23 | let target: ModuleFactoryWrapper;
|
@@ -40,6 +46,27 @@ describe('ModuleFactoryWrapper', () => {
|
40 | 46 | });
|
41 | 47 | });
|
42 | 48 |
|
| 49 | + describe('owner', () => { |
| 50 | + test('should call to owner', async () => { |
| 51 | + const expectedResult = '0x0123456789012345678901234567890123456789'; |
| 52 | + // Mocked method |
| 53 | + const mockedMethod = mock(MockedCallMethod); |
| 54 | + // Stub the method |
| 55 | + when(mockedContract.owner).thenReturn(instance(mockedMethod)); |
| 56 | + // Stub the request |
| 57 | + when(mockedMethod.callAsync()).thenResolve(expectedResult); |
| 58 | + |
| 59 | + // Real call |
| 60 | + const result = await target.owner(); |
| 61 | + // Result expectation |
| 62 | + expect(result).toBe(expectedResult); |
| 63 | + // Verifications |
| 64 | + verify(mockedContract.owner).once(); |
| 65 | + verify(mockedMethod.callAsync()).once(); |
| 66 | + }); |
| 67 | + }); |
| 68 | + |
| 69 | + |
43 | 70 | describe('Name', () => {
|
44 | 71 | test('should get name', async () => {
|
45 | 72 | // Address expected
|
@@ -145,6 +172,94 @@ describe('ModuleFactoryWrapper', () => {
|
145 | 172 | });
|
146 | 173 | });
|
147 | 174 |
|
| 175 | + describe('GetTypes', () => { |
| 176 | + test('should get types', async () => { |
| 177 | + // Address expected |
| 178 | + const expectedResult = [new BigNumber(ModuleType.STO), new BigNumber(ModuleType.Dividends)]; |
| 179 | + // Mocked method |
| 180 | + const mockedMethod = mock(MockedCallMethod); |
| 181 | + // Stub the method |
| 182 | + when(mockedContract.getTypes).thenReturn(instance(mockedMethod)); |
| 183 | + // Stub the request |
| 184 | + when(mockedMethod.callAsync()).thenResolve(expectedResult); |
| 185 | + |
| 186 | + // Real call |
| 187 | + const result = await target.getTypes(); |
| 188 | + // Result expectation |
| 189 | + expect(result).toEqual(expectedResult.map(parseModuleTypeValue)); |
| 190 | + // Verifications |
| 191 | + verify(mockedContract.getTypes).once(); |
| 192 | + verify(mockedMethod.callAsync()).once(); |
| 193 | + }); |
| 194 | + }); |
| 195 | + |
| 196 | + describe('getTags', () => { |
| 197 | + test('should get tags', async () => { |
| 198 | + // Address expected |
| 199 | + const expectedResult = stringArrayToBytes32Array(['Tag1', 'Tag2']); |
| 200 | + // Mocked method |
| 201 | + const mockedMethod = mock(MockedCallMethod); |
| 202 | + // Stub the method |
| 203 | + when(mockedContract.getTags).thenReturn(instance(mockedMethod)); |
| 204 | + // Stub the request |
| 205 | + when(mockedMethod.callAsync()).thenResolve(expectedResult); |
| 206 | + |
| 207 | + // Real call |
| 208 | + const result = await target.getTags(); |
| 209 | + // Result expectation |
| 210 | + expect(stringArrayToBytes32Array(result)).toEqual(expectedResult); |
| 211 | + // Verifications |
| 212 | + verify(mockedContract.getTags).once(); |
| 213 | + verify(mockedMethod.callAsync()).once(); |
| 214 | + }); |
| 215 | + }); |
| 216 | + |
| 217 | + describe('changeSetupCost', () => { |
| 218 | + test.todo('should fail as changeSetupCost is 0'); |
| 219 | + test('should send the transaction to changeSetupCost', async () => { |
| 220 | + // Mocked parameters |
| 221 | + const mockedParams = { |
| 222 | + setupCost: new BigNumber(100), |
| 223 | + txData: {}, |
| 224 | + safetyFactor: 10, |
| 225 | + }; |
| 226 | + const expectedResult = getMockedPolyResponse(); |
| 227 | + // Mocked method |
| 228 | + const mockedMethod = mock(MockedSendMethod); |
| 229 | + // Stub the method |
| 230 | + when(mockedContract.changeSetupCost).thenReturn(instance(mockedMethod)); |
| 231 | + // Stub the request |
| 232 | + when( |
| 233 | + mockedMethod.sendTransactionAsync(objectContaining(mockedParams.setupCost), mockedParams.txData, mockedParams.safetyFactor), |
| 234 | + ).thenResolve(expectedResult); |
| 235 | + |
| 236 | + // Owner Address expected |
| 237 | + const expectedOwnerResult = '0x5555555555555555555555555555555555555555'; |
| 238 | + // Mocked method |
| 239 | + const mockedOwnerMethod = mock(MockedCallMethod); |
| 240 | + // Stub the method |
| 241 | + when(mockedContract.owner).thenReturn(instance(mockedOwnerMethod)); |
| 242 | + // Stub the request |
| 243 | + when(mockedOwnerMethod.callAsync()).thenResolve(expectedOwnerResult); |
| 244 | + // Mock web3 wrapper owner |
| 245 | + when(mockedWrapper.getAvailableAddressesAsync()).thenResolve([expectedOwnerResult]); |
| 246 | + |
| 247 | + // Real call |
| 248 | + const result = await target.changeSetupCost(mockedParams); |
| 249 | + |
| 250 | + // Result expectation |
| 251 | + expect(result).toBe(expectedResult); |
| 252 | + // Verifications |
| 253 | + verify(mockedContract.owner).once(); |
| 254 | + verify(mockedOwnerMethod.callAsync()).once(); |
| 255 | + verify(mockedContract.changeSetupCost).once(); |
| 256 | + verify( |
| 257 | + mockedMethod.sendTransactionAsync(objectContaining(mockedParams.setupCost), mockedParams.txData, mockedParams.safetyFactor), |
| 258 | + ).once(); |
| 259 | + verify(mockedWrapper.getAvailableAddressesAsync()).once(); |
| 260 | + }); |
| 261 | + }); |
| 262 | + |
148 | 263 | describe('setupCost', () => {
|
149 | 264 | test('should get setupCost', async () => {
|
150 | 265 | // Address expected
|
|
0 commit comments