diff --git a/api/proto/discovery/pingpong_test.go b/api/proto/discovery/pingpong_test.go index 0257ab4cf..3895190c8 100644 --- a/api/proto/discovery/pingpong_test.go +++ b/api/proto/discovery/pingpong_test.go @@ -89,6 +89,9 @@ func TestSerialize(test *testing.T) { buf2 = pong1.ConstructPongMessage() msg2, err := proto.GetMessagePayload(buf2) + if err != nil { + test.Error("GetMessagePayload Failed!") + } pong, err := GetPongMessage(msg2) if err != nil { test.Error("Pong failed!") diff --git a/api/service/explorer/service.go b/api/service/explorer/service.go index 30b4f597b..ef66e8906 100644 --- a/api/service/explorer/service.go +++ b/api/service/explorer/service.go @@ -146,12 +146,19 @@ func (s *Service) GetExplorerBlocks(w http.ResponseWriter, r *http.Request) { } db := s.storage.GetDB() fromInt, err := strconv.Atoi(from) + if err != nil { + json.NewEncoder(w).Encode(data.Blocks) + return + } var toInt int if to == "" { - bytes, err := db.Get([]byte(BlockHeightKey)) - if err == nil { - toInt, err = strconv.Atoi(string(bytes)) - } + toInt, err = func() (int, error) { + bytes, err := db.Get([]byte(BlockHeightKey)) + if err == nil { + return strconv.Atoi(string(bytes)) + } + return toInt, err + }() } else { toInt, err = strconv.Atoi(to) } diff --git a/consensus/consensus_validator_test.go b/consensus/consensus_validator_test.go index 1a13aa82b..c7b893115 100644 --- a/consensus/consensus_validator_test.go +++ b/consensus/consensus_validator_test.go @@ -79,8 +79,14 @@ func TestProcessMessageValidatorAnnounce(test *testing.T) { test.Fatalf("Cannot craeate consensus: %v", err) } blockBytes, err := hex.DecodeString("f902a5f902a0a00000000000000000000000000000000000000000000000000000000000000000940000000000000000000000000000000000000000a02b418211410ee3e75b32abd925bbeba215172afa509d65c1953d4b4e505a4a2aa056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000083020000808502540be400808080a000000000000000000000000000000000000000000000000000000000000000008800000000000000008400000001b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000c0c0") + if err != nil { + test.Fatalf("Cannot decode blockByte: %v", err) + } consensusLeader.block = blockBytes hashBytes, err := hex.DecodeString("bdd66a8211ffcbf0ad431b506c854b49264951fd9f690928e9cf44910c381053") + if err != nil { + test.Fatalf("Cannot decode hashByte: %v", err) + } copy(consensusLeader.blockHash[:], hashBytes[:]) @@ -140,8 +146,14 @@ func TestProcessMessageValidatorPrepared(test *testing.T) { test.Fatalf("Cannot craeate consensus: %v", err) } blockBytes, err := hex.DecodeString("f902a5f902a0a00000000000000000000000000000000000000000000000000000000000000000940000000000000000000000000000000000000000a02b418211410ee3e75b32abd925bbeba215172afa509d65c1953d4b4e505a4a2aa056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000083020000808502540be400808080a000000000000000000000000000000000000000000000000000000000000000008800000000000000008400000001b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000c0c0") + if err != nil { + test.Fatalf("Cannot decode blockByte: %v", err) + } consensusLeader.block = blockBytes hashBytes, err := hex.DecodeString("bdd66a8211ffcbf0ad431b506c854b49264951fd9f690928e9cf44910c381053") + if err != nil { + test.Fatalf("Cannot decode hashByte: %v", err) + } copy(consensusLeader.blockHash[:], hashBytes[:]) @@ -216,8 +228,14 @@ func TestProcessMessageValidatorCommitted(test *testing.T) { test.Fatalf("Cannot craeate consensus: %v", err) } blockBytes, err := hex.DecodeString("f902a5f902a0a00000000000000000000000000000000000000000000000000000000000000000940000000000000000000000000000000000000000a02b418211410ee3e75b32abd925bbeba215172afa509d65c1953d4b4e505a4a2aa056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000083020000808502540be400808080a000000000000000000000000000000000000000000000000000000000000000008800000000000000008400000001b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000c0c0") + if err != nil { + test.Fatalf("Cannot decode blockByte: %v", err) + } consensusLeader.block = blockBytes hashBytes, err := hex.DecodeString("bdd66a8211ffcbf0ad431b506c854b49264951fd9f690928e9cf44910c381053") + if err != nil { + test.Fatalf("Cannot decode hashByte: %v", err) + } copy(consensusLeader.blockHash[:], hashBytes[:]) diff --git a/node/contract.go b/node/contract.go index 5d6697577..47e1f7176 100644 --- a/node/contract.go +++ b/node/contract.go @@ -75,6 +75,11 @@ func (node *Node) QueryStakeInfo() *structs.StakeInfoReturnValue { state, err := node.blockchain.State() + if err != nil { + utils.GetLogInstance().Error("Failed to get blockchain state", "error", err) + return nil + } + stakingContractAddress := crypto.CreateAddress(deployerAddress, uint64(0)) tx := types.NewTransaction( state.GetNonce(deployerAddress), diff --git a/node/demo_contract.go b/node/demo_contract.go index 1d28931d1..b1477fdc0 100644 --- a/node/demo_contract.go +++ b/node/demo_contract.go @@ -130,6 +130,10 @@ func (node *Node) GetResult(priKey string) (players []string, balances []*big.In demoContractAddress := node.DemoContractAddress key, err := crypto.HexToECDSA(priKey) + if err != nil { + utils.GetLogInstance().Error("Failed to parse private key", "error", err) + } + nonce := node.GetNonceOfAddress(crypto.PubkeyToAddress(key.PublicKey)) tx := types.NewTransaction( diff --git a/test/p2pchat/chat.go b/test/p2pchat/chat.go index 3bfac7c9f..af4680690 100644 --- a/test/p2pchat/chat.go +++ b/test/p2pchat/chat.go @@ -136,12 +136,17 @@ func main() { } if err != nil { - fmt.Printf("pubsub error: %v", err) + fmt.Printf("pub error: %v", err) panic(err) } sub, err := ps.Subscribe("pubsubtestchannel") + if err != nil { + fmt.Printf("sub error: %v", err) + panic(err) + } + go writePubsub(ps) go readPubsub(sub)