github.com/koko1123/flow-go-1@v0.29.6/fvm/environment/unsafe_random_generator_test.go (about) 1 package environment_test 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/require" 7 8 "github.com/koko1123/flow-go-1/fvm/environment" 9 "github.com/koko1123/flow-go-1/fvm/tracing" 10 "github.com/koko1123/flow-go-1/model/flow" 11 ) 12 13 func TestUnsafeRandomGenerator(t *testing.T) { 14 t.Run("UnsafeRandom doesnt re-seed the random", func(t *testing.T) { 15 bh := &flow.Header{} 16 17 urg := environment.NewUnsafeRandomGenerator(tracing.NewTracerSpan(), bh) 18 19 // 10 random numbers. extremely unlikely to get the same number all the time and just fail the test by chance 20 N := 10 21 22 numbers := make([]uint64, N) 23 24 for i := 0; i < N; i++ { 25 u, err := urg.UnsafeRandom() 26 require.NoError(t, err) 27 numbers[i] = u 28 } 29 30 allEqual := true 31 for i := 1; i < N; i++ { 32 allEqual = allEqual && numbers[i] == numbers[0] 33 } 34 require.True(t, !allEqual) 35 }) 36 }