Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

txscript/hashcache_test: fix flake due to resetting RNG #1689

Merged
merged 2 commits into from
Feb 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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