From 9d4ccf0fcc2a0256a2ffe76f88519b8cf3923af8 Mon Sep 17 00:00:00 2001 From: Evgeniy Stratonikov Date: Fri, 19 Feb 2021 12:05:30 +0300 Subject: [PATCH] smartcontract: add test for Optional methods They should be checked only if name + parameter count matches. This is how methods are identified in NEO. --- .../manifest/standard/comply_test.go | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/pkg/smartcontract/manifest/standard/comply_test.go b/pkg/smartcontract/manifest/standard/comply_test.go index 9d2f6bf76..a7f7e03e5 100644 --- a/pkg/smartcontract/manifest/standard/comply_test.go +++ b/pkg/smartcontract/manifest/standard/comply_test.go @@ -121,3 +121,39 @@ func TestCheck(t *testing.T) { m.ABI.Events = append(m.ABI.Events, nep17.ABI.Events...) require.NoError(t, Check(m, manifest.NEP17StandardName)) } + +func TestOptional(t *testing.T) { + var m Standard + m.Optional = []manifest.Method{{ + Name: "optMet", + Parameters: []manifest.Parameter{{Type: smartcontract.ByteArrayType}}, + ReturnType: smartcontract.IntegerType, + }} + + t.Run("wrong parameter count, do not check", func(t *testing.T) { + var actual manifest.Manifest + actual.ABI.Methods = []manifest.Method{{ + Name: "optMet", + ReturnType: smartcontract.IntegerType, + }} + require.NoError(t, Comply(&actual, &m)) + }) + t.Run("good parameter count, bad return", func(t *testing.T) { + var actual manifest.Manifest + actual.ABI.Methods = []manifest.Method{{ + Name: "optMet", + Parameters: []manifest.Parameter{{Type: smartcontract.ArrayType}}, + ReturnType: smartcontract.IntegerType, + }} + require.Error(t, Comply(&actual, &m)) + }) + t.Run("good parameter count, good return", func(t *testing.T) { + var actual manifest.Manifest + actual.ABI.Methods = []manifest.Method{{ + Name: "optMet", + Parameters: []manifest.Parameter{{Type: smartcontract.ByteArrayType}}, + ReturnType: smartcontract.IntegerType, + }} + require.NoError(t, Comply(&actual, &m)) + }) +}