Skip to content

Commit da1dcc9

Browse files
authored
Merge pull request #1339 from GeorgeTsagk/aux-inv-prop-flake
tapchannel: add specifier in property test rfq generator
2 parents c8055a4 + 6584bb5 commit da1dcc9

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

tapchannel/aux_invoice_manager_test.go

+17-13
Original file line numberDiff line numberDiff line change
@@ -594,11 +594,13 @@ func genHopHints(t *rapid.T, rfqID rfqmsg.ID) []*lnrpc.HopHint {
594594
// genCustomRecords generates custom records that have a random amount of random
595595
// asset units, and may have an SCID as routing hint.
596596
func genCustomRecords(t *rapid.T, amtMsat int64,
597-
rfqID rfqmsg.ID) (lnwire.CustomRecords, uint64) {
597+
rfqID rfqmsg.ID) (asset.ID, lnwire.CustomRecords, uint64) {
598+
599+
var assetID asset.ID
598600

599601
// Introduce a chance of no wire custom records.
600602
if rapid.Bool().Draw(t, "no_wire_custom_records") {
601-
return nil, 0
603+
return assetID, nil, 0
602604
}
603605

604606
// Pick a random number of asset units. The amount of units may be as
@@ -609,19 +611,18 @@ func genCustomRecords(t *rapid.T, amtMsat int64,
609611
uint64(amtMsat*1000)+1,
610612
).Draw(t, "asset_units")
611613

614+
assetID = dummyAssetID(rapid.Byte().Draw(t, "asset_id"))
615+
612616
balance := []*rfqmsg.AssetBalance{
613-
rfqmsg.NewAssetBalance(
614-
dummyAssetID(rapid.Byte().Draw(t, "asset_id")),
615-
assetUnits,
616-
),
617+
rfqmsg.NewAssetBalance(assetID, assetUnits),
617618
}
618619

619620
htlc := genHtlc(t, balance, rfqID)
620621

621622
customRecords, err := lnwire.ParseCustomRecords(htlc.Bytes())
622623
require.NoError(t, err)
623624

624-
return customRecords, assetUnits
625+
return assetID, customRecords, assetUnits
625626
}
626627

627628
// genHtlc generates an instance of rfqmsg.Htlc with the provided asset amounts
@@ -648,7 +649,7 @@ func genHtlc(t *rapid.T, balance []*rfqmsg.AssetBalance,
648649
// genRequest generates an InvoiceHtlcModifyRequest with random values. This
649650
// method also returns the assetUnits and the rfqID used by the htlc.
650651
func genRequest(t *rapid.T) (lndclient.InvoiceHtlcModifyRequest, uint64,
651-
rfqmsg.ID) {
652+
asset.ID, rfqmsg.ID) {
652653

653654
request := lndclient.InvoiceHtlcModifyRequest{}
654655

@@ -661,13 +662,13 @@ func genRequest(t *rapid.T) (lndclient.InvoiceHtlcModifyRequest, uint64,
661662
recordsAmt = request.Invoice.ValueMsat
662663
}
663664

664-
wireRecords, assetUnits := genCustomRecords(
665+
assetID, wireRecords, assetUnits := genCustomRecords(
665666
t, recordsAmt, rfqID,
666667
)
667668
request.WireCustomRecords = wireRecords
668669
request.ExitHtlcAmt = lnwire.MilliSatoshi(recordsAmt)
669670

670-
return request, assetUnits, rfqID
671+
return request, assetUnits, assetID, rfqID
671672
}
672673

673674
// genRequests generates a random array of requests to be processed by the
@@ -681,15 +682,15 @@ func genRequests(t *rapid.T) ([]lndclient.InvoiceHtlcModifyRequest,
681682
requests := make([]lndclient.InvoiceHtlcModifyRequest, 0)
682683

683684
for range numRequests {
684-
req, numAssets, scid := genRequest(t)
685+
req, numAssets, assetID, scid := genRequest(t)
685686
requests = append(requests, req)
686687

687688
quoteAmt := uint64(0)
688689
if req.Invoice != nil {
689690
quoteAmt = uint64(req.Invoice.ValueMsat)
690691
}
691692

692-
genBuyQuotes(t, rfqMap, numAssets, quoteAmt, scid)
693+
genBuyQuotes(t, rfqMap, numAssets, quoteAmt, assetID, scid)
693694
}
694695

695696
return requests, rfqMap
@@ -708,7 +709,7 @@ func genRandomVertex(t *rapid.T) route.Vertex {
708709
// genBuyQuotes populates the provided map of rfq quotes with the desired values
709710
// for a specific
710711
func genBuyQuotes(t *rapid.T, rfqMap rfq.BuyAcceptMap, units, amtMsat uint64,
711-
scid rfqmsg.ID) {
712+
assetID asset.ID, scid rfqmsg.ID) {
712713

713714
// If the passed asset units is set to 0 this means that no wire custom
714715
// records were set. To avoid a division by zero in the lines below we
@@ -762,6 +763,9 @@ func genBuyQuotes(t *rapid.T, rfqMap rfq.BuyAcceptMap, units, amtMsat uint64,
762763
rfqMap[rfqScid.Scid()] = rfqmsg.BuyAccept{
763764
Peer: peer,
764765
AssetRate: rfqmsg.NewAssetRate(rateFp, time.Now()),
766+
Request: rfqmsg.BuyRequest{
767+
AssetSpecifier: asset.NewSpecifierFromId(assetID),
768+
},
765769
}
766770
}
767771

0 commit comments

Comments
 (0)