Skip to content

Commit

Permalink
[#267] nns: Add SetAdmin event
Browse files Browse the repository at this point in the history
Port neo-project/non-native-contracts#11.

Signed-off-by: Anna Shaleva <[email protected]>
  • Loading branch information
AnnaShaleva authored and roman-khimov committed Nov 12, 2024
1 parent 67f42e1 commit 18180d3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
8 changes: 8 additions & 0 deletions contracts/nns/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ events:
type: Integer
- name: tokenId
type: ByteArray
- name: SetAdmin
parameters:
- name: name
type: String
- name: oldAdmin
type: Hash160
- name: newAdmin
type: Hash160
permissions:
- hash: fffdc93764dbaddd97c48f252a53ea4643faa3fd
methods: ["update"]
Expand Down
2 changes: 2 additions & 0 deletions contracts/nns/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,8 +522,10 @@ func SetAdmin(name string, admin interop.Hash160) {
ctx := storage.GetContext()
ns := getFragmentedNameState(ctx, []byte(name), fragments)
common.CheckOwnerWitness(ns.Owner)
oldAdm := ns.Admin
ns.Admin = admin
putNameState(ctx, ns)
runtime.Notify("SetAdmin", name, oldAdm, admin)
}

// SetRecord updates existing domain record with the specified type and ID.
Expand Down
12 changes: 11 additions & 1 deletion tests/nns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"time"

"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/encoding/address"
"github.com/nspcc-dev/neo-go/pkg/neotest"
"github.com/nspcc-dev/neo-go/pkg/util"
Expand Down Expand Up @@ -354,7 +355,16 @@ func TestNNSSetAdmin(t *testing.T) {
"testdomain.com", int64(recordtype.TXT), "won't be added")

c1 := c.WithSigners(c.Committee, acc)
c1.Invoke(t, stackitem.Null{}, "setAdmin", "testdomain.com", acc.ScriptHash())
h := c1.Invoke(t, stackitem.Null{}, "setAdmin", "testdomain.com", acc.ScriptHash())
c1.CheckTxNotificationEvent(t, h, 0, state.NotificationEvent{
ScriptHash: c1.Hash,
Name: "SetAdmin",
Item: stackitem.NewArray([]stackitem.Item{
stackitem.NewByteArray([]byte("testdomain.com")),
stackitem.Null{},
stackitem.NewByteArray(acc.ScriptHash().BytesBE()),
}),
})

expiration := top.Timestamp + uint64(expire*1000)
expectedProps := stackitem.NewMapWithValue([]stackitem.MapElement{
Expand Down

0 comments on commit 18180d3

Please sign in to comment.