use chain time, not host time

This commit is contained in:
Alain Brenzikofer committed 2026-09-22 16:50:19 +02:00
1 parent 2ffec2aad6
commit adcdb54c02
3 files changed
+21 -9

No files matched your search

+4 -3
View File
@@ -893,8 +893,9 @@ def owned_by(address: str, offset: int = 0):
Enumeration is read off the ERC-721 registrar, so a name acquired by
transfer counts, and a lapsed one stays listed until re-registered - it is
reported with its `status`, not filtered. `inUse` is what a recovery scan
asks; holding a name is only one way to be in use, so the nonce and balance
it is derived from are reported too.
asks, derived from this chain's nonce and balance and the names above: an
account holding only other tokens is not seen, and neither is one used on
another chain.
"""
if not is_address(address):
return 400, {
@@ -919,7 +920,7 @@ def owned_by(address: str, offset: int = 0):
"configuredTlds": [],
}
now = int(time.time())
now = chain_now()
names, truncated = [], False
for tld, registrar in configured.items():
grace = grace_period(registrar)
+12 -2
View File
@@ -1048,12 +1048,13 @@ class OwnedByTests(unittest.TestCase):
ALICE = 0x9C0257114EB9399A2985F8E75DAD7600C5D89FE3824FFA99EC1C3EB8BF3B0501
def setUp(self):
self._saved = (snrc.REGISTRARS, snrc.eth_call, snrc.rpc)
self._saved = (snrc.REGISTRARS, snrc.eth_call, snrc.rpc, snrc.chain_now)
snrc.REGISTRARS = {"testing": self.REGISTRAR, "simplex": ""}
snrc.rpc = lambda method, params: "0x0"
snrc.chain_now = lambda: int(time.time())
def tearDown(self):
snrc.REGISTRARS, snrc.eth_call, snrc.rpc = self._saved
snrc.REGISTRARS, snrc.eth_call, snrc.rpc, snrc.chain_now = self._saved
def _chain(self, held, expires, label=b"alice"):
def call(to, data):
@@ -1125,6 +1126,15 @@ class OwnedByTests(unittest.TestCase):
self.assertEqual(status, 400)
self.assertEqual(body["error"], "badAddress")
def test_status_follows_the_block_clock_not_the_host(self):
"""A name the host clock still calls registered is in grace once the
chain has passed its expiry."""
expires = int(time.time()) + 86400
snrc.eth_call = self._chain(1, expires)
snrc.chain_now = lambda: expires + 1
_, body = snrc.owned_by(self.ADDR)
self.assertEqual(body["names"][0]["status"], "grace")
def test_a_negative_offset_is_refused(self):
snrc.eth_call = self._chain(1, int(time.time()) + 86400)
status, body = snrc.owned_by(self.ADDR, -1)
+5 -4
View File
@@ -92,10 +92,11 @@ data NameRegistration
NRReserved {reservedReason :: NameReservedReason}
deriving (Eq, Show)
-- | What the registry holds for an address: the names it owns, and whether
-- the account has been used at all. Holding a name is only one way to be in
-- use, so a recovery scan that reads only `ownNames` hands out an account its
-- owner is already using.
-- | What the registry holds for an address: the names it owns, and whether the
-- account is in use, which holding a name is only one way to be. `ownInUse` is
-- what the resolver could see on its own chain - the nonce, the balance and the
-- names - so an account used only for other tokens, or on another chain, reads
-- as unused.
data OwnedNames = OwnedNames
{ ownNames :: [OwnedName],
ownInUse :: Bool,