@@ -18,6 +18,7 @@ import {
1818} from '../../types' ;
1919import { PolymathError } from '../../PolymathError' ;
2020import { mockFactories } from '../../testUtils/mockFactories' ;
21+ import { SecurityToken , TaxWithholding } from '../../entities' ;
2122
2223const testAddress = '0x6666666666666666666666666666666666666666' ;
2324const testAddress2 = '0x9999999999999999999999999999999999999999' ;
@@ -39,6 +40,7 @@ describe('UpdateDividendsTaxWithholdingList', () => {
3940 let ethDividendsMock : MockManager < contractWrappersModule . EtherDividendCheckpoint_3_0_0 > ;
4041 let taxWithholdingFactoryMock : MockManager < taxWithholdingFactoryModule . TaxWithholdingFactory > ;
4142 let factoriesMockedSetup : Factories ;
43+ let securityTokenId : string ;
4244
4345 beforeEach ( ( ) => {
4446 // Mock the context, wrappers, tokenFactory and securityToken to test update dividends tax withholding list
@@ -68,6 +70,10 @@ describe('UpdateDividendsTaxWithholdingList', () => {
6870 factoriesMockedSetup . taxWithholdingFactory = taxWithholdingFactoryMock . getMockInstance ( ) ;
6971 contextMock . set ( 'factories' , factoriesMockedSetup ) ;
7072
73+ securityTokenId = SecurityToken . generateId ( {
74+ symbol : params . symbol ,
75+ } ) ;
76+
7177 target = new UpdateDividendsTaxWithholdingList ( params , contextMock . getMockInstance ( ) ) ;
7278 } ) ;
7379
@@ -194,30 +200,79 @@ describe('UpdateDividendsTaxWithholdingList', () => {
194200 expect ( addTransactionSpy . callCount ) . toEqual ( 1 ) ;
195201 } ) ;
196202
197- // TODO test the resolver
198- test ( 'should update the dividends tax withholding list for erc20 token' , async ( ) => {
199- const updateStub = taxWithholdingFactoryMock . mock ( 'update' , Promise . resolve ( ) ) ;
203+ test ( 'should update the dividends tax withholding list for erc20 dividend type' , async ( ) => {
204+ const updateStub = taxWithholdingFactoryMock . mock ( 'update' , Promise . resolve ( undefined ) ) ;
200205
201206 const resolverValue = await updateDividendsTaxWithholdingListModule . updateDividendsTaxWithholdingListResolver (
202207 factoriesMockedSetup ,
203208 params . symbol ,
204- DividendType . Erc20 ,
205- [ 10 , 20 ] ,
206- [ testAddress , testAddress2 ]
207- ) ;
208- // expect(
209- // updateStub.getCall(0).calledWithExactly(
210- // TaxWithholding.generateId({
211- // securityTokenId: SecurityToken.generateId({
212- // symbol: params.symbol,
213- // }),
214- // dividendType: DividendType.Erc20,
215- // shareholderAddress: testAddress,
216- // })
217- // )
218- // ).toEqual(true);
219- // expect(resolverValue).toEqual(Promise.resolve());
220- // expect(updateStub.callCount).toEqual(1);
209+ params . dividendType ,
210+ params . percentages ,
211+ params . shareholderAddresses
212+ ) ( ) ;
213+
214+ expect (
215+ updateStub . getCall ( 0 ) . calledWithExactly (
216+ TaxWithholding . generateId ( {
217+ securityTokenId,
218+ dividendType : params . dividendType ,
219+ shareholderAddress : params . shareholderAddresses [ 0 ] ,
220+ } ) ,
221+ { percentage : params . percentages [ 0 ] }
222+ )
223+ ) . toEqual ( true ) ;
224+
225+ expect (
226+ updateStub . getCall ( 1 ) . calledWithExactly (
227+ TaxWithholding . generateId ( {
228+ securityTokenId,
229+ dividendType : params . dividendType ,
230+ shareholderAddress : params . shareholderAddresses [ 1 ] ,
231+ } ) ,
232+ { percentage : params . percentages [ 1 ] }
233+ )
234+ ) . toEqual ( true ) ;
235+
236+ expect ( resolverValue ) . toEqual ( undefined ) ;
237+ expect ( updateStub . callCount ) . toEqual ( 2 ) ;
238+ } ) ;
239+
240+ test ( 'should update the dividends tax withholding list for ether dividend type' , async ( ) => {
241+ const updateStub = taxWithholdingFactoryMock . mock ( 'update' , Promise . resolve ( undefined ) ) ;
242+ const dividendType = DividendType . Erc20 ;
243+
244+ const resolverValue = await updateDividendsTaxWithholdingListModule . updateDividendsTaxWithholdingListResolver (
245+ factoriesMockedSetup ,
246+ params . symbol ,
247+ dividendType ,
248+ params . percentages ,
249+ params . shareholderAddresses
250+ ) ( ) ;
251+
252+ expect (
253+ updateStub . getCall ( 0 ) . calledWithExactly (
254+ TaxWithholding . generateId ( {
255+ securityTokenId,
256+ dividendType,
257+ shareholderAddress : params . shareholderAddresses [ 0 ] ,
258+ } ) ,
259+ { percentage : params . percentages [ 0 ] }
260+ )
261+ ) . toEqual ( true ) ;
262+
263+ expect (
264+ updateStub . getCall ( 1 ) . calledWithExactly (
265+ TaxWithholding . generateId ( {
266+ securityTokenId,
267+ dividendType,
268+ shareholderAddress : params . shareholderAddresses [ 1 ] ,
269+ } ) ,
270+ { percentage : params . percentages [ 1 ] }
271+ )
272+ ) . toEqual ( true ) ;
273+
274+ expect ( resolverValue ) . toEqual ( undefined ) ;
275+ expect ( updateStub . callCount ) . toEqual ( 2 ) ;
221276 } ) ;
222277 } ) ;
223278} ) ;
0 commit comments