[#261] nns: Set expiration time based on arguments

Signed-off-by: Evgenii Stratonikov <evgeniy@morphbits.ru>
This commit is contained in:
Evgenii Stratonikov 2022-08-18 15:17:16 +03:00 committed by fyrchik
parent bed1a88dee
commit 5b5ff8cb33
4 changed files with 37 additions and 9 deletions

View file

@ -3,6 +3,9 @@ Changelog for NeoFS Contract
## Unrelease ## Unrelease
### Updated
- NNS contract now sets domain expiration based on `register` arguments (#262)
## [0.15.5] - 2022-08-23 ## [0.15.5] - 2022-08-23
### Updated ### Updated

View file

@ -321,7 +321,8 @@ func Register(name string, owner interop.Hash160, email string, refresh, retry,
ns := NameState{ ns := NameState{
Owner: owner, Owner: owner,
Name: name, Name: name,
Expiration: int64(runtime.GetTime()) + millisecondsInYear, // NNS expiration is in milliseconds
Expiration: int64(runtime.GetTime() + expire*1000),
} }
putNameStateWithKey(ctx, tokenKey, ns) putNameStateWithKey(ctx, tokenKey, ns)
putSoaRecord(ctx, name, email, refresh, retry, expire, ttl) putSoaRecord(ctx, name, email, refresh, retry, expire, ttl)

View file

@ -161,11 +161,11 @@ func TestContainerPut(t *testing.T) {
cNNS.Invoke(t, true, "register", cNNS.Invoke(t, true, "register",
"cdn", c.CommitteeHash, "cdn", c.CommitteeHash,
"whateveriwant@world.com", int64(0), int64(0), int64(0), int64(0)) "whateveriwant@world.com", int64(0), int64(0), int64(100_000), int64(0))
cNNS.Invoke(t, true, "register", cNNS.Invoke(t, true, "register",
"domain.cdn", c.CommitteeHash, "domain.cdn", c.CommitteeHash,
"whateveriwant@world.com", int64(0), int64(0), int64(0), int64(0)) "whateveriwant@world.com", int64(0), int64(0), int64(100_000), int64(0))
balanceMint(t, cBal, acc, (containerFee+containerAliasFee)*1, []byte{}) balanceMint(t, cBal, acc, (containerFee+containerAliasFee)*1, []byte{})

View file

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"math/big" "math/big"
"path" "path"
"strings"
"testing" "testing"
"time" "time"
@ -25,7 +26,8 @@ func newNNSInvoker(t *testing.T, addRoot bool) *neotest.ContractInvoker {
c := e.CommitteeInvoker(ctr.Hash) c := e.CommitteeInvoker(ctr.Hash)
if addRoot { if addRoot {
refresh, retry, expire, ttl := int64(101), int64(102), int64(103), int64(104) // Set expiration big enough to pass all tests.
refresh, retry, expire, ttl := int64(101), int64(102), int64(msPerYear/1000*100), int64(104)
c.Invoke(t, true, "register", c.Invoke(t, true, "register",
"com", c.CommitteeHash, "com", c.CommitteeHash,
"myemail@nspcc.ru", refresh, retry, expire, ttl) "myemail@nspcc.ru", refresh, retry, expire, ttl)
@ -252,14 +254,36 @@ func TestNNSGetAllRecords(t *testing.T) {
func TestExpiration(t *testing.T) { func TestExpiration(t *testing.T) {
c := newNNSInvoker(t, true) c := newNNSInvoker(t, true)
refresh, retry, expire, ttl := int64(101), int64(102), int64(103), int64(104) refresh, retry, expire, ttl := int64(101), int64(102), int64(msPerYear/1000*10), int64(104)
c.Invoke(t, true, "register", c.Invoke(t, true, "register",
"testdomain.com", c.CommitteeHash, "testdomain.com", c.CommitteeHash,
"myemail@nspcc.ru", refresh, retry, expire, ttl) "myemail@nspcc.ru", refresh, retry, expire, ttl)
checkProperties := func(t *testing.T, expiration uint64) {
expected := stackitem.NewMapWithValue([]stackitem.MapElement{
{Key: stackitem.Make("name"), Value: stackitem.Make("testdomain.com")},
{Key: stackitem.Make("expiration"), Value: stackitem.Make(expiration)}})
s, err := c.TestInvoke(t, "properties", "testdomain.com")
require.NoError(t, err)
require.Equal(t, expected.Value(), s.Top().Item().Value())
}
top := c.TopBlock(t)
expiration := top.Timestamp + uint64(expire*1000)
checkProperties(t, expiration)
b := c.NewUnsignedBlock(t) b := c.NewUnsignedBlock(t)
b.Timestamp = c.TopBlock(t).Timestamp + uint64(msPerYear) - 1 b.Timestamp = expiration - 2 // test invoke is done with +1 timestamp
require.NoError(t, c.Chain.AddBlock(c.SignBlock(b))) require.NoError(t, c.Chain.AddBlock(c.SignBlock(b)))
checkProperties(t, expiration)
b = c.NewUnsignedBlock(t)
b.Timestamp = expiration - 1
require.NoError(t, c.Chain.AddBlock(c.SignBlock(b)))
_, err := c.TestInvoke(t, "properties", "testdomain.com")
require.Error(t, err)
require.True(t, strings.Contains(err.Error(), "name has expired"))
c.InvokeFail(t, "name has expired", "getAllRecords", "testdomain.com") c.InvokeFail(t, "name has expired", "getAllRecords", "testdomain.com")
c.InvokeFail(t, "name has expired", "ownerOf", "testdomain.com") c.InvokeFail(t, "name has expired", "ownerOf", "testdomain.com")
@ -320,7 +344,7 @@ func TestNNSRenew(t *testing.T) {
const msPerYear = 365 * 24 * time.Hour / time.Millisecond const msPerYear = 365 * 24 * time.Hour / time.Millisecond
b := c.TopBlock(t) b := c.TopBlock(t)
ts := b.Timestamp + 2*uint64(msPerYear) ts := b.Timestamp + uint64(expire*1000) + uint64(msPerYear)
cAcc := c.WithSigners(acc) cAcc := c.WithSigners(acc)
cAcc.Invoke(t, ts, "renew", "testdomain.com") cAcc.Invoke(t, ts, "renew", "testdomain.com")