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

@@ -9,7 +9,7 @@ import (
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/libs/rand"
"github.com/tendermint/tendermint/proxy"
sm "github.com/tendermint/tendermint/state"
"github.com/tendermint/tendermint/types"
@@ -64,7 +64,7 @@ func makeAndApplyGoodBlock(state sm.State, height int64, lastCommit *types.Commi
return state, types.BlockID{}, err
}
blockID := types.BlockID{Hash: block.Hash(),
PartsHeader: types.PartSetHeader{Total: 3, Hash: cmn.RandBytes(32)}}
PartsHeader: types.PartSetHeader{Total: 3, Hash: rand.RandBytes(32)}}
state, err := blockExec.ApplyBlock(state, blockID, block)
if err != nil {
return state, types.BlockID{}, err

View File

@@ -12,8 +12,8 @@ import (
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto/ed25519"
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/libs/kv"
"github.com/tendermint/tendermint/libs/rand"
sm "github.com/tendermint/tendermint/state"
dbm "github.com/tendermint/tm-db"
@@ -316,17 +316,17 @@ func TestProposerFrequency(t *testing.T) {
maxPower := 1000
nTestCases := 5
for i := 0; i < nTestCases; i++ {
N := cmn.RandInt()%maxVals + 1
N := rand.RandInt()%maxVals + 1
vals := make([]*types.Validator, N)
totalVotePower := int64(0)
for j := 0; j < N; j++ {
// make sure votePower > 0
votePower := int64(cmn.RandInt()%maxPower) + 1
votePower := int64(rand.RandInt()%maxPower) + 1
totalVotePower += votePower
privVal := types.NewMockPV()
pubKey := privVal.GetPubKey()
val := types.NewValidator(pubKey, votePower)
val.ProposerPriority = cmn.RandInt64()
val.ProposerPriority = rand.RandInt64()
vals[j] = val
}
valSet := types.NewValidatorSet(vals)
@@ -343,7 +343,7 @@ func genValSetWithPowers(powers []int64) *types.ValidatorSet {
for i := 0; i < size; i++ {
totalVotePower += powers[i]
val := types.NewValidator(ed25519.GenPrivKey().PubKey(), powers[i])
val.ProposerPriority = cmn.RandInt64()
val.ProposerPriority = rand.RandInt64()
vals[i] = val
}
valSet := types.NewValidatorSet(vals)

View File

@@ -7,7 +7,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/libs/rand"
sm "github.com/tendermint/tendermint/state"
"github.com/tendermint/tendermint/types"
dbm "github.com/tendermint/tm-db"
@@ -23,12 +23,12 @@ func TestTxFilter(t *testing.T) {
tx types.Tx
isErr bool
}{
{types.Tx(cmn.RandBytes(250)), false},
{types.Tx(cmn.RandBytes(1811)), false},
{types.Tx(cmn.RandBytes(1831)), false},
{types.Tx(cmn.RandBytes(1838)), true},
{types.Tx(cmn.RandBytes(1839)), true},
{types.Tx(cmn.RandBytes(3000)), true},
{types.Tx(rand.RandBytes(250)), false},
{types.Tx(rand.RandBytes(1811)), false},
{types.Tx(rand.RandBytes(1831)), false},
{types.Tx(rand.RandBytes(1838)), true},
{types.Tx(rand.RandBytes(1839)), true},
{types.Tx(rand.RandBytes(3000)), true},
}
for i, tc := range testCases {

View File

@@ -12,9 +12,9 @@ import (
db "github.com/tendermint/tm-db"
abci "github.com/tendermint/tendermint/abci/types"
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/libs/kv"
"github.com/tendermint/tendermint/libs/pubsub/query"
"github.com/tendermint/tendermint/libs/rand"
"github.com/tendermint/tendermint/state/txindex"
"github.com/tendermint/tendermint/types"
)
@@ -325,7 +325,7 @@ func benchmarkTxIndex(txsCount int64, b *testing.B) {
batch := txindex.NewBatch(txsCount)
txIndex := uint32(0)
for i := int64(0); i < txsCount; i++ {
tx := cmn.RandBytes(250)
tx := rand.RandBytes(250)
txResult := &types.TxResult{
Height: 1,
Index: txIndex,