Merge pull request #1689 from cfromknecht/hashcache-flake

txscript/hashcache_test: fix flake due to resetting RNG
This commit is contained in:
Olaoluwa Osuntokun 2021-02-03 19:32:39 -08:00 committed by GitHub
commit fa683a69dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -13,12 +13,16 @@ import (
"github.com/davecgh/go-spew/spew" "github.com/davecgh/go-spew/spew"
) )
func init() {
rand.Seed(time.Now().Unix())
}
// genTestTx creates a random transaction for uses within test cases. // genTestTx creates a random transaction for uses within test cases.
func genTestTx() (*wire.MsgTx, error) { func genTestTx() (*wire.MsgTx, error) {
tx := wire.NewMsgTx(2) tx := wire.NewMsgTx(2)
tx.Version = rand.Int31() tx.Version = rand.Int31()
numTxins := rand.Intn(11) numTxins := 1 + rand.Intn(11)
for i := 0; i < numTxins; i++ { for i := 0; i < numTxins; i++ {
randTxIn := wire.TxIn{ randTxIn := wire.TxIn{
PreviousOutPoint: wire.OutPoint{ PreviousOutPoint: wire.OutPoint{
@ -34,7 +38,7 @@ func genTestTx() (*wire.MsgTx, error) {
tx.TxIn = append(tx.TxIn, &randTxIn) tx.TxIn = append(tx.TxIn, &randTxIn)
} }
numTxouts := rand.Intn(11) numTxouts := 1 + rand.Intn(11)
for i := 0; i < numTxouts; i++ { for i := 0; i < numTxouts; i++ {
randTxOut := wire.TxOut{ randTxOut := wire.TxOut{
Value: rand.Int63(), Value: rand.Int63(),
@ -56,8 +60,6 @@ func genTestTx() (*wire.MsgTx, error) {
func TestHashCacheAddContainsHashes(t *testing.T) { func TestHashCacheAddContainsHashes(t *testing.T) {
t.Parallel() t.Parallel()
rand.Seed(time.Now().Unix())
cache := NewHashCache(10) cache := NewHashCache(10)
var err error var err error
@ -109,8 +111,6 @@ func TestHashCacheAddContainsHashes(t *testing.T) {
func TestHashCacheAddGet(t *testing.T) { func TestHashCacheAddGet(t *testing.T) {
t.Parallel() t.Parallel()
rand.Seed(time.Now().Unix())
cache := NewHashCache(10) cache := NewHashCache(10)
// To start, we'll generate a random transaction and compute the set of // To start, we'll generate a random transaction and compute the set of
@ -144,8 +144,6 @@ func TestHashCacheAddGet(t *testing.T) {
func TestHashCachePurge(t *testing.T) { func TestHashCachePurge(t *testing.T) {
t.Parallel() t.Parallel()
rand.Seed(time.Now().Unix())
cache := NewHashCache(10) cache := NewHashCache(10)
var err error var err error