forked from TrueCloudLab/neoneo-go
manifest: fix wildcard permission handling
Wildcard contract can coexist with restricted set of methods. Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
3646270af0
commit
4283e1003f
2 changed files with 10 additions and 2 deletions
|
@ -5,6 +5,7 @@ import (
|
|||
"math/big"
|
||||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/internal/random"
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
|
@ -69,8 +70,16 @@ func TestPermission_IsAllowed(t *testing.T) {
|
|||
manifest := DefaultManifest("Test")
|
||||
|
||||
t.Run("wildcard", func(t *testing.T) {
|
||||
h := random.Uint160()
|
||||
|
||||
perm := NewPermission(PermissionWildcard)
|
||||
require.True(t, perm.IsAllowed(util.Uint160{}, manifest, "AAA"))
|
||||
require.True(t, perm.IsAllowed(h, manifest, "AAA"))
|
||||
|
||||
perm.Methods.Restrict()
|
||||
require.False(t, perm.IsAllowed(h, manifest, "AAA"))
|
||||
|
||||
perm.Methods.Add("AAA")
|
||||
require.True(t, perm.IsAllowed(h, manifest, "AAA"))
|
||||
})
|
||||
|
||||
t.Run("hash", func(t *testing.T) {
|
||||
|
|
|
@ -162,7 +162,6 @@ func (ps Permissions) AreValid() error {
|
|||
func (p *Permission) IsAllowed(hash util.Uint160, m *Manifest, method string) bool {
|
||||
switch p.Contract.Type {
|
||||
case PermissionWildcard:
|
||||
return true
|
||||
case PermissionHash:
|
||||
if !p.Contract.Hash().Equals(hash) {
|
||||
return false
|
||||
|
|
Loading…
Reference in a new issue