Skip to content

Commit 8eff420

Browse files
authored
Merge pull request #811 from lightninglabs/flake-fix
Fix unit and integration test flakes
2 parents f756868 + 14940ca commit 8eff420

11 files changed

+93
-22
lines changed

Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,15 @@ endif
212212

213213
flakehunter: build-itest
214214
@$(call print, "Flake hunting ${backend} integration tests.")
215-
while [ $$? -eq 0 ]; do make itest-only; done
215+
while [ $$? -eq 0 ]; do make itest-only-trace; done
216216

217217
flake-unit:
218218
@$(call print, "Flake hunting unit tests.")
219-
while [ $$? -eq 0 ]; do '$(GOLIST) | $(XARGS) env $(GOTEST) -test.timeout=20m -count=1'; done
219+
while [ $$? -eq 0 ]; do make unit nocache=1; done
220+
221+
flake-unit-trace:
222+
@$(call print, "Flake hunting unit tests in debug mode.")
223+
while [ $$? -eq 0 ]; do make unit-trace nocache=1; done
220224

221225
flake-unit-race:
222226
@$(call print, "Flake hunting races in unit tests.")

itest/assertions.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,6 +1198,34 @@ func AssertUniverseRootEquality(t *testing.T,
11981198
))
11991199
}
12001200

1201+
// AssertUniverseRootEqualityEventually checks that the universe roots returned
1202+
// by two daemons are either equal eventually.
1203+
func AssertUniverseRootEqualityEventually(t *testing.T,
1204+
clientA, clientB unirpc.UniverseClient) {
1205+
1206+
ctxb := context.Background()
1207+
ctxt, cancel := context.WithTimeout(ctxb, defaultWaitTimeout)
1208+
defer cancel()
1209+
1210+
err := wait.NoError(func() error {
1211+
rootRequest := &unirpc.AssetRootRequest{}
1212+
universeRootsAlice, err := clientA.AssetRoots(ctxt, rootRequest)
1213+
require.NoError(t, err)
1214+
universeRootsBob, err := clientB.AssetRoots(ctxt, rootRequest)
1215+
require.NoError(t, err)
1216+
1217+
if !AssertUniverseRootsEqual(
1218+
universeRootsAlice, universeRootsBob,
1219+
) {
1220+
1221+
return fmt.Errorf("roots not equal")
1222+
}
1223+
1224+
return nil
1225+
}, defaultWaitTimeout)
1226+
require.NoError(t, err)
1227+
}
1228+
12011229
// AssertUniverseRoot makes sure the given universe root exists with the given
12021230
// sum, either identified by the asset ID or group key.
12031231
func AssertUniverseRoot(t *testing.T, client unirpc.UniverseClient,

itest/multi_asset_group_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,10 @@ func testMultiAssetGroupSend(t *harnessTest) {
317317
collectibleGroupMembers + 1,
318318
})
319319

320+
AssertUniverseRootEqualityEventually(
321+
t.t, t.tapd, t.universeServer.service,
322+
)
323+
320324
// We'll make a second node now that'll be the receiver of all the
321325
// assets made above.
322326
secondTapd := setupTapdHarness(
@@ -326,6 +330,10 @@ func testMultiAssetGroupSend(t *harnessTest) {
326330
require.NoError(t.t, secondTapd.stop(!*noDelete))
327331
}()
328332

333+
AssertUniverseRootEqualityEventually(
334+
t.t, secondTapd, t.universeServer.service,
335+
)
336+
329337
// Send 5 of the assets to Bob, and verify that they are received.
330338
numUnits := issuableAsset.Asset.Amount
331339
assetType := issuableAsset.Asset.AssetType

proof/mock.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,29 @@ func (m *MockProofCourier) ReceiveProof(_ context.Context,
268268
return nil, ErrProofNotFound
269269
}
270270

271-
return proof, nil
271+
return &AnnotatedProof{
272+
Locator: Locator{
273+
AssetID: proof.Locator.AssetID,
274+
GroupKey: proof.Locator.GroupKey,
275+
ScriptKey: proof.Locator.ScriptKey,
276+
OutPoint: proof.Locator.OutPoint,
277+
},
278+
Blob: proof.Blob,
279+
AssetSnapshot: &AssetSnapshot{
280+
Asset: proof.AssetSnapshot.Asset,
281+
OutPoint: proof.AssetSnapshot.OutPoint,
282+
AnchorBlockHash: proof.AssetSnapshot.AnchorBlockHash,
283+
AnchorBlockHeight: proof.AssetSnapshot.AnchorBlockHeight,
284+
AnchorTxIndex: proof.AssetSnapshot.AnchorTxIndex,
285+
AnchorTx: proof.AssetSnapshot.AnchorTx,
286+
OutputIndex: proof.AssetSnapshot.OutputIndex,
287+
InternalKey: proof.AssetSnapshot.InternalKey,
288+
ScriptRoot: proof.AssetSnapshot.ScriptRoot,
289+
TapscriptSibling: proof.AssetSnapshot.TapscriptSibling,
290+
SplitAsset: proof.AssetSnapshot.SplitAsset,
291+
MetaReveal: proof.AssetSnapshot.MetaReveal,
292+
},
293+
}, nil
272294
}
273295

