11/* eslint-disable import/no-duplicates */
22import { ImportMock , MockManager } from 'ts-mock-imports' ;
3- import { spy , restore } from 'sinon' ;
3+ import { restore , stub } from 'sinon' ;
44import { BigNumber , TransferStatusCode } from '@polymathnetwork/contract-wrappers' ;
55import * as contractWrappersModule from '@polymathnetwork/contract-wrappers' ;
6+ import sinon from 'sinon' ;
67import { TransferSecurityTokens } from '../../procedures/TransferSecurityTokens' ;
78import { Procedure } from '../../procedures/Procedure' ;
89import * as transferSecurityTokensModule from '../../procedures/TransferSecurityTokens' ;
@@ -90,10 +91,8 @@ describe('TransferSecurityTokens', () => {
9091 } ) ;
9192
9293 test ( 'should add a transaction to the queue to execute a transfer security token using a different sender address' , async ( ) => {
93- target = new TransferSecurityTokens (
94- { ...params , from : '0x1FB52cef867d95E69d398Fe9F6486fAF92C7ED7F' } ,
95- contextMock . getMockInstance ( )
96- ) ;
94+ const from = '0x1FB52cef867d95E69d398Fe9F6486fAF92C7ED7F' ;
95+ target = new TransferSecurityTokens ( { ...params , from } , contextMock . getMockInstance ( ) ) ;
9796 contextMock . set (
9897 'currentWallet' ,
9998 new Wallet ( { address : ( ) => Promise . resolve ( '0x0e6b236a504fce78527497e46dc90c0a6fdc9495' ) } )
@@ -106,20 +105,31 @@ describe('TransferSecurityTokens', () => {
106105 } )
107106 ) ;
108107
109- const addTransactionSpy = spy ( target , 'addTransaction' ) ;
108+ const transferFromWithDataArgsSpy = sinon . spy ( ) ;
109+ const addTransactionStub = stub ( target , 'addTransaction' ) ;
110110 securityTokenMock . mock ( 'transferFromWithData' , Promise . resolve ( 'TransferFromWithData' ) ) ;
111+ const { transferFromWithData } = securityTokenMock . getMockInstance ( ) ;
112+ addTransactionStub . withArgs ( transferFromWithData ) . returns ( transferFromWithDataArgsSpy ) ;
111113
112114 await target . prepareTransactions ( ) ;
113115
116+ expect ( transferFromWithDataArgsSpy . getCall ( 0 ) . args [ 0 ] ) . toEqual ( {
117+ from,
118+ to : params . to ,
119+ value : params . amount ,
120+ data : '' ,
121+ } ) ;
122+ expect ( transferFromWithDataArgsSpy . callCount ) . toEqual ( 1 ) ;
123+
114124 expect (
115- addTransactionSpy
125+ addTransactionStub
116126 . getCall ( 0 )
117127 . calledWith ( securityTokenMock . getMockInstance ( ) . transferFromWithData )
118128 ) . toEqual ( true ) ;
119- expect ( addTransactionSpy . getCall ( 0 ) . lastArg . tag ) . toEqual (
129+ expect ( addTransactionStub . getCall ( 0 ) . lastArg . tag ) . toEqual (
120130 PolyTransactionTag . TransferSecurityTokens
121131 ) ;
122- expect ( addTransactionSpy . callCount ) . toEqual ( 1 ) ;
132+ expect ( addTransactionStub . callCount ) . toEqual ( 1 ) ;
123133 } ) ;
124134
125135 test ( 'should throw error if canTransferFrom method returns status code different than success' , async ( ) => {
0 commit comments