diff --git a/contracts/nns/config.yml b/contracts/nns/config.yml index 2c156972..8341e943 100644 --- a/contracts/nns/config.yml +++ b/contracts/nns/config.yml @@ -22,6 +22,14 @@ events: type: Hash160 - name: newAdmin type: Hash160 + - name: Renew + parameters: + - name: name + type: String + - name: oldExpiration + type: Integer + - name: newExpiration + type: Integer permissions: - hash: fffdc93764dbaddd97c48f252a53ea4643faa3fd methods: ["update"] diff --git a/contracts/nns/contract.go b/contracts/nns/contract.go index a32dbb9b..d2a8ef79 100644 --- a/contracts/nns/contract.go +++ b/contracts/nns/contract.go @@ -483,6 +483,7 @@ func Renew(name string, years int) int64 { ctx := storage.GetContext() ns := getNameState(ctx, []byte(name)) ns.checkAdmin() + oldExpiration := ns.Expiration ns.Expiration += millisecondsInYear * int64(years) fragments := splitAndCheck(name) @@ -491,6 +492,7 @@ func Renew(name string, years int) int64 { panic("10 years of expiration period at max is allowed") } putNameState(ctx, ns) + runtime.Notify("Renew", name, oldExpiration, ns.Expiration) return ns.Expiration } diff --git a/tests/nns_test.go b/tests/nns_test.go index a8afa383..3f8e421b 100644 --- a/tests/nns_test.go +++ b/tests/nns_test.go @@ -412,11 +412,21 @@ func TestNNSRenew(t *testing.T) { const msPerYear = 365 * 24 * time.Hour / time.Millisecond b := c.TopBlock(t) renewalPeriod := int64(2) - ts := b.Timestamp + uint64(expire*1000) + uint64(msPerYear)*uint64(renewalPeriod) + oldExpiration := b.Timestamp + uint64(expire*1000) + ts := oldExpiration + uint64(msPerYear)*uint64(renewalPeriod) cAcc := c.WithSigners(acc) cAcc.InvokeFail(t, "not witnessed by admin", "renew", "testdomain.com", renewalPeriod) - c1.Invoke(t, ts, "renew", "testdomain.com", renewalPeriod) + h := c1.Invoke(t, ts, "renew", "testdomain.com", renewalPeriod) + cAcc.CheckTxNotificationEvent(t, h, 0, state.NotificationEvent{ + ScriptHash: cAcc.Hash, + Name: "Renew", + Item: stackitem.NewArray([]stackitem.Item{ + stackitem.NewByteArray([]byte("testdomain.com")), + stackitem.Make(oldExpiration), + stackitem.Make(ts), + }), + }) expected := stackitem.NewMapWithValue([]stackitem.MapElement{ {Key: stackitem.Make("name"), Value: stackitem.Make("testdomain.com")}, {Key: stackitem.Make("expiration"), Value: stackitem.Make(ts)}, @@ -429,7 +439,16 @@ func TestNNSRenew(t *testing.T) { c1.InvokeFail(t, "10 years of expiration period at max is allowed", "renew", "testdomain.com", 10) // Default renewal period. - c1.Invoke(t, ts+uint64(msPerYear), "renew", "testdomain.com") + h = c1.Invoke(t, ts+uint64(msPerYear), "renew", "testdomain.com") + c1.CheckTxNotificationEvent(t, h, 0, state.NotificationEvent{ + ScriptHash: cAcc.Hash, + Name: "Renew", + Item: stackitem.NewArray([]stackitem.Item{ + stackitem.NewByteArray([]byte("testdomain.com")), + stackitem.Make(ts), + stackitem.Make(ts + uint64(msPerYear)), + }), + }) } func TestNNSResolve(t *testing.T) {