@@ -127,6 +127,7 @@ describe('CreateDividendDistribution', () => {
127
127
tokenAddress : params . erc20Address ,
128
128
} ) ;
129
129
expect ( approveErc20ArgsSpy . callCount ) . toBe ( 1 ) ;
130
+
130
131
expect ( createDividendWithCheckpointAndExclusionsArgsStub . getCall ( 0 ) . args [ 0 ] ) . toEqual ( {
131
132
maturity : params . maturityDate ,
132
133
expiry : params . expiryDate ,
@@ -149,27 +150,35 @@ describe('CreateDividendDistribution', () => {
149
150
expect ( addTransactionStub . getCall ( 0 ) . lastArg . tag ) . toEqual (
150
151
PolyTransactionTag . CreateErc20DividendDistribution
151
152
) ;
152
- expect ( addTransactionStub . callCount ) . toEqual ( 1 ) ;
153
153
154
+ expect ( addTransactionStub . callCount ) . toEqual ( 1 ) ;
154
155
expect ( addProcedureStub . callCount ) . toEqual ( 1 ) ;
155
156
} ) ;
156
157
157
158
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 ;
158
161
target = new CreateDividendDistribution (
159
162
{
160
163
...params ,
161
164
taxWithholdings : [
162
165
{
163
- address : '0x5555555555555555555555555555555555555555' ,
164
- percentage : 50 ,
166
+ address : taxWithholdingAddress ,
167
+ percentage : taxWithholdingPercentage ,
165
168
} ,
166
169
] ,
167
170
} ,
168
171
contextMock . getMockInstance ( )
169
172
) ;
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
+
173
182
const addTransactionStub = stub ( target , 'addTransaction' ) ;
174
183
erc20DividendsMock . mock (
175
184
'createDividendWithCheckpointAndExclusions' ,
@@ -181,16 +190,22 @@ describe('CreateDividendDistribution', () => {
181
190
const { setWithholding } = erc20DividendsMock . getMockInstance ( ) ;
182
191
addTransactionStub
183
192
. withArgs ( createDividendWithCheckpointAndExclusions )
184
- . returns ( createDividendWithCheckpointAndExclusionsArgsSpy ) ;
185
- addTransactionStub . withArgs ( setWithholding ) . returns ( setWithholdingArgsSpy ) ;
193
+ . returns ( createDividendWithCheckpointAndExclusionsArgsStub ) ;
194
+ addTransactionStub . withArgs ( setWithholding ) . returns ( setWithholdingArgsStub ) ;
186
195
187
196
// Real call
188
197
await target . prepareTransactions ( ) ;
189
198
190
199
// 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 ) ;
192
207
193
- expect ( createDividendWithCheckpointAndExclusionsArgsSpy . getCall ( 0 ) . args [ 0 ] ) . toEqual ( {
208
+ expect ( createDividendWithCheckpointAndExclusionsArgsStub . getCall ( 0 ) . args [ 0 ] ) . toEqual ( {
194
209
maturity : params . maturityDate ,
195
210
expiry : params . expiryDate ,
196
211
token : params . erc20Address ,
@@ -199,7 +214,7 @@ describe('CreateDividendDistribution', () => {
199
214
name : params . name ,
200
215
excluded : [ ] ,
201
216
} ) ;
202
- expect ( createDividendWithCheckpointAndExclusionsArgsSpy . callCount ) . toEqual ( 1 ) ;
217
+ expect ( createDividendWithCheckpointAndExclusionsArgsStub . callCount ) . toEqual ( 1 ) ;
203
218
expect (
204
219
addTransactionStub
205
220
. getCall ( 0 )
@@ -210,12 +225,12 @@ describe('CreateDividendDistribution', () => {
210
225
expect ( addTransactionStub . getCall ( 0 ) . lastArg . tag ) . toEqual (
211
226
PolyTransactionTag . CreateErc20DividendDistribution
212
227
) ;
228
+ expect ( setWithholdingArgsStub . getCall ( 0 ) . args [ 0 ] . investors ) . toEqual ( [ taxWithholdingAddress ] ) ;
229
+ expect ( setWithholdingArgsStub . getCall ( 0 ) . args [ 0 ] . withholding [ 0 ] . toNumber ( ) ) . toEqual (
230
+ taxWithholdingPercentage
231
+ ) ;
213
232
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 ) ;
219
234
expect (
220
235
addTransactionStub
221
236
. getCall ( 1 )
@@ -224,8 +239,9 @@ describe('CreateDividendDistribution', () => {
224
239
expect ( addTransactionStub . getCall ( 1 ) . lastArg . tag ) . toEqual (
225
240
PolyTransactionTag . SetErc20TaxWithholding
226
241
) ;
242
+
227
243
expect ( addTransactionStub . callCount ) . toEqual ( 2 ) ;
228
- expect ( addProcedureSpy . callCount ) . toEqual ( 1 ) ;
244
+ expect ( addProcedureStub . callCount ) . toEqual ( 1 ) ;
229
245
} ) ;
230
246
231
247
test ( 'should throw if there is no valid security token supplied' , async ( ) => {
0 commit comments