From 6e5c3e7264e4d46eb33dcff91ad86b671ef860d0 Mon Sep 17 00:00:00 2001 From: johnwhitton Date: Fri, 29 Mar 2019 17:39:54 -0700 Subject: [PATCH] Handle NewMask errors --- cmd/client/txgen/main.go | 7 +++++- cmd/harmony/main.go | 6 ++++- consensus/consensus.go | 14 ++++++++--- consensus/consensus_leader_msg_test.go | 10 ++++++-- consensus/consensus_leader_test.go | 30 ++++++++++++++++++----- consensus/consensus_test.go | 25 +++++++++++++++---- consensus/consensus_validator_msg_test.go | 10 ++++++-- consensus/consensus_validator_test.go | 30 ++++++++++++++++++----- node/contract_test.go | 5 +++- node/node_handler_test.go | 10 ++++++-- node/node_test.go | 26 +++++++++++++++----- node/staking_test.go | 5 +++- 12 files changed, 141 insertions(+), 37 deletions(-) diff --git a/cmd/client/txgen/main.go b/cmd/client/txgen/main.go index 262e3bd43..f557e5b40 100644 --- a/cmd/client/txgen/main.go +++ b/cmd/client/txgen/main.go @@ -124,7 +124,12 @@ func main() { } // Client/txgenerator server node setup - consensusObj := consensus.New(host, 0, nil, p2p.Peer{}, nil) + consensusObj, err := consensus.New(host, 0, nil, p2p.Peer{}, nil) + if err != nil { + fmt.Fprintf(os.Stderr, "Error :%v \n", err) + os.Exit(1) + } + clientNode := node.New(host, consensusObj, nil, false) clientNode.Client = client.NewClient(clientNode.GetHost(), shardIDs) diff --git a/cmd/harmony/main.go b/cmd/harmony/main.go index e230ac482..72a31bed7 100644 --- a/cmd/harmony/main.go +++ b/cmd/harmony/main.go @@ -199,7 +199,11 @@ func setUpConsensusAndNode(nodeConfig *nodeconfig.ConfigType) (*consensus.Consen // Consensus object. // TODO: consensus object shouldn't start here // TODO(minhdoan): During refactoring, found out that the peers list is actually empty. Need to clean up the logic of consensus later. - consensus := consensus.New(nodeConfig.Host, nodeConfig.ShardID, []p2p.Peer{}, nodeConfig.Leader, nodeConfig.ConsensusPriKey) + consensus, err := consensus.New(nodeConfig.Host, nodeConfig.ShardID, []p2p.Peer{}, nodeConfig.Leader, nodeConfig.ConsensusPriKey) + if err != nil { + fmt.Fprintf(os.Stderr, "Error :%v \n", err) + os.Exit(1) + } consensus.MinPeers = *minPeers // Current node. diff --git a/consensus/consensus.go b/consensus/consensus.go index 5d4cca2fd..0fcda6e0b 100644 --- a/consensus/consensus.go +++ b/consensus/consensus.go @@ -154,7 +154,7 @@ func (consensus *Consensus) GetNextRnd() ([32]byte, [32]byte, error) { // New creates a new Consensus object // TODO: put shardId into chain reader's chain config -func New(host p2p.Host, ShardID uint32, peers []p2p.Peer, leader p2p.Peer, blsPriKey *bls.SecretKey) *Consensus { +func New(host p2p.Host, ShardID uint32, peers []p2p.Peer, leader p2p.Peer, blsPriKey *bls.SecretKey) (*Consensus, error) { consensus := Consensus{} consensus.host = host consensus.ConsensusIDLowChan = make(chan struct{}) @@ -183,8 +183,14 @@ func New(host p2p.Host, ShardID uint32, peers []p2p.Peer, leader p2p.Peer, blsPr consensus.PublicKeys = allPublicKeys - prepareBitmap, _ := bls_cosi.NewMask(consensus.PublicKeys, consensus.leader.ConsensusPubKey) - commitBitmap, _ := bls_cosi.NewMask(consensus.PublicKeys, consensus.leader.ConsensusPubKey) + prepareBitmap, err := bls_cosi.NewMask(consensus.PublicKeys, consensus.leader.ConsensusPubKey) + if err != nil { + return nil, err + } + commitBitmap, err := bls_cosi.NewMask(consensus.PublicKeys, consensus.leader.ConsensusPubKey) + if err != nil { + return nil, err + } consensus.prepareBitmap = prepareBitmap consensus.commitBitmap = commitBitmap @@ -220,7 +226,7 @@ func New(host p2p.Host, ShardID uint32, peers []p2p.Peer, leader p2p.Peer, blsPr consensus.OfflinePeerList = make([]p2p.Peer, 0) // consensus.Log.Info("New Consensus", "IP", ip, "Port", port, "NodeID", consensus.nodeID, "priKey", consensus.priKey, "PubKey", consensus.PubKey) - return &consensus + return &consensus, nil } // RegisterPRndChannel registers the channel for receiving randomness preimage from DRG protocol diff --git a/consensus/consensus_leader_msg_test.go b/consensus/consensus_leader_msg_test.go index b093a2c20..4aba96435 100644 --- a/consensus/consensus_leader_msg_test.go +++ b/consensus/consensus_leader_msg_test.go @@ -21,7 +21,10 @@ func TestConstructAnnounceMessage(test *testing.T) { if err != nil { test.Fatalf("newhost failure: %v", err) } - consensus := New(host, 0, []p2p.Peer{leader, validator}, leader, bls.RandPrivateKey()) + consensus, err := New(host, 0, []p2p.Peer{leader, validator}, leader, bls.RandPrivateKey()) + if err != nil { + test.Fatalf("Cannot craeate consensus: %v", err) + } consensus.blockHash = [32]byte{} message := &msg_pb.Message{} @@ -49,7 +52,10 @@ func TestConstructPreparedMessage(test *testing.T) { if err != nil { test.Fatalf("newhost failure: %v", err) } - consensus := New(host, 0, []p2p.Peer{leader, validator}, leader, bls.RandPrivateKey()) + consensus, err := New(host, 0, []p2p.Peer{leader, validator}, leader, bls.RandPrivateKey()) + if err != nil { + test.Fatalf("Cannot craeate consensus: %v", err) + } consensus.blockHash = [32]byte{} message := "test string" diff --git a/consensus/consensus_leader_test.go b/consensus/consensus_leader_test.go index 86e7f4614..47d8d8c39 100644 --- a/consensus/consensus_leader_test.go +++ b/consensus/consensus_leader_test.go @@ -54,7 +54,10 @@ func TestProcessMessageLeaderPrepare(test *testing.T) { m.EXPECT().GetSelfPeer().Return(leader) m.EXPECT().SendMessageToGroups([]p2p.GroupID{p2p.GroupIDBeacon}, gomock.Any()) - consensusLeader := New(m, 0, validators, leader, leaderPriKey) + consensusLeader, err := New(m, 0, validators, leader, leaderPriKey) + if err != nil { + test.Fatalf("Cannot craeate consensus: %v", err) + } consensusLeader.blockHash = blockHash consensusValidators := make([]*Consensus, 3) @@ -66,7 +69,10 @@ func TestProcessMessageLeaderPrepare(test *testing.T) { } hosts[i] = host - consensusValidators[i] = New(hosts[i], 0, validators, leader, validatorsPriKeys[i]) + consensusValidators[i], err = New(hosts[i], 0, validators, leader, validatorsPriKeys[i]) + if err != nil { + test.Fatalf("Cannot craeate consensus: %v", err) + } consensusValidators[i].blockHash = blockHash msg := consensusValidators[i].constructPrepareMessage() msgPayload, _ := proto.GetConsensusMessagePayload(msg) @@ -102,7 +108,10 @@ func TestProcessMessageLeaderPrepareInvalidSignature(test *testing.T) { // Anything else will fail. m.EXPECT().GetSelfPeer().Return(leader) - consensusLeader := New(m, 0, validators, leader, leaderPriKey) + consensusLeader, err := New(m, 0, validators, leader, leaderPriKey) + if err != nil { + test.Fatalf("Cannot craeate consensus: %v", err) + } consensusLeader.blockHash = blockHash consensusValidators := make([]*Consensus, 3) @@ -114,7 +123,10 @@ func TestProcessMessageLeaderPrepareInvalidSignature(test *testing.T) { } hosts[i] = host - consensusValidators[i] = New(hosts[i], 0, validators, leader, validatorKeys[i]) + consensusValidators[i], err = New(hosts[i], 0, validators, leader, validatorKeys[i]) + if err != nil { + test.Fatalf("Cannot craeate consensus: %v", err) + } consensusValidators[i].blockHash = blockHash msgBytes := consensusValidators[i].constructPrepareMessage() msgPayload, _ := proto.GetConsensusMessagePayload(msgBytes) @@ -169,7 +181,10 @@ func TestProcessMessageLeaderCommit(test *testing.T) { hosts[i] = host } - consensusLeader := New(m, 0, validators, leader, leaderPriKey) + consensusLeader, err := New(m, 0, validators, leader, leaderPriKey) + if err != nil { + test.Fatalf("Cannot craeate consensus: %v", err) + } consensusLeader.state = PreparedDone consensusLeader.blockHash = blockHash consensusLeader.OnConsensusDone = func(newBlock *types.Block) {} @@ -187,7 +202,10 @@ func TestProcessMessageLeaderCommit(test *testing.T) { <-consensusLeader.ReadySignal }() for i := 0; i < 3; i++ { - consensusValidators[i] = New(hosts[i], 0, validators, leader, validatorKeys[i]) + consensusValidators[i], err = New(hosts[i], 0, validators, leader, validatorKeys[i]) + if err != nil { + test.Fatalf("Cannot craeate consensus: %v", err) + } consensusValidators[i].blockHash = blockHash payload := consensusValidators[i].constructCommitMessage(multiSigAndBitmap) msg, err := proto.GetConsensusMessagePayload(payload) diff --git a/consensus/consensus_test.go b/consensus/consensus_test.go index 8b53fd810..3a8428635 100644 --- a/consensus/consensus_test.go +++ b/consensus/consensus_test.go @@ -20,7 +20,10 @@ func TestNew(test *testing.T) { if err != nil { test.Fatalf("newhost failure: %v", err) } - consensus := New(host, 0, []p2p.Peer{leader, validator}, leader, bls.RandPrivateKey()) + consensus, err := New(host, 0, []p2p.Peer{leader, validator}, leader, bls.RandPrivateKey()) + if err != nil { + test.Fatalf("Cannot craeate consensus: %v", err) + } if consensus.consensusID != 0 { test.Errorf("Consensus Id is initialized to the wrong value: %d", consensus.consensusID) } @@ -56,7 +59,10 @@ func TestRemovePeers(t *testing.T) { if err != nil { t.Fatalf("newhost failure: %v", err) } - consensus := New(host, 0, peers, leader, nil) + consensus, err := New(host, 0, peers, leader, nil) + if err != nil { + t.Fatalf("Cannot craeate consensus: %v", err) + } // consensus.DebugPrintPublicKeys() f := consensus.RemovePeers(peerRemove) @@ -77,7 +83,10 @@ func TestGetPeerFromID(t *testing.T) { if err != nil { t.Fatalf("newhost failure: %v", err) } - consensus := New(host, 0, []p2p.Peer{leader, validator}, leader, leaderPriKey) + consensus, err := New(host, 0, []p2p.Peer{leader, validator}, leader, leaderPriKey) + if err != nil { + t.Fatalf("Cannot craeate consensus: %v", err) + } leaderAddress := utils.GetAddressFromBlsPubKey(leader.ConsensusPubKey) validatorAddress := utils.GetAddressFromBlsPubKey(validator.ConsensusPubKey) l := consensus.GetPeerByAddress(leaderAddress.Hex()) @@ -99,7 +108,10 @@ func TestPopulateMessageFields(t *testing.T) { t.Fatalf("newhost failure: %v", err) } blsPriKey := bls.RandPrivateKey() - consensus := New(host, 0, []p2p.Peer{leader, validator}, leader, blsPriKey) + consensus, err := New(host, 0, []p2p.Peer{leader, validator}, leader, blsPriKey) + if err != nil { + t.Fatalf("Cannot craeate consensus: %v", err) + } consensus.consensusID = 2 consensus.blockHash = blockHash @@ -130,7 +142,10 @@ func TestSignAndMarshalConsensusMessage(t *testing.T) { if err != nil { t.Fatalf("newhost failure: %v", err) } - consensus := New(host, 0, []p2p.Peer{leader, validator}, leader, bls.RandPrivateKey()) + consensus, err := New(host, 0, []p2p.Peer{leader, validator}, leader, bls.RandPrivateKey()) + if err != nil { + t.Fatalf("Cannot craeate consensus: %v", err) + } consensus.consensusID = 2 consensus.blockHash = blockHash consensus.SelfAddress = "fake address" diff --git a/consensus/consensus_validator_msg_test.go b/consensus/consensus_validator_msg_test.go index c394af6f0..e4e995321 100644 --- a/consensus/consensus_validator_msg_test.go +++ b/consensus/consensus_validator_msg_test.go @@ -21,7 +21,10 @@ func TestConstructPrepareMessage(test *testing.T) { if err != nil { test.Fatalf("newhost failure: %v", err) } - consensus := New(host, 0, []p2p.Peer{leader, validator}, leader, bls.RandPrivateKey()) + consensus, err := New(host, 0, []p2p.Peer{leader, validator}, leader, bls.RandPrivateKey()) + if err != nil { + test.Fatalf("Cannot craeate consensus: %v", err) + } consensus.blockHash = [32]byte{} msgBytes := consensus.constructPrepareMessage() msgBytes, err = proto.GetConsensusMessagePayload(msgBytes) @@ -47,7 +50,10 @@ func TestConstructCommitMessage(test *testing.T) { if err != nil { test.Fatalf("newhost failure: %v", err) } - consensus := New(host, 0, []p2p.Peer{leader, validator}, leader, bls.RandPrivateKey()) + consensus, err := New(host, 0, []p2p.Peer{leader, validator}, leader, bls.RandPrivateKey()) + if err != nil { + test.Fatalf("Cannot craeate consensus: %v", err) + } consensus.blockHash = [32]byte{} msg := consensus.constructCommitMessage([]byte("random string")) msg, err = proto.GetConsensusMessagePayload(msg) diff --git a/consensus/consensus_validator_test.go b/consensus/consensus_validator_test.go index 91337f267..1a13aa82b 100644 --- a/consensus/consensus_validator_test.go +++ b/consensus/consensus_validator_test.go @@ -74,7 +74,10 @@ func TestProcessMessageValidatorAnnounce(test *testing.T) { if err != nil { test.Fatalf("newhost failure: %v", err) } - consensusLeader := New(host, 0, []p2p.Peer{validator1, validator2, validator3}, leader, leaderPriKey) + consensusLeader, err := New(host, 0, []p2p.Peer{validator1, validator2, validator3}, leader, leaderPriKey) + if err != nil { + test.Fatalf("Cannot craeate consensus: %v", err) + } blockBytes, err := hex.DecodeString("f902a5f902a0a00000000000000000000000000000000000000000000000000000000000000000940000000000000000000000000000000000000000a02b418211410ee3e75b32abd925bbeba215172afa509d65c1953d4b4e505a4a2aa056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000083020000808502540be400808080a000000000000000000000000000000000000000000000000000000000000000008800000000000000008400000001b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000c0c0") consensusLeader.block = blockBytes hashBytes, err := hex.DecodeString("bdd66a8211ffcbf0ad431b506c854b49264951fd9f690928e9cf44910c381053") @@ -92,7 +95,10 @@ func TestProcessMessageValidatorAnnounce(test *testing.T) { test.Errorf("Failed to unmarshal message payload") } - consensusValidator1 := New(m, 0, []p2p.Peer{validator1, validator2, validator3}, leader, bls_cosi.RandPrivateKey()) + consensusValidator1, err := New(m, 0, []p2p.Peer{validator1, validator2, validator3}, leader, bls_cosi.RandPrivateKey()) + if err != nil { + test.Fatalf("Cannot craeate consensus: %v", err) + } consensusValidator1.ChainReader = MockChainReader{} copy(consensusValidator1.blockHash[:], hashBytes[:]) @@ -129,7 +135,10 @@ func TestProcessMessageValidatorPrepared(test *testing.T) { if err != nil { test.Fatalf("newhost failure: %v", err) } - consensusLeader := New(host, 0, []p2p.Peer{validator1, validator2, validator3}, leader, leaderPriKey) + consensusLeader, err := New(host, 0, []p2p.Peer{validator1, validator2, validator3}, leader, leaderPriKey) + if err != nil { + test.Fatalf("Cannot craeate consensus: %v", err) + } blockBytes, err := hex.DecodeString("f902a5f902a0a00000000000000000000000000000000000000000000000000000000000000000940000000000000000000000000000000000000000a02b418211410ee3e75b32abd925bbeba215172afa509d65c1953d4b4e505a4a2aa056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000083020000808502540be400808080a000000000000000000000000000000000000000000000000000000000000000008800000000000000008400000001b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000c0c0") consensusLeader.block = blockBytes hashBytes, err := hex.DecodeString("bdd66a8211ffcbf0ad431b506c854b49264951fd9f690928e9cf44910c381053") @@ -141,7 +150,10 @@ func TestProcessMessageValidatorPrepared(test *testing.T) { preparedMsg, _ := consensusLeader.constructPreparedMessage() - consensusValidator1 := New(m, 0, []p2p.Peer{validator1, validator2, validator3}, leader, bls_cosi.RandPrivateKey()) + consensusValidator1, err := New(m, 0, []p2p.Peer{validator1, validator2, validator3}, leader, bls_cosi.RandPrivateKey()) + if err != nil { + test.Fatalf("Cannot craeate consensus: %v", err) + } consensusValidator1.ChainReader = MockChainReader{} // Get actual consensus messages. @@ -199,7 +211,10 @@ func TestProcessMessageValidatorCommitted(test *testing.T) { test.Fatalf("newhost failure: %v", err) } message := &msg_pb.Message{} - consensusLeader := New(host, 0, []p2p.Peer{validator1, validator2, validator3}, leader, leaderPriKey) + consensusLeader, err := New(host, 0, []p2p.Peer{validator1, validator2, validator3}, leader, leaderPriKey) + if err != nil { + test.Fatalf("Cannot craeate consensus: %v", err) + } blockBytes, err := hex.DecodeString("f902a5f902a0a00000000000000000000000000000000000000000000000000000000000000000940000000000000000000000000000000000000000a02b418211410ee3e75b32abd925bbeba215172afa509d65c1953d4b4e505a4a2aa056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000083020000808502540be400808080a000000000000000000000000000000000000000000000000000000000000000008800000000000000008400000001b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000c0c0") consensusLeader.block = blockBytes hashBytes, err := hex.DecodeString("bdd66a8211ffcbf0ad431b506c854b49264951fd9f690928e9cf44910c381053") @@ -230,7 +245,10 @@ func TestProcessMessageValidatorCommitted(test *testing.T) { test.Errorf("Failed to get consensus message") } - consensusValidator1 := New(m, 0, []p2p.Peer{validator1, validator2, validator3}, leader, bls_cosi.RandPrivateKey()) + consensusValidator1, err := New(m, 0, []p2p.Peer{validator1, validator2, validator3}, leader, bls_cosi.RandPrivateKey()) + if err != nil { + test.Fatalf("Cannot craeate consensus: %v", err) + } consensusValidator1.ChainReader = MockChainReader{} consensusValidator1.OnConsensusDone = func(newBlock *types.Block) {} diff --git a/node/contract_test.go b/node/contract_test.go index f8c9b09db..2a1f709d5 100644 --- a/node/contract_test.go +++ b/node/contract_test.go @@ -20,7 +20,10 @@ func prepareNode(t *testing.T) *Node { if err != nil { t.Fatalf("newhost failure: %v", err) } - consensus := consensus.New(host, 0, []p2p.Peer{leader, validator}, leader, nil) + consensus, err := consensus.New(host, 0, []p2p.Peer{leader, validator}, leader, nil) + if err != nil { + t.Fatalf("Cannot craeate consensus: %v", err) + } return New(host, consensus, nil, false) } diff --git a/node/node_handler_test.go b/node/node_handler_test.go index dc014d64f..0a699e6ad 100644 --- a/node/node_handler_test.go +++ b/node/node_handler_test.go @@ -20,7 +20,10 @@ func TestAddNewBlock(t *testing.T) { if err != nil { t.Fatalf("newhost failure: %v", err) } - consensus := consensus.New(host, 0, []p2p.Peer{leader, validator}, leader, nil) + consensus, err := consensus.New(host, 0, []p2p.Peer{leader, validator}, leader, nil) + if err != nil { + t.Fatalf("Cannot craeate consensus: %v", err) + } node := New(host, consensus, nil, false) selectedTxs := node.getTransactionsForNewBlock(MaxNumberOfTransactionsPerBlock) @@ -43,7 +46,10 @@ func TestVerifyNewBlock(t *testing.T) { if err != nil { t.Fatalf("newhost failure: %v", err) } - consensus := consensus.New(host, 0, []p2p.Peer{leader, validator}, leader, nil) + consensus, err := consensus.New(host, 0, []p2p.Peer{leader, validator}, leader, nil) + if err != nil { + t.Fatalf("Cannot craeate consensus: %v", err) + } node := New(host, consensus, nil, false) selectedTxs := node.getTransactionsForNewBlock(MaxNumberOfTransactionsPerBlock) diff --git a/node/node_test.go b/node/node_test.go index fb8f03f2b..81a9eaa7c 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -28,7 +28,10 @@ func TestNewNode(t *testing.T) { if err != nil { t.Fatalf("newhost failure: %v", err) } - consensus := consensus.New(host, 0, []p2p.Peer{leader, validator}, leader, nil) + consensus, err := consensus.New(host, 0, []p2p.Peer{leader, validator}, leader, nil) + if err != nil { + t.Fatalf("Cannot craeate consensus: %v", err) + } node := New(host, consensus, nil, false) if node.Consensus == nil { t.Error("Consensus is not initialized for the node") @@ -53,8 +56,10 @@ func TestGetSyncingPeers(t *testing.T) { t.Fatalf("newhost failure: %v", err) } - consensus := consensus.New(host, 0, []p2p.Peer{leader, validator}, leader, nil) - + consensus, err := consensus.New(host, 0, []p2p.Peer{leader, validator}, leader, nil) + if err != nil { + t.Fatalf("Cannot craeate consensus: %v", err) + } node := New(host, consensus, nil, false) peer := p2p.Peer{IP: "127.0.0.1", Port: "8000"} peer2 := p2p.Peer{IP: "127.0.0.1", Port: "8001"} @@ -93,7 +98,10 @@ func TestAddPeers(t *testing.T) { if err != nil { t.Fatalf("newhost failure: %v", err) } - consensus := consensus.New(host, 0, []p2p.Peer{leader, validator}, leader, nil) + consensus, err := consensus.New(host, 0, []p2p.Peer{leader, validator}, leader, nil) + if err != nil { + t.Fatalf("Cannot craeate consensus: %v", err) + } dRand := drand.New(host, 0, []p2p.Peer{leader, validator}, leader, nil, nil) node := New(host, consensus, nil, false) @@ -136,7 +144,10 @@ func TestAddBeaconPeer(t *testing.T) { if err != nil { t.Fatalf("newhost failure: %v", err) } - consensus := consensus.New(host, 0, []p2p.Peer{leader, validator}, leader, nil) + consensus, err := consensus.New(host, 0, []p2p.Peer{leader, validator}, leader, nil) + if err != nil { + t.Fatalf("Cannot craeate consensus: %v", err) + } dRand := drand.New(host, 0, []p2p.Peer{leader, validator}, leader, nil, nil) node := New(host, consensus, nil, false) @@ -207,7 +218,10 @@ func TestPingPongHandler(t *testing.T) { if err != nil { t.Fatalf("newhost failure: %v", err) } - consensus := consensus.New(host, 0, []p2p.Peer{leader}, leader, nil) + consensus, err := consensus.New(host, 0, []p2p.Peer{leader}, leader, nil) + if err != nil { + t.Fatalf("Cannot craeate consensus: %v", err) + } node := New(host, consensus, nil, false) //go sendPingMessage(leader) go sendPongMessage(node, leader) diff --git a/node/staking_test.go b/node/staking_test.go index 71e56b161..f6d9daaaa 100644 --- a/node/staking_test.go +++ b/node/staking_test.go @@ -32,7 +32,10 @@ func TestUpdateStakingList(t *testing.T) { if err != nil { t.Fatalf("newhost failure: %v", err) } - consensus := consensus.New(host, 0, []p2p.Peer{leader, validator}, leader, nil) + consensus, err := consensus.New(host, 0, []p2p.Peer{leader, validator}, leader, nil) + if err != nil { + t.Fatalf("Cannot craeate consensus: %v", err) + } node := New(host, consensus, nil, false) for i := 0; i < 5; i++ {