Skip to content

Commit 7c3a8d4

Browse files
committed
proof: return copy of mock proof
This fixes a unit test race condition where two goroutines would be operating on the same proof because they both received the same reference from the mock. This would not happen in production as the proof archive always creates a new proof object. So we fix the race by also creating a unique copy of the mocked proof whenever it is requested.
1 parent e3144a9 commit 7c3a8d4

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

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

0 commit comments

Comments
 (0)