11package tapchannel
22
33import (
4+ "bytes"
45 "context"
56 "crypto/sha256"
7+ "encoding/json"
68 "fmt"
79 "math/big"
810 "testing"
@@ -298,7 +300,9 @@ func (m *mockHtlcModifierProperty) HtlcModifier(ctx context.Context,
298300 }
299301 } else {
300302 if assetValueMsat != res .AmtPaid {
301- m .t .Errorf ("unexpected final asset value" )
303+ m .t .Errorf ("unexpected final asset value, " +
304+ "wanted %d, got %d" , assetValueMsat ,
305+ res .AmtPaid )
302306 }
303307 }
304308 }
@@ -309,6 +313,19 @@ func (m *mockHtlcModifierProperty) HtlcModifier(ctx context.Context,
309313 return nil
310314}
311315
316+ type mockLndClient struct {
317+ lndclient.LightningClient
318+
319+ channels []lndclient.ChannelInfo
320+ }
321+
322+ // ListChannels retrieves all channels of the backing lnd node.
323+ func (m * mockLndClient ) ListChannels (_ context.Context , _ ,
324+ _ bool ) ([]lndclient.ChannelInfo , error ) {
325+
326+ return m .channels , nil
327+ }
328+
312329// TestAuxInvoiceManager tests that the htlc modifications of the aux invoice
313330// manager align with our expectations.
314331func TestAuxInvoiceManager (t * testing.T ) {
@@ -609,6 +626,7 @@ func TestAuxInvoiceManager(t *testing.T) {
609626 peerBuyQuotes : testCase .buyQuotes ,
610627 localSellQuotes : testCase .sellQuotes ,
611628 }
629+ mockLnd := & mockLndClient {}
612630
613631 done := make (chan bool )
614632
@@ -626,6 +644,7 @@ func TestAuxInvoiceManager(t *testing.T) {
626644 ChainParams : testChainParams ,
627645 InvoiceHtlcModifier : mockModifier ,
628646 RfqManager : mockRfq ,
647+ LightningClient : mockLnd ,
629648 },
630649 )
631650
@@ -800,13 +819,12 @@ func genRequest(t *rapid.T) (lndclient.InvoiceHtlcModifyRequest, uint64,
800819// genRequests generates a random array of requests to be processed by the
801820// AuxInvoiceManager. It also returns the rfq map with the related rfq quotes.
802821func genRequests (t * rapid.T ) ([]lndclient.InvoiceHtlcModifyRequest ,
803- rfq.BuyAcceptMap ) {
822+ rfq.BuyAcceptMap , []lndclient. ChannelInfo ) {
804823
805824 rfqMap := rfq.BuyAcceptMap {}
806825
807826 numRequests := rapid .IntRange (1 , 5 ).Draw (t , "requestsLen" )
808- requests := make ([]lndclient.InvoiceHtlcModifyRequest , 0 )
809-
827+ var requests []lndclient.InvoiceHtlcModifyRequest
810828 for range numRequests {
811829 req , numAssets , assetID , scid := genRequest (t )
812830 requests = append (requests , req )
@@ -819,7 +837,37 @@ func genRequests(t *rapid.T) ([]lndclient.InvoiceHtlcModifyRequest,
819837 genBuyQuotes (t , rfqMap , numAssets , quoteAmt , assetID , scid )
820838 }
821839
822- return requests , rfqMap
840+ channels := make ([]lndclient.ChannelInfo , len (requests ))
841+ for i , req := range requests {
842+ var (
843+ buf bytes.Buffer
844+ htlc rfqmsg.Htlc
845+ jsonAssetChan rfqmsg.JsonAssetChannel
846+ )
847+ err := req .WireCustomRecords .SerializeTo (& buf )
848+ require .NoError (t , err )
849+
850+ err = htlc .Decode (& buf )
851+ require .NoError (t , err )
852+
853+ jsonAssetChan .FundingAssets = make (
854+ []rfqmsg.JsonAssetUtxo , len (htlc .Balances ()),
855+ )
856+ for idx , balance := range htlc .Balances () {
857+ fundingAsset := & jsonAssetChan .FundingAssets [idx ]
858+ fundingAssetGen := & fundingAsset .AssetGenesis
859+ fundingAssetGen .AssetID = balance .AssetID .Val .String ()
860+ }
861+
862+ jsonChan , err := json .Marshal (jsonAssetChan )
863+ require .NoError (t , err )
864+ channels [i ] = lndclient.ChannelInfo {
865+ ChannelID : req .CircuitKey .ChanID .ToUint64 (),
866+ CustomChannelData : jsonChan ,
867+ }
868+ }
869+
870+ return requests , rfqMap , channels
823871}
824872
825873// genRandomVertex generates a route.Vertex instance filled with random bytes.
@@ -898,11 +946,14 @@ func genBuyQuotes(t *rapid.T, rfqMap rfq.BuyAcceptMap, units, amtMsat uint64,
898946// testInvoiceManager creates an array of requests to be processed by the
899947// AuxInvoiceManager. Uses the enhanced HtlcModifierMockProperty instance.
900948func testInvoiceManager (t * rapid.T ) {
901- requests , rfqMap := genRequests (t )
949+ requests , rfqMap , channels := genRequests (t )
902950
903951 mockRfq := & mockRfqManager {
904952 peerBuyQuotes : rfqMap ,
905953 }
954+ mockLnd := & mockLndClient {
955+ channels : channels ,
956+ }
906957
907958 done := make (chan bool )
908959
@@ -913,13 +964,12 @@ func testInvoiceManager(t *rapid.T) {
913964 t : t ,
914965 }
915966
916- manager := NewAuxInvoiceManager (
917- & InvoiceManagerConfig {
918- ChainParams : testChainParams ,
919- InvoiceHtlcModifier : mockModifier ,
920- RfqManager : mockRfq ,
921- },
922- )
967+ manager := NewAuxInvoiceManager (& InvoiceManagerConfig {
968+ ChainParams : testChainParams ,
969+ InvoiceHtlcModifier : mockModifier ,
970+ RfqManager : mockRfq ,
971+ LightningClient : mockLnd ,
972+ })
923973
924974 err := manager .Start ()
925975 require .NoError (t , err )
0 commit comments