@@ -3652,3 +3652,114 @@ func testCustomChannelsForwardBandwidth(ctxb context.Context,
36523652 universeTap , noOpCoOpCloseBalanceCheck ,
36533653 )
36543654}
3655+
3656+ // testCustomChannelsDecodeAssetInvoice tests that we're able to properly
3657+ // decode and display asset invoice related information.
3658+ //
3659+ // TODO(roasbeef): just move to tapd repo due to new version that doesn't req a
3660+ // chan?
3661+ func testCustomChannelsDecodeAssetInvoice (ctx context.Context ,
3662+ net * NetworkHarness , t * harnessTest ) {
3663+
3664+ // First, we'll set up some information for our custom oracle that we'll use
3665+ // to feed in price information.
3666+ oracleAddr := fmt .Sprintf ("localhost:%d" , port .NextAvailablePort ())
3667+ oracle := newOracleHarness (oracleAddr )
3668+ oracle .start (t .t )
3669+ t .t .Cleanup (oracle .stop )
3670+
3671+ ctxb := context .Background ()
3672+ lndArgs := slices .Clone (lndArgsTemplate )
3673+ litdArgs := slices .Clone (litdArgsTemplateNoOracle )
3674+ litdArgs = append (litdArgs , fmt .Sprintf (
3675+ "--taproot-assets.experimental.rfq.priceoracleaddress=" +
3676+ "rfqrpc://%s" , oracleAddr ,
3677+ ))
3678+
3679+ // For this test, Zane will be our dedicated Universe server for all parties.
3680+ zane , err := net .NewNode (
3681+ t .t , "Zane" , lndArgs , false , true , litdArgs ... ,
3682+ )
3683+ require .NoError (t .t , err )
3684+
3685+ litdArgs = append (litdArgs , fmt .Sprintf (
3686+ "--taproot-assets.proofcourieraddr=%s://%s" ,
3687+ proof .UniverseRpcCourierType , zane .Cfg .LitAddr (),
3688+ ))
3689+
3690+ // We'll just make a single node here, as this doesn't actually rely on a set
3691+ // of active channels.
3692+ alice , err := net .NewNode (t .t , "Alice" , lndArgs , false , true , litdArgs ... )
3693+ aliceTap := newTapClient (t .t , alice )
3694+
3695+ // Next, we'll make a new asset with a specified decimal display. We'll also
3696+ // make grouped asset as well.
3697+ usdMetaData := & taprpc.AssetMeta {
3698+ Data : []byte (`{
3699+ "description":"this is a USD stablecoin with decimal display of 6"
3700+ }` ),
3701+ Type : taprpc .AssetMetaType_META_TYPE_JSON ,
3702+ }
3703+
3704+ const decimalDisplay = 6
3705+ itestAsset = & mintrpc.MintAsset {
3706+ AssetType : taprpc .AssetType_NORMAL ,
3707+ Name : "USD" ,
3708+ AssetMeta : usdMetaData ,
3709+ // We mint 1 million USD with a decimal display of 6, which
3710+ // results in 1 trillion asset units.
3711+ Amount : 1_000_000_000_000 ,
3712+ DecimalDisplay : decimalDisplay ,
3713+ NewGroupedAsset : true ,
3714+ }
3715+
3716+ // Mint an asset on Charlie and sync Dave to Charlie as the universe.
3717+ mintedAssets := itest .MintAssetsConfirmBatch (
3718+ t .t , t .lndHarness .Miner .Client , aliceTap ,
3719+ []* mintrpc.MintAssetRequest {
3720+ {
3721+ Asset : itestAsset ,
3722+ },
3723+ },
3724+ )
3725+ usdAsset := mintedAssets [0 ]
3726+ assetID := usdAsset .AssetGenesis .AssetId
3727+
3728+ // Now that we've minted the asset, we can set the price in the oracle.
3729+ var id asset.ID
3730+ copy (id [:], assetID )
3731+
3732+ // We'll assume a price of $100,000.00 USD for a single BTC. This is just the
3733+ // current subjective price our oracle will use. From this BTC price, we'll
3734+ // scale things up to be in the precision of the asset we minted above.
3735+ btcPrice := rfqmath .NewBigIntFixedPoint (
3736+ 100_000_000 , 2 ,
3737+ ).ScaleTo (decimalDisplay )
3738+ oracle .setPrice (id , btcPrice , btcPrice )
3739+
3740+ // Now we'll make a normal invoice for 1 BTC using Alice.
3741+ expirySeconds := 10
3742+ amountSat := 100_000_000
3743+ invoiceResp , err := alice .AddInvoice (ctxb , & lnrpc.Invoice {
3744+ Value : int64 (amountSat ),
3745+ Memo : "normal invoice" ,
3746+ Expiry : int64 (expirySeconds ),
3747+ })
3748+ require .NoError (t .t , err )
3749+
3750+ payReq := invoiceResp .PaymentRequest
3751+
3752+ // Now that we have our payment request, we'll call into the new decode asset
3753+ // pay req call.
3754+ decodeResp , err := aliceTap .DecodeAssetInvoice (ctxb , & taprpc.DecodeAssetPayReq {
3755+ AssetId : assetID ,
3756+ PayReqString : & lnrpc.PayReqString {
3757+ PayReq : payReq ,
3758+ },
3759+ })
3760+ require .NoError (t .t , err )
3761+
3762+ // The 1 BTC invoice should map to 1 asset unit.
3763+ const expectedUnits = 1
3764+ require .Equal (t .t , expectedUnits , decodeResp .AssetAmount )
3765+ }
0 commit comments