diff --git a/tapchannel/aux_invoice_manager_test.go b/tapchannel/aux_invoice_manager_test.go index b8d55c1e2..204be247e 100644 --- a/tapchannel/aux_invoice_manager_test.go +++ b/tapchannel/aux_invoice_manager_test.go @@ -4,6 +4,7 @@ import ( "context" "crypto/sha256" "fmt" + "math/big" "testing" "time" @@ -11,6 +12,7 @@ import ( "github.com/lightninglabs/taproot-assets/asset" "github.com/lightninglabs/taproot-assets/fn" "github.com/lightninglabs/taproot-assets/rfq" + "github.com/lightninglabs/taproot-assets/rfqmath" "github.com/lightninglabs/taproot-assets/rfqmsg" "github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnwire" @@ -27,6 +29,8 @@ const ( var ( // The node ID to be used for the RFQ peer. testNodeID = route.Vertex{1, 2, 3} + + assetRate = big.NewInt(1_000_000) ) // mockRfqManager mocks the interface of the rfq manager required by the aux @@ -139,8 +143,10 @@ func (m *mockHtlcModifierProperty) HtlcModifier(ctx context.Context, quote, ok := m.rfqMap[rfqID.Scid()] require.True(m.t, ok) + assetRate := lnwire.MilliSatoshi(quote.AssetRate.ToUint64()) + assetUnits := lnwire.MilliSatoshi(htlc.Amounts.Val.Sum()) - assetValueMsat := assetUnits * quote.AskPrice + assetValueMsat := assetUnits * assetRate acceptedMsat := lnwire.MilliSatoshi(0) for _, htlc := range r.Invoice.Htlcs { @@ -148,7 +154,7 @@ func (m *mockHtlcModifierProperty) HtlcModifier(ctx context.Context, } marginHtlcs := lnwire.MilliSatoshi(len(r.Invoice.Htlcs) + 1) - marginMsat := marginHtlcs * quote.AskPrice + marginMsat := marginHtlcs * assetRate totalMsatIn := marginMsat + assetValueMsat + acceptedMsat @@ -240,8 +246,11 @@ func TestAuxInvoiceManager(t *testing.T) { }, buyQuotes: rfq.BuyAcceptMap{ dummyRfqID(31).Scid(): { - Peer: testNodeID, - AskPrice: 1_000_000, + Peer: testNodeID, + AssetRate: rfqmath.FixedPoint[rfqmath.BigInt]{ + Coefficient: rfqmath.NewBigInt(assetRate), + Scale: 0, + }, }, }, }, @@ -270,8 +279,11 @@ func TestAuxInvoiceManager(t *testing.T) { }, buyQuotes: rfq.BuyAcceptMap{ dummyRfqID(31).Scid(): { - Peer: testNodeID, - AskPrice: 500_000, + Peer: testNodeID, + AssetRate: rfqmath.FixedPoint[rfqmath.BigInt]{ + Coefficient: rfqmath.NewBigInt(assetRate), + Scale: 0, + }, }, }, }, @@ -455,7 +467,7 @@ func genBuyQuotes(t *rapid.T, rfqMap rfq.BuyAcceptMap, units, amtMsat uint64, scid rfqmsg.ID) { var peer route.Vertex - askPrice := lnwire.MilliSatoshi(0) + askPrice := assetRate // Introduce a 1/8 chance that the quote's peerID is not correct. noPeerMatch := rapid.Uint16().Draw(t, "nodeID_mismatch_probability") @@ -469,17 +481,23 @@ func genBuyQuotes(t *rapid.T, rfqMap rfq.BuyAcceptMap, units, amtMsat uint64, // a random total asset value. noValueMatch := rapid.Uint16().Draw(t, "no_asset_value_match") if noValueMatch%5 == 0 { - askPrice = lnwire.MilliSatoshi( - rapid.Uint64Range( - 0, 250_000, - ).Draw(t, "asset_msat_value")) + askPrice = big.NewInt( + rapid.Int64Range(0, 250_000).Draw( + t, "asset_msat_value", + ), + ) } else { - askPrice = lnwire.MilliSatoshi(amtMsat / units) + bigAmtMsat := big.NewInt(int64(amtMsat)) + bigUnits := big.NewInt(int64(units)) + askPrice.Div(bigAmtMsat, bigUnits) } rfqMap[scid.Scid()] = rfqmsg.BuyAccept{ - Peer: peer, - AskPrice: askPrice, + Peer: peer, + AssetRate: rfqmath.FixedPoint[rfqmath.BigInt]{ + Coefficient: rfqmath.NewBigInt(askPrice), + Scale: 0, + }, } }