Fixed random hash function for unit test.

This commit is contained in:
parmmarrushabh 2018-10-23 12:21:59 +05:30
parent 4582a6238d
commit 97e089b50c
3 changed files with 26 additions and 16 deletions

View file

@ -9,9 +9,9 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/contracts"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/crypto"
"math/rand"
)
var (
@ -40,7 +40,7 @@ func TestBlockSigner(t *testing.T) {
}
contractBackend.ForEachStorageAt(ctx, blockSignerAddress, nil, f)
byte0 := contracts.RandomHash()
byte0 := randomHash()
// Test sign.
tx, err := blockSigner.Sign(big.NewInt(50), byte0)
@ -57,4 +57,15 @@ func TestBlockSigner(t *testing.T) {
for _, it := range signers {
t.Log("signer", it.String())
}
}
// Generate random string.
func randomHash() common.Hash {
letterBytes := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789"
var b common.Hash
for i := range b {
rand.Seed(time.Now().UnixNano())
b[i] = letterBytes[rand.Intn(len(letterBytes))]
}
return b
}

View file

@ -14,8 +14,6 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"math/big"
"math/rand"
"time"
)
const (
@ -224,15 +222,4 @@ func GetRewardBalancesRate(masterAddr common.Address, totalReward *big.Int, vali
log.Info("Holders reward", "holders", string(jsonHolders), "master node", masterAddr.String())
return balances, nil
}
// Generate random string.
func RandomHash() common.Hash {
letterBytes := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789"
var b common.Hash
for i := range b {
rand.Seed(time.Now().UnixNano())
b[i] = letterBytes[rand.Intn(len(letterBytes))]
}
return b
}

View file

@ -13,6 +13,7 @@ import (
"math/big"
"math/rand"
"testing"
"time"
)
func TestSendTxSign(t *testing.T) {
@ -56,7 +57,7 @@ func TestSendTxSign(t *testing.T) {
signCount := int64(0)
blockHashes := make([]common.Hash, 10)
for i := int64(0); i < 10; i++ {
blockHash := RandomHash()
blockHash := randomHash()
blockHashes[i] = blockHash
randIndex := rand.Intn(len(keys))
accKey := keys[randIndex]
@ -118,4 +119,15 @@ func TestSendTxSign(t *testing.T) {
//if rewards.Cmp(new(big.Int).SetUint64(14999999999999999996)) != 0 {
// t.Errorf("Total reward not same reward checkpoint: %v - %v", chainReward, rewards)
//}
}
// Generate random string.
func randomHash() common.Hash {
letterBytes := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789"
var b common.Hash
for i := range b {
rand.Seed(time.Now().UnixNano())
b[i] = letterBytes[rand.Intn(len(letterBytes))]
}
return b
}