Skip to content

Commit 62b431e

Browse files
committed
itest: check batch equality after a transfer
1 parent 4f16d2d commit 62b431e

File tree

2 files changed

+94
-1
lines changed

2 files changed

+94
-1
lines changed

itest/assets_test.go

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"context"
66
"crypto/tls"
77
"net/http"
8+
"slices"
9+
"strings"
810
"time"
911

1012
"github.com/btcsuite/btcd/btcec/v2"
@@ -24,6 +26,7 @@ import (
2426
"github.com/stretchr/testify/require"
2527
"golang.org/x/exp/maps"
2628
"golang.org/x/net/http2"
29+
"google.golang.org/protobuf/proto"
2730
)
2831

2932
var (
@@ -438,7 +441,6 @@ func testMintAssetsWithTapscriptSibling(t *harnessTest) {
438441
rpcIssuableAssets := MintAssetsConfirmBatch(
439442
t.t, t.lndHarness.Miner.Client, t.tapd, issuableAssets,
440443
)
441-
442444
AssertAssetBalances(t.t, t.tapd, rpcSimpleAssets, rpcIssuableAssets)
443445

444446
// Filter the managed UTXOs to select the genesis UTXO with the
@@ -528,3 +530,90 @@ func testMintAssetsWithTapscriptSibling(t *harnessTest) {
528530
t.lndHarness.MineBlocksAndAssertNumTxes(1, 1)
529531
t.lndHarness.AssertNumUTXOsWithConf(t.lndHarness.Bob, 1, 1, 1)
530532
}
533+
534+
// testMintBatchAndTransfer tests that we can mint a batch of assets, observe
535+
// the finalized batch state, and observe the same batch state after a transfer
536+
// of an asset from the batch.
537+
func testMintBatchAndTransfer(t *harnessTest) {
538+
ctxb := context.Background()
539+
rpcSimpleAssets := MintAssetsConfirmBatch(
540+
t.t, t.lndHarness.Miner.Client, t.tapd, simpleAssets,
541+
)
542+
543+
// List the batch right after minting.
544+
originalBatches, err := t.tapd.ListBatches(
545+
ctxb, &mintrpc.ListBatchRequest{},
546+
)
547+
require.NoError(t.t, err)
548+
549+
// We'll make a second node now that'll be the receiver of all the
550+
// assets made above.
551+
secondTapd := setupTapdHarness(
552+
t.t, t, t.lndHarness.Bob, t.universeServer,
553+
)
554+
defer func() {
555+
require.NoError(t.t, secondTapd.stop(!*noDelete))
556+
}()
557+
558+
// In order to force a split, we don't try to send the full first asset.
559+
a := rpcSimpleAssets[0]
560+
addr, events := NewAddrWithEventStream(
561+
t.t, secondTapd, &taprpc.NewAddrRequest{
562+
AssetId: a.AssetGenesis.AssetId,
563+
Amt: a.Amount - 1,
564+
AssetVersion: a.Version,
565+
},
566+
)
567+
568+
AssertAddrCreated(t.t, secondTapd, a, addr)
569+
570+
sendResp, sendEvents := sendAssetsToAddr(t, t.tapd, addr)
571+
sendRespJSON, err := formatProtoJSON(sendResp)
572+
require.NoError(t.t, err)
573+
574+
t.Logf("Got response from sending assets: %v", sendRespJSON)
575+
576+
// Make sure that eventually we see a single event for the
577+
// address.
578+
AssertAddrEvent(t.t, secondTapd, addr, 1, statusDetected)
579+
580+
// Mine a block to make sure the events are marked as confirmed.
581+
MineBlocks(t.t, t.lndHarness.Miner.Client, 1, 1)
582+
583+
// Eventually the event should be marked as confirmed.
584+
AssertAddrEvent(t.t, secondTapd, addr, 1, statusConfirmed)
585+
586+
// Make sure we have imported and finalized all proofs.
587+
AssertNonInteractiveRecvComplete(t.t, secondTapd, 1)
588+
AssertSendEventsComplete(t.t, addr.ScriptKey, sendEvents)
589+
590+
// Make sure the receiver has received all events in order for
591+
// the address.
592+
AssertReceiveEvents(t.t, addr, events)
593+
594+
afterBatches, err := t.tapd.ListBatches(
595+
ctxb, &mintrpc.ListBatchRequest{},
596+
)
597+
require.NoError(t.t, err)
598+
599+
// The batch listed after the transfer should be identical to the batch
600+
// listed before the transfer.
601+
require.Equal(
602+
t.t, len(originalBatches.Batches), len(afterBatches.Batches),
603+
)
604+
605+
originalBatch := originalBatches.Batches[0].Batch
606+
afterBatch := afterBatches.Batches[0].Batch
607+
608+
// Sort the assets from the listed batch before comparison.
609+
slices.SortFunc(originalBatch.Assets,
610+
func(a, b *mintrpc.PendingAsset) int {
611+
return strings.Compare(a.Name, b.Name)
612+
})
613+
slices.SortFunc(afterBatch.Assets,
614+
func(a, b *mintrpc.PendingAsset) int {
615+
return strings.Compare(a.Name, b.Name)
616+
})
617+
618+
require.True(t.t, proto.Equal(originalBatch, afterBatch))
619+
}

itest/test_list_on_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ var testCases = []*testCase{
1313
name: "mint batch resume",
1414
test: testMintBatchResume,
1515
},
16+
{
17+
name: "mint batch and transfer",
18+
test: testMintBatchAndTransfer,
19+
},
1620
{
1721
name: "asset meta validation",
1822
test: testAssetMeta,

0 commit comments

Comments
 (0)