@@ -127,6 +127,7 @@ describe('CreateDividendDistribution', () => {
127127 tokenAddress : params . erc20Address ,
128128 } ) ;
129129 expect ( approveErc20ArgsSpy . callCount ) . toBe ( 1 ) ;
130+
130131 expect ( createDividendWithCheckpointAndExclusionsArgsStub . getCall ( 0 ) . args [ 0 ] ) . toEqual ( {
131132 maturity : params . maturityDate ,
132133 expiry : params . expiryDate ,
@@ -149,27 +150,35 @@ describe('CreateDividendDistribution', () => {
149150 expect ( addTransactionStub . getCall ( 0 ) . lastArg . tag ) . toEqual (
150151 PolyTransactionTag . CreateErc20DividendDistribution
151152 ) ;
152- expect ( addTransactionStub . callCount ) . toEqual ( 1 ) ;
153153
154+ expect ( addTransactionStub . callCount ) . toEqual ( 1 ) ;
154155 expect ( addProcedureStub . callCount ) . toEqual ( 1 ) ;
155156 } ) ;
156157
157158 test ( 'should send add a transaction to the queue to create arc20 dividend distribution with taxWitholding data' , async ( ) => {
159+ const taxWithholdingAddress = '0x5555555555555555555555555555555555555555' ;
160+ const taxWithholdingPercentage = 50 ;
158161 target = new CreateDividendDistribution (
159162 {
160163 ...params ,
161164 taxWithholdings : [
162165 {
163- address : '0x5555555555555555555555555555555555555555' ,
164- percentage : 50 ,
166+ address : taxWithholdingAddress ,
167+ percentage : taxWithholdingPercentage ,
165168 } ,
166169 ] ,
167170 } ,
168171 contextMock . getMockInstance ( )
169172 ) ;
170- const addProcedureSpy = spy ( target , 'addProcedure' ) ;
171- const createDividendWithCheckpointAndExclusionsArgsSpy = sinon . spy ( ) ;
172- const setWithholdingArgsSpy = sinon . spy ( ) ;
173+ const approveErc20ArgsSpy = sinon . spy ( ) ;
174+ const addProcedureStub = stub ( target , 'addProcedure' ) ;
175+ addProcedureStub . withArgs ( ApproveErc20 ) . returns ( approveErc20ArgsSpy ) ;
176+
177+ const createDividendWithCheckpointAndExclusionsArgsStub = sinon . stub ( ) ;
178+ createDividendWithCheckpointAndExclusionsArgsStub . returns ( [ { } ] ) ;
179+ const setWithholdingArgsStub = sinon . stub ( ) ;
180+ setWithholdingArgsStub . returns ( [ { } ] ) ;
181+
173182 const addTransactionStub = stub ( target , 'addTransaction' ) ;
174183 erc20DividendsMock . mock (
175184 'createDividendWithCheckpointAndExclusions' ,
@@ -181,16 +190,22 @@ describe('CreateDividendDistribution', () => {
181190 const { setWithholding } = erc20DividendsMock . getMockInstance ( ) ;
182191 addTransactionStub
183192 . withArgs ( createDividendWithCheckpointAndExclusions )
184- . returns ( createDividendWithCheckpointAndExclusionsArgsSpy ) ;
185- addTransactionStub . withArgs ( setWithholding ) . returns ( setWithholdingArgsSpy ) ;
193+ . returns ( createDividendWithCheckpointAndExclusionsArgsStub ) ;
194+ addTransactionStub . withArgs ( setWithholding ) . returns ( setWithholdingArgsStub ) ;
186195
187196 // Real call
188197 await target . prepareTransactions ( ) ;
189198
190199 // Verifications
191- expect ( addProcedureSpy . getCall ( 0 ) . calledWithExactly ( ApproveErc20 ) ) . toEqual ( true ) ;
200+ expect ( addProcedureStub . getCall ( 0 ) . calledWithExactly ( ApproveErc20 ) ) . toEqual ( true ) ;
201+ expect ( approveErc20ArgsSpy . getCall ( 0 ) . args [ 0 ] ) . toEqual ( {
202+ amount : params . amount ,
203+ spender : dividendsModuleAddress ,
204+ tokenAddress : params . erc20Address ,
205+ } ) ;
206+ expect ( approveErc20ArgsSpy . callCount ) . toBe ( 1 ) ;
192207
193- expect ( createDividendWithCheckpointAndExclusionsArgsSpy . getCall ( 0 ) . args [ 0 ] ) . toEqual ( {
208+ expect ( createDividendWithCheckpointAndExclusionsArgsStub . getCall ( 0 ) . args [ 0 ] ) . toEqual ( {
194209 maturity : params . maturityDate ,
195210 expiry : params . expiryDate ,
196211 token : params . erc20Address ,
@@ -199,7 +214,7 @@ describe('CreateDividendDistribution', () => {
199214 name : params . name ,
200215 excluded : [ ] ,
201216 } ) ;
202- expect ( createDividendWithCheckpointAndExclusionsArgsSpy . callCount ) . toEqual ( 1 ) ;
217+ expect ( createDividendWithCheckpointAndExclusionsArgsStub . callCount ) . toEqual ( 1 ) ;
203218 expect (
204219 addTransactionStub
205220 . getCall ( 0 )
@@ -210,12 +225,12 @@ describe('CreateDividendDistribution', () => {
210225 expect ( addTransactionStub . getCall ( 0 ) . lastArg . tag ) . toEqual (
211226 PolyTransactionTag . CreateErc20DividendDistribution
212227 ) ;
228+ expect ( setWithholdingArgsStub . getCall ( 0 ) . args [ 0 ] . investors ) . toEqual ( [ taxWithholdingAddress ] ) ;
229+ expect ( setWithholdingArgsStub . getCall ( 0 ) . args [ 0 ] . withholding [ 0 ] . toNumber ( ) ) . toEqual (
230+ taxWithholdingPercentage
231+ ) ;
213232
214- expect ( setWithholdingArgsSpy . getCall ( 0 ) . args [ 0 ] ) . toEqual ( {
215- investors : [ '0x5555555555555555555555555555555555555555' ] ,
216- withholding : [ 50 ] ,
217- } ) ;
218- expect ( setWithholdingArgsSpy . callCount ) . toEqual ( 1 ) ;
233+ expect ( setWithholdingArgsStub . callCount ) . toEqual ( 1 ) ;
219234 expect (
220235 addTransactionStub
221236 . getCall ( 1 )
@@ -224,8 +239,9 @@ describe('CreateDividendDistribution', () => {
224239 expect ( addTransactionStub . getCall ( 1 ) . lastArg . tag ) . toEqual (
225240 PolyTransactionTag . SetErc20TaxWithholding
226241 ) ;
242+
227243 expect ( addTransactionStub . callCount ) . toEqual ( 2 ) ;
228- expect ( addProcedureSpy . callCount ) . toEqual ( 1 ) ;
244+ expect ( addProcedureStub . callCount ) . toEqual ( 1 ) ;
229245 } ) ;
230246
231247 test ( 'should throw if there is no valid security token supplied' , async ( ) => {
0 commit comments