diff --git a/pkg/core/native/nativenames/names.go b/pkg/core/native/nativenames/names.go index c7cbe2ca2..74b4f9d8c 100644 --- a/pkg/core/native/nativenames/names.go +++ b/pkg/core/native/nativenames/names.go @@ -14,3 +14,18 @@ const ( CryptoLib = "CryptoLib" StdLib = "StdLib" ) + +// IsValid checks that name is a valid native contract's name. +func IsValid(name string) bool { + return name == Management || + name == Ledger || + name == Neo || + name == Gas || + name == Policy || + name == Oracle || + name == Designation || + name == Notary || + name == NameService || + name == CryptoLib || + name == StdLib +} diff --git a/pkg/core/native/nativenames_test.go b/pkg/core/native/nativenames_test.go new file mode 100644 index 000000000..24770ab2e --- /dev/null +++ b/pkg/core/native/nativenames_test.go @@ -0,0 +1,19 @@ +package native + +import ( + "fmt" + "testing" + + "github.com/nspcc-dev/neo-go/pkg/core/native/nativenames" + "github.com/stretchr/testify/require" +) + +func TestNativenamesIsValid(t *testing.T) { + // test that all native names has been added to IsValid + contracts := NewContracts(true) + for _, c := range contracts.Contracts { + require.True(t, nativenames.IsValid(c.Metadata().Name), fmt.Errorf("add %s to nativenames.IsValid(...)", c)) + } + + require.False(t, nativenames.IsValid("unkonwn")) +}