@@ -18,7 +18,7 @@ import {
18
18
import { AddressType , Bip32Account , GroupedAddress , KeyRole , util } from '@cardano-sdk/key-management' ;
19
19
import { AssetId , mockProviders as mocks } from '@cardano-sdk/util-dev' ;
20
20
import { BaseWallet , ObservableWallet , cip30 , createPersonalWallet } from '../../src' ;
21
- import { CallbackConfirmation , GetCollateralCallbackParams } from '../../src/cip30' ;
21
+ import { CallbackConfirmation } from '../../src/cip30' ;
22
22
import {
23
23
Cardano ,
24
24
OutsideOfValidityIntervalData ,
@@ -45,14 +45,10 @@ const {
45
45
mockRewardsProvider,
46
46
mockTxSubmitProvider,
47
47
utxo : mockUtxo ,
48
- utxosWithLowCoins,
49
- utxosWithLowCoinsAndMixedAssets,
50
- sortedUtxosWithLowCoins,
51
- impureUtxos
48
+ utxosWithLowCoins
52
49
} = mocks ;
53
50
54
51
type TestProviders = Required < Pick < Providers , 'txSubmitProvider' | 'networkInfoProvider' > > ;
55
- const mockCollateralCallback = jest . fn ( ) . mockResolvedValue ( [ mockUtxo [ 3 ] ] ) ;
56
52
const createMockGenericCallback = < T > ( result : T ) => jest . fn ( ) . mockResolvedValue ( result ) ;
57
53
const foreignTx = Serialization . TxCBOR (
58
54
'84a70081825820dce442e983f3f5cd5b2644bc57f749075390f1fbae9ab55bf454342959c885db00018182583900d161d64eef0eeb59f9124f520f8c8f3b717ed04198d54c8b17e604aea63c153fb3ea8a4ea4f165574ea91173756de0bf30222ca0e95a649a1a0082607b021a0016360509a1581cb77934706fa311b6568d1070c2d23f092324b35ad623aa571a0e3726a14e4d6573685f476966745f43617264200b5820d8175f3b1276a48939a6ccee220a7f81b6422167317ba3ff6325cba1fb6ccbe70d818258208d68748457cd0f1a8596f41fd2125a415315897d2da4a4b94335829cee7198ae001281825820dce442e983f3f5cd5b2644bc57f749075390f1fbae9ab55bf454342959c885db00a2068259016b590168010000333232323232323223223222253330083232533300d3010002132533300b3370e6eb4c034009200113371e0020122940dd718058008b180700099299980499b8748008c028dd50008a5eb7bdb1804dd5980718059baa001323300100132330010013756601e602060206020602060186ea8c03cc030dd50019129998070008a5eb7bdb1804c8c8c8c94ccc03ccdc8a45000021533300f3371e91010000210031005133013337606ea4008dd3000998030030019bab3010003375c601c0046024004602000244a66601a002298103d87a8000132323232533300e337220140042a66601c66e3c0280084cdd2a4000660246e980052f5c02980103d87a80001330060060033756601e0066eb8c034008c044008c03c00452613656375c0026eb80055cd2ab9d5573caae7d5d02ba157449810f4e4d6573685f476966745f43617264004c011e581cb77934706fa311b6568d1070c2d23f092324b35ad623aa571a0e3726000159023c59023901000033323232323232322322232323225333009323232533300c3007300d3754002264646464a666026602c00426464a666024601a60266ea803854ccc048c034c04cdd5191980080080311299980b8008a60103d87a80001323253330163375e603660306ea800804c4cdd2a40006603400497ae0133004004001301b002301900115333012300c00113371e00402029405854ccc048cdc3800a4002266e3c0080405281bad3013002375c60220022c602800264a66601e601260206ea800452f5bded8c026eacc050c044dd500099191980080099198008009bab3016301730173017301700522533301500114bd6f7b630099191919299980b19b91488100002153330163371e9101000021003100513301a337606ea4008dd3000998030030019bab3017003375c602a0046032004602e00244a666028002298103d87a800013232323253330153372200e0042a66602a66e3c01c0084cdd2a4000660326e980052f5c02980103d87a80001330060060033756602c0066eb8c050008c060008c058004dd7180998081baa00337586024002601c6ea800858c040c044008c03c004c02cdd50008a4c26cac64a66601060060022a66601660146ea8010526161533300830020011533300b300a37540082930b0b18041baa003370e90011b8748000dd7000ab9a5573aaae7955cfaba05742ae8930010f4e4d6573685f476966745f43617264004c012bd8799fd8799f58203159a6f2ae24c5bfbed947fe0ecfe936f088c8d265484e6979cacb607d33c811ff05ff0001058284000040821a006acfc01ab2d05e00840100d87a80821a006acfc01ab2d05e00f5f6'
@@ -61,7 +57,6 @@ const foreignTx = Serialization.TxCBOR(
61
57
const createWalletAndApiWithStores = async (
62
58
unspendableUtxos : Cardano . Utxo [ ] ,
63
59
providers ?: TestProviders ,
64
- getCollateralCallback ?: ( args : GetCollateralCallbackParams ) => Promise < Cardano . Utxo [ ] > ,
65
60
settle = true ,
66
61
availableUtxos ?: Cardano . Utxo [ ]
67
62
) => {
@@ -79,8 +74,7 @@ const createWalletAndApiWithStores = async (
79
74
const confirmationCallback = {
80
75
signData : createMockGenericCallback ( { cancel$ : NEVER } ) ,
81
76
signTx : createMockGenericCallback ( { cancel$ : NEVER } ) ,
82
- submitTx : createMockGenericCallback ( true ) ,
83
- ...( ! ! getCollateralCallback && { getCollateral : getCollateralCallback } )
77
+ submitTx : createMockGenericCallback ( true )
84
78
} ;
85
79
wallet . governance . getPubDRepKey = jest . fn ( wallet . governance . getPubDRepKey ) ;
86
80
@@ -123,12 +117,7 @@ describe('cip30', () => {
123
117
} )
124
118
) ;
125
119
// CREATE A WALLET
126
- ( { wallet, api, confirmationCallback } = await createWalletAndApiWithStores (
127
- [ mockUtxo [ 2 ] ] ,
128
- providers ,
129
- undefined ,
130
- false
131
- ) ) ;
120
+ ( { wallet, api, confirmationCallback } = await createWalletAndApiWithStores ( [ mockUtxo [ 2 ] ] , providers , false ) ) ;
132
121
} ) ;
133
122
134
123
afterEach ( ( ) => {
@@ -302,26 +291,6 @@ describe('cip30', () => {
302
291
let wallet4 : BaseWallet ;
303
292
let api4 : WithSenderContext < WalletApi > ;
304
293
305
- // Wallet 5
306
- let wallet5 : BaseWallet ;
307
- let api5 : WithSenderContext < WalletApi > ;
308
-
309
- // Wallet 6
310
- let wallet6 : BaseWallet ;
311
- let api6 : WithSenderContext < WalletApi > ;
312
-
313
- // Wallet 7
314
- let wallet7 : BaseWallet ;
315
- let api7 : WithSenderContext < WalletApi > ;
316
-
317
- // Wallet 8
318
- let wallet8 : BaseWallet ;
319
- let api8 : WithSenderContext < WalletApi > ;
320
-
321
- // Wallet 9
322
- let wallet9 : BaseWallet ;
323
- let api9 : WithSenderContext < WalletApi > ;
324
-
325
294
beforeAll ( async ( ) => {
326
295
// CREATE A WALLET WITH LOW COINS UTxOs
327
296
( { wallet : wallet2 , api : api2 } = await createWalletAndApiWithStores ( utxosWithLowCoins ) ) ;
@@ -331,51 +300,6 @@ describe('cip30', () => {
331
300
332
301
// CREATE A WALLET WITH UTxOS WITH ASSETS
333
302
( { wallet : wallet4 , api : api4 } = await createWalletAndApiWithStores ( [ mockUtxo [ 1 ] , mockUtxo [ 2 ] ] ) ) ;
334
-
335
- // CREATE WALLET WITH CALLBACK FOR GET COLLATERAL (UNSPENDABLES DOES NOT FULFILL AMOUNT, AVAILABLE UTxOs WITH MIXED ASSETS)
336
- ( { wallet : wallet5 , api : api5 } = await createWalletAndApiWithStores (
337
- utxosWithLowCoins ,
338
- providers ,
339
- mockCollateralCallback ,
340
- true ,
341
- utxosWithLowCoinsAndMixedAssets
342
- ) ) ;
343
-
344
- // CREATE WALLET WITH CALLBACK FOR GET COLLATERAL (NO UNSPENDABLES, AVAILABLE UTxOs WITH MIXED ASSETS)
345
- ( { wallet : wallet6 , api : api6 } = await createWalletAndApiWithStores (
346
- [ ] ,
347
- providers ,
348
- mockCollateralCallback ,
349
- true ,
350
- utxosWithLowCoinsAndMixedAssets
351
- ) ) ;
352
-
353
- // WALLET WITH CALLBACK FOR GET COLLATERAL (UNSPENDABLES DOES NOT FULFILL AMOUNT, NO AVAILABLE UTxOS)
354
- ( { wallet : wallet7 , api : api7 } = await createWalletAndApiWithStores (
355
- utxosWithLowCoins ,
356
- providers ,
357
- mockCollateralCallback ,
358
- true ,
359
- [ ]
360
- ) ) ;
361
-
362
- // WALLET WITH CALLBACK FOR GET COLLATERAL (BRAND NEW WALLET, NO UTXOS)
363
- ( { wallet : wallet8 , api : api8 } = await createWalletAndApiWithStores (
364
- [ ] ,
365
- providers ,
366
- mockCollateralCallback ,
367
- true ,
368
- [ ]
369
- ) ) ;
370
-
371
- // WALLET WITH CALLBACK FOR GET COLLATERAL (ONLY IMPURE UTXOs)
372
- ( { wallet : wallet9 , api : api9 } = await createWalletAndApiWithStores (
373
- [ ] ,
374
- providers ,
375
- mockCollateralCallback ,
376
- true ,
377
- impureUtxos
378
- ) ) ;
379
303
} ) ;
380
304
381
305
afterAll ( ( ) => {
@@ -384,81 +308,11 @@ describe('cip30', () => {
384
308
wallet4 . shutdown ( ) ;
385
309
} ) ;
386
310
387
- beforeEach ( ( ) => {
388
- mockCollateralCallback . mockClear ( ) ;
389
- } ) ;
390
-
391
311
test ( 'can handle serialization errors' , async ( ) => {
392
312
// YYYY is invalid hex that will throw at serialization
393
313
await expect ( api . getCollateral ( context , { amount : 'YYYY' } ) ) . rejects . toThrowError ( ApiError ) ;
394
314
} ) ;
395
315
396
- it ( 'executes collateral callback if provided and unspendable UTxOs do not meet amount required' , async ( ) => {
397
- const collateral = await api5 . getCollateral ( context ) ;
398
- expect ( mockCollateralCallback ) . toHaveBeenCalledWith ( {
399
- data : {
400
- amount : 5_000_000n ,
401
- utxos : sortedUtxosWithLowCoins
402
- } ,
403
- sender : {
404
- url : 'https://lace.io'
405
- } ,
406
- type : 'get_collateral'
407
- } ) ;
408
-
409
- expect ( collateral ) . toEqual ( [ Serialization . TransactionUnspentOutput . fromCore ( mockUtxo [ 3 ] ) . toCbor ( ) ] ) ;
410
- wallet5 . shutdown ( ) ;
411
- } ) ;
412
-
413
- it ( 'executes collateral callback if provided and no unspendable UTxOs are available' , async ( ) => {
414
- const collateral = await api6 . getCollateral ( context ) ;
415
- expect ( mockCollateralCallback ) . toHaveBeenCalledWith ( {
416
- data : {
417
- amount : 5_000_000n ,
418
- utxos : sortedUtxosWithLowCoins
419
- } ,
420
- sender : {
421
- url : 'https://lace.io'
422
- } ,
423
- type : 'get_collateral'
424
- } ) ;
425
-
426
- expect ( collateral ) . toEqual ( [ Serialization . TransactionUnspentOutput . fromCore ( mockUtxo [ 3 ] ) . toCbor ( ) ] ) ;
427
- wallet6 . shutdown ( ) ;
428
- } ) ;
429
-
430
- it ( 'does not execute collateral callback if provided with no available UTxOs' , async ( ) => {
431
- await expect ( api7 . getCollateral ( context ) ) . rejects . toThrow ( ApiError ) ;
432
- expect ( mockCollateralCallback ) . not . toHaveBeenCalled ( ) ;
433
- wallet7 . shutdown ( ) ;
434
- } ) ;
435
-
436
- it ( 'does not execute collateral callback and returns null if brand new wallet (no UTXOS)' , async ( ) => {
437
- await expect ( api8 . getCollateral ( context ) ) . resolves . toBeNull ( ) ;
438
- expect ( mockCollateralCallback ) . not . toHaveBeenCalled ( ) ;
439
- wallet8 . shutdown ( ) ;
440
- } ) ;
441
-
442
- it ( 'does executes collateral callback with empty array if wallet has only impure UTXOS' , async ( ) => {
443
- await expect ( api9 . getCollateral ( context ) ) . resolves . not . toBeNull ( ) ;
444
- expect ( mockCollateralCallback ) . toHaveBeenCalledWith ( {
445
- data : {
446
- amount : 5_000_000n ,
447
- utxos : [ ]
448
- } ,
449
- sender : {
450
- url : 'https://lace.io'
451
- } ,
452
- type : 'get_collateral'
453
- } ) ;
454
- wallet9 . shutdown ( ) ;
455
- } ) ;
456
-
457
- it ( 'does not execute collateral callback if not provided' , async ( ) => {
458
- await expect ( api2 . getCollateral ( context ) ) . rejects . toThrow ( ApiError ) ;
459
- expect ( mockCollateralCallback ) . not . toHaveBeenCalled ( ) ;
460
- } ) ;
461
-
462
316
test ( 'accepts amount as tagged integer' , async ( ) => {
463
317
await expect ( api . getCollateral ( context , { amount : 'c2434c4b40' } ) ) . resolves . not . toThrow ( ) ;
464
318
} ) ;
0 commit comments