Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'beta' into test/reclaim-funds-procedure
- Loading branch information
Showing
6 changed files
with
111 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { ImportMock, MockManager } from 'ts-mock-imports'; | ||
import { spy, restore } from 'sinon'; | ||
import { BigNumber } from '@polymathnetwork/contract-wrappers'; | ||
import * as contractWrappersModule from '@polymathnetwork/contract-wrappers'; | ||
import * as contextModule from '../../Context'; | ||
import * as wrappersModule from '../../PolymathBase'; | ||
import * as tokenFactoryModule from '../../testUtils/MockedTokenFactoryModule'; | ||
import { EnableGeneralTransferManager } from '../../procedures/EnableGeneralTransferManager'; | ||
import { Procedure } from '../Procedure'; | ||
import { PolymathError } from '../../PolymathError'; | ||
import { ErrorCode, PolyTransactionTag, ProcedureType } from '../../types'; | ||
|
||
const params = { | ||
symbol: 'TEST1', | ||
address: '0x4444444444444444444444444444444444444444', | ||
}; | ||
const securityTokenAddress = '0x2222222222222222222222222222222222222222'; | ||
const moduleFactoryAddress = '0x3333333333333333333333333333333333333333'; | ||
|
||
describe('EnableGeneralTransferManager', () => { | ||
let target: EnableGeneralTransferManager; | ||
let contextMock: MockManager<contextModule.Context>; | ||
let wrappersMock: MockManager<wrappersModule.PolymathBase>; | ||
let tokenFactoryMock: MockManager<tokenFactoryModule.MockedTokenFactoryModule>; | ||
let etherDividendsMock: MockManager<contractWrappersModule.EtherDividendCheckpoint_3_0_0>; | ||
let securityTokenMock: MockManager<contractWrappersModule.SecurityToken_3_0_0>; | ||
|
||
beforeAll(() => { | ||
// Mock the context, wrappers, and tokenFactory to test EnableGeneralTransferManagers | ||
contextMock = ImportMock.mockClass(contextModule, 'Context'); | ||
wrappersMock = ImportMock.mockClass(wrappersModule, 'PolymathBase'); | ||
tokenFactoryMock = ImportMock.mockClass(tokenFactoryModule, 'MockedTokenFactoryModule'); | ||
contextMock.set('contractWrappers', wrappersMock.getMockInstance()); | ||
wrappersMock.set('tokenFactory', tokenFactoryMock.getMockInstance()); | ||
|
||
securityTokenMock = ImportMock.mockClass(contractWrappersModule, 'SecurityToken_3_0_0'); | ||
securityTokenMock.mock('address', Promise.resolve(securityTokenAddress)); | ||
|
||
etherDividendsMock = ImportMock.mockClass( | ||
contractWrappersModule, | ||
'EtherDividendCheckpoint_3_0_0' | ||
); | ||
wrappersMock.mock('getModuleFactoryAddress', Promise.resolve(moduleFactoryAddress)); | ||
tokenFactoryMock.mock( | ||
'getSecurityTokenInstanceFromTicker', | ||
securityTokenMock.getMockInstance() | ||
); | ||
|
||
// Instantiate EnableGeneralTransferManagers | ||
target = new EnableGeneralTransferManager(params, contextMock.getMockInstance()); | ||
}); | ||
afterEach(() => { | ||
restore(); | ||
}); | ||
|
||
describe('Types', () => { | ||
test('should extend procedure and have EnableGeneralTransferManager type', async () => { | ||
expect(target instanceof Procedure).toBe(true); | ||
expect(target.type).toBe(ProcedureType.EnableGeneralTransferManager); | ||
}); | ||
}); | ||
|
||
describe('EnableGeneralTransferManager', () => { | ||
test('should add a transaction to the queue to enable general transfer manager', async () => { | ||
const addTransactionSpy = spy(target, 'addTransaction'); | ||
securityTokenMock.mock('addModuleWithLabel', Promise.resolve('AddModuleWithLabel')); | ||
|
||
// Real call | ||
await target.prepareTransactions(); | ||
|
||
// Verifications | ||
expect( | ||
addTransactionSpy | ||
.getCall(0) | ||
.calledWithExactly(securityTokenMock.getMockInstance().addModuleWithLabel, { | ||
tag: PolyTransactionTag.EnableGeneralTransferManager, | ||
}) | ||
).toEqual(true); | ||
expect(addTransactionSpy.callCount).toEqual(1); | ||
}); | ||
|
||
test('should throw if there is no valid security token supplied', async () => { | ||
tokenFactoryMock | ||
.mock('getSecurityTokenInstanceFromTicker') | ||
.withArgs(params.symbol) | ||
.throws(); | ||
|
||
await expect(target.prepareTransactions()).rejects.toThrow( | ||
new PolymathError({ | ||
code: ErrorCode.ProcedureValidationError, | ||
message: `There is no Security Token with symbol ${params.symbol}`, | ||
}) | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters