11import { ImportMock , MockManager } from 'ts-mock-imports' ;
2- import { spy , restore } from 'sinon' ;
2+ import sinon , { restore , stub } from 'sinon' ;
33import * as contractWrappersModule from '@polymathnetwork/contract-wrappers' ;
44import * as contextModule from '../../Context' ;
55import * as wrappersModule from '../../PolymathBase' ;
@@ -85,30 +85,41 @@ describe('ModifyPercentageExemptions', () => {
8585 { symbol : params . symbol , allowPrimaryIssuance : true } ,
8686 contextMock . getMockInstance ( )
8787 ) ;
88- const addTransactionSpy = spy ( target , 'addTransaction' ) ;
88+ const setAllowPrimaryIssuanceArgsSpy = sinon . spy ( ) ;
89+ const addTransactionStub = stub ( target , 'addTransaction' ) ;
8990
9091 percentageTransferMock . mock (
9192 'setAllowPrimaryIssuance' ,
9293 Promise . resolve ( 'SetAllowPrimaryIssuance' )
9394 ) ;
9495 percentageTransferMock . mock ( 'allowPrimaryIssuance' , Promise . resolve ( false ) ) ;
9596
97+ const { setAllowPrimaryIssuance } = percentageTransferMock . getMockInstance ( ) ;
98+ addTransactionStub . withArgs ( setAllowPrimaryIssuance ) . returns ( setAllowPrimaryIssuanceArgsSpy ) ;
99+
96100 // Real call
97101 await target . prepareTransactions ( ) ;
98102
99103 // Verifications
104+ expect ( setAllowPrimaryIssuanceArgsSpy . getCall ( 0 ) . args [ 0 ] ) . toEqual ( {
105+ allowPrimaryIssuance : params . allowPrimaryIssuance ,
106+ } ) ;
107+ expect ( setAllowPrimaryIssuanceArgsSpy . callCount ) . toEqual ( 1 ) ;
108+
100109 expect (
101- addTransactionSpy
110+ addTransactionStub
102111 . getCall ( 0 )
103112 . calledWithExactly ( percentageTransferMock . getMockInstance ( ) . setAllowPrimaryIssuance , {
104113 tag : PolyTransactionTag . SetAllowPrimaryIssuance ,
105114 } )
106115 ) . toEqual ( true ) ;
107- expect ( addTransactionSpy . callCount ) . toEqual ( 1 ) ;
116+ expect ( addTransactionStub . callCount ) . toEqual ( 1 ) ;
108117 } ) ;
109118
110119 test ( 'should add a transaction to the queue to modify percentage exemptions and make a change to allow primary issuance' , async ( ) => {
111- const addTransactionSpy = spy ( target , 'addTransaction' ) ;
120+ const setAllowPrimaryIssuanceArgsSpy = sinon . spy ( ) ;
121+ const modifyWhitelistMultiArgsSpy = sinon . spy ( ) ;
122+ const addTransactionStub = stub ( target , 'addTransaction' ) ;
112123
113124 percentageTransferMock . mock (
114125 'setAllowPrimaryIssuance' ,
@@ -117,26 +128,40 @@ describe('ModifyPercentageExemptions', () => {
117128 percentageTransferMock . mock ( 'modifyWhitelistMulti' , Promise . resolve ( 'ModifyWhitelistMulti' ) ) ;
118129 percentageTransferMock . mock ( 'allowPrimaryIssuance' , Promise . resolve ( false ) ) ;
119130
131+ const { modifyWhitelistMulti } = percentageTransferMock . getMockInstance ( ) ;
132+ addTransactionStub . withArgs ( modifyWhitelistMulti ) . returns ( modifyWhitelistMultiArgsSpy ) ;
133+ const { setAllowPrimaryIssuance } = percentageTransferMock . getMockInstance ( ) ;
134+ addTransactionStub . withArgs ( setAllowPrimaryIssuance ) . returns ( setAllowPrimaryIssuanceArgsSpy ) ;
135+
120136 // Real call
121137 await target . prepareTransactions ( ) ;
122138
123139 // Verifications
140+ expect ( modifyWhitelistMultiArgsSpy . getCall ( 0 ) . args [ 0 ] ) . toEqual ( {
141+ investors : [ params . whitelistEntries ! [ 0 ] . address , params . whitelistEntries ! [ 1 ] . address ] ,
142+ valids : [ params . whitelistEntries ! [ 0 ] . whitelisted , params . whitelistEntries ! [ 1 ] . whitelisted ] ,
143+ } ) ;
144+ expect ( modifyWhitelistMultiArgsSpy . callCount ) . toEqual ( 1 ) ;
124145 expect (
125- addTransactionSpy
146+ addTransactionStub
126147 . getCall ( 0 )
127148 . calledWithExactly ( percentageTransferMock . getMockInstance ( ) . modifyWhitelistMulti , {
128149 tag : PolyTransactionTag . ModifyWhitelistMulti ,
129150 } )
130151 ) . toEqual ( true ) ;
131152
153+ expect ( setAllowPrimaryIssuanceArgsSpy . getCall ( 0 ) . args [ 0 ] ) . toEqual ( {
154+ allowPrimaryIssuance : params . allowPrimaryIssuance ,
155+ } ) ;
156+ expect ( setAllowPrimaryIssuanceArgsSpy . callCount ) . toEqual ( 1 ) ;
132157 expect (
133- addTransactionSpy
158+ addTransactionStub
134159 . getCall ( 1 )
135160 . calledWithExactly ( percentageTransferMock . getMockInstance ( ) . setAllowPrimaryIssuance , {
136161 tag : PolyTransactionTag . SetAllowPrimaryIssuance ,
137162 } )
138163 ) . toEqual ( true ) ;
139- expect ( addTransactionSpy . callCount ) . toEqual ( 2 ) ;
164+ expect ( addTransactionStub . callCount ) . toEqual ( 2 ) ;
140165 } ) ;
141166
142167 test ( 'should add a transaction to the queue to only modify percentage exemptions' , async ( ) => {
@@ -146,21 +171,30 @@ describe('ModifyPercentageExemptions', () => {
146171 contextMock . getMockInstance ( )
147172 ) ;
148173
174+ const modifyWhitelistMultiArgsSpy = sinon . spy ( ) ;
175+ const addTransactionStub = stub ( target , 'addTransaction' ) ;
149176 percentageTransferMock . mock ( 'modifyWhitelistMulti' , Promise . resolve ( 'ModifyWhitelistMulti' ) ) ;
150- const addTransactionSpy = spy ( target , 'addTransaction' ) ;
177+ const { modifyWhitelistMulti } = percentageTransferMock . getMockInstance ( ) ;
178+ addTransactionStub . withArgs ( modifyWhitelistMulti ) . returns ( modifyWhitelistMultiArgsSpy ) ;
151179
152180 // Real call
153181 await target . prepareTransactions ( ) ;
154182
155183 // Verifications
184+ expect ( modifyWhitelistMultiArgsSpy . getCall ( 0 ) . args [ 0 ] ) . toEqual ( {
185+ investors : [ params . whitelistEntries ! [ 0 ] . address , params . whitelistEntries ! [ 1 ] . address ] ,
186+ valids : [ params . whitelistEntries ! [ 0 ] . whitelisted , params . whitelistEntries ! [ 1 ] . whitelisted ] ,
187+ } ) ;
188+ expect ( modifyWhitelistMultiArgsSpy . callCount ) . toEqual ( 1 ) ;
189+
156190 expect (
157- addTransactionSpy
191+ addTransactionStub
158192 . getCall ( 0 )
159193 . calledWithExactly ( percentageTransferMock . getMockInstance ( ) . modifyWhitelistMulti , {
160194 tag : PolyTransactionTag . ModifyWhitelistMulti ,
161195 } )
162196 ) . toEqual ( true ) ;
163- expect ( addTransactionSpy . callCount ) . toEqual ( 1 ) ;
197+ expect ( addTransactionStub . callCount ) . toEqual ( 1 ) ;
164198 } ) ;
165199
166200 test ( 'should throw if there is no valid security token supplied' , async ( ) => {
0 commit comments