Skip to content

Commit dbe3eff

Browse files
committed
tapgarden: wait for asset registration in TestBookAssetSyncer
Update TestBookAssetSyncer to wait until the asset is registered with the address book. This reduces test flakiness and improves reliability of the unit tests.
1 parent 44e6844 commit dbe3eff

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

tapgarden/custodian_test.go

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -584,12 +584,28 @@ func TestBookAssetSyncer(t *testing.T) {
584584
// If we add the asset to the asset syncer, address creation should
585585
// succeed.
586586
h.syncer.AddAsset(*newAsset)
587-
addrVersion = test.RandFlip(address.V0, address.V1)
588-
newAddr, err := h.addrBook.NewAddress(
589-
ctx, addrVersion, newAsset.ID(), 1, nil, proofCourierAddr,
590-
)
587+
588+
// Fetch the asset from the syncer. This should trigger the
589+
// background goroutine to add the asset to the address book.
590+
_, err = h.syncer.FetchAsset(newAsset.ID())
591591
require.NoError(t, err)
592-
require.NotNil(t, newAddr)
592+
593+
// Eventually, the asset should be registered and we should be able to
594+
// create a new address for it.
595+
var newAddr *address.AddrWithKeyInfo
596+
addrVersion = test.RandFlip(address.V0, address.V1)
597+
598+
require.Eventually(t, func() bool {
599+
newAddr, err = h.addrBook.NewAddress(
600+
ctx, addrVersion, newAsset.ID(), 1, nil,
601+
proofCourierAddr,
602+
)
603+
if err != nil {
604+
return false
605+
}
606+
607+
return newAddr != nil
608+
}, defaultTimeout, wait.PollInterval)
593609

594610
h.keyRing.AssertNumberOfCalls(t, "DeriveNextTaprootAssetKey", 2)
595611

0 commit comments

Comments
 (0)