274296
// SetSubscribers sets the set of subscribers that will be notified

rpcserver.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3873,7 +3873,7 @@ func (r *rpcServer) QueryProof(ctx context.Context,
38733873
}
38743874

38753875
rpcsLog.Tracef("[QueryProof]: fetching proof at (universeID=%v, "+
3876-
"leafKey=%x)", universeID, leafKey.UniverseKey())
3876+
"leafKey=%x)", universeID.StringForLog(), leafKey.UniverseKey())
38773877

38783878
// Retrieve proof export config for the given universe.
38793879
syncConfigs, err := r.cfg.UniverseFederation.QuerySyncConfigs(ctx)
@@ -3937,7 +3937,8 @@ func (r *rpcServer) QueryProof(ctx context.Context,
39373937

39383938
rpcsLog.Debugf("[QueryProof]: error querying for "+
39393939
"proof at (universeID=%v, leafKey=%x)",
3940-
universeID, leafKey.UniverseKey())
3940+
universeID.StringForLog(),
3941+
leafKey.UniverseKey())
39413942
return nil, err
39423943
}
39433944

@@ -3953,12 +3954,13 @@ func (r *rpcServer) QueryProof(ctx context.Context,
39533954

39543955
// TODO(roasbeef): query may return multiple proofs, if allow key to
39553956
// not be fully specified
3956-
proof := proofs[0]
3957+
firstProof := proofs[0]
39573958

39583959
rpcsLog.Tracef("[QueryProof]: found proof at (universeID=%v, "+
3959-
"leafKey=%x)", universeID, leafKey.UniverseKey())
3960+
"leafKey=%x)", universeID.StringForLog(),
3961+
leafKey.UniverseKey())
39603962

3961-
return r.marshalUniverseProofLeaf(ctx, req, proof)
3963+
return r.marshalUniverseProofLeaf(ctx, req, firstProof)
39623964
}
39633965

39643966
// unmarshalAssetLeaf unmarshals an asset leaf from the RPC form.

tapdb/asset_minting.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,10 +1096,11 @@ func (a *AssetMintingStore) CommitSignedGenesisTx(ctx context.Context,
10961096
AnchorUtxoID: sqlInt64(utxoID),
10971097
})
10981098
if err != nil {
1099-
return fmt.Errorf("unable to anchor pending assets: %w", err)
1099+
return fmt.Errorf("unable to anchor pending assets: %w",
1100+
err)
11001101
}
11011102

