mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-26 19:42:23 +00:00
state: check for array length in (*Contract).FromStackItem
Panicing here is not appropriate.
This commit is contained in:
parent
f8857c5ebe
commit
f7c5ab4f43
2 changed files with 4 additions and 0 deletions
|
@ -61,6 +61,9 @@ func (c *Contract) FromStackItem(item stackitem.Item) error {
|
|||
if !ok {
|
||||
return errors.New("not an array")
|
||||
}
|
||||
if len(arr) != 5 {
|
||||
return errors.New("invalid structure")
|
||||
}
|
||||
bi, ok := arr[0].Value().(*big.Int)
|
||||
if !ok {
|
||||
return errors.New("ID is not an integer")
|
||||
|
|
|
@ -98,6 +98,7 @@ func TestContractFromStackItem(t *testing.T) {
|
|||
item stackitem.Item
|
||||
}{
|
||||
{"not an array", stackitem.Make(1)},
|
||||
{"wrong array", stackitem.Make([]stackitem.Item{})},
|
||||
{"id is not a number", stackitem.Make([]stackitem.Item{manifItem, counter, chash, nefItem, manifItem})},
|
||||
{"id is out of range", stackitem.Make([]stackitem.Item{stackitem.Make(math.MaxUint32), counter, chash, nefItem, manifItem})},
|
||||
{"counter is not a number", stackitem.Make([]stackitem.Item{id, manifItem, chash, nefItem, manifItem})},
|
||||
|
|
Loading…
Reference in a new issue