mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-25 23:42:23 +00:00
nns: add Renew event
Port https://github.com/neo-project/non-native-contracts/pull/31.
This commit is contained in:
parent
748a7d3eea
commit
abd332f764
3 changed files with 33 additions and 2 deletions
|
@ -441,11 +441,13 @@ func Renew(name string, years int64) int {
|
||||||
|
|
||||||
ctx := storage.GetContext()
|
ctx := storage.GetContext()
|
||||||
ns := getNameState(ctx, []byte(name))
|
ns := getNameState(ctx, []byte(name))
|
||||||
|
oldExpiration := ns.Expiration
|
||||||
ns.Expiration += int(millisecondsInYear * years)
|
ns.Expiration += int(millisecondsInYear * years)
|
||||||
if ns.Expiration > int(runtime.GetTime())+millisecondsInTenYears {
|
if ns.Expiration > int(runtime.GetTime())+millisecondsInTenYears {
|
||||||
panic("10 years of expiration period at max is allowed")
|
panic("10 years of expiration period at max is allowed")
|
||||||
}
|
}
|
||||||
putNameState(ctx, ns)
|
putNameState(ctx, ns)
|
||||||
|
runtime.Notify("Renew", name, oldExpiration, ns.Expiration)
|
||||||
return ns.Expiration
|
return ns.Expiration
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,14 @@ events:
|
||||||
type: Hash160
|
type: Hash160
|
||||||
- name: newAdmin
|
- name: newAdmin
|
||||||
type: Hash160
|
type: Hash160
|
||||||
|
- name: Renew
|
||||||
|
parameters:
|
||||||
|
- name: name
|
||||||
|
type: String
|
||||||
|
- name: oldExpiration
|
||||||
|
type: Integer
|
||||||
|
- name: newExpiration
|
||||||
|
type: Integer
|
||||||
permissions:
|
permissions:
|
||||||
- hash: fffdc93764dbaddd97c48f252a53ea4643faa3fd
|
- hash: fffdc93764dbaddd97c48f252a53ea4643faa3fd
|
||||||
methods: ["update"]
|
methods: ["update"]
|
||||||
|
|
|
@ -210,8 +210,18 @@ func TestRegisterAndRenew(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
// Renew
|
// Renew
|
||||||
|
oldExpiration := expectedExpiration
|
||||||
expectedExpiration += millisecondsInYear
|
expectedExpiration += millisecondsInYear
|
||||||
c.Invoke(t, expectedExpiration, "renew", "neo-go.com")
|
h := c.Invoke(t, expectedExpiration, "renew", "neo-go.com")
|
||||||
|
c.CheckTxNotificationEvent(t, h, 0, state.NotificationEvent{
|
||||||
|
ScriptHash: c.Hash,
|
||||||
|
Name: "Renew",
|
||||||
|
Item: stackitem.NewArray([]stackitem.Item{
|
||||||
|
stackitem.NewByteArray([]byte("neo-go.com")),
|
||||||
|
stackitem.Make(oldExpiration),
|
||||||
|
stackitem.Make(expectedExpiration),
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
|
||||||
props.Add(stackitem.Make("expiration"), stackitem.Make(expectedExpiration))
|
props.Add(stackitem.Make("expiration"), stackitem.Make(expectedExpiration))
|
||||||
c.Invoke(t, props, "properties", "neo-go.com")
|
c.Invoke(t, props, "properties", "neo-go.com")
|
||||||
|
@ -222,8 +232,19 @@ func TestRegisterAndRenew(t *testing.T) {
|
||||||
c.InvokeFail(t, "10 years of expiration period at max is allowed", "renew", "neo-go.com", 10)
|
c.InvokeFail(t, "10 years of expiration period at max is allowed", "renew", "neo-go.com", 10)
|
||||||
|
|
||||||
// Non-default renewal period.
|
// Non-default renewal period.
|
||||||
|
oldExpiration = expectedExpiration
|
||||||
mult := 2
|
mult := 2
|
||||||
c.Invoke(t, expectedExpiration+uint64(mult*millisecondsInYear), "renew", "neo-go.com", mult)
|
expectedExpiration += uint64(mult * millisecondsInYear)
|
||||||
|
h = c.Invoke(t, expectedExpiration, "renew", "neo-go.com", mult)
|
||||||
|
c.CheckTxNotificationEvent(t, h, 0, state.NotificationEvent{
|
||||||
|
ScriptHash: c.Hash,
|
||||||
|
Name: "Renew",
|
||||||
|
Item: stackitem.NewArray([]stackitem.Item{
|
||||||
|
stackitem.NewByteArray([]byte("neo-go.com")),
|
||||||
|
stackitem.Make(oldExpiration),
|
||||||
|
stackitem.Make(expectedExpiration),
|
||||||
|
}),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSetAddGetRecord(t *testing.T) {
|
func TestSetAddGetRecord(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue