Skip to content

Commit e7918c1

Browse files
committed
itest: add proper assertions for asset UTXOs
1 parent 5aa2a03 commit e7918c1

File tree

2 files changed

+73
-10
lines changed

2 files changed

+73
-10
lines changed

itest/assets_test.go

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/lightninglabs/taproot-assets/proof"
2121
"github.com/lightninglabs/taproot-assets/rfqmsg"
2222
"github.com/lightninglabs/taproot-assets/tapchannel"
23+
"github.com/lightninglabs/taproot-assets/tapfreighter"
2324
"github.com/lightninglabs/taproot-assets/taprpc"
2425
"github.com/lightninglabs/taproot-assets/taprpc/assetwalletrpc"
2526
"github.com/lightninglabs/taproot-assets/taprpc/mintrpc"
@@ -890,16 +891,41 @@ func createAssetInvoice(t *testing.T, dstRfqPeer, dst *HarnessNode,
890891
return invoiceResp
891892
}
892893

894+
func waitForSendEvent(t *testing.T,
895+
sendEvents taprpc.TaprootAssets_SubscribeSendEventsClient,
896+
expectedState tapfreighter.SendState) {
897+
898+
for {
899+
sendEvent, err := sendEvents.Recv()
900+
require.NoError(t, err)
901+
902+
t.Logf("Received send event: %v", sendEvent.SendState)
903+
if sendEvent.SendState == expectedState.String() {
904+
return
905+
}
906+
}
907+
}
908+
893909
func closeAssetChannelAndAssert(t *harnessTest, net *NetworkHarness,
894910
local, remote *HarnessNode, chanPoint *lnrpc.ChannelPoint,
895911
assetID, groupKey []byte, universeTap *tapClient, remoteBtcBalance,
896912
remoteAssetBalance bool) {
897913

914+
ctxb := context.Background()
915+
ctxt, cancel := context.WithTimeout(ctxb, defaultTimeout)
916+
defer cancel()
917+
898918
closeStream, _, err := t.lndHarness.CloseChannel(
899919
local, chanPoint, false,
900920
)
901921
require.NoError(t.t, err)
902922

923+
localTapd := newTapClient(t.t, local)
924+
sendEvents, err := localTapd.SubscribeSendEvents(
925+
ctxt, &taprpc.SubscribeSendEventsRequest{},
926+
)
927+
require.NoError(t.t, err)
928+
903929
mineBlocks(t, net, 1, 1)
904930

905931
closeUpdate, err := t.lndHarness.WaitForChannelClose(closeStream)
@@ -913,6 +939,14 @@ func closeAssetChannelAndAssert(t *harnessTest, net *NetworkHarness,
913939
t.Logf("Channel closed with txid: %v", closeTxid)
914940
t.Logf("Close transaction: %v", spew.Sdump(closeTx))
915941

942+
// TODO(guggero): Remove this if once the receiver of a channel imports
943+
// the proofs correctly as well.
944+
if localTapd.node.Name() != "Yara" {
945+
waitForSendEvent(
946+
t.t, sendEvents, tapfreighter.SendStateComplete,
947+
)
948+
}
949+
916950
// With the channel closed, we'll now assert that the co-op close
917951
// transaction was inserted into the local universe.
918952
//
@@ -1028,8 +1062,6 @@ func closeAssetChannelAndAssert(t *harnessTest, net *NetworkHarness,
10281062
fmt.Sprintf("%v:%v", closeTxid, localAssetIndex),
10291063
)
10301064

1031-
localTapd := newTapClient(t.t, local)
1032-
10331065
scriptKey, err := btcec.ParsePubKey(scriptKeyBytes)
10341066
require.NoError(t.t, err)
10351067
assertAssetExists(

itest/litd_custom_channels_test.go

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ func testCustomChannels(_ context.Context, net *NetworkHarness,
447447
)
448448

449449
// Charlie should still have four asset pieces, two with the same size.
450+
assertNumAssetOutputs(t.t, charlieTap, assetID, 2)
450451
assertAssetExists(
451452
t.t, charlieTap, assetID, charlieAssetBalance-fundingAmount,
452453
nil, true, false, false,
@@ -456,14 +457,44 @@ func testCustomChannels(_ context.Context, net *NetworkHarness,
456457
false,
457458
)
458459

459-
// For some reason, the channel funding output of the immediately closed
460-
// channel is still present in the asset DB, even after we import the
461-
// co-op close transaction proof.
462-
// TODO(guggero): Investigate this. The actual number of outputs should
463-
// be two here, and we shouldn't have the extra fundingAmount in the
464-
// balance.
465-
charlieAssetBalance += fundingAmount
466-
assertNumAssetOutputs(t.t, charlieTap, assetID, 3)
460+
// Dave should have two outputs, one from the initial channel with Yara
461+
// and one from the remaining amount of the channel with Charlie.
462+
assertNumAssetOutputs(t.t, daveTap, assetID, 2)
463+
daveFirstChannelRemainder := daveFundingAmount - yaraInvoiceAssetAmount1
464+
assertAssetExists(
465+
t.t, daveTap, assetID, daveFirstChannelRemainder, nil, true,
466+
true, false,
467+
)
468+
assertAssetExists(
469+
t.t, daveTap, assetID,
470+
daveAssetBalance-daveFirstChannelRemainder, nil, true, true,
471+
false,
472+
)
473+
474+
// Fabia and Yara should all have a single output each, just what was
475+
// left over from the initial channel.
476+
assertNumAssetOutputs(t.t, fabiaTap, assetID, 1)
477+
assertAssetExists(
478+
t.t, fabiaTap, assetID, fabiaAssetBalance, nil, true, true,
479+
false,
480+
)
481+
assertNumAssetOutputs(t.t, yaraTap, assetID, 1)
482+
assertAssetExists(
483+
t.t, yaraTap, assetID, yaraAssetBalance, nil, true, true, false,
484+
)
485+
486+
// Erin didn't use all of his assets when opening the channel, so he
487+
// should have two outputs, the change from the channel opening and the
488+
// remaining amount after closing the channel.
489+
assertNumAssetOutputs(t.t, erinTap, assetID, 2)
490+
erinChange := startAmount - erinFundingAmount
491+
assertAssetExists(
492+
t.t, erinTap, assetID, erinAssetBalance-erinChange, nil, true,
493+
true, false,
494+
)
495+
assertAssetExists(
496+
t.t, erinTap, assetID, erinChange, nil, true, false, false,
497+
)
467498

468499
// The asset balances should still remain unchanged.
469500
assertAssetBalance(t.t, charlieTap, assetID, charlieAssetBalance)

0 commit comments

Comments
 (0)