From 15732580eba1d5ae7f3bb3696883cba73304f614 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Mon, 22 Aug 2022 13:26:12 +0300 Subject: [PATCH] smartcontract: improve manifest validness errors It should be clear from error what's wrong with ABI (specify bad method/event/parameter identifier). --- pkg/smartcontract/manifest/abi.go | 7 ++++--- pkg/smartcontract/manifest/manifest.go | 3 ++- pkg/smartcontract/manifest/parameter.go | 3 ++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/pkg/smartcontract/manifest/abi.go b/pkg/smartcontract/manifest/abi.go index 15f89daf4..3027e5c97 100644 --- a/pkg/smartcontract/manifest/abi.go +++ b/pkg/smartcontract/manifest/abi.go @@ -2,6 +2,7 @@ package manifest import ( "errors" + "fmt" "sort" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" @@ -53,12 +54,12 @@ func (a *ABI) GetEvent(name string) *Event { // IsValid checks ABI consistency and correctness. func (a *ABI) IsValid() error { if len(a.Methods) == 0 { - return errors.New("ABI contains no methods") + return errors.New("no methods") } for i := range a.Methods { err := a.Methods[i].IsValid() if err != nil { - return err + return fmt.Errorf("method %q/%d: %w", a.Methods[i].Name, len(a.Methods[i].Parameters), err) } } if len(a.Methods) > 1 { @@ -92,7 +93,7 @@ func (a *ABI) IsValid() error { for i := range a.Events { err := a.Events[i].IsValid() if err != nil { - return err + return fmt.Errorf("event %q/%d: %w", a.Events[i].Name, len(a.Events[i].Parameters), err) } } if len(a.Events) > 1 { diff --git a/pkg/smartcontract/manifest/manifest.go b/pkg/smartcontract/manifest/manifest.go index e0b968772..ba391a657 100644 --- a/pkg/smartcontract/manifest/manifest.go +++ b/pkg/smartcontract/manifest/manifest.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/json" "errors" + "fmt" "math" ojson "github.com/nspcc-dev/go-ordered-json" @@ -104,7 +105,7 @@ func (m *Manifest) IsValid(hash util.Uint160) error { } err = m.ABI.IsValid() if err != nil { - return err + return fmt.Errorf("ABI: %w", err) } err = Groups(m.Groups).AreValid(hash) if err != nil { diff --git a/pkg/smartcontract/manifest/parameter.go b/pkg/smartcontract/manifest/parameter.go index 88445adde..3e7424522 100644 --- a/pkg/smartcontract/manifest/parameter.go +++ b/pkg/smartcontract/manifest/parameter.go @@ -2,6 +2,7 @@ package manifest import ( "errors" + "fmt" "sort" "github.com/nspcc-dev/neo-go/pkg/smartcontract" @@ -75,7 +76,7 @@ func (p Parameters) AreValid() error { for i := range p { err := p[i].IsValid() if err != nil { - return err + return fmt.Errorf("parameter #%d/%q: %w", i, p[i].Name, err) } } if len(p) < 2 {