From bb217067f442a53a6c86101965ea142979afde42 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Tue, 27 Apr 2021 09:52:23 +0300 Subject: [PATCH] [#275] reputation/convert: Add nil check In `SendIntermediateResultRequestBody` add nil check for `trust` field. If true, allocate new `PeerToPeerTrust`. Signed-off-by: Pavel Karpy --- v2/reputation/convert.go | 15 ++++++++++++--- v2/reputation/test/generate.go | 3 +-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/v2/reputation/convert.go b/v2/reputation/convert.go index 8aa9aa0..2e31df9 100644 --- a/v2/reputation/convert.go +++ b/v2/reputation/convert.go @@ -476,9 +476,18 @@ func (x *SendIntermediateResultRequestBody) FromGRPCMessage(m grpc.Message) erro return message.NewUnexpectedMessageType(m, v) } - err := x.trust.FromGRPCMessage(v.GetTrust()) - if err != nil { - return err + trust := v.GetTrust() + if trust == nil { + x.trust = nil + } else { + if x.trust == nil { + x.trust = new(PeerToPeerTrust) + } + + err := x.trust.FromGRPCMessage(trust) + if err != nil { + return err + } } x.epoch = v.GetEpoch() diff --git a/v2/reputation/test/generate.go b/v2/reputation/test/generate.go index fbd4bd1..8b2adc5 100644 --- a/v2/reputation/test/generate.go +++ b/v2/reputation/test/generate.go @@ -111,10 +111,9 @@ func GenerateSendIntermediateResultRequestBody(empty bool) *reputation.SendInter if !empty { m.SetEpoch(123) m.SetIteration(564) + m.SetTrust(GeneratePeerToPeerTrust(empty)) } - m.SetTrust(GeneratePeerToPeerTrust(empty)) - return m }