From 7d51688d2cf8e452d83bded2b21dd60b9ac20071 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Wed, 7 Oct 2020 19:22:22 +0300 Subject: [PATCH] [#82] Return length check of serialized container In #37 we've decided to remove length check, because smart contract would fail on casting `nil` value from storage to `[]byte` producing FAULT state. Apparently it does not fail, so we have to check length explicitly. Signed-off-by: Alex Vanin --- pkg/morph/client/container/wrapper/container.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/morph/client/container/wrapper/container.go b/pkg/morph/client/container/wrapper/container.go index 8fa408a8..3f467027 100644 --- a/pkg/morph/client/container/wrapper/container.go +++ b/pkg/morph/client/container/wrapper/container.go @@ -71,7 +71,14 @@ func (w *Wrapper) Get(cid *container.ID) (*container.Container, error) { // ask RPC neo node to get serialized container rpcAnswer, err := w.client.Get(args) if err != nil { - return nil, errors.Wrap(core.ErrNotFound, err.Error()) + return nil, err + } + + // In #37 we've decided to remove length check, because smart contract would + // fail on casting `nil` value from storage to `[]byte` producing FAULT state. + // Apparently it does not fail, so we have to check length explicitly. + if len(rpcAnswer.Container()) == 0 { + return nil, core.ErrNotFound } // convert serialized bytes into GRPC structure