Skip to content

Commit f3b095b

Browse files
committed
wip
1 parent a9f4a2c commit f3b095b

File tree

4 files changed

+116
-9
lines changed

4 files changed

+116
-9
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module github.com/lightninglabs/lightning-terminal
22

33
require (
4-
github.com/btcsuite/btcd v0.24.3-0.20240921052913-67b8efd3ba53
4+
github.com/btcsuite/btcd v0.24.3-0.20241210095828-e646d437e95b
55
github.com/btcsuite/btcd/btcec/v2 v2.3.4
66
github.com/btcsuite/btcd/btcutil v1.1.5
77
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0
@@ -236,4 +236,4 @@ replace google.golang.org/protobuf => github.com/lightninglabs/protobuf-go-hex-d
236236

237237
replace github.com/lightninglabs/taproot-assets => ../taproot-assets
238238

239-
go 1.22.6
239+
go 1.23.6

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -651,8 +651,8 @@ github.com/boombuler/barcode v1.0.1/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl
651651
github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ=
652652
github.com/btcsuite/btcd v0.22.0-beta.0.20220111032746-97732e52810c/go.mod h1:tjmYdS6MLJ5/s0Fj4DbLgSbDHbEqLJrtnHecBFkdz5M=
653653
github.com/btcsuite/btcd v0.23.5-0.20231215221805-96c9fd8078fd/go.mod h1:nm3Bko6zh6bWP60UxwoT5LzdGJsQJaPo6HjduXq9p6A=
654-
github.com/btcsuite/btcd v0.24.3-0.20240921052913-67b8efd3ba53 h1:XOZ/wRGHkKv0AqxfDks5IkzaQ1Ge6fq322ZOOG5VIkU=
655-
github.com/btcsuite/btcd v0.24.3-0.20240921052913-67b8efd3ba53/go.mod h1:zHK7t7sw8XbsCkD64WePHE3r3k9/XoGAcf6mXV14c64=
654+
github.com/btcsuite/btcd v0.24.3-0.20241210095828-e646d437e95b h1:VQoobSrWdxICuqFU3tKVu/Lzk7BTk9SsCgRr5dUvC70=
655+
github.com/btcsuite/btcd v0.24.3-0.20241210095828-e646d437e95b/go.mod h1:zHK7t7sw8XbsCkD64WePHE3r3k9/XoGAcf6mXV14c64=
656656
github.com/btcsuite/btcd/btcec/v2 v2.1.0/go.mod h1:2VzYrv4Gm4apmbVVsSq5bqf1Ec8v56E48Vt0Y/umPgA=
657657
github.com/btcsuite/btcd/btcec/v2 v2.1.3/go.mod h1:ctjw4H1kknNJmRN4iP1R7bTQ+v3GJkZBd6mui8ZsAZE=
658658
github.com/btcsuite/btcd/btcec/v2 v2.3.4 h1:3EJjcN70HCu/mwqlUsGK8GcNVyLVxFDlWurTXGPFfiQ=

itest/assets_test.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2208,6 +2208,69 @@ func assertSpendableBalance(t *testing.T, client *tapClient, assetID []byte,
22082208
}
22092209
}
22102210

