@@ -531,69 +531,61 @@ describe('precompile client session', () => {
531531 } ,
532532 )
533533
534- test ( 'keeps a selected direct channel direct when a machine channel later appears' , async ( ) => {
535- const directChannelId = Channel . computeId ( {
536- ...descriptor ,
534+ test ( 'keeps a direct fallback selected when a persisted machine route recovers' , async ( ) => {
535+ const machineDescriptor = getMachineDescriptor ( )
536+ const machineChannelId = Channel . computeId ( {
537+ ...machineDescriptor ,
538+ chainId,
539+ escrow : tip20ChannelEscrow ,
540+ } )
541+ const machineKey = channelKey ( {
537542 chainId,
538543 escrow : tip20ChannelEscrow ,
544+ payee : machineDescriptor . payee ,
545+ token : machineDescriptor . token ,
539546 } )
540547 const channelStore = createChannelStore ( )
541548 await channelStore . set ( {
542549 chainId,
543- channelId : directChannelId ,
550+ channelId : machineChannelId ,
544551 cumulativeAmount : 100n ,
545552 deposit : 1_000n ,
546- descriptor,
553+ descriptor : machineDescriptor ,
547554 escrow : tip20ChannelEscrow ,
548555 opened : true ,
549556 } )
557+ let currentClient = createMachineClient ( { routeError : true } )
550558 const method = session ( {
551559 account,
552560 channelStore,
553561 decimals : 0 ,
554- getClient : ( ) => machineClient ,
562+ getClient : ( ) => currentClient ,
555563 } )
556564 const challenge = ( ) =>
557565 makeSessionChallenge ( {
558566 methodDetails : { escrowContract : tip20ChannelEscrow , machineTokenEnabled : true } ,
559567 } )
560568
561- expect (
562- deserialize ( await method . createCredential ( { challenge : challenge ( ) , context : { } } ) ) ,
563- ) . toMatchObject ( {
564- action : 'voucher' ,
565- channelId : directChannelId ,
566- cumulativeAmount : '200' ,
567- } )
568-
569- const machineDescriptor = getMachineDescriptor ( )
570- const machineChannelId = Channel . computeId ( {
571- ...machineDescriptor ,
572- chainId,
573- escrow : tip20ChannelEscrow ,
574- } )
575- const machineKey = channelKey ( {
576- chainId,
577- escrow : tip20ChannelEscrow ,
578- payee : machineDescriptor . payee ,
579- token : machineDescriptor . token ,
580- } )
581- await channelStore . set ( {
582- chainId,
583- channelId : machineChannelId ,
584- cumulativeAmount : 100n ,
585- deposit : 1_000n ,
586- descriptor : machineDescriptor ,
587- escrow : tip20ChannelEscrow ,
588- opened : true ,
569+ const opened = deserialize (
570+ await method . createCredential ( { challenge : challenge ( ) , context : { } } ) ,
571+ )
572+ expect ( opened ) . toMatchObject ( {
573+ action : 'open' ,
574+ descriptor : {
575+ operator : descriptor . operator ,
576+ payee : descriptor . payee ,
577+ token : descriptor . token ,
578+ } ,
579+ cumulativeAmount : '100' ,
589580 } )
581+ currentClient = machineClient
590582
591583 expect (
592584 deserialize ( await method . createCredential ( { challenge : challenge ( ) , context : { } } ) ) ,
593585 ) . toMatchObject ( {
594586 action : 'voucher' ,
595- channelId : directChannelId ,
596- cumulativeAmount : '300 ' ,
587+ channelId : opened . channelId ,
588+ cumulativeAmount : '200 ' ,
597589 } )
598590 expect ( await channelStore . get ( machineKey ) ) . toMatchObject ( { cumulativeAmount : 100n } )
599591 } )
0 commit comments