@@ -70,6 +70,58 @@ describe('WalletUtil', () => {
7070 } )
7171 ) . toBeNull ( ) ;
7272 } ) ;
73+
74+ it ( 'resolveInput resolves inputs from provided hints' , async ( ) => {
75+ const tx = {
76+ body : {
77+ outputs : [
78+ {
79+ address : Cardano . PaymentAddress (
80+ 'addr_test1qzs0umu0s2ammmpw0hea0w2crtcymdjvvlqngpgqy76gpfnuzcjqw982pcftgx53fu5527z2cj2tkx2h8ux2vxsg475qp3y3vz'
81+ ) ,
82+ value : { coins : 50_000_000n }
83+ } ,
84+ {
85+ address : Cardano . PaymentAddress (
86+ 'addr_test1qzs0umu0s2ammmpw0hea0w2crtcymdjvvlqngpgqy76gpfnuzcjqw982pcftgx53fu5527z2cj2tkx2h8ux2vxsg475qp3y3vz'
87+ ) ,
88+ value : { coins : 150_000_000n }
89+ }
90+ ]
91+ } ,
92+ id : Cardano . TransactionId ( '0f3abbc8fc19c2e61bab6059bf8a466e6e754833a08a62a6c56fe0e78f19d9d5' )
93+ } as Cardano . HydratedTx ;
94+
95+ const resolver = createInputResolver ( { utxo : { available$ : of ( [ ] ) } } ) ;
96+
97+ expect (
98+ await resolver . resolveInput (
99+ {
100+ index : 0 ,
101+ txId : Cardano . TransactionId ( '0f3abbc8fc19c2e61bab6059bf8a466e6e754833a08a62a6c56fe0e78f19d9d5' )
102+ } ,
103+ { hints : [ tx ] }
104+ )
105+ ) . toEqual ( {
106+ address :
107+ 'addr_test1qzs0umu0s2ammmpw0hea0w2crtcymdjvvlqngpgqy76gpfnuzcjqw982pcftgx53fu5527z2cj2tkx2h8ux2vxsg475qp3y3vz' ,
108+ value : { coins : 50_000_000n }
109+ } ) ;
110+
111+ expect (
112+ await resolver . resolveInput (
113+ {
114+ index : 1 ,
115+ txId : Cardano . TransactionId ( '0f3abbc8fc19c2e61bab6059bf8a466e6e754833a08a62a6c56fe0e78f19d9d5' )
116+ } ,
117+ { hints : [ tx ] }
118+ )
119+ ) . toEqual ( {
120+ address :
121+ 'addr_test1qzs0umu0s2ammmpw0hea0w2crtcymdjvvlqngpgqy76gpfnuzcjqw982pcftgx53fu5527z2cj2tkx2h8ux2vxsg475qp3y3vz' ,
122+ value : { coins : 150_000_000n }
123+ } ) ;
124+ } ) ;
73125 } ) ;
74126
75127 describe ( 'createBackendInputResolver' , ( ) => {
@@ -117,6 +169,58 @@ describe('WalletUtil', () => {
117169 value : { coins : 150_000_000n }
118170 } ) ;
119171 } ) ;
172+
173+ it ( 'resolveInput resolves inputs from provided hints' , async ( ) => {
174+ const tx = {
175+ body : {
176+ outputs : [
177+ {
178+ address : Cardano . PaymentAddress (
179+ 'addr_test1qzs0umu0s2ammmpw0hea0w2crtcymdjvvlqngpgqy76gpfnuzcjqw982pcftgx53fu5527z2cj2tkx2h8ux2vxsg475qp3y3vz'
180+ ) ,
181+ value : { coins : 50_000_000n }
182+ } ,
183+ {
184+ address : Cardano . PaymentAddress (
185+ 'addr_test1qzs0umu0s2ammmpw0hea0w2crtcymdjvvlqngpgqy76gpfnuzcjqw982pcftgx53fu5527z2cj2tkx2h8ux2vxsg475qp3y3vz'
186+ ) ,
187+ value : { coins : 150_000_000n }
188+ }
189+ ]
190+ } ,
191+ id : Cardano . TransactionId ( '0f3abbc8fc19c2e61bab6059bf8a466e6e754833a08a62a6c56fe0e78f19d9d5' )
192+ } as Cardano . HydratedTx ;
193+
194+ const resolver = createBackendInputResolver ( createMockChainHistoryProvider ( [ ] ) ) ;
195+
196+ expect (
197+ await resolver . resolveInput (
198+ {
199+ index : 0 ,
200+ txId : Cardano . TransactionId ( '0f3abbc8fc19c2e61bab6059bf8a466e6e754833a08a62a6c56fe0e78f19d9d5' )
201+ } ,
202+ { hints : [ tx ] }
203+ )
204+ ) . toEqual ( {
205+ address :
206+ 'addr_test1qzs0umu0s2ammmpw0hea0w2crtcymdjvvlqngpgqy76gpfnuzcjqw982pcftgx53fu5527z2cj2tkx2h8ux2vxsg475qp3y3vz' ,
207+ value : { coins : 50_000_000n }
208+ } ) ;
209+
210+ expect (
211+ await resolver . resolveInput (
212+ {
213+ index : 1 ,
214+ txId : Cardano . TransactionId ( '0f3abbc8fc19c2e61bab6059bf8a466e6e754833a08a62a6c56fe0e78f19d9d5' )
215+ } ,
216+ { hints : [ tx ] }
217+ )
218+ ) . toEqual ( {
219+ address :
220+ 'addr_test1qzs0umu0s2ammmpw0hea0w2crtcymdjvvlqngpgqy76gpfnuzcjqw982pcftgx53fu5527z2cj2tkx2h8ux2vxsg475qp3y3vz' ,
221+ value : { coins : 150_000_000n }
222+ } ) ;
223+ } ) ;
120224 } ) ;
121225
122226 describe ( 'combineInputResolvers' , ( ) => {
@@ -206,7 +310,23 @@ describe('WalletUtil', () => {
206310 } ) ;
207311 } ) ;
208312
209- it ( 'can resolve inputs from own transactions and from chain history provider' , async ( ) => {
313+ it ( 'can resolve inputs from own transactions, hints and from chain history provider' , async ( ) => {
314+ const hints = [
315+ {
316+ body : {
317+ outputs : [
318+ {
319+ address : Cardano . PaymentAddress (
320+ 'addr_test1qzs0umu0s2ammmpw0hea0w2crtcymdjvvlqngpgqy76gpfnuzcjqw982pcftgx53fu5527z2cj2tkx2h8ux2vxsg475qp3y3vz'
321+ ) ,
322+ value : { coins : 200_000_000n }
323+ }
324+ ]
325+ } ,
326+ id : Cardano . TransactionId ( '0000bbc8fc19c2e61bab6059bf8a466e6e754833a08a62a6c56fe0FFFFFFFFFF' )
327+ } as Cardano . HydratedTx
328+ ] ;
329+
210330 const tx = {
211331 body : {
212332 outputs : [
@@ -248,36 +368,58 @@ describe('WalletUtil', () => {
248368 ) ;
249369
250370 expect (
251- await resolver . resolveInput ( {
252- index : 0 ,
253- txId : Cardano . TransactionId ( '0f3abbc8fc19c2e61bab6059bf8a466e6e754833a08a62a6c56fe0e78f19d9d5' )
254- } )
371+ await resolver . resolveInput (
372+ {
373+ index : 0 ,
374+ txId : Cardano . TransactionId ( '0f3abbc8fc19c2e61bab6059bf8a466e6e754833a08a62a6c56fe0e78f19d9d5' )
375+ } ,
376+ { hints }
377+ )
255378 ) . toEqual ( {
256379 address : 'addr_test1vr8nl4u0u6fmtfnawx2rxfz95dy7m46t6dhzdftp2uha87syeufdg' ,
257380 value : { coins : 50_000_000n }
258381 } ) ;
259382
260383 expect (
261- await resolver . resolveInput ( {
262- index : 0 ,
263- txId : Cardano . TransactionId ( '0f3abbc8fc19c2e61bab6059bf8a466e6e754833a08a62a6c56fe0e7FFFFFFFF' )
264- } )
384+ await resolver . resolveInput (
385+ {
386+ index : 0 ,
387+ txId : Cardano . TransactionId ( '0f3abbc8fc19c2e61bab6059bf8a466e6e754833a08a62a6c56fe0e7FFFFFFFF' )
388+ } ,
389+ { hints }
390+ )
265391 ) . toEqual ( {
266392 address :
267393 'addr_test1qzs0umu0s2ammmpw0hea0w2crtcymdjvvlqngpgqy76gpfnuzcjqw982pcftgx53fu5527z2cj2tkx2h8ux2vxsg475qp3y3vz' ,
268394 value : { coins : 50_000_000n }
269395 } ) ;
270396
271397 expect (
272- await resolver . resolveInput ( {
273- index : 1 ,
274- txId : Cardano . TransactionId ( '0f3abbc8fc19c2e61bab6059bf8a466e6e754833a08a62a6c56fe0e7FFFFFFFF' )
275- } )
398+ await resolver . resolveInput (
399+ {
400+ index : 1 ,
401+ txId : Cardano . TransactionId ( '0f3abbc8fc19c2e61bab6059bf8a466e6e754833a08a62a6c56fe0e7FFFFFFFF' )
402+ } ,
403+ { hints }
404+ )
276405 ) . toEqual ( {
277406 address :
278407 'addr_test1qzs0umu0s2ammmpw0hea0w2crtcymdjvvlqngpgqy76gpfnuzcjqw982pcftgx53fu5527z2cj2tkx2h8ux2vxsg475qp3y3vz' ,
279408 value : { coins : 150_000_000n }
280409 } ) ;
410+ expect (
411+ await resolver . resolveInput (
412+ {
413+ index : 0 ,
414+ txId : Cardano . TransactionId ( '0000bbc8fc19c2e61bab6059bf8a466e6e754833a08a62a6c56fe0FFFFFFFFFF' )
415+ } ,
416+ { hints }
417+ )
418+ ) . toEqual ( {
419+ address :
420+ 'addr_test1qzs0umu0s2ammmpw0hea0w2crtcymdjvvlqngpgqy76gpfnuzcjqw982pcftgx53fu5527z2cj2tkx2h8ux2vxsg475qp3y3vz' ,
421+ value : { coins : 200_000_000n }
422+ } ) ;
281423 } ) ;
282424
283425 it ( 'resolveInput resolves to null if the input can not be found' , async ( ) => {
0 commit comments