mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-02-16 11:16:30 +00:00
manifest: disallow null groups, fix #3522
IsValid() is used by both compiler and ContractManagement then. Signed-off-by: Roman Khimov <roman@nspcc.ru>
This commit is contained in:
parent
f0ae14e4db
commit
e861aeec2e
4 changed files with 15 additions and 4 deletions
|
@ -712,7 +712,8 @@ func TestSystemRuntimeNotify_HFBasilisk(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
m := &manifest.Manifest{
|
m := &manifest.Manifest{
|
||||||
Name: "ctr",
|
Name: "ctr",
|
||||||
|
Groups: []manifest.Group{},
|
||||||
ABI: manifest.ABI{
|
ABI: manifest.ABI{
|
||||||
Methods: []manifest.Method{
|
Methods: []manifest.Method{
|
||||||
{
|
{
|
||||||
|
|
|
@ -52,7 +52,8 @@ func TestManagement_DeployUpdate_HFBasilisk(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
m := &manifest.Manifest{
|
m := &manifest.Manifest{
|
||||||
Name: "ctr",
|
Name: "ctr",
|
||||||
|
Groups: []manifest.Group{},
|
||||||
ABI: manifest.ABI{
|
ABI: manifest.ABI{
|
||||||
Methods: []manifest.Method{
|
Methods: []manifest.Method{
|
||||||
{
|
{
|
||||||
|
@ -87,7 +88,8 @@ func TestManagement_CallInTheSameBlock(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
m := &manifest.Manifest{
|
m := &manifest.Manifest{
|
||||||
Name: "ctr",
|
Name: "ctr",
|
||||||
|
Groups: []manifest.Group{},
|
||||||
ABI: manifest.ABI{
|
ABI: manifest.ABI{
|
||||||
Methods: []manifest.Method{
|
Methods: []manifest.Method{
|
||||||
{
|
{
|
||||||
|
|
|
@ -40,6 +40,9 @@ func (g *Group) IsValid(h util.Uint160) error {
|
||||||
// AreValid checks for groups correctness and uniqueness.
|
// AreValid checks for groups correctness and uniqueness.
|
||||||
// If the contract hash is empty, then hash-related checks are omitted.
|
// If the contract hash is empty, then hash-related checks are omitted.
|
||||||
func (g Groups) AreValid(h util.Uint160) error {
|
func (g Groups) AreValid(h util.Uint160) error {
|
||||||
|
if g == nil {
|
||||||
|
return errors.New("null groups")
|
||||||
|
}
|
||||||
if !h.Equals(util.Uint160{}) {
|
if !h.Equals(util.Uint160{}) {
|
||||||
for i := range g {
|
for i := range g {
|
||||||
err := g[i].IsValid(h)
|
err := g[i].IsValid(h)
|
||||||
|
|
|
@ -19,6 +19,10 @@ func TestGroupJSONInOut(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGroupsAreValid(t *testing.T) {
|
func TestGroupsAreValid(t *testing.T) {
|
||||||
|
var gps Groups
|
||||||
|
|
||||||
|
require.Error(t, gps.AreValid(util.Uint160{})) // null
|
||||||
|
|
||||||
h := util.Uint160{42, 42, 42}
|
h := util.Uint160{42, 42, 42}
|
||||||
priv, err := keys.NewPrivateKey()
|
priv, err := keys.NewPrivateKey()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -29,7 +33,8 @@ func TestGroupsAreValid(t *testing.T) {
|
||||||
gcorrect := Group{pub, priv.Sign(h.BytesBE())}
|
gcorrect := Group{pub, priv.Sign(h.BytesBE())}
|
||||||
gcorrect2 := Group{pub2, priv2.Sign(h.BytesBE())}
|
gcorrect2 := Group{pub2, priv2.Sign(h.BytesBE())}
|
||||||
gincorrect := Group{pub, priv.Sign(h.BytesLE())}
|
gincorrect := Group{pub, priv.Sign(h.BytesLE())}
|
||||||
gps := Groups{gcorrect}
|
|
||||||
|
gps = Groups{gcorrect}
|
||||||
require.NoError(t, gps.AreValid(h))
|
require.NoError(t, gps.AreValid(h))
|
||||||
|
|
||||||
gps = Groups{gincorrect}
|
gps = Groups{gincorrect}
|
||||||
|
|
Loading…
Add table
Reference in a new issue