core: DeepCopy notifiction event args inside System.Runtime.Notify

This commit is contained in:
Anna Shaleva 2022-05-30 11:01:12 +03:00
parent 7296f0c913
commit 42a051e55a
5 changed files with 5 additions and 5 deletions

View file

@ -319,7 +319,7 @@ func TestNEP11_ND_OwnerOf_BalanceOf_Transfer(t *testing.T) {
ScriptHash: verifyH, ScriptHash: verifyH,
Name: "OnNEP11Payment", Name: "OnNEP11Payment",
Item: stackitem.NewArray([]stackitem.Item{ Item: stackitem.NewArray([]stackitem.Item{
stackitem.NewBuffer(nftOwnerHash.BytesBE()), stackitem.NewByteArray(nftOwnerHash.BytesBE()),
stackitem.NewBigInteger(big.NewInt(1)), stackitem.NewBigInteger(big.NewInt(1)),
stackitem.NewByteArray(tokenID1), stackitem.NewByteArray(tokenID1),
stackitem.NewByteArray([]byte("some_data")), stackitem.NewByteArray([]byte("some_data")),

View file

@ -68,7 +68,7 @@ func Notify(ic *interop.Context) error {
if len(bytes) > MaxNotificationSize { if len(bytes) > MaxNotificationSize {
return fmt.Errorf("notification size shouldn't exceed %d", MaxNotificationSize) return fmt.Errorf("notification size shouldn't exceed %d", MaxNotificationSize)
} }
ic.AddNotification(ic.VM.GetCurrentScriptHash(), name, stackitem.DeepCopy(stackitem.NewArray(args), false).(*stackitem.Array)) ic.AddNotification(ic.VM.GetCurrentScriptHash(), name, stackitem.DeepCopy(stackitem.NewArray(args), true).(*stackitem.Array))
return nil return nil
} }

View file

@ -53,7 +53,7 @@ func GetNotifications(ic *interop.Context) error {
ev := stackitem.NewArray([]stackitem.Item{ ev := stackitem.NewArray([]stackitem.Item{
stackitem.NewByteArray(notifications[i].ScriptHash.BytesBE()), stackitem.NewByteArray(notifications[i].ScriptHash.BytesBE()),
stackitem.Make(notifications[i].Name), stackitem.Make(notifications[i].Name),
stackitem.DeepCopy(notifications[i].Item, false).(*stackitem.Array), notifications[i].Item,
}) })
arr.Append(ev) arr.Append(ev)
} }

View file

@ -65,7 +65,7 @@ func opParamSlotsPushVM(op opcode.Opcode, param []byte, sslot int, slotloc int,
for i := range items { for i := range items {
item, ok := items[i].(stackitem.Item) item, ok := items[i].(stackitem.Item)
if ok { if ok {
item = stackitem.DeepCopy(item, false) item = stackitem.DeepCopy(item, true)
} else { } else {
item = stackitem.Make(items[i]) item = stackitem.Make(items[i])
} }

View file

@ -1217,7 +1217,7 @@ func deepCopy(item Item, seen map[Item]Item, asImmutable bool) Item {
return NewByteArray(slice.Copy(*it)) return NewByteArray(slice.Copy(*it))
case *Buffer: case *Buffer:
if asImmutable { if asImmutable {
return NewByteArray(slice.Copy(*it)) // TODO: ported as is from C#, but is this correct? return NewByteArray(slice.Copy(*it))
} }
return NewBuffer(slice.Copy(*it)) return NewBuffer(slice.Copy(*it))
case Bool: case Bool: