Skip to content

Commit 6ef81a5

Browse files
committed
universe: ensure that randProof produces unique outpoints
This is a bug fix to ensure that randProof makes proofs that have unique outpoints. Otherwise, it's possbile that the outpoints collide if used as a map key.
1 parent 5b4395e commit 6ef81a5

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

tapdb/universe_test.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package tapdb
22

33
import (
44
"context"
5+
crand "crypto/rand"
56
"database/sql"
67
"math"
78
"math/rand"
@@ -167,6 +168,14 @@ func randProof(t *testing.T, argAsset *asset.Asset) *proof.Proof {
167168
proofAsset = *argAsset
168169
}
169170

171+
var witnessData [32]byte
172+
_, err := crand.Read(witnessData[:])
173+
require.NoError(t, err)
174+
175+
var pkScript [32]byte
176+
_, err = crand.Read(pkScript[:])
177+
require.NoError(t, err)
178+
170179
return &proof.Proof{
171180
PrevOut: wire.OutPoint{},
172181
BlockHeader: wire.BlockHeader{
@@ -175,7 +184,11 @@ func randProof(t *testing.T, argAsset *asset.Asset) *proof.Proof {
175184
AnchorTx: wire.MsgTx{
176185
Version: 2,
177186
TxIn: []*wire.TxIn{{
178-
Witness: [][]byte{[]byte("foo")},
187+
Witness: [][]byte{witnessData[:]},
188+
}},
189+
TxOut: []*wire.TxOut{{
190+
PkScript: pkScript[:],
191+
Value: 1000,
179192
}},
180193
},
181194
TxMerkleProof: proof.TxMerkleProof{},

0 commit comments

Comments
 (0)