Skip to content

Commit

Permalink
Merge pull request #1689 from cfromknecht/hashcache-flake
Browse files Browse the repository at this point in the history
txscript/hashcache_test: fix flake due to resetting RNG
  • Loading branch information
Roasbeef committed Feb 4, 2021
2 parents 77fd967 + 5300a19 commit fa683a6
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions txscript/hashcache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ import (
"github.com/davecgh/go-spew/spew"
)

func init() {
rand.Seed(time.Now().Unix())
}

// genTestTx creates a random transaction for uses within test cases.
func genTestTx() (*wire.MsgTx, error) {
tx := wire.NewMsgTx(2)
tx.Version = rand.Int31()

numTxins := rand.Intn(11)
numTxins := 1 + rand.Intn(11)
for i := 0; i < numTxins; i++ {
randTxIn := wire.TxIn{
PreviousOutPoint: wire.OutPoint{
Expand All @@ -34,7 +38,7 @@ func genTestTx() (*wire.MsgTx, error) {
tx.TxIn = append(tx.TxIn, &randTxIn)
}

numTxouts := rand.Intn(11)
numTxouts := 1 + rand.Intn(11)
for i := 0; i < numTxouts; i++ {
randTxOut := wire.TxOut{
Value: rand.Int63(),
Expand All @@ -56,8 +60,6 @@ func genTestTx() (*wire.MsgTx, error) {
func TestHashCacheAddContainsHashes(t *testing.T) {
t.Parallel()

rand.Seed(time.Now().Unix())

cache := NewHashCache(10)

var err error
Expand Down Expand Up @@ -109,8 +111,6 @@ func TestHashCacheAddContainsHashes(t *testing.T) {
func TestHashCacheAddGet(t *testing.T) {
t.Parallel()

rand.Seed(time.Now().Unix())

cache := NewHashCache(10)

// To start, we'll generate a random transaction and compute the set of
Expand Down Expand Up @@ -144,8 +144,6 @@ func TestHashCacheAddGet(t *testing.T) {
func TestHashCachePurge(t *testing.T) {
t.Parallel()

rand.Seed(time.Now().Unix())

cache := NewHashCache(10)

var err error
Expand Down

0 comments on commit fa683a6

Please sign in to comment.