From ea4d14d20df637f800d3cc4204b64a68c37318c7 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 8 Dec 2020 13:47:05 +0300 Subject: [PATCH] manifest/standard: check `Safe` flag in `Comply()` --- pkg/smartcontract/manifest/standard/comply.go | 4 ++++ pkg/smartcontract/manifest/standard/comply_test.go | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/pkg/smartcontract/manifest/standard/comply.go b/pkg/smartcontract/manifest/standard/comply.go index afd6e4000..b629723bc 100644 --- a/pkg/smartcontract/manifest/standard/comply.go +++ b/pkg/smartcontract/manifest/standard/comply.go @@ -14,6 +14,7 @@ var ( ErrInvalidReturnType = errors.New("invalid return type") ErrInvalidParameterCount = errors.New("invalid parameter count") ErrInvalidParameterType = errors.New("invalid parameter type") + ErrSafeMethodMismatch = errors.New("method has wrong safe flag") ) var checks = map[string]*manifest.Manifest{ @@ -55,6 +56,9 @@ func Comply(m, st *manifest.Manifest) error { name, i, stm.Parameters[i].Type, md.Parameters[i].Type) } } + if stm.Safe != md.Safe { + return fmt.Errorf("%w: expected %t", ErrSafeMethodMismatch, stm.Safe) + } } for _, ste := range st.ABI.Events { name := ste.Name diff --git a/pkg/smartcontract/manifest/standard/comply_test.go b/pkg/smartcontract/manifest/standard/comply_test.go index 34e0b52fd..8a1851d42 100644 --- a/pkg/smartcontract/manifest/standard/comply_test.go +++ b/pkg/smartcontract/manifest/standard/comply_test.go @@ -20,6 +20,7 @@ func fooMethodBarEvent() *manifest.Manifest { {Type: smartcontract.PublicKeyType}, }, ReturnType: smartcontract.IntegerType, + Safe: true, }, }, Events: []manifest.Event{ @@ -87,6 +88,13 @@ func TestMissingEvent(t *testing.T) { require.True(t, errors.Is(err, ErrEventMissing)) } +func TestSafeFlag(t *testing.T) { + m := fooMethodBarEvent() + m.ABI.GetMethod("foo").Safe = false + err := Comply(m, fooMethodBarEvent()) + require.True(t, errors.Is(err, ErrSafeMethodMismatch)) +} + func TestComplyValid(t *testing.T) { m := fooMethodBarEvent() m.ABI.Methods = append(m.ABI.Methods, manifest.Method{