@@ -19,6 +19,7 @@ import (
1919 "github.com/lightninglabs/taproot-assets/internal/test"
2020 "github.com/lightninglabs/taproot-assets/proof"
2121 "github.com/lightninglabs/taproot-assets/taprpc"
22+ wrpc "github.com/lightninglabs/taproot-assets/taprpc/assetwalletrpc"
2223 "github.com/lightninglabs/taproot-assets/taprpc/mintrpc"
2324 "github.com/lightninglabs/taproot-assets/taprpc/tapdevrpc"
2425 "github.com/lightningnetwork/lnd/lnrpc"
@@ -109,7 +110,9 @@ func testMintAssets(t *harnessTest) {
109110 // Now that all our assets have been issued, we'll use the balance
110111 // calls to ensure that we're able to retrieve the proper balance for
111112 // them all.
112- AssertAssetBalances (t .t , t .tapd , rpcSimpleAssets , rpcIssuableAssets )
113+ AssertAssetBalances (
114+ t .t , t .tapd , rpcSimpleAssets , rpcIssuableAssets , false ,
115+ )
113116
114117 // Check that we can retrieve the group keys for the issuable assets.
115118 assertGroups (t .t , t .tapd , issuableAssets )
@@ -441,7 +444,9 @@ func testMintAssetsWithTapscriptSibling(t *harnessTest) {
441444 rpcIssuableAssets := MintAssetsConfirmBatch (
442445 t .t , t .lndHarness .Miner .Client , t .tapd , issuableAssets ,
443446 )
444- AssertAssetBalances (t .t , t .tapd , rpcSimpleAssets , rpcIssuableAssets )
447+ AssertAssetBalances (
448+ t .t , t .tapd , rpcSimpleAssets , rpcIssuableAssets , false ,
449+ )
445450
446451 // Filter the managed UTXOs to select the genesis UTXO with the
447452 // tapscript sibling.
@@ -617,3 +622,77 @@ func testMintBatchAndTransfer(t *harnessTest) {
617622
618623 require .True (t .t , proto .Equal (originalBatch , afterBatch ))
619624}
625+
626+ // testAssetBalances tests the balance retrieval functionality for issued
627+ // assets. The function mints two batches of assets and asserts if the tapcli
628+ // `assets balance` returns the correct balances. It then funds a vPSBT, putting
629+ // a lease on one of the two batches. It then asserts whether the endpoint still
630+ // returns the correct balances, taking into account the `include_leased` flag.
631+ func testAssetBalances (t * harnessTest ) {
632+ ctxb := context .Background ()
633+ ctxt , cancel := context .WithTimeout (ctxb , defaultWaitTimeout )
634+ defer cancel ()
635+
636+ rpcSimpleAssets := MintAssetsConfirmBatch (
637+ t .t , t .lndHarness .Miner .Client , t .tapd , simpleAssets ,
638+ )
639+ rpcIssuableAssets := MintAssetsConfirmBatch (
640+ t .t , t .lndHarness .Miner .Client , t .tapd , issuableAssets ,
641+ )
642+ targetAsset := rpcSimpleAssets [0 ]
643+
644+ // Now that all our assets have been issued, we'll use the balance
645+ // calls to ensure that we're able to retrieve the proper balance for
646+ // them all.
647+ AssertAssetBalances (
648+ t .t , t .tapd , rpcSimpleAssets , rpcIssuableAssets , false ,
649+ )
650+
651+ var (
652+ targetAssetGenesis = targetAsset .AssetGenesis
653+ aliceTapd = t .tapd
654+ bobLnd = t .lndHarness .Bob
655+ )
656+
657+ // We create a second tapd node that will be used to simulate a second
658+ // party in the test. This tapd node is connected to lnd "Bob".
659+ bobTapd := setupTapdHarness (t .t , t , bobLnd , t .universeServer )
660+ defer func () {
661+ require .NoError (t .t , bobTapd .stop (! * noDelete ))
662+ }()
663+
664+ const assetsToSend = 1000
665+ bobAddr , err := bobTapd .NewAddr (ctxt , & taprpc.NewAddrRequest {
666+ AssetId : targetAssetGenesis .AssetId ,
667+ Amt : assetsToSend ,
668+ })
669+ require .NoError (t .t , err )
670+
671+ // Now we can create our virtual transaction and ask Alice's tapd to
672+ // fund it.
673+ recipients := map [string ]uint64 {
674+ bobAddr .Encoded : bobAddr .Amount ,
675+ }
676+ _ , err = aliceTapd .FundVirtualPsbt (
677+ ctxt , & wrpc.FundVirtualPsbtRequest {
678+ Template : & wrpc.FundVirtualPsbtRequest_Raw {
679+ Raw : & wrpc.TxTemplate {
680+ Recipients : recipients ,
681+ },
682+ },
683+ },
684+ )
685+ require .NoError (t .t , err )
686+
687+ // With a transaction funding should have led to a lease on the simple
688+ // assets, we'll use the balance calls to ensure that we're able to
689+ // retrieve the proper balances.
690+ rpcEmptyAssets := []* taprpc.Asset {}
691+ AssertAssetBalances (
692+ t .t , t .tapd , rpcEmptyAssets , rpcIssuableAssets , false ,
693+ )
694+
695+ AssertAssetBalances (
696+ t .t , t .tapd , rpcSimpleAssets , rpcIssuableAssets , true ,
697+ )
698+ }
0 commit comments