From 3bc53b3aa1ff7e9f2c56081fc4a32b0e05c56311 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Wed, 13 Jul 2022 18:54:19 +0300 Subject: [PATCH] nft-nd-nns: clean up old entries on re-registration, fix #2570 --- examples/nft-nd-nns/nns.go | 4 ++++ examples/nft-nd-nns/nns_test.go | 3 +++ 2 files changed, 7 insertions(+) diff --git a/examples/nft-nd-nns/nns.go b/examples/nft-nd-nns/nns.go index 516f476c2..8f67beecb 100644 --- a/examples/nft-nd-nns/nns.go +++ b/examples/nft-nd-nns/nns.go @@ -265,6 +265,10 @@ func Register(name string, owner interop.Hash160) bool { } oldOwner = ns.Owner updateBalance(ctx, []byte(name), oldOwner, -1) + it := storage.Find(ctx, append([]byte{prefixRecord}, tokenKey...), storage.KeysOnly) + for iterator.Next(it) { + storage.Delete(ctx, iterator.Value(it)) + } } else { updateTotalSupply(ctx, +1) } diff --git a/examples/nft-nd-nns/nns_test.go b/examples/nft-nd-nns/nns_test.go index bcb92afee..dcd0f6993 100644 --- a/examples/nft-nd-nns/nns_test.go +++ b/examples/nft-nd-nns/nns_test.go @@ -132,6 +132,9 @@ func TestExpiration(t *testing.T) { b5.Timestamp = b4.Timestamp + 1000 require.NoError(t, bc.AddBlock(e.SignBlock(b5))) e.CheckFault(t, tx.Hash(), "name has expired") + + cAcc.Invoke(t, true, "register", "first.com", acc.ScriptHash()) // Re-register. + cAcc.Invoke(t, stackitem.Null{}, "resolve", "first.com", int64(nns.TXT)) } const millisecondsInYear = 365 * 24 * 3600 * 1000