2211+
// assertSpendableBalanceGroup differs from assertAssetBalance in that it
2212+
// asserts that the entire balance is spendable. We consider something spendable
2213+
// if we have a local script key for it.
2214+
func assertSpendableBalanceGroup(t *testing.T, client *tapClient,
2215+
gropupKey []byte, expectedBalance uint64) {
2216+
2217+
t.Helper()
2218+
2219+
ctxb := context.Background()
2220+
ctxt, cancel := context.WithTimeout(ctxb, shortTimeout)
2221+
defer cancel()
2222+
2223+
err := wait.NoError(func() error {
2224+
utxos, err := client.ListUtxos(ctxt, &taprpc.ListUtxosRequest{})
2225+
if err != nil {
2226+
return err
2227+
}
2228+
2229+
assets := tapfn.FlatMap(
2230+
maps.Values(utxos.ManagedUtxos),
2231+
func(utxo *taprpc.ManagedUtxo) []*taprpc.Asset {
2232+
return utxo.Assets
2233+
},
2234+
)
2235+
2236+
relevantAssets := fn.Filter(func(utxo *taprpc.Asset) bool {
2237+
return bytes.Equal(
2238+
utxo.AssetGroup.TweakedGroupKey, gropupKey,
2239+
)
2240+
}, assets)
2241+
2242+
var assetSum uint64
2243+
for _, asset := range relevantAssets {
2244+
if asset.ScriptKeyIsLocal {
2245+
assetSum += asset.Amount
2246+
}
2247+
}
2248+
2249+
if assetSum != expectedBalance {
2250+
return fmt.Errorf("expected balance %d, got %d",
2251+
expectedBalance, assetSum)
2252+
}
2253+
2254+
return nil
2255+
}, shortTimeout)
2256+
if err != nil {
2257+
r, err2 := client.ListAssets(ctxb, &taprpc.ListAssetRequest{})
2258+
require.NoError(t, err2)
2259+
2260+
t.Logf("Failed to assert expected balance of %d, current "+
2261+
"assets: %v", expectedBalance, toProtoJSON(t, r))
2262+
2263+
utxos, err3 := client.ListUtxos(
2264+
ctxb, &taprpc.ListUtxosRequest{},
2265+
)
2266+
require.NoError(t, err3)
2267+
2268+
t.Logf("Current UTXOs: %v", toProtoJSON(t, utxos))
2269+
2270+
t.Fatalf("Failed to assert balance: %v", err)
2271+
}
2272+
}
2273+
22112274
func assertNumAssetOutputs(t *testing.T, client *tapClient, assetID []byte,
22122275
numPieces int) {
22132276

itest/litd_custom_channels_test.go

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,9 +1256,18 @@ func testCustomChannelsGroupedAssetTranches(ctx context.Context,
12561256

12571257
// ------------
12581258
// Test case 1: Send a few direct keysend payment from Charlie to Dave.
1259+
// We want to send at least 30k assets, so we use up one channel
1260+
// internal tranche of assets and should at least once have an HTLC
1261+
// that transports assets from two tranches.
12591262
// ------------
1260-
const keySendAmount = 100
1261-
for i := 0; i < 5; i++ {
1263+
const (
1264+
keySendAmount = 5000
1265+
numSends = 6
1266+
totalFirstSend = keySendAmount * numSends
1267+
)
1268+
for i := 0; i < numSends; i++ {
1269+
// TODO(guggero): Actually specify group key here instead of
1270+
// assetID1 once that is supported by the API.
12621271
sendAssetKeySendPayment(
12631272
t.t, charlie, dave, keySendAmount, assetID1,
12641273
fn.None[int64](),
@@ -1269,7 +1278,9 @@ func testCustomChannelsGroupedAssetTranches(ctx context.Context,
12691278
// ------------
12701279
// Test case 2: Send a few direct keysend payment from Erin to Fabia.
12711280
// ------------
1272-
for i := 0; i < 5; i++ {
1281+
for i := 0; i < numSends; i++ {
1282+
// TODO(guggero): Actually specify group key here instead of
1283+
// assetID1 once that is supported by the API.
12731284
sendAssetKeySendPayment(
12741285
t.t, erin, fabia, keySendAmount, assetID1,
12751286
fn.None[int64](),
@@ -1290,7 +1301,10 @@ func testCustomChannelsGroupedAssetTranches(ctx context.Context,
12901301
noOpCoOpCloseBalanceCheck,
12911302
)
12921303

1293-
// TODO: assertSpendableBalance(t.t, charlieTap, assetID1, 0)
1304+
assertSpendableBalanceGroup(
1305+
t.t, charlieTap, groupKey, fundingAmount-totalFirstSend+2,
1306+
)
1307+
assertSpendableBalanceGroup(t.t, daveTap, groupKey, totalFirstSend)
12941308

12951309
// ------------
12961310
// Test case 4: Force close the channel between Erin and Fabia.
@@ -1340,7 +1354,37 @@ func testCustomChannelsGroupedAssetTranches(ctx context.Context,
13401354

13411355
mineBlocks(t, net, 1, 1)
13421356

1343-
// TODO: assertSpendableBalance(t.t, charlieTap, assetID1, 0)
1357+
// Fabia should have her sweep output confirmed now and the assets
1358+
// should be back in her on-chain wallet and spendable.
1359+
assertSpendableBalanceGroup(t.t, fabiaTap, groupKey, totalFirstSend)
1360+
1361+
// Next, we'll mine three additional blocks to trigger the CSV delay
1362+
// for Erin.
1363+
mineBlocks(t, net, 3, 0)
1364+
1365+
// We expect that Erin's sweep transaction has been broadcast.
1366+
erinSweepTxid, err := waitForNTxsInMempool(
1367+
net.Miner.Client, 1, shortTimeout,
1368+
)
1369+
require.NoError(t.t, err)
1370+
1371+
t.Logf("Erin sweep txid: %v", erinSweepTxid)
1372+
1373+
// Now we'll mine a block to confirm Erin's sweep transaction.
1374+
mineBlocks(t, net, 1, 0)
1375+
1376+
// Charlie should now have an asset transfer for his sweep transaction.
1377+
erinSweepTransfer := locateAssetTransfers(
1378+
t.t, erinTap, *erinSweepTxid[0],
1379+
)
1380+
1381+
t.Logf("Erin sweep transfer: %v", toProtoJSON(
1382+
t.t, erinSweepTransfer,
1383+
))
1384+
1385+
assertSpendableBalanceGroup(
1386+
t.t, erinTap, groupKey, fundingAmount-totalFirstSend,
1387+
)
13441388
}
13451389

13461390
// testCustomChannelsForceClose tests a force close scenario after both parties

0 commit comments

Comments
 (0)