From 59a7f7d665614e0c71b2d32f128775caaf0d6ccf Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Wed, 29 Nov 2023 23:38:34 +0300 Subject: [PATCH] nns: fix deployments with 0.38.1 adm I'm not yet sure we need it, but old adm (before nspcc-dev/neofs-node#2625) creates a broken deploy script with actual data that has no fields inside. Not a problem for updates, not a problem for newer adm, but still. Signed-off-by: Roman Khimov --- nns/nns_contract.go | 42 +++++++++++++++++++++++++----------------- tests/nns_test.go | 6 ++++++ 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/nns/nns_contract.go b/nns/nns_contract.go index f25f481d..34d26b78 100644 --- a/nns/nns_contract.go +++ b/nns/nns_contract.go @@ -133,24 +133,32 @@ func _deploy(data any, isUpdate bool) { storage.Put(ctx, []byte{prefixTotalSupply}, 0) storage.Put(ctx, []byte{prefixRegisterPrice}, defaultRegisterPrice) - if data != nil { // for backward compatibility - args := data.(struct { - tldSet []struct { - name string - email string - } - }) - - for i := range args.tldSet { - const ( - refresh = 3600 - retry = 600 - expire = 10 * 365 * 24 * 60 * 60 // 10 years - ttl = 3600 - ) - saveCommitteeDomain(ctx, args.tldSet[i].name, args.tldSet[i].email, refresh, retry, expire, ttl) - runtime.Log("registered committee domain " + args.tldSet[i].name) + if data == nil { // TLDs are optional. + return + } + + s := data.([]any) + + if len(s) == 0 { // pre-0.39.0 neofs-adm happily pushes an empty slice into data + return + } + + args := data.(struct { + tldSet []struct { + name string + email string } + }) + + for i := range args.tldSet { + const ( + refresh = 3600 + retry = 600 + expire = 10 * 365 * 24 * 60 * 60 // 10 years + ttl = 3600 + ) + saveCommitteeDomain(ctx, args.tldSet[i].name, args.tldSet[i].email, refresh, retry, expire, ttl) + runtime.Log("registered committee domain " + args.tldSet[i].name) } } diff --git a/tests/nns_test.go b/tests/nns_test.go index 7de7bc94..90d75257 100644 --- a/tests/nns_test.go +++ b/tests/nns_test.go @@ -71,6 +71,12 @@ func TestNNSGeneric(t *testing.T) { c.Invoke(t, 0, "totalSupply") } +func TestOldAdmDeploy(t *testing.T) { + e := newExecutor(t) + ctr := neotest.CompileFile(t, e.CommitteeHash, nnsPath, path.Join(nnsPath, "config.yml")) + e.DeployContract(t, ctr, []any{}) +} + func TestNNSRegisterTLD(t *testing.T) { c := newNNSInvoker(t, false)