libs/common: refactor libs/common 2 (#4231)

* libs/common: refactor libs/common 2

- move random function to there own pkg

Signed-off-by: Marko Baricevic <marbar3778@yahoo.com>

* change imports and usage throughout repo

* fix goimports

* add changelog entry
This commit is contained in:
Marko
2019-12-10 18:38:34 +01:00
committed by GitHub
parent dfebac86f7
commit afc4d7a61f
55 changed files with 221 additions and 196 deletions

View File

@@ -5,7 +5,7 @@ import (
"github.com/stretchr/testify/require"
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/libs/rand"
. "github.com/tendermint/tendermint/libs/test"
"github.com/tendermint/tendermint/crypto/tmhash"
@@ -23,7 +23,7 @@ func TestSimpleProof(t *testing.T) {
items := make([][]byte, total)
for i := 0; i < total; i++ {
items[i] = testItem(cmn.RandBytes(tmhash.Size))
items[i] = testItem(rand.RandBytes(tmhash.Size))
}
rootHash := SimpleHashFromByteSlices(items)
@@ -47,7 +47,7 @@ func TestSimpleProof(t *testing.T) {
// Trail too long should make it fail
origAunts := proof.Aunts
proof.Aunts = append(proof.Aunts, cmn.RandBytes(32))
proof.Aunts = append(proof.Aunts, rand.RandBytes(32))
err = proof.Verify(rootHash, item)
require.Error(t, err, "Expected verification to fail for wrong trail length")
@@ -76,7 +76,7 @@ func TestSimpleHashAlternatives(t *testing.T) {
items := make([][]byte, total)
for i := 0; i < total; i++ {
items[i] = testItem(cmn.RandBytes(tmhash.Size))
items[i] = testItem(rand.RandBytes(tmhash.Size))
}
rootHash1 := SimpleHashFromByteSlicesIterative(items)
@@ -89,7 +89,7 @@ func BenchmarkSimpleHashAlternatives(b *testing.B) {
items := make([][]byte, total)
for i := 0; i < total; i++ {
items[i] = testItem(cmn.RandBytes(tmhash.Size))
items[i] = testItem(rand.RandBytes(tmhash.Size))
}
b.ResetTimer()

View File

@@ -7,12 +7,12 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
cmn "github.com/tendermint/tendermint/libs/common"
tmrand "github.com/tendermint/tendermint/libs/rand"
)
func randCompactBitArray(bits int) (*CompactBitArray, []byte) {
numBytes := (bits + 7) / 8
src := cmn.RandBytes((bits + 7) / 8)
src := tmrand.RandBytes((bits + 7) / 8)
bA := NewCompactBitArray(bits)
for i := 0; i < numBytes-1; i++ {