From f52360867c9009c8e15bcc8118feb8db313fdd72 Mon Sep 17 00:00:00 2001 From: dawn-to-dusk <1927529251@qq.com> Date: Fri, 18 Dec 2020 17:08:28 +0800 Subject: [PATCH] fix(internal,tester): add the judgment of whether transactionhash is null 1. Add the judgment of whether transactionhash is null. --- internal/coreapi/broker.go | 16 ++++++++++++++++ tester/case001_api_test.go | 1 + 2 files changed, 17 insertions(+) diff --git a/internal/coreapi/broker.go b/internal/coreapi/broker.go index 13d4356..113a040 100644 --- a/internal/coreapi/broker.go +++ b/internal/coreapi/broker.go @@ -21,6 +21,14 @@ type BrokerAPI CoreAPI var _ api.BrokerAPI = (*BrokerAPI)(nil) func (b *BrokerAPI) HandleTransaction(tx *pb.Transaction) error { + if tx.TransactionHash == nil { + if tx.Hash() != nil { + tx.TransactionHash = tx.Hash() + } else { + return fmt.Errorf("transaction hash is nil") + } + } + b.logger.WithFields(logrus.Fields{ "hash": tx.TransactionHash.String(), }).Debugf("Receive tx") @@ -35,6 +43,14 @@ func (b *BrokerAPI) HandleTransaction(tx *pb.Transaction) error { } func (b *BrokerAPI) HandleView(tx *pb.Transaction) (*pb.Receipt, error) { + if tx.TransactionHash == nil { + if tx.Hash() != nil { + tx.TransactionHash = tx.Hash() + } else { + return nil, fmt.Errorf("transaction hash is nil") + } + } + b.logger.WithFields(logrus.Fields{ "hash": tx.TransactionHash.String(), }).Debugf("Receive view") diff --git a/tester/case001_api_test.go b/tester/case001_api_test.go index f3c114b..385db97 100644 --- a/tester/case001_api_test.go +++ b/tester/case001_api_test.go @@ -72,6 +72,7 @@ func testSendView(suite *API) { suite.Equal(receipt.Status, pb.Receipt_SUCCESS) suite.Equal(value, string(receipt.Ret)) } + // //func (suite *API) TestDelVPNode() { // err := suite.api.Broker().DelVPNode(1)