99
99
)
100
100
101
101
const (
102
- fundingAmount = 50_000
102
+ fundingAmount = 50_000
103
+ eventuallyTimeout = time .Second * 30
104
+ eventuallyTicker = time .Millisecond * 250
103
105
)
104
106
105
107
// testCustomChannels tests that we can create a network with custom channels
@@ -380,13 +382,23 @@ func testCustomChannels(_ context.Context, net *NetworkHarness,
380
382
assertAssetChan (t .t , dave , yara , daveFundingAmount , assetID )
381
383
assertAssetChan (t .t , erin , fabia , erinFundingAmount , assetID )
382
384
385
+ // Before we start sending out payments, let's make sure each node can
386
+ // see the other one in the graph and has all required features.
387
+ require .NoError (t .t , t .lndHarness .AssertNodeKnown (charlie , dave ))
388
+ require .NoError (t .t , t .lndHarness .AssertNodeKnown (dave , charlie ))
389
+ require .NoError (t .t , t .lndHarness .AssertNodeKnown (dave , yara ))
390
+ require .NoError (t .t , t .lndHarness .AssertNodeKnown (yara , dave ))
391
+ require .NoError (t .t , t .lndHarness .AssertNodeKnown (erin , fabia ))
392
+ require .NoError (t .t , t .lndHarness .AssertNodeKnown (fabia , erin ))
393
+ require .NoError (t .t , t .lndHarness .AssertNodeKnown (charlie , erin ))
394
+
383
395
// Print initial channel balances.
384
396
logBalance (t .t , nodes , assetID , "initial" )
385
397
386
398
// ------------
387
399
// Test case 1: Send a direct keysend payment from Charlie to Dave.
388
400
// ------------
389
- const keySendAmount = 100
401
+ const keySendAmount = 1000
390
402
sendAssetKeySendPayment (
391
403
t .t , charlie , dave , keySendAmount , assetID , fn .None [int64 ](),
392
404
)
@@ -395,6 +407,12 @@ func testCustomChannels(_ context.Context, net *NetworkHarness,
395
407
charlieAssetBalance -= keySendAmount
396
408
daveAssetBalance += keySendAmount
397
409
410
+ require .Eventually (t .t , func () bool {
411
+ local , _ := getAssetChannelBalance (t .t , dave , assetID , false )
412
+
413
+ return local == daveAssetBalance
414
+ }, eventuallyTimeout , eventuallyTicker )
415
+
398
416
// We should be able to send the 100 assets back immediately, because
399
417
// there is enough on-chain balance on Dave's side to be able to create
400
418
// an HTLC.
@@ -723,18 +741,16 @@ func testCustomChannelsGroupedAsset(_ context.Context, net *NetworkHarness,
723
741
fabiaTap := newTapClient (t .t , fabia )
724
742
yaraTap := newTapClient (t .t , yara )
725
743
726
- groupAsset := itestAsset
727
- groupAsset .NewGroupedAsset = true
744
+ groupAssetReq := itest .CopyRequest (& mintrpc.MintAssetRequest {
745
+ Asset : itestAsset ,
746
+ })
747
+ groupAssetReq .Asset .NewGroupedAsset = true
728
748
729
749
// Mint an asset on Charlie and sync all nodes to Charlie as the
730
750
// universe.
731
751
mintedAssets := itest .MintAssetsConfirmBatch (
732
752
t .t , t .lndHarness .Miner .Client , charlieTap ,
733
- []* mintrpc.MintAssetRequest {
734
- {
735
- Asset : groupAsset ,
736
- },
737
- },
753
+ []* mintrpc.MintAssetRequest {groupAssetReq },
738
754
)
739
755
740
756
cents := mintedAssets [0 ]
@@ -924,13 +940,23 @@ func testCustomChannelsGroupedAsset(_ context.Context, net *NetworkHarness,
924
940
assertAssetChan (t .t , dave , yara , daveFundingAmount , assetID )
925
941
assertAssetChan (t .t , erin , fabia , erinFundingAmount , assetID )
926
942
943
+ // Before we start sending out payments, let's make sure each node can
944
+ // see the other one in the graph and has all required features.
945
+ require .NoError (t .t , t .lndHarness .AssertNodeKnown (charlie , dave ))
946
+ require .NoError (t .t , t .lndHarness .AssertNodeKnown (dave , charlie ))
947
+ require .NoError (t .t , t .lndHarness .AssertNodeKnown (dave , yara ))
948
+ require .NoError (t .t , t .lndHarness .AssertNodeKnown (yara , dave ))
949
+ require .NoError (t .t , t .lndHarness .AssertNodeKnown (erin , fabia ))
950
+ require .NoError (t .t , t .lndHarness .AssertNodeKnown (fabia , erin ))
951
+ require .NoError (t .t , t .lndHarness .AssertNodeKnown (charlie , erin ))
952
+
927
953
// Print initial channel balances.
928
954
logBalance (t .t , nodes , assetID , "initial" )
929
955
930
956
// ------------
931
957
// Test case 1: Send a direct keysend payment from Charlie to Dave.
932
958
// ------------
933
- const keySendAmount = 100
959
+ const keySendAmount = 1000
934
960
sendAssetKeySendPayment (
935
961
t .t , charlie , dave , keySendAmount , assetID , fn .None [int64 ](),
936
962
)
@@ -939,6 +965,12 @@ func testCustomChannelsGroupedAsset(_ context.Context, net *NetworkHarness,
939
965
charlieAssetBalance -= keySendAmount
940
966
daveAssetBalance += keySendAmount
941
967
968
+ require .Eventually (t .t , func () bool {
969
+ local , _ := getAssetChannelBalance (t .t , dave , assetID , false )
970
+
971
+ return local == daveAssetBalance
972
+ }, eventuallyTimeout , eventuallyTicker )
973
+
942
974
// We should be able to send the 100 assets back immediately, because
943
975
// there is enough on-chain balance on Dave's side to be able to create
944
976
// an HTLC.
@@ -1261,7 +1293,7 @@ func testCustomChannelsForceClose(_ context.Context, net *NetworkHarness,
1261
1293
t .Logf ("Funded channel between Charlie and Dave: %v" , assetFundResp )
1262
1294
1263
1295
// With the channel open, mine a block to confirm it.
1264
- mineBlocks (t , net , 6 , 1 )
1296
+ mineBlocksSlow (t , net , 6 , 1 )
1265
1297
1266
1298
// A transfer for the funding transaction should be found in Charlie's
1267
1299
// DB.
@@ -1276,9 +1308,7 @@ func testCustomChannelsForceClose(_ context.Context, net *NetworkHarness,
1276
1308
1277
1309
// Charlie's balance should reflect that the funding asset was added to
1278
1310
// the DB.
1279
- assertAssetBalance (
1280
- t .t , charlieTap , assetID , uint64 (itestAsset .Amount ),
1281
- )
1311
+ assertAssetBalance (t .t , charlieTap , assetID , itestAsset .Amount )
1282
1312
1283
1313
// Make sure that Charlie properly uploaded funding proof to the
1284
1314
// Universe server.
@@ -1291,6 +1321,14 @@ func testCustomChannelsForceClose(_ context.Context, net *NetworkHarness,
1291
1321
),
1292
1322
)
1293
1323
1324
+ // Make sure the channel shows the correct asset information.
1325
+ assertAssetChan (t .t , charlie , dave , fundingAmount , assetID )
1326
+
1327
+ // Before we start sending out payments, let's make sure each node can
1328
+ // see the other one in the graph and has all required features.
1329
+ require .NoError (t .t , t .lndHarness .AssertNodeKnown (charlie , dave ))
1330
+ require .NoError (t .t , t .lndHarness .AssertNodeKnown (dave , charlie ))
1331
+
1294
1332
// We'll also have dave sync with Charlie+Zane to ensure he has the
1295
1333
// proof for the funding output. We sync the transfers as well so he
1296
1334
// has all the proofs needed.
@@ -1441,22 +1479,6 @@ func testCustomChannelsForceClose(_ context.Context, net *NetworkHarness,
1441
1479
t .t , charlieSweepTransfer ,
1442
1480
))
1443
1481
1444
- charlieUTXOs , err := charlieTap .ListUtxos (
1445
- ctxb , & taprpc.ListUtxosRequest {},
1446
- )
1447
- require .NoError (t .t , err )
1448
-
1449
- t .Logf ("Charlie UTXOs: %v" , toProtoJSON (t .t , charlieUTXOs ))
1450
-
1451
- daveUTXOs , err := daveTap .ListUtxos (
1452
- ctxb , & taprpc.ListUtxosRequest {},
1453
- )
1454
- require .NoError (t .t , err )
1455
-
1456
- t .Logf ("Dave UTXOs: %v" , toProtoJSON (t .t , daveUTXOs ))
1457
-
1458
- // TODO(roasbeef): assert 2 charlie UTXOs
1459
-
1460
1482
// Both sides should now reflect their updated asset balances.
1461
1483
daveBalance := uint64 (numPayments * keySendAmount )
1462
1484
charlieBalance := itestAsset .Amount - daveBalance
@@ -1465,26 +1487,12 @@ func testCustomChannelsForceClose(_ context.Context, net *NetworkHarness,
1465
1487
1466
1488
// Dave should have a single managed UTXO that shows he has a new asset
1467
1489
// UTXO he can use.
1468
- err = wait .NoError (func () error {
1469
- daveUTXOs , err = daveTap .ListUtxos (
1470
- ctxb , & taprpc.ListUtxosRequest {},
1471
- )
1472
- if err != nil {
1473
- return err
1474
- }
1475
-
1476
- if len (daveUTXOs .ManagedUtxos ) != 1 {
1477
- return fmt .Errorf ("expected 1 UTXO, got %d" ,
1478
- len (daveUTXOs .ManagedUtxos ))
1479
- }
1480
-
1481
- return nil
1482
- }, defaultTimeout )
1483
- require .NoError (t .t , err )
1484
-
1485
- t .Logf ("Dave UTXOs: %v" , toProtoJSON (t .t , daveUTXOs ))
1490
+ assertNumAssetUTXOs (t .t , daveTap , 1 )
1491
+ assertNumAssetUTXOs (t .t , charlieTap , 2 )
1486
1492
}
1487
1493
1494
+ // testCustomChannelsBreach tests a force close scenario that breaches an old
1495
+ // state, after both parties have an active asset balance.
1488
1496
func testCustomChannelsBreach (_ context.Context , net * NetworkHarness ,
1489
1497
t * harnessTest ) {
1490
1498
@@ -1528,6 +1536,7 @@ func testCustomChannelsBreach(_ context.Context, net *NetworkHarness,
1528
1536
connectAllNodes (t .t , net , nodes )
1529
1537
fundAllNodes (t .t , net , nodes )
1530
1538
1539
+ universeTap := newTapClient (t .t , zane )
1531
1540
charlieTap := newTapClient (t .t , charlie )
1532
1541
daveTap := newTapClient (t .t , dave )
1533
1542
@@ -1569,7 +1578,39 @@ func testCustomChannelsBreach(_ context.Context, net *NetworkHarness,
1569
1578
// With the channel open, mine a block to confirm it.
1570
1579
mineBlocks (t , net , 6 , 1 )
1571
1580
1572
- time .Sleep (time .Second * 1 )
1581
+ // A transfer for the funding transaction should be found in Charlie's
1582
+ // DB.
1583
+ fundingTxid , err := chainhash .NewHashFromStr (assetFundResp .Txid )
1584
+ require .NoError (t .t , err )
1585
+ assetFundingTransfer := locateAssetTransfers (
1586
+ t .t , charlieTap , * fundingTxid ,
1587
+ )
1588
+
1589
+ t .Logf ("Channel funding transfer: %v" ,
1590
+ toProtoJSON (t .t , assetFundingTransfer ))
1591
+
1592
+ // Charlie's balance should reflect that the funding asset was added to
1593
+ // the DB.
1594
+ assertAssetBalance (t .t , charlieTap , assetID , itestAsset .Amount )
1595
+
1596
+ // Make sure that Charlie properly uploaded funding proof to the
1597
+ // Universe server.
1598
+ fundingScriptTree := tapchannel .NewFundingScriptTree ()
1599
+ fundingScriptKey := fundingScriptTree .TaprootKey
1600
+ fundingScriptTreeBytes := fundingScriptKey .SerializeCompressed ()
1601
+ assertUniverseProofExists (
1602
+ t .t , universeTap , assetID , fundingScriptTreeBytes , fmt .Sprintf (
1603
+ "%v:%v" , assetFundResp .Txid , assetFundResp .OutputIndex ,
1604
+ ),
1605
+ )
1606
+
1607
+ // Make sure the channel shows the correct asset information.
1608
+ assertAssetChan (t .t , charlie , dave , fundingAmount , assetID )
1609
+
1610
+ // Before we start sending out payments, let's make sure each node can
1611
+ // see the other one in the graph and has all required features.
1612
+ require .NoError (t .t , t .lndHarness .AssertNodeKnown (charlie , dave ))
1613
+ require .NoError (t .t , t .lndHarness .AssertNodeKnown (dave , charlie ))
1573
1614
1574
1615
// Next, we'll make keysend payments from Charlie to Dave. we'll use
1575
1616
// this to reach a state where both parties have funds in the channel.
@@ -1672,8 +1713,10 @@ func assertNumAssetUTXOs(t *testing.T, tapdClient *tapClient,
1672
1713
1673
1714
ctxb := context .Background ()
1674
1715
1716
+ var clientUTXOs * taprpc.ListUtxosResponse
1675
1717
err := wait .NoError (func () error {
1676
- clientUTXOs , err := tapdClient .ListUtxos (
1718
+ var err error
1719
+ clientUTXOs , err = tapdClient .ListUtxos (
1677
1720
ctxb , & taprpc.ListUtxosRequest {},
1678
1721
)
1679
1722
if err != nil {
@@ -1687,21 +1730,8 @@ func assertNumAssetUTXOs(t *testing.T, tapdClient *tapClient,
1687
1730
1688
1731
return nil
1689
1732
}, defaultTimeout )
1690
-
1691
- clientUTXOs , err2 := tapdClient .ListUtxos (
1692
- ctxb , & taprpc.ListUtxosRequest {},
1693
- )
1694
- require .NoError (t , err2 )
1695
-
1696
- if err != nil {
1697
- t .Logf ("wrong amount of UTXOs, got %d, expected %d: %v" ,
1698
- len (clientUTXOs .ManagedUtxos ), numUTXOs ,
1699
- toProtoJSON (t , clientUTXOs ))
1700
-
1701
- t .Fatalf ("failed to assert UTXOs: %v" , err )
1702
-
1703
- return nil
1704
- }
1733
+ require .NoErrorf (t , err , "failed to assert UTXOs: %v, last state: %v" ,
1734
+ err , clientUTXOs )
1705
1735
1706
1736
return clientUTXOs
1707
1737
}
0 commit comments