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

Commit

Permalink
refactor: 💡 remove pause(d) unpause from the wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Wiebe committed Sep 23, 2019
1 parent 319371c commit 5eacf6d
Show file tree
Hide file tree
Showing 19 changed files with 2 additions and 1,607 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,27 +69,6 @@ describe('DividendCheckpointWrapper', () => {
});
});

describe('Paused', () => {
test('should get isPaused', async () => {
// Address expected
const expectedResult = true;
// Mocked method
const mockedMethod = mock(MockedCallMethod);
// Stub the method
when(mockedContract.paused).thenReturn(instance(mockedMethod));
// Stub the request
when(mockedMethod.callAsync()).thenResolve(expectedResult);

// Real call
const result = await target.paused();
// Result expectation
expect(result).toBe(expectedResult);
// Verifications
verify(mockedContract.paused).once();
verify(mockedMethod.callAsync()).once();
});
});

describe('Wallet', () => {
test('should get the wallet address', async () => {
// Address expected
Expand Down Expand Up @@ -132,132 +111,6 @@ describe('DividendCheckpointWrapper', () => {
});
});

describe('Pause/Unpause', () => {
test('should call to pause', async () => {
// Pause Result expected
const expectedPauseResult = false;
// Mocked method
const mockedPauseMethod = mock(MockedCallMethod);
// Stub the method
when(mockedContract.paused).thenReturn(instance(mockedPauseMethod));
// Stub the request
when(mockedPauseMethod.callAsync()).thenResolve(expectedPauseResult);

// Owner Address expected
const expectedOwnerResult = '0x5555555555555555555555555555555555555555';
// Security Token Address expected
const expectedSecurityTokenAddress = '0x3333333333333333333333333333333333333333';

// Setup get Security Token Address
const mockedGetSecurityTokenAddressMethod = mock(MockedCallMethod);
when(mockedContract.securityToken).thenReturn(instance(mockedGetSecurityTokenAddressMethod));
when(mockedGetSecurityTokenAddressMethod.callAsync()).thenResolve(expectedSecurityTokenAddress);

when(mockedContractFactory.getSecurityTokenContract(expectedSecurityTokenAddress)).thenResolve(
instance(mockedSecurityTokenContract),
);
const mockedSecurityTokenOwnerMethod = mock(MockedCallMethod);
when(mockedSecurityTokenOwnerMethod.callAsync()).thenResolve(expectedOwnerResult);
when(mockedSecurityTokenContract.owner).thenReturn(instance(mockedSecurityTokenOwnerMethod));

// Mock web3 wrapper owner
when(mockedWrapper.getAvailableAddressesAsync()).thenResolve([expectedOwnerResult]);

const mockedParams = {
txData: {},
safetyFactor: 10,
};
const expectedResult = getMockedPolyResponse();
// Mocked method
const mockedMethod = mock(MockedSendMethod);
// Stub the method
when(mockedContract.pause).thenReturn(instance(mockedMethod));
// Stub the request
when(mockedMethod.sendTransactionAsync(mockedParams.txData, mockedParams.safetyFactor)).thenResolve(
expectedResult,
);

// Real call
const result = await target.pause(mockedParams);

// Result expectation
expect(result).toBe(expectedResult);
// Verifications
verify(mockedContract.pause).once();
verify(mockedMethod.sendTransactionAsync(mockedParams.txData, mockedParams.safetyFactor)).once();
verify(mockedContract.paused).once();
verify(mockedPauseMethod.callAsync()).once();
verify(mockedSecurityTokenOwnerMethod.callAsync()).once();
verify(mockedSecurityTokenContract.owner).once();
verify(mockedContract.securityToken).once();
verify(mockedGetSecurityTokenAddressMethod.callAsync()).once();
verify(mockedContractFactory.getSecurityTokenContract(expectedSecurityTokenAddress)).once();
verify(mockedWrapper.getAvailableAddressesAsync()).once();
});

test('should call to unpause', async () => {
// Pause Result expected
const expectedPauseResult = true;
// Mocked method
const mockedPauseMethod = mock(MockedCallMethod);
// Stub the method
when(mockedContract.paused).thenReturn(instance(mockedPauseMethod));
// Stub the request
when(mockedPauseMethod.callAsync()).thenResolve(expectedPauseResult);

// Owner Address expected
const expectedOwnerResult = '0x5555555555555555555555555555555555555555';
// Security Token Address expected
const expectedSecurityTokenAddress = '0x3333333333333333333333333333333333333333';

// Setup get Security Token Address
const mockedGetSecurityTokenAddressMethod = mock(MockedCallMethod);
when(mockedContract.securityToken).thenReturn(instance(mockedGetSecurityTokenAddressMethod));
when(mockedGetSecurityTokenAddressMethod.callAsync()).thenResolve(expectedSecurityTokenAddress);

when(mockedContractFactory.getSecurityTokenContract(expectedSecurityTokenAddress)).thenResolve(
instance(mockedSecurityTokenContract),
);
const mockedSecurityTokenOwnerMethod = mock(MockedCallMethod);
when(mockedSecurityTokenOwnerMethod.callAsync()).thenResolve(expectedOwnerResult);
when(mockedSecurityTokenContract.owner).thenReturn(instance(mockedSecurityTokenOwnerMethod));

// Mock web3 wrapper owner
when(mockedWrapper.getAvailableAddressesAsync()).thenResolve([expectedOwnerResult]);

const mockedParams = {
txData: {},
safetyFactor: 10,
};
const expectedResult = getMockedPolyResponse();
// Mocked method
const mockedMethod = mock(MockedSendMethod);
// Stub the method
when(mockedContract.unpause).thenReturn(instance(mockedMethod));
// Stub the request
when(mockedMethod.sendTransactionAsync(mockedParams.txData, mockedParams.safetyFactor)).thenResolve(
expectedResult,
);

// Real call
const result = await target.unpause(mockedParams);

// Result expectation
expect(result).toBe(expectedResult);
// Verifications
verify(mockedContract.unpause).once();
verify(mockedMethod.sendTransactionAsync(mockedParams.txData, mockedParams.safetyFactor)).once();
verify(mockedPauseMethod.callAsync()).once();
verify(mockedContract.paused).once();
verify(mockedSecurityTokenOwnerMethod.callAsync()).once();
verify(mockedSecurityTokenContract.owner).once();
verify(mockedContract.securityToken).once();
verify(mockedGetSecurityTokenAddressMethod.callAsync()).once();
verify(mockedContractFactory.getSecurityTokenContract(expectedSecurityTokenAddress)).once();
verify(mockedWrapper.getAvailableAddressesAsync()).once();
});
});

describe('Dividends', () => {
test('should get dividend info', async () => {
// Get Decimals
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,6 @@ export default abstract class DividendCheckpointCommon extends ModuleWrapper {
return (await this.contract).getTreasuryWallet.callAsync();
};

/**
* check if the module is paused
*/
public paused = async (): Promise<boolean> => {
return (await this.contract).paused.callAsync();
};

/**
* check dividend information at a specific dividend index
* @return checkpointId, created, maturity, expiry, token amount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,6 @@ export default class CappedSTOCommon extends STOCommon {
return (await this.contract).allowBeneficialInvestments.callAsync();
};

/**
* check if the module is paused
* @return boolean if paused
*/
public paused = async (): Promise<boolean> => {
return (await this.contract).paused.callAsync();
};

/**
* Access mapping of Capped STO investors
* @return amount of investor investment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,153 +67,6 @@ describe('BlacklistTransferManagerWrapper', () => {
});
});

describe('paused', () => {
test('should get Paused', async () => {
// Address expected
const expectedResult = true;
// Mocked method
const mockedMethod = mock(MockedCallMethod);
// Stub the method
when(mockedContract.paused).thenReturn(instance(mockedMethod));
// Stub the request
when(mockedMethod.callAsync()).thenResolve(expectedResult);

// Real call
const result = await target.paused();
// Result expectation
expect(result).toBe(expectedResult);
// Verifications
verify(mockedContract.paused).once();
verify(mockedMethod.callAsync()).once();
});
});

describe('pause/unpause', () => {
test('should call to pause', async () => {
// Pause Result expected
const expectedPauseResult = false;
// Mocked method
const mockedPauseMethod = mock(MockedCallMethod);
// Stub the method
when(mockedContract.paused).thenReturn(instance(mockedPauseMethod));
// Stub the request
when(mockedPauseMethod.callAsync()).thenResolve(expectedPauseResult);

// Owner Address expected
const expectedOwnerResult = '0x5555555555555555555555555555555555555555';
// Security Token Address expected
const expectedSecurityTokenAddress = '0x3333333333333333333333333333333333333333';

// Setup get Security Token Address
const mockedGetSecurityTokenAddressMethod = mock(MockedCallMethod);
when(mockedContract.securityToken).thenReturn(instance(mockedGetSecurityTokenAddressMethod));
when(mockedGetSecurityTokenAddressMethod.callAsync()).thenResolve(expectedSecurityTokenAddress);

when(mockedContractFactory.getSecurityTokenContract(expectedSecurityTokenAddress)).thenResolve(
instance(mockedSecurityTokenContract),
);
const mockedSecurityTokenOwnerMethod = mock(MockedCallMethod);
when(mockedSecurityTokenOwnerMethod.callAsync()).thenResolve(expectedOwnerResult);
when(mockedSecurityTokenContract.owner).thenReturn(instance(mockedSecurityTokenOwnerMethod));

// Mock web3 wrapper owner
when(mockedWrapper.getAvailableAddressesAsync()).thenResolve([expectedOwnerResult]);

const mockedParams = {
txData: {},
safetyFactor: 10,
};
const expectedResult = getMockedPolyResponse();
// Mocked method
const mockedMethod = mock(MockedSendMethod);
// Stub the method
when(mockedContract.pause).thenReturn(instance(mockedMethod));
// Stub the request
when(mockedMethod.sendTransactionAsync(mockedParams.txData, mockedParams.safetyFactor)).thenResolve(
expectedResult,
);

// Real call
const result = await target.pause(mockedParams);

// Result expectation
expect(result).toBe(expectedResult);
// Verifications
verify(mockedContract.pause).once();
verify(mockedMethod.sendTransactionAsync(mockedParams.txData, mockedParams.safetyFactor)).once();
verify(mockedContract.paused).once();
verify(mockedPauseMethod.callAsync()).once();
verify(mockedContract.securityToken).once();
verify(mockedGetSecurityTokenAddressMethod.callAsync()).once();
verify(mockedSecurityTokenOwnerMethod.callAsync()).once();
verify(mockedSecurityTokenContract.owner).once();
verify(mockedWrapper.getAvailableAddressesAsync()).once();
verify(mockedContractFactory.getSecurityTokenContract(expectedSecurityTokenAddress)).once();
});

test('should call to unpause', async () => {
// Pause Result expected
const expectedPauseResult = true;
// Mocked method
const mockedPauseMethod = mock(MockedCallMethod);
// Stub the method
when(mockedContract.paused).thenReturn(instance(mockedPauseMethod));
// Stub the request
when(mockedPauseMethod.callAsync()).thenResolve(expectedPauseResult);

// Owner Address expected
const expectedOwnerResult = '0x5555555555555555555555555555555555555555';
// Security Token Address expected
const expectedSecurityTokenAddress = '0x3333333333333333333333333333333333333333';

// Setup get Security Token Address
const mockedGetSecurityTokenAddressMethod = mock(MockedCallMethod);
when(mockedContract.securityToken).thenReturn(instance(mockedGetSecurityTokenAddressMethod));
when(mockedGetSecurityTokenAddressMethod.callAsync()).thenResolve(expectedSecurityTokenAddress);

when(mockedContractFactory.getSecurityTokenContract(expectedSecurityTokenAddress)).thenResolve(
instance(mockedSecurityTokenContract),
);
const mockedSecurityTokenOwnerMethod = mock(MockedCallMethod);
when(mockedSecurityTokenOwnerMethod.callAsync()).thenResolve(expectedOwnerResult);
when(mockedSecurityTokenContract.owner).thenReturn(instance(mockedSecurityTokenOwnerMethod));

// Mock web3 wrapper owner
when(mockedWrapper.getAvailableAddressesAsync()).thenResolve([expectedOwnerResult]);

const mockedParams = {
txData: {},
safetyFactor: 10,
};
const expectedResult = getMockedPolyResponse();
// Mocked method
const mockedMethod = mock(MockedSendMethod);
// Stub the method
when(mockedContract.unpause).thenReturn(instance(mockedMethod));
// Stub the request
when(mockedMethod.sendTransactionAsync(mockedParams.txData, mockedParams.safetyFactor)).thenResolve(
expectedResult,
);

// Real call
const result = await target.unpause(mockedParams);

// Result expectation
expect(result).toBe(expectedResult);
// Verifications
verify(mockedContract.unpause).once();
verify(mockedMethod.sendTransactionAsync(mockedParams.txData, mockedParams.safetyFactor)).once();
verify(mockedContract.paused).once();
verify(mockedPauseMethod.callAsync()).once();
verify(mockedContract.securityToken).once();
verify(mockedGetSecurityTokenAddressMethod.callAsync()).once();
verify(mockedSecurityTokenOwnerMethod.callAsync()).once();
verify(mockedSecurityTokenContract.owner).once();
verify(mockedContractFactory.getSecurityTokenContract(expectedSecurityTokenAddress)).once();
verify(mockedWrapper.getAvailableAddressesAsync()).once();
});
});

describe('verifyTransfer', () => {
test('should verify Transfer', async () => {
const statusCode = new BigNumber(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,39 +326,6 @@ export default class BlacklistTransferManagerCommon extends ModuleWrapper {
this.contract = contract;
}

/**
* Unpause the module
*/
public unpause = async (params: TxParams): Promise<PolyResponse> => {
assert.assert(await this.paused(), ErrorCode.PreconditionRequired, 'Controller not currently paused');
assert.assert(
await this.isCallerTheSecurityTokenOwner(params.txData),
ErrorCode.Unauthorized,
'Sender is not owner',
);
return (await this.contract).unpause.sendTransactionAsync(params.txData, params.safetyFactor);
};

/**
* Check if the module is paused
*/
public paused = async (): Promise<boolean> => {
return (await this.contract).paused.callAsync();
};

/**
* Pause the module
*/
public pause = async (params: TxParams): Promise<PolyResponse> => {
assert.assert(!(await this.paused()), ErrorCode.ContractPaused, 'Controller currently paused');
assert.assert(
await this.isCallerTheSecurityTokenOwner(params.txData),
ErrorCode.Unauthorized,
'Sender is not owner',
);
return (await this.contract).pause.sendTransactionAsync(params.txData, params.safetyFactor);
};

/**
* Return the different blacklist details corresponding to a blacklists name
*/
Expand Down
Loading

0 comments on commit 5eacf6d

Please sign in to comment.