mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-22 19:19:09 +00:00
smartcontrct: take care of manifest permission descriptor wildcardness
Starting from b10af1ed31
(*WildPermissionDescs).Add method's call is not enough to construct a
proper restricted permission descriptor, because Wildcard field should
be set properly at the same time. Ref. #3523.
Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
This commit is contained in:
parent
d8e3e57f88
commit
2c7430583c
2 changed files with 17 additions and 2 deletions
|
@ -64,8 +64,12 @@ func (c *WildPermissionDescs) Restrict() {
|
|||
// Add adds v to the container.
|
||||
func (c *WildStrings) Add(v string) { c.Value = append(c.Value, v) }
|
||||
|
||||
// Add adds v to the container.
|
||||
func (c *WildPermissionDescs) Add(v PermissionDesc) { c.Value = append(c.Value, v) }
|
||||
// Add adds v to the container and converts container to non-wildcard (if it's still
|
||||
// wildcard).
|
||||
func (c *WildPermissionDescs) Add(v PermissionDesc) {
|
||||
c.Value = append(c.Value, v)
|
||||
c.Wildcard = false
|
||||
}
|
||||
|
||||
// MarshalJSON implements the json.Marshaler interface.
|
||||
func (c WildStrings) MarshalJSON() ([]byte, error) {
|
||||
|
|
|
@ -81,6 +81,17 @@ func TestContainer_Add(t *testing.T) {
|
|||
require.False(t, c.Contains(PermissionDesc{Type: PermissionHash, Value: random.Uint160()}))
|
||||
require.False(t, c.Contains(PermissionDesc{Type: PermissionGroup, Value: pkRand.PublicKey()}))
|
||||
})
|
||||
|
||||
t.Run("from wildcard", func(t *testing.T) {
|
||||
c := &WildPermissionDescs{
|
||||
Value: nil,
|
||||
Wildcard: true,
|
||||
}
|
||||
require.True(t, c.IsWildcard())
|
||||
|
||||
c.Add(PermissionDesc{Type: PermissionHash, Value: random.Uint160()})
|
||||
require.False(t, c.IsWildcard())
|
||||
})
|
||||
}
|
||||
|
||||
func TestContainer_MarshalJSON(t *testing.T) {
|
||||
|
|
Loading…
Reference in a new issue