mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-26 09:42:22 +00:00
smartcontract: add test for Optional methods
They should be checked only if name + parameter count matches. This is how methods are identified in NEO.
This commit is contained in:
parent
ae30e30321
commit
9d4ccf0fcc
1 changed files with 36 additions and 0 deletions
|
@ -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))
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue