Merge pull request #1113 from LeoHChen/blskey_nil_error

[blskey] add error message when blskey is nil
pull/1115/head
Leo Chen 5 years ago committed by GitHub
commit d3d5a45d35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      consensus/consensus.go
  2. 10
      node/node_handler_test.go
  3. 25
      node/node_test.go

@ -2,6 +2,7 @@
package consensus // consensus
import (
"fmt"
"math/big"
"sync"
"time"
@ -256,6 +257,9 @@ func New(host p2p.Host, ShardID uint32, leader p2p.Peer, blsPriKey *bls.SecretKe
consensus.priKey = blsPriKey
consensus.PubKey = blsPriKey.GetPublicKey()
utils.GetLogInstance().Info("my pubkey is", "pubkey", consensus.PubKey.SerializeToHexStr())
} else {
utils.GetLogInstance().Error("the bls key is nil")
return nil, fmt.Errorf("nil bls key, aborting")
}
// viewID has to be initialized as the height of the blockchain during initialization

@ -12,14 +12,15 @@ import (
)
func TestAddNewBlock(t *testing.T) {
pubKey := bls.RandPrivateKey().GetPublicKey()
blsKey := bls.RandPrivateKey()
pubKey := blsKey.GetPublicKey()
leader := p2p.Peer{IP: "127.0.0.1", Port: "9882", ConsensusPubKey: pubKey}
priKey, _, _ := utils.GenKeyP2P("127.0.0.1", "9902")
host, err := p2pimpl.NewHost(&leader, priKey)
if err != nil {
t.Fatalf("newhost failure: %v", err)
}
consensus, err := consensus.New(host, 0, leader, nil)
consensus, err := consensus.New(host, 0, leader, blsKey)
if err != nil {
t.Fatalf("Cannot craeate consensus: %v", err)
}
@ -37,14 +38,15 @@ func TestAddNewBlock(t *testing.T) {
}
func TestVerifyNewBlock(t *testing.T) {
pubKey := bls.RandPrivateKey().GetPublicKey()
blsKey := bls.RandPrivateKey()
pubKey := blsKey.GetPublicKey()
leader := p2p.Peer{IP: "127.0.0.1", Port: "8882", ConsensusPubKey: pubKey}
priKey, _, _ := utils.GenKeyP2P("127.0.0.1", "9902")
host, err := p2pimpl.NewHost(&leader, priKey)
if err != nil {
t.Fatalf("newhost failure: %v", err)
}
consensus, err := consensus.New(host, 0, leader, nil)
consensus, err := consensus.New(host, 0, leader, blsKey)
if err != nil {
t.Fatalf("Cannot craeate consensus: %v", err)
}

@ -24,14 +24,15 @@ import (
var testDBFactory = &shardchain.MemDBFactory{}
func TestNewNode(t *testing.T) {
pubKey := bls2.RandPrivateKey().GetPublicKey()
blsKey := bls2.RandPrivateKey()
pubKey := blsKey.GetPublicKey()
leader := p2p.Peer{IP: "127.0.0.1", Port: "8882", ConsensusPubKey: pubKey}
priKey, _, _ := utils.GenKeyP2P("127.0.0.1", "9902")
host, err := p2pimpl.NewHost(&leader, priKey)
if err != nil {
t.Fatalf("newhost failure: %v", err)
}
consensus, err := consensus.New(host, 0, leader, nil)
consensus, err := consensus.New(host, 0, leader, blsKey)
if err != nil {
t.Fatalf("Cannot craeate consensus: %v", err)
}
@ -50,7 +51,8 @@ func TestNewNode(t *testing.T) {
}
func TestGetSyncingPeers(t *testing.T) {
pubKey := bls2.RandPrivateKey().GetPublicKey()
blsKey := bls2.RandPrivateKey()
pubKey := blsKey.GetPublicKey()
leader := p2p.Peer{IP: "127.0.0.1", Port: "8882", ConsensusPubKey: pubKey}
priKey, _, _ := utils.GenKeyP2P("127.0.0.1", "9902")
host, err := p2pimpl.NewHost(&leader, priKey)
@ -58,7 +60,7 @@ func TestGetSyncingPeers(t *testing.T) {
t.Fatalf("newhost failure: %v", err)
}
consensus, err := consensus.New(host, 0, leader, nil)
consensus, err := consensus.New(host, 0, leader, blsKey)
if err != nil {
t.Fatalf("Cannot craeate consensus: %v", err)
}
@ -92,7 +94,8 @@ func TestAddPeers(t *testing.T) {
ConsensusPubKey: pubKey2,
},
}
pubKey := bls2.RandPrivateKey().GetPublicKey()
blsKey := bls2.RandPrivateKey()
pubKey := blsKey.GetPublicKey()
leader := p2p.Peer{IP: "127.0.0.1", Port: "8982", ConsensusPubKey: pubKey}
validator := p2p.Peer{IP: "127.0.0.1", Port: "8985"}
priKey, _, _ := utils.GenKeyP2P("127.0.0.1", "9902")
@ -100,7 +103,7 @@ func TestAddPeers(t *testing.T) {
if err != nil {
t.Fatalf("newhost failure: %v", err)
}
consensus, err := consensus.New(host, 0, leader, nil)
consensus, err := consensus.New(host, 0, leader, blsKey)
if err != nil {
t.Fatalf("Cannot craeate consensus: %v", err)
}
@ -138,7 +141,8 @@ func TestAddBeaconPeer(t *testing.T) {
PeerID: "4567",
},
}
pubKey := bls2.RandPrivateKey().GetPublicKey()
blsKey := bls2.RandPrivateKey()
pubKey := blsKey.GetPublicKey()
leader := p2p.Peer{IP: "127.0.0.1", Port: "8982", ConsensusPubKey: pubKey}
validator := p2p.Peer{IP: "127.0.0.1", Port: "8985"}
priKey, _, _ := utils.GenKeyP2P("127.0.0.1", "9902")
@ -146,7 +150,7 @@ func TestAddBeaconPeer(t *testing.T) {
if err != nil {
t.Fatalf("newhost failure: %v", err)
}
consensus, err := consensus.New(host, 0, leader, nil)
consensus, err := consensus.New(host, 0, leader, blsKey)
if err != nil {
t.Fatalf("Cannot craeate consensus: %v", err)
}
@ -212,7 +216,8 @@ func exitServer() {
}
func TestPingPongHandler(t *testing.T) {
pubKey := bls2.RandPrivateKey().GetPublicKey()
blsKey := bls2.RandPrivateKey()
pubKey := blsKey.GetPublicKey()
leader := p2p.Peer{IP: "127.0.0.1", Port: "8881", ConsensusPubKey: pubKey}
// validator := p2p.Peer{IP: "127.0.0.1", Port: "9991"}
priKey, _, _ := utils.GenKeyP2P("127.0.0.1", "9902")
@ -220,7 +225,7 @@ func TestPingPongHandler(t *testing.T) {
if err != nil {
t.Fatalf("newhost failure: %v", err)
}
consensus, err := consensus.New(host, 0, leader, nil)
consensus, err := consensus.New(host, 0, leader, blsKey)
if err != nil {
t.Fatalf("Cannot craeate consensus: %v", err)
}

Loading…
Cancel
Save