nns: add SetAdmin event

Port https://github.com/neo-project/non-native-contracts/pull/11.
This commit is contained in:
Anna Shaleva 2022-09-16 11:37:33 +03:00
parent 9eed7c856e
commit 748a7d3eea
3 changed files with 32 additions and 2 deletions

View file

@ -462,8 +462,10 @@ func SetAdmin(name string, admin interop.Hash160) {
if !runtime.CheckWitness(ns.Owner) { if !runtime.CheckWitness(ns.Owner) {
panic("not witnessed by owner") panic("not witnessed by owner")
} }
oldAdm := ns.Admin
ns.Admin = admin ns.Admin = admin
putNameState(ctx, ns) putNameState(ctx, ns)
runtime.Notify("SetAdmin", name, oldAdm, admin)
} }
// SetRecord updates record of the specified type and ID. // SetRecord updates record of the specified type and ID.

View file

@ -15,6 +15,14 @@ events:
type: Integer type: Integer
- name: tokenId - name: tokenId
type: ByteArray type: ByteArray
- name: SetAdmin
parameters:
- name: name
type: String
- name: oldAdmin
type: Hash160
- name: newAdmin
type: Hash160
permissions: permissions:
- hash: fffdc93764dbaddd97c48f252a53ea4643faa3fd - hash: fffdc93764dbaddd97c48f252a53ea4643faa3fd
methods: ["update"] methods: ["update"]

View file

@ -9,6 +9,7 @@ import (
nns "github.com/nspcc-dev/neo-go/examples/nft-nd-nns" nns "github.com/nspcc-dev/neo-go/examples/nft-nd-nns"
"github.com/nspcc-dev/neo-go/pkg/compiler" "github.com/nspcc-dev/neo-go/pkg/compiler"
"github.com/nspcc-dev/neo-go/pkg/core/interop/storage" "github.com/nspcc-dev/neo-go/pkg/core/interop/storage"
"github.com/nspcc-dev/neo-go/pkg/core/state"
"github.com/nspcc-dev/neo-go/pkg/neotest" "github.com/nspcc-dev/neo-go/pkg/neotest"
"github.com/nspcc-dev/neo-go/pkg/neotest/chain" "github.com/nspcc-dev/neo-go/pkg/neotest/chain"
"github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/smartcontract"
@ -369,7 +370,17 @@ func TestSetAdmin(t *testing.T) {
cOwner.InvokeFail(t, "not witnessed by admin", "setAdmin", "neo.com", admin.ScriptHash()) cOwner.InvokeFail(t, "not witnessed by admin", "setAdmin", "neo.com", admin.ScriptHash())
cAdmin.InvokeFail(t, "not witnessed by owner", "setAdmin", "neo.com", admin.ScriptHash()) cAdmin.InvokeFail(t, "not witnessed by owner", "setAdmin", "neo.com", admin.ScriptHash())
cc := c.WithSigners(owner, admin) cc := c.WithSigners(owner, admin)
cc.Invoke(t, stackitem.Null{}, "setAdmin", "neo.com", admin.ScriptHash()) h := cc.Invoke(t, stackitem.Null{}, "setAdmin", "neo.com", admin.ScriptHash())
cc.CheckTxNotificationEvent(t, h, 0, state.NotificationEvent{
ScriptHash: cc.Hash,
Name: "SetAdmin",
Item: stackitem.NewArray([]stackitem.Item{
stackitem.NewByteArray([]byte("neo.com")),
stackitem.Null{},
stackitem.NewByteArray(admin.ScriptHash().BytesBE()),
}),
})
props := stackitem.NewMap() props := stackitem.NewMap()
props.Add(stackitem.Make("name"), stackitem.Make("neo.com")) props.Add(stackitem.Make("name"), stackitem.Make("neo.com"))
props.Add(stackitem.Make("expiration"), stackitem.Make(expectedExpiration)) props.Add(stackitem.Make("expiration"), stackitem.Make(expectedExpiration))
@ -384,7 +395,16 @@ func TestSetAdmin(t *testing.T) {
t.Run("set admin to null", func(t *testing.T) { t.Run("set admin to null", func(t *testing.T) {
cAdmin.Invoke(t, stackitem.Null{}, "addRecord", "neo.com", int64(nns.TXT), "sometext") cAdmin.Invoke(t, stackitem.Null{}, "addRecord", "neo.com", int64(nns.TXT), "sometext")
cOwner.Invoke(t, stackitem.Null{}, "setAdmin", "neo.com", nil) h = cOwner.Invoke(t, stackitem.Null{}, "setAdmin", "neo.com", nil)
cc.CheckTxNotificationEvent(t, h, 0, state.NotificationEvent{
ScriptHash: cc.Hash,
Name: "SetAdmin",
Item: stackitem.NewArray([]stackitem.Item{
stackitem.NewByteArray([]byte("neo.com")),
stackitem.NewByteArray(admin.ScriptHash().BytesBE()),
stackitem.Null{},
}),
})
cAdmin.InvokeFail(t, "not witnessed by admin", "deleteRecords", "neo.com", int64(nns.TXT)) cAdmin.InvokeFail(t, "not witnessed by admin", "deleteRecords", "neo.com", int64(nns.TXT))
}) })
} }