1102-
// Next, we'll anchor the genesis point to point to the chain
1103+
// Next, we'll anchor the genesis point-to-point to the chain
11031104
// transaction we inserted above.
11041105
if err := q.AnchorGenesisPoint(ctx, GenesisPointAnchor{
11051106
PrevOut: genesisOutpoint,

tapdb/asset_minting_test.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ func TestCommitMintingBatchSeedlings(t *testing.T) {
244244
mintingBatch := tapgarden.RandSeedlingMintingBatch(t, numSeedlings)
245245
addRandGroupToBatch(t, assetStore, ctx, mintingBatch.Seedlings)
246246
err := assetStore.CommitMintingBatch(ctx, mintingBatch)
247-
require.NoError(t, err, "unable to write batch: %v", err)
247+
require.NoError(t, err)
248248

249249
batchKey := mintingBatch.BatchKey.PubKey
250250

@@ -267,11 +267,9 @@ func TestCommitMintingBatchSeedlings(t *testing.T) {
267267
// Pick a random seedling and give it a specific group.
268268
addRandGroupToBatch(t, assetStore, ctx, seedlings)
269269
mintingBatch.Seedlings = mergeMap(mintingBatch.Seedlings, seedlings)
270-
require.NoError(t,
271-
assetStore.AddSeedlingsToBatch(
272-
ctx, batchKey, maps.Values(seedlings)...,
273-
), "unable to write seedlings: %v", err,
274-
)
270+
require.NoError(t, assetStore.AddSeedlingsToBatch(
271+
ctx, batchKey, maps.Values(seedlings)...,
272+
))
275273

276274
// If we read the batch from disk again, then we should have 10 total
277275
// seedlings, and the batch still matches what we wrote to disk.
@@ -1088,7 +1086,7 @@ func TestGroupAnchors(t *testing.T) {
10881086
)
10891087
addMultiAssetGroupToBatch(t, mintingBatch.Seedlings)
10901088
err := assetStore.CommitMintingBatch(ctx, mintingBatch)
1091-
require.NoError(t, err, "unable to write batch: %v", err)
1089+
require.NoError(t, err)
10921090

10931091
batchKey := mintingBatch.BatchKey.PubKey
10941092

tapdb/multiverse.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ func namespaceForProof(proofType universe.ProofType) (string, error) {
538538
return transferMultiverseNS, nil
539539

540540
default:
541-
return "", fmt.Errorf("unknown proof type: %v", int(proofType))
541+
return "", fmt.Errorf("unknown proof type: %d", int(proofType))
542542
}
543543
}
544544

tapdb/sqlutils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func parseCoalesceNumericType[T constraints.Integer](value any) (T, error) {
167167
parsedValue, err := strconv.ParseInt(typedValue, 10, 64)
168168
if err != nil {
169169
return 0, fmt.Errorf("unable to parse value '%v' as "+
170-
"number: %v", value, err)
170+
"number: %w", value, err)
171171
}
172172

173173
return T(parsedValue), nil

tapgarden/custodian.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,14 @@ func (c *Custodian) watchInboundAssets() {
284284
continue
285285
}
286286

287+
// If this event is not yet confirmed, we don't yet expect a
288+
// proof to be delivered. We'll wait for the confirmation to
289+
// come in, and then we'll launch a goroutine to use the
290+
// ProofCourier to import the proof into our local DB.
291+
if event.ConfirmationHeight == 0 {
292+
continue
293+
}
294+
287295
// If we didn't find a proof, we'll launch a goroutine to use
288296
// the ProofCourier to import the proof into our local DB.
289297
c.Wg.Add(1)
@@ -530,7 +538,8 @@ func (c *Custodian) receiveProof(addr *address.Tap, op wire.OutPoint) error {
530538
ctx, headerVerifier, c.cfg.GroupVerifier, false, addrProof,
531539
)
532540
if err != nil {
533-
return fmt.Errorf("unable to import proofs: %w", err)
541+
return fmt.Errorf("unable to import proofs script_key=%x, "+
542+
"asset_id=%x: %w", scriptKeyBytes, assetID[:], err)
534543
}
535544

536545
// The proof is now verified and in our local archive. We will now

tapgarden/planter_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import (
1111
"testing"
1212
"time"
1313

14-
"github.com/lightninglabs/taproot-assets/tapsend"
15-
1614
"github.com/btcsuite/btcd/blockchain"
1715
"github.com/btcsuite/btcd/btcec/v2"
1816
"github.com/btcsuite/btcd/btcutil"
@@ -30,6 +28,7 @@ import (
3028
_ "github.com/lightninglabs/taproot-assets/tapdb" // Register relevant drivers.
3129
"github.com/lightninglabs/taproot-assets/tapgarden"
3230
"github.com/lightninglabs/taproot-assets/tapscript"
31+
"github.com/lightninglabs/taproot-assets/tapsend"
3332
"github.com/lightningnetwork/lnd/build"
3433
"github.com/lightningnetwork/lnd/keychain"
3534
"github.com/lightningnetwork/lnd/lntest/wait"

0 commit comments

Comments
 (0)