diff options
author | Sonic <sonic@cobinhood.com> | 2018-10-17 18:02:52 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-04-09 21:32:50 +0800 |
commit | bd9a6326be84eb74f6fec8c4045d931208a051ed (patch) | |
tree | 4722d6c7d5fa758c8cc6d2ab80b12d95c216c1d4 /dex/nodetable_test.go | |
parent | cd094147171175d49c82dd9783ce880f6307e175 (diff) | |
download | dexon-bd9a6326be84eb74f6fec8c4045d931208a051ed.tar dexon-bd9a6326be84eb74f6fec8c4045d931208a051ed.tar.gz dexon-bd9a6326be84eb74f6fec8c4045d931208a051ed.tar.bz2 dexon-bd9a6326be84eb74f6fec8c4045d931208a051ed.tar.lz dexon-bd9a6326be84eb74f6fec8c4045d931208a051ed.tar.xz dexon-bd9a6326be84eb74f6fec8c4045d931208a051ed.tar.zst dexon-bd9a6326be84eb74f6fec8c4045d931208a051ed.zip |
dex: polish network related function
Diffstat (limited to 'dex/nodetable_test.go')
-rw-r--r-- | dex/nodetable_test.go | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/dex/nodetable_test.go b/dex/nodetable_test.go index 5b3f7de57..2e44eabe5 100644 --- a/dex/nodetable_test.go +++ b/dex/nodetable_test.go @@ -1,11 +1,13 @@ package dex import ( - "math/rand" + "crypto/ecdsa" "testing" "time" "github.com/dexon-foundation/dexon/common" + "github.com/dexon-foundation/dexon/crypto" + "github.com/dexon-foundation/dexon/p2p/discover" "github.com/dexon-foundation/dexon/p2p/enode" ) @@ -85,9 +87,14 @@ func TestNodeTable(t *testing.T) { } } -func randomID() (id enode.ID) { - for i := range id { - id[i] = byte(rand.Intn(255)) +func randomID() enode.ID { + var err error + var privkey *ecdsa.PrivateKey + for { + privkey, err = crypto.GenerateKey() + if err == nil { + break + } } - return id + return discover.PubkeyID(&(privkey.PublicKey)) } |