forked from TrueCloudLab/neoneo-go
manifest/standard: check Safe
flag in Comply()
This commit is contained in:
parent
b7e86fa6a3
commit
ea4d14d20d
2 changed files with 12 additions and 0 deletions
|
@ -14,6 +14,7 @@ var (
|
||||||
ErrInvalidReturnType = errors.New("invalid return type")
|
ErrInvalidReturnType = errors.New("invalid return type")
|
||||||
ErrInvalidParameterCount = errors.New("invalid parameter count")
|
ErrInvalidParameterCount = errors.New("invalid parameter count")
|
||||||
ErrInvalidParameterType = errors.New("invalid parameter type")
|
ErrInvalidParameterType = errors.New("invalid parameter type")
|
||||||
|
ErrSafeMethodMismatch = errors.New("method has wrong safe flag")
|
||||||
)
|
)
|
||||||
|
|
||||||
var checks = map[string]*manifest.Manifest{
|
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)
|
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 {
|
for _, ste := range st.ABI.Events {
|
||||||
name := ste.Name
|
name := ste.Name
|
||||||
|
|
|
@ -20,6 +20,7 @@ func fooMethodBarEvent() *manifest.Manifest {
|
||||||
{Type: smartcontract.PublicKeyType},
|
{Type: smartcontract.PublicKeyType},
|
||||||
},
|
},
|
||||||
ReturnType: smartcontract.IntegerType,
|
ReturnType: smartcontract.IntegerType,
|
||||||
|
Safe: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Events: []manifest.Event{
|
Events: []manifest.Event{
|
||||||
|
@ -87,6 +88,13 @@ func TestMissingEvent(t *testing.T) {
|
||||||
require.True(t, errors.Is(err, ErrEventMissing))
|
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) {
|
func TestComplyValid(t *testing.T) {
|
||||||
m := fooMethodBarEvent()
|
m := fooMethodBarEvent()
|
||||||
m.ABI.Methods = append(m.ABI.Methods, manifest.Method{
|
m.ABI.Methods = append(m.ABI.Methods, manifest.Method{
|
||||||
|
|
Loading…
Reference in a new issue