diff --git a/src/keri/app/cli/commands/local/watch.py b/src/keri/app/cli/commands/local/watch.py index a66c136dd..6529f80e9 100644 --- a/src/keri/app/cli/commands/local/watch.py +++ b/src/keri/app/cli/commands/local/watch.py @@ -219,11 +219,11 @@ def diffState(wit, preksn, witksn): witstate = WitnessState() witstate.wit = wit - mysn = preksn.sner.num - mydig = preksn.ked['d'] - witstate.sn = coring.Number(num=witksn.ked["f"]).num - witstate.dig = witksn.ked['d'] - + mysn = int(preksn.s, 16) + mydig = preksn.d + witstate.sn = int(witksn.f, 16) + witstate.dig = witksn.d + # At the same sequence number, check the DIGs if mysn == witstate.sn: if mydig == witstate.dig: diff --git a/src/keri/app/kiwiing.py b/src/keri/app/kiwiing.py index 345ff8406..915c21449 100644 --- a/src/keri/app/kiwiing.py +++ b/src/keri/app/kiwiing.py @@ -768,7 +768,7 @@ def on_get(self, _, rep, prefix): res = dict( pre=pre, - state=kever.state().ked + state=kever.state()._asdict() ) kel = [] diff --git a/src/keri/app/querying.py b/src/keri/app/querying.py index 0cfd0ef87..74235bb9c 100644 --- a/src/keri/app/querying.py +++ b/src/keri/app/querying.py @@ -43,10 +43,10 @@ def recur(self, tyme, deeds=None): match cue['kin']: case "keyStateSaved": kcue = cue - ksn = kcue['serder'] - match ksn.pre: + ksn = kcue['serder'] # key state notice dict + match ksn["i"]: case self.pre: - if kever.sn < ksn.sn: + if kever.sn < int(ksn["s"], 16): # Add new doer here instead of cueing to a while loop self.extend([LogQuerier(hby=self.hby, hab=self.hab, ksn=ksn)]) self.remove([self.witq]) @@ -70,7 +70,7 @@ def __init__(self, hby, hab, ksn, **opts): self.hab = hab self.ksn = ksn self.witq = agenting.WitnessInquisitor(hby=self.hby) - self.witq.query(src=self.hab.pre, pre=self.ksn.pre) + self.witq.query(src=self.hab.pre, pre=self.ksn["i"]) super(LogQuerier, self).__init__(doers=[self.witq], **opts) def recur(self, tyme, deeds=None): @@ -79,8 +79,8 @@ def recur(self, tyme, deeds=None): Usage: add result of doify on this method to doers list """ - kever = self.hab.kevers[self.ksn.pre] - if kever.sn >= self.ksn.sn: + kever = self.hab.kevers[self.ksn["i"]] + if kever.sn >= int(self.ksn['s'], 16): self.remove([self.witq]) return True diff --git a/src/keri/core/eventing.py b/src/keri/core/eventing.py index e26f9a1c2..2273e0dfc 100644 --- a/src/keri/core/eventing.py +++ b/src/keri/core/eventing.py @@ -7,7 +7,7 @@ import json import logging from collections import namedtuple -from dataclasses import dataclass, astuple +from dataclasses import dataclass, astuple, asdict from urllib.parse import urlsplit from math import ceil from ordered_set import OrderedSet as oset @@ -20,6 +20,7 @@ from .. import help from .. import kering from ..db import basing, dbing +from ..db.basing import KeyStateRecord from ..db.dbing import dgKey, snKey, fnKey, splitKeySN, splitKey from ..kering import (MissingEntryError, @@ -28,7 +29,7 @@ MissingDelegationError, OutOfOrderError, LikelyDuplicitousError, UnverifiedWitnessReceiptError, UnverifiedReceiptError, UnverifiedTransferableReceiptError, QueryNotFoundError) -from ..kering import Version +from ..kering import Version, Versionage from ..kering import (ICP_LABELS, DIP_LABELS, ROT_LABELS, DRT_LABELS, IXN_LABELS, KSN_LABELS, RPY_LABELS) @@ -1144,8 +1145,8 @@ def state(pre, raise ValueError(f"Intersecting cuts = {cuts} and adds = {adds} in " f"latest est event.") - - ksd = dict(v=vs, # version string + ksr = basing.KeyStateRecord( + v=vs, # version string vn=list(version), # version number as list [major, minor] i=pre, # qb64 prefix s=sner.numh, # lowercase hex string no leading zeros @@ -1166,8 +1167,31 @@ def state(pre, ee=eevt._asdict(), # latest est event dict di=dpre if dpre is not None else "", ) - - return Serder(ked=ksd) # return serialized ksd + return ksr # return KeyStateRecord use asdict(ksr) to get dict version + + #ksd = dict(v=vs, # version string + #vn=list(version), # version number as list [major, minor] + #i=pre, # qb64 prefix + #s=sner.numh, # lowercase hex string no leading zeros + #p=pig, + #d=dig, + #f=fner.numh, # lowercase hex string no leading zeros + #dt=stamp, + #et=eilk, + #kt=(tholder.num if intive and tholder.num is not None and + #tholder.num <= MaxIntThold else tholder.sith), + #k=keys, # list of qb64 + #nt=(ntholder.num if intive and ntholder.num is not None and + #ntholder.num <= MaxIntThold else ntholder.sith), + #n=ndigs, + #bt=toader.num if intive and toader.num <= MaxIntThold else toader.numh, + #b=wits, # list of qb64 may be empty + #c=cnfg if cnfg is not None else [], + #ee=eevt._asdict(), # latest est event dict + #di=dpre if dpre is not None else "", + #) + + #return Serder(ked=ksd) # return serialized ksd def query(route="", @@ -1607,7 +1631,7 @@ def __init__(self, *, state=None, serder=None, sigers=None, wigers=None, Verify incepting serder against sigers raises ValidationError if not Parameters: - state (Serder | None): instance of key state notice 'ksn' message body + state (KeyStateRecord | None): instance for key state notice serder (Serder | None): instance of inception event sigers (list | None): of Siger instances of indexed controller signatures of event. Index is offset into keys list from latest est event @@ -1706,8 +1730,10 @@ def __init__(self, *, state=None, serder=None, sigers=None, wigers=None, self.fner = Number(num=fn) self.dater = Dater(dts=dts) self.db.states.pin(keys=self.prefixer.qb64, - val=helping.datify(basing.KeyStateRecord, - self.state().ked)) + val=self.state()) + #self.db.states.pin(keys=self.prefixer.qb64, + #val=helping.datify(basing.KeyStateRecord, + #self.state().ked)) @property @@ -1758,43 +1784,43 @@ def transferable(self): def reload(self, state): """ - Reload Kever attributes (aka its state) from state serder + Reload Kever attributes (aka its state) from state (KeyStateRecord) Parameters: - state (Serder): instance of key state notice 'ksn' message body + state (KeyStateRecord | None): instance for key state notice """ - for k in KSN_LABELS: - if k not in state.ked: - raise ValidationError(f"Missing element = {k} from state." - f" = {state}.") - - self.version = state.version - self.prefixer = Prefixer(qb64=state.pre) - self.sner = state.sner # sequence number Number instance hex str - self.fner = state.fner # first seen ordinal Number hex str - self.dater = Dater(dts=state.ked["dt"]) - self.ilk = state.ked["et"] - self.tholder = Tholder(sith=state.ked["kt"]) - self.ntholder = Tholder(sith=state.ked["nt"]) - self.verfers = [Verfer(qb64=key) for key in state.ked["k"]] - self.digers = [Diger(qb64=dig) for dig in state.ked["n"]] - self.toader = Number(num=state.ked["bt"]) # auto converts from hex num - self.wits = state.ked["b"] - self.cuts = state.ked["ee"]["br"] - self.adds = state.ked["ee"]["ba"] + #for k in KSN_LABELS: + #if k not in state.ked: + #raise ValidationError(f"Missing element = {k} from state." + #f" = {state}.") + + self.version = Versionage._make(state.vn) + self.prefixer = Prefixer(qb64=state.i) + self.sner = Number(numh=state.s) # sequence number Number instance hex str + self.fner = Number(numh=state.f) # first seen ordinal Number hex str + self.dater = Dater(dts=state.dt) + self.ilk = state.et + self.tholder = Tholder(sith=state.kt) + self.ntholder = Tholder(sith=state.nt) + self.verfers = [Verfer(qb64=key) for key in state.k] + self.digers = [Diger(qb64=dig) for dig in state.n] + self.toader = Number(numh=state.bt) # auto converts from hex num + self.wits = state.b + self.cuts = state.ee["br"] + self.adds = state.ee["ba"] self.estOnly = False - self.doNotDelegate = True if "DND" in state.ked["c"] else False - self.estOnly = True if "EO" in state.ked["c"] else False - self.lastEst = LastEstLoc(s=int(state.ked['ee']['s'], 16), - d=state.ked['ee']['d']) - self.delegator = state.ked['di'] if state.ked['di'] else None + self.doNotDelegate = True if "DND" in state.c else False + self.estOnly = True if "EO" in state.c else False + self.lastEst = LastEstLoc(s=int(state.ee['s'], 16), + d=state.ee['d']) + self.delegator = state.di if state.di else None self.delegated = True if self.delegator else False if (raw := self.db.getEvt(key=dgKey(pre=self.prefixer.qb64, - dig=state.ked['d']))) is None: - raise MissingEntryError("Corresponding event for state={} not found." - "".format(state.pretty())) + dig=state.d))) is None: + raise MissingEntryError(f"Corresponding event not found for state=" + f"{state}.") self.serder = Serder(raw=bytes(raw)) # May want to do additional checks here @@ -2020,9 +2046,7 @@ def update(self, serder, sigers, wigers=None, delseqner=None, delsaider=None, if fn is not None: # first is non-idempotent for fn check mode fn is None self.fner = Number(num=fn) self.dater = Dater(dts=dts) - self.db.states.pin(keys=self.prefixer.qb64, - val=helping.datify(basing.KeyStateRecord, - self.state().ked)) + self.db.states.pin(keys=self.prefixer.qb64, val=self.state()) elif ilk == Ilks.ixn: # subsequent interaction event @@ -2069,9 +2093,7 @@ def update(self, serder, sigers, wigers=None, delseqner=None, delsaider=None, if fn is not None: # first is non-idempotent for fn check mode fn is None self.fner = Number(num=fn) self.dater = Dater(dts=dts) - self.db.states.pin(keys=self.prefixer.qb64, - val=helping.datify(basing.KeyStateRecord, - self.state().ked)) + self.db.states.pin(keys=self.prefixer.qb64, val=self.state()) else: # unsupported event ilk so discard raise ValidationError("Unsupported ilk = {} for evt = {}.".format(ilk, ked)) @@ -2586,12 +2608,10 @@ def escrowPWEvent(self, serder, wigers, sigers=None, seqner=None, saider=None): return self.db.addPwe(snKey(serder.preb, serder.sn), serder.saidb) - def state(self, kind=Serials.json): + def state(self): """ - Returns Serder instance of current key state notification message + Returns KeyStateRecord instance of current key state - Parameters: - kind is serialization kind for message json, cbor, mgpk """ eevt = StateEstEvent(s="{:x}".format(self.lastEst.s), d=self.lastEst.d, @@ -2620,7 +2640,6 @@ def state(self, kind=Serials.json): wits=self.wits, cnfg=cnfg, dpre=self.delegator, - kind=kind ) ) @@ -3459,6 +3478,7 @@ def removeStaleReplyEndRole(self, saider): """ pass + def removeStaleReplyLocScheme(self, saider): """ Process reply escrow at saider for route "/loc/scheme" @@ -3477,6 +3497,7 @@ def registerReplyRoutes(self, router): router.addRoute("/loc/scheme", self, suffix="LocScheme") router.addRoute("/ksn/{aid}", self, suffix="KeyStateNotice") + def processReplyEndRole(self, *, serder, saider, route, cigars=None, tsgs=None, **kwargs): """ @@ -3665,6 +3686,7 @@ def processReplyLocScheme(self, *, serder, saider, route, self.updateLoc(keys=keys, saider=saider, url=url) # update .lans and .locs + def processReplyKeyStateNotice(self, *, serder, saider, route, cigars=None, tsgs=None, **kwargs): """ Process one reply message for key state = /ksn @@ -3737,41 +3759,43 @@ def processReplyKeyStateNotice(self, *, serder, saider, route, f"msg={serder.ked}.") aid = kwargs["aid"] data = serder.ked["a"] - kserder = coring.Serder(ked=data) - - for k in KSN_LABELS: - if k not in kserder.ked: - raise ValidationError("Missing element = {} from {} msg." - " ksn = {}.".format(k, Ilks.ksn, - serder.pretty())) + try: + ksr = KeyStateRecord._fromdict(d=data) + except Exception as ex: + raise ValidationError(f"Malformed key state notice = {data}.") from ex + + #for k in KSN_LABELS: + #if k not in ksr.ked: + #raise ValidationError("Missing element = {} from {} msg." + #" ksn = {}.".format(k, Ilks.ksn, + #serder.pretty())) # fetch from serder to process - ked = kserder.ked - pre = kserder.pre - sn = kserder.sn + pre = ksr.i + sn = int(ksr.s, 16) # check source and ensure we should accept it - baks = ked["b"] + baks = ksr.b wats = set() for _, habr in self.db.habs.getItemIter(): wats |= set(habr.watchers) # not in promiscuous mode if not self.lax: - if aid != kserder.pre and \ + if aid != ksr.i and \ aid not in baks and \ aid not in wats: raise kering.UntrustedKeyStateSource("key state notice for {} from untrusted source {} " - .format(kserder.pre, aid)) + .format(ksr.pre, aid)) - if kserder.pre in self.kevers: - kever = self.kevers[kserder.pre] - if kserder.sn < kever.sner.num: + if ksr.i in self.kevers: + kever = self.kevers[ksr.i] + if int(ksr.s, 16) < kever.sner.num: raise ValidationError("Skipped stale key state at sn {} for {}." - "".format(kserder.sn, kserder.pre)) + "".format(int(ksr.s, 16), ksr.i)) keys = (pre, aid,) osaider = self.db.knas.get(keys=keys) # get old said if any - dater = coring.Dater(dts=serder.ked["dt"]) + dater = coring.Dater(dts=ksr.dt) # BADA Logic accepted = self.rvy.acceptReply(serder=serder, saider=saider, route=route, @@ -3781,7 +3805,7 @@ def processReplyKeyStateNotice(self, *, serder, saider, route, raise UnverifiedReplyError(f"Unverified reply.") ldig = self.db.getKeLast(key=snKey(pre=pre, sn=sn)) # retrieve dig of last event at sn. - diger = coring.Diger(qb64=ked["d"]) + diger = coring.Diger(qb64=ksr.d) # Only accept key state if for last seen version of event at sn if ldig is not None: # escrow because event does not yet exist in database @@ -3792,12 +3816,12 @@ def processReplyKeyStateNotice(self, *, serder, saider, route, sserder = Serder(raw=bytes(sraw)) if not sserder.compare(said=diger.qb64b): # mismatch events problem with replay - raise ValidationError("Mismatch keystate at sn = {} with db." - "".format(ked["s"])) + raise ValidationError(f"Mismatch keystate at sn = {int(ksr.s,16)}" + f" with db.") ksaider = coring.Saider(qb64=diger.qb64) - self.updateKeyState(aid=aid, serder=kserder, saider=ksaider, dater=dater) - self.cues.append(dict(kin="keyStateSaved", serder=kserder)) + self.updateKeyState(aid=aid, ksr=ksr, saider=ksaider, dater=dater) + self.cues.append(dict(kin="keyStateSaved", serder=serder)) def updateEnd(self, keys, saider, allowed=None): @@ -3835,14 +3859,14 @@ def updateLoc(self, keys, saider, url): self.db.locs.pin(keys=keys, val=locer) # overwrite - def escrowKeyStateNotice(self, *, pre, aid, serder, saider, dater, cigars=None, tsgs=None): + def escrowKeyStateNotice(self, *, pre, aid, ksr, saider, dater, cigars=None, tsgs=None): """ Escrow reply by route Parameters: pre (str): identifier of key state aid (str): identifier of authorizer of key state - serder (Serder): instance of reply msg (SAD) + ksr (KeyStateRecord): instance holds key state notice saider (Saider): instance from said in serder (SAD) dater (Dater): instance from date-time in serder (SAD) cigars (list): of Cigar instances that contain nontrans signing couple @@ -3856,7 +3880,7 @@ def escrowKeyStateNotice(self, *, pre, aid, serder, saider, dater, cigars=None, """ keys = (saider.qb64,) self.db.kdts.put(keys=keys, val=dater) # first one idempotent - self.db.ksns.put(keys=keys, val=serder) # first one idempotent + self.db.ksns.put(keys=keys, val=ksr) # first one idempotent for prefixer, seqner, diger, sigers in tsgs: # iterate over each tsg quadkeys = (saider.qb64, prefixer.qb64, f"{seqner.sn:032x}", diger.qb64) @@ -3866,7 +3890,8 @@ def escrowKeyStateNotice(self, *, pre, aid, serder, saider, dater, cigars=None, return self.db.knes.put(keys=(pre, aid), vals=[saider]) # overwrite - def updateKeyState(self, aid, serder, saider, dater): + + def updateKeyState(self, aid, ksr, saider, dater): """ Update Reply SAD in database given by by serder and associated databases for attached cig couple or sig quadruple. @@ -3874,7 +3899,7 @@ def updateKeyState(self, aid, serder, saider, dater): Parameters: aid (str): identifier of key state - serder (Serder): instance of reply msg (SAD) + ksr (KeyStateRecord): converted from key state notice dict in reply msg saider (Saider): instance from said in serder (SAD) dater (Dater): instance from date-time in serder (SAD) """ @@ -3882,9 +3907,10 @@ def updateKeyState(self, aid, serder, saider, dater): # Add source of ksn to the key for DATEs too... (source AID, ksn AID) self.db.kdts.put(keys=keys, val=dater) # first one idempotent - self.db.ksns.pin(keys=keys, val=serder) # first one idempotent - # Add source of ksn to the key... (source AID, ksn AID) - self.db.knas.pin(keys=(serder.pre, aid), val=saider) # overwrite + self.db.ksns.pin(keys=keys, val=ksr) # first one idempotent + # Add source of ksr to the key... (ksr AID, source aid) + self.db.knas.pin(keys=(ksr.i, aid), val=saider) # overwrite + def removeKeyState(self, saider): if saider: @@ -3895,9 +3921,10 @@ def removeKeyState(self, saider): self.db.ksns.rem(keys=keys) self.db.kdts.rem(keys=keys) + def processEscrowKeyState(self): """ - Process escrows for reply messages. Escrows are keyed by reply pre + Process escrows for key state reply messages. Escrows are keyed by reply pre and val is reply said triple (prefixer, seqner, diger) @@ -3910,6 +3937,8 @@ def processEscrowKeyState(self): keys = (saider.qb64,) dater = self.db.kdts.get(keys=keys) + # following is wrong need the actual serder of the reply message not + # the embedded key state notice or key state record serder = self.db.ksns.get(keys=keys) vcigars = self.db.kcgs.get(keys=keys) @@ -3933,7 +3962,10 @@ def processEscrowKeyState(self): raise ValidationError(f"Stale key state escrow at pre = {pre}.") - self.processReplyKeyStateNotice(serder=serder, saider=saider, route=serder.ked["r"], cigars=cigars, + self.processReplyKeyStateNotice(serder=serder, + saider=saider, + route=serder.ked["r"], + cigars=cigars, tsgs=tsgs, aid=aid) except kering.OutOfOrderKeyStateError as ex: @@ -3964,6 +3996,7 @@ def processEscrowKeyState(self): else: logger.error("Kevery unescrowed due to error: %s\n", ex.args[0]) + def processQuery(self, serder, source=None, sigers=None, cigars=None): """ Process query mode replay message for collective or single element query. @@ -4036,8 +4069,9 @@ def processQuery(self, serder, source=None, sigers=None, cigars=None): self.escrowQueryNotFoundEvent(serder=serder, prefixer=source, sigers=sigers, cigars=cigars) raise QueryNotFoundError("Query not found error={}.".format(ked)) - ksn = reply(route=f"/ksn/{src}", data=kever.state().ked) - self.cues.push(dict(kin="reply", src=src, route="/ksn", serder=ksn, dest=source.qb64)) + rserder = reply(route=f"/ksn/{src}", data=kever.state()._asdict()) + self.cues.push(dict(kin="reply", src=src, route="/ksn", serder=rserder, + dest=source.qb64)) elif route == "mbx": pre = qry["i"] diff --git a/src/keri/db/basing.py b/src/keri/db/basing.py index 2c2262ccd..a3bef068a 100644 --- a/src/keri/db/basing.py +++ b/src/keri/db/basing.py @@ -23,7 +23,11 @@ import shutil from contextlib import contextmanager from dataclasses import dataclass, asdict, field +import json + +import cbor2 as cbor +import msgpack import lmdb from ordered_set import OrderedSet as oset @@ -35,6 +39,7 @@ from ..core import coring, eventing, parsing from .. import help +from ..help import helping logger = help.ogler.getLogger() @@ -58,10 +63,10 @@ def __getitem__(self, k): except KeyError as ex: if not self.db: raise ex # reraise KeyError - if (ked := self.db.states.getDict(keys=k)) is None: + if (ksr := self.db.states.get(keys=k)) is None: raise ex # reraise KeyError try: - kever = eventing.Kever(state=coring.Serder(ked=ked), db=self.db) + kever = eventing.Kever(state=ksr, db=self.db) except kering.MissingEntryError: # no kel event for keystate raise ex # reraise KeyError self.__setitem__(k, kever) @@ -83,8 +88,51 @@ def get(self, k, default=None): else: return self.__getitem__(k) + +@dataclass +class RawRecord: + """RawRecord is base class for dataclasses that provides private utility + methods for representing the dataclass as some other format like dict, + json bytes, cbor bytes, mgpk bytes as a raw format. Typically uses case + is to transform dataclass into dict or serialization of its transformation + into dict so that it can be included in messages or stored in a database. + """ + + @classmethod + def _fromdict(cls, d: dict): + """returns instance of clas initialized from dict d """ + return helping.datify(cls, d) + + + def __iter__(self): + return iter(asdict(self)) + + + def _asdict(self): + """Returns dict version of record""" + return helping.dictify(self) + + + def _asjson(self): + """Returns json bytes version of record""" + return json.dumps(self._asdict(), + separators=(",", ":"), + ensure_ascii=False).encode("utf-8") + + + def _ascbor(self): + """Returns cbor bytes version of record""" + return cbor.dumps(self._asdict()) + + + def _asmgpk(self): + """Returns mgpk bytes version of record""" + return msgpack.dumps(self._asdict()) + + + @dataclass -class KeyStateRecord: # baser.state +class KeyStateRecord(RawRecord): # baser.state """ Key State information keyed by Identifier Prefix of associated KEL. For local AIDs that correspond to Habs this is the Hab AID. @@ -123,9 +171,6 @@ class KeyStateRecord: # baser.state # ba = backer (witness) add list (adds) from latest est event di: str = '' # delegator aid qb64 if any otherwise empty '' str - def __iter__(self): - return iter(asdict(self)) - @@ -860,9 +905,12 @@ def reopen(self, **kwa): self.kdts = subing.CesrSuber(db=self, subkey='kdts.', klas=coring.Dater) # all key state messages. Maps key state said to serialization. ksns are - # versioned sads ( with version string) so use Serder to deserialize and + # KeyStateRecords so use ._asdict or ._asjson as appropriate # use .kdts, .ksgs, and .kcgs for datetimes and signatures - self.ksns = subing.SerderSuber(db=self, subkey='ksns.') + self.ksns = koming.Komer(db=self, + schema=KeyStateRecord, + subkey='ksns.') + #self.ksns = subing.SerderSuber(db=self, subkey='ksns.') # all key state ksgs (ksn indexed signature serializations) maps ksn quadkeys # given by quadruple (saider.qb64, prefixer.qb64, seqner.q64, diger.qb64) @@ -979,9 +1027,9 @@ def reload(self): """ removes = [] for keys, data in self.habs.getItemIter(): - if (ked := self.states.getDict(keys=data.hid)) is not None: + if (ksr := self.states.get(keys=data.hid)) is not None: try: - kever = eventing.Kever(state=coring.Serder(ked=ked), + kever = eventing.Kever(state=ksr, db=self, prefixes=self.prefixes, local=True) @@ -999,9 +1047,9 @@ def reload(self): # Load namespaced Habs removes = [] for keys, data in self.nmsp.getItemIter(): - if (ked := self.states.getDict(keys=data.hid)) is not None: + if (ksr := self.states.get(keys=data.hid)) is not None: try: - kever = eventing.Kever(state=coring.Serder(ked=ked), + kever = eventing.Kever(state=ksr, db=self, prefixes=self.prefixes, local=True) diff --git a/tests/app/test_querying.py b/tests/app/test_querying.py index df62d9489..e892e79ca 100644 --- a/tests/app/test_querying.py +++ b/tests/app/test_querying.py @@ -44,8 +44,8 @@ def test_querying(): # Cue up a saved key state equal to the one we have hby.kvy.cues.clear() - ksn = subHab.kever.state() - cue = dict(kin="keyStateSaved", serder=ksn) + ksr = subHab.kever.state() + cue = dict(kin="keyStateSaved", serder=ksr._asdict()) hby.kvy.cues.append(cue) doist.recur(deeds=deeds) @@ -62,8 +62,8 @@ def test_querying(): # rotate AID and submit as a new keyStateSave rot = subHab.rotate() - ksn = subHab.kever.state() - cue = dict(kin="keyStateSaved", serder=ksn) + ksr = subHab.kever.state() + cue = dict(kin="keyStateSaved", serder=ksr._asdict()) hby.kvy.cues.append(cue) deeds = doist.enter(doers=[qdoer]) doist.recur(deeds=deeds) diff --git a/tests/core/test_eventing.py b/tests/core/test_eventing.py index b003b41d7..048fd736e 100644 --- a/tests/core/test_eventing.py +++ b/tests/core/test_eventing.py @@ -9,7 +9,7 @@ import pysodium import pytest -from keri import help + from keri.app import habbing, keeping from keri.app.keeping import openKS, Manager from keri.core import coring, eventing, parsing @@ -32,6 +32,9 @@ from keri.db.dbing import dgKey, snKey from keri.kering import (ValidationError, DerivationError) +from keri import help +from keri.help import helping + logger = help.ogler.getLogger() @@ -1570,7 +1573,7 @@ def test_state(mockHelpingNowUTC): br=[preW0], ba=[preW3]) - serderK = state(pre=preC, + ksr = state(pre=preC, sn=4, pig='EAskHI462CuIMS_gNkcl_QewzrRSKH2p9zHQIO132Z30', dig='EANkcl_QewzrRSKH2p9zUskHI462CuIMS_HQIO132Z30', @@ -1584,20 +1587,21 @@ def test_state(mockHelpingNowUTC): wits=wits, ) - assert serderK.raw == (b'{"v":"KERI10JSON0002d5_","vn":[1,0],"i":"DN6WBhWqp6wC08no2iWhgFYTaUgrasnqz6l' - b'lSvWQTWZN","s":"4","p":"EAskHI462CuIMS_gNkcl_QewzrRSKH2p9zHQIO132Z30","d":"E' - b'ANkcl_QewzrRSKH2p9zUskHI462CuIMS_HQIO132Z30","f":"4","dt":"2021-01-01T00:00:' - b'00.000000+00:00","et":"ixn","kt":"1","k":["DN6WBhWqp6wC08no2iWhgFYTaUgrasnqz' - b'6llSvWQTWZN"],"nt":"1","n":["EDDOarj1lzr8pqG5a-SSnM2cc_3JgstRRjmzrrA_Bibg"],' - b'"bt":"2","b":["BGhCNcrRBR6mlBduhbuCYL7Bwc3gbuyaGo9opZsd0D8F","BO7x6ctSA7FllJ' - b'x39hlObnetizGFjuZT1jq0geno0NRK","BK7isi_2-A-RE6Pbtdg7S1NSeinNQkJ4oCFASqwRc_9' - b'W"],"c":[],"ee":{"s":"3","d":"EUskHI462CuIMS_gNkcl_QewzrRSKH2p9zHQIO132Z30",' - b'"br":["BDU5LLVHxQSb9EdSKDTYyqViusxGT8Y4DHOyktkOv5Rt"],"ba":["BK7isi_2-A-RE6P' - b'btdg7S1NSeinNQkJ4oCFASqwRc_9W"]},"di":""}') - - assert serderK.said == 'EANkcl_QewzrRSKH2p9zUskHI462CuIMS_HQIO132Z30' - assert serderK.pre == preC == 'DN6WBhWqp6wC08no2iWhgFYTaUgrasnqz6llSvWQTWZN' - assert serderK.sn == 4 + raw = ksr._asjson() + assert raw == (b'{"v":"KERI10JSON000000_","vn":[1,0],"i":"DN6WBhWqp6wC08no2iWhgFYTaUgrasnqz6l' + b'lSvWQTWZN","s":"4","p":"EAskHI462CuIMS_gNkcl_QewzrRSKH2p9zHQIO132Z30","d":"E' + b'ANkcl_QewzrRSKH2p9zUskHI462CuIMS_HQIO132Z30","f":"4","dt":"2021-01-01T00:00:' + b'00.000000+00:00","et":"ixn","kt":"1","k":["DN6WBhWqp6wC08no2iWhgFYTaUgrasnqz' + b'6llSvWQTWZN"],"nt":"1","n":["EDDOarj1lzr8pqG5a-SSnM2cc_3JgstRRjmzrrA_Bibg"],' + b'"bt":"2","b":["BGhCNcrRBR6mlBduhbuCYL7Bwc3gbuyaGo9opZsd0D8F","BO7x6ctSA7FllJ' + b'x39hlObnetizGFjuZT1jq0geno0NRK","BK7isi_2-A-RE6Pbtdg7S1NSeinNQkJ4oCFASqwRc_9' + b'W"],"c":[],"ee":{"s":"3","d":"EUskHI462CuIMS_gNkcl_QewzrRSKH2p9zHQIO132Z30",' + b'"br":["BDU5LLVHxQSb9EdSKDTYyqViusxGT8Y4DHOyktkOv5Rt"],"ba":["BK7isi_2-A-RE6P' + b'btdg7S1NSeinNQkJ4oCFASqwRc_9W"]},"di":""}') + + assert ksr.d == 'EANkcl_QewzrRSKH2p9zUskHI462CuIMS_HQIO132Z30' + assert ksr.i == preC == 'DN6WBhWqp6wC08no2iWhgFYTaUgrasnqz6llSvWQTWZN' + assert ksr.s == '4' # create endorsed ksn with nontrans endorser # create nontrans key pair for endorder of KSN @@ -1606,23 +1610,23 @@ def test_state(mockHelpingNowUTC): preE = signerE.verfer.qb64 # use public key verfer.qb64 as pre assert preE == 'BMrwi0a-Zblpqe5Hg7w7iz9JCKnMgWKu_W9w4aNUL64y' - cigarE = signerE.sign(ser=serderK.raw) - assert signerE.verfer.verify(sig=cigarE.raw, ser=serderK.raw) - msg = messagize(serderK, cigars=[cigarE]) - assert msg == (b'{"v":"KERI10JSON0002d5_","vn":[1,0],"i":"DN6WBhWqp6wC08no2iWhgFY' - b'TaUgrasnqz6llSvWQTWZN","s":"4","p":"EAskHI462CuIMS_gNkcl_QewzrRS' - b'KH2p9zHQIO132Z30","d":"EANkcl_QewzrRSKH2p9zUskHI462CuIMS_HQIO132' - b'Z30","f":"4","dt":"2021-01-01T00:00:00.000000+00:00","et":"ixn",' - b'"kt":"1","k":["DN6WBhWqp6wC08no2iWhgFYTaUgrasnqz6llSvWQTWZN"],"n' - b't":"1","n":["EDDOarj1lzr8pqG5a-SSnM2cc_3JgstRRjmzrrA_Bibg"],"bt"' - b':"2","b":["BGhCNcrRBR6mlBduhbuCYL7Bwc3gbuyaGo9opZsd0D8F","BO7x6c' - b'tSA7FllJx39hlObnetizGFjuZT1jq0geno0NRK","BK7isi_2-A-RE6Pbtdg7S1N' - b'SeinNQkJ4oCFASqwRc_9W"],"c":[],"ee":{"s":"3","d":"EUskHI462CuIMS' - b'_gNkcl_QewzrRSKH2p9zHQIO132Z30","br":["BDU5LLVHxQSb9EdSKDTYyqViu' - b'sxGT8Y4DHOyktkOv5Rt"],"ba":["BK7isi_2-A-RE6Pbtdg7S1NSeinNQkJ4oCF' - b'ASqwRc_9W"]},"di":""}-CABBMrwi0a-Zblpqe5Hg7w7iz9JCKnMgWKu_W9w4aN' - b'UL64y0BAxhIlDV7ZlsV2OoDi1ltOQOFA7Z7NnjdoEL_rKdO2mn2q3LEtbPPYgJ9t' - b'UOIE3F0BABStJ5RMOrqnrwntbZesG') + cigarE = signerE.sign(ser=raw) + assert signerE.verfer.verify(sig=cigarE.raw, ser=raw) + #msg = messagize(serderK, cigars=[cigarE]) + #assert msg == (b'{"v":"KERI10JSON0002d5_","vn":[1,0],"i":"DN6WBhWqp6wC08no2iWhgFY' + #b'TaUgrasnqz6llSvWQTWZN","s":"4","p":"EAskHI462CuIMS_gNkcl_QewzrRS' + #b'KH2p9zHQIO132Z30","d":"EANkcl_QewzrRSKH2p9zUskHI462CuIMS_HQIO132' + #b'Z30","f":"4","dt":"2021-01-01T00:00:00.000000+00:00","et":"ixn",' + #b'"kt":"1","k":["DN6WBhWqp6wC08no2iWhgFYTaUgrasnqz6llSvWQTWZN"],"n' + #b't":"1","n":["EDDOarj1lzr8pqG5a-SSnM2cc_3JgstRRjmzrrA_Bibg"],"bt"' + #b':"2","b":["BGhCNcrRBR6mlBduhbuCYL7Bwc3gbuyaGo9opZsd0D8F","BO7x6c' + #b'tSA7FllJx39hlObnetizGFjuZT1jq0geno0NRK","BK7isi_2-A-RE6Pbtdg7S1N' + #b'SeinNQkJ4oCFASqwRc_9W"],"c":[],"ee":{"s":"3","d":"EUskHI462CuIMS' + #b'_gNkcl_QewzrRSKH2p9zHQIO132Z30","br":["BDU5LLVHxQSb9EdSKDTYyqViu' + #b'sxGT8Y4DHOyktkOv5Rt"],"ba":["BK7isi_2-A-RE6Pbtdg7S1NSeinNQkJ4oCF' + #b'ASqwRc_9W"]},"di":""}-CABBMrwi0a-Zblpqe5Hg7w7iz9JCKnMgWKu_W9w4aN' + #b'UL64y0BAxhIlDV7ZlsV2OoDi1ltOQOFA7Z7NnjdoEL_rKdO2mn2q3LEtbPPYgJ9t' + #b'UOIE3F0BABStJ5RMOrqnrwntbZesG') # create endorsed ksn with trans endorser # create trans key pair for endorder of KSN @@ -1637,24 +1641,24 @@ def test_state(mockHelpingNowUTC): d='EAuNWHss_H_kH4cG7Li1jn2DXfrEaqN7zhqTEhkeDZ2z') # create endorsed ksn - sigerE = signerE.sign(ser=serderK.raw, index=0) - assert signerE.verfer.verify(sig=sigerE.raw, ser=serderK.raw) - msg = messagize(serderK, sigers=[sigerE], seal=seal) - assert msg == (b'{"v":"KERI10JSON0002d5_","vn":[1,0],"i":"DN6WBhWqp6wC08no2iWhgFY' - b'TaUgrasnqz6llSvWQTWZN","s":"4","p":"EAskHI462CuIMS_gNkcl_QewzrRS' - b'KH2p9zHQIO132Z30","d":"EANkcl_QewzrRSKH2p9zUskHI462CuIMS_HQIO132' - b'Z30","f":"4","dt":"2021-01-01T00:00:00.000000+00:00","et":"ixn",' - b'"kt":"1","k":["DN6WBhWqp6wC08no2iWhgFYTaUgrasnqz6llSvWQTWZN"],"n' - b't":"1","n":["EDDOarj1lzr8pqG5a-SSnM2cc_3JgstRRjmzrrA_Bibg"],"bt"' - b':"2","b":["BGhCNcrRBR6mlBduhbuCYL7Bwc3gbuyaGo9opZsd0D8F","BO7x6c' - b'tSA7FllJx39hlObnetizGFjuZT1jq0geno0NRK","BK7isi_2-A-RE6Pbtdg7S1N' - b'SeinNQkJ4oCFASqwRc_9W"],"c":[],"ee":{"s":"3","d":"EUskHI462CuIMS' - b'_gNkcl_QewzrRSKH2p9zHQIO132Z30","br":["BDU5LLVHxQSb9EdSKDTYyqViu' - b'sxGT8Y4DHOyktkOv5Rt"],"ba":["BK7isi_2-A-RE6Pbtdg7S1NSeinNQkJ4oCF' - b'ASqwRc_9W"]},"di":""}-FABDMrwi0a-Zblpqe5Hg7w7iz9JCKnMgWKu_W9w4aN' - b'UL64y0AAAAAAAAAAAAAAAAAAAAAAAEAuNWHss_H_kH4cG7Li1jn2DXfrEaqN7zhq' - b'TEhkeDZ2z-AABAAAxhIlDV7ZlsV2OoDi1ltOQOFA7Z7NnjdoEL_rKdO2mn2q3LEt' - b'bPPYgJ9tUOIE3F0BABStJ5RMOrqnrwntbZesG') + sigerE = signerE.sign(ser=raw, index=0) + assert signerE.verfer.verify(sig=sigerE.raw, ser=raw) + #msg = messagize(serderK, sigers=[sigerE], seal=seal) + #assert msg == (b'{"v":"KERI10JSON0002d5_","vn":[1,0],"i":"DN6WBhWqp6wC08no2iWhgFY' + #b'TaUgrasnqz6llSvWQTWZN","s":"4","p":"EAskHI462CuIMS_gNkcl_QewzrRS' + #b'KH2p9zHQIO132Z30","d":"EANkcl_QewzrRSKH2p9zUskHI462CuIMS_HQIO132' + #b'Z30","f":"4","dt":"2021-01-01T00:00:00.000000+00:00","et":"ixn",' + #b'"kt":"1","k":["DN6WBhWqp6wC08no2iWhgFYTaUgrasnqz6llSvWQTWZN"],"n' + #b't":"1","n":["EDDOarj1lzr8pqG5a-SSnM2cc_3JgstRRjmzrrA_Bibg"],"bt"' + #b':"2","b":["BGhCNcrRBR6mlBduhbuCYL7Bwc3gbuyaGo9opZsd0D8F","BO7x6c' + #b'tSA7FllJx39hlObnetizGFjuZT1jq0geno0NRK","BK7isi_2-A-RE6Pbtdg7S1N' + #b'SeinNQkJ4oCFASqwRc_9W"],"c":[],"ee":{"s":"3","d":"EUskHI462CuIMS' + #b'_gNkcl_QewzrRSKH2p9zHQIO132Z30","br":["BDU5LLVHxQSb9EdSKDTYyqViu' + #b'sxGT8Y4DHOyktkOv5Rt"],"ba":["BK7isi_2-A-RE6Pbtdg7S1NSeinNQkJ4oCF' + #b'ASqwRc_9W"]},"di":""}-FABDMrwi0a-Zblpqe5Hg7w7iz9JCKnMgWKu_W9w4aN' + #b'UL64y0AAAAAAAAAAAAAAAAAAAAAAAEAuNWHss_H_kH4cG7Li1jn2DXfrEaqN7zhq' + #b'TEhkeDZ2z-AABAAAxhIlDV7ZlsV2OoDi1ltOQOFA7Z7NnjdoEL_rKdO2mn2q3LEt' + #b'bPPYgJ9tUOIE3F0BABStJ5RMOrqnrwntbZesG') # State Delegated (key state notification) @@ -1707,7 +1711,7 @@ def test_state(mockHelpingNowUTC): preD = signerD.verfer.qb64 # use public key verfer.qb64 as trans pre assert preD == 'DBs-gd3nJGtF0Ch2jn7NLaUKsCKB7l3nLs-993_s5Ie1' - serderK = state(pre=preC, + ksr = state(pre=preC, sn=4, pig='EAskHI462CuIMS_gNkcl_QewzrRSKH2p9zHQIO132Z30', dig='EANkcl_QewzrRSKH2p9zUskHI462CuIMS_HQIO132Z30', @@ -1722,21 +1726,23 @@ def test_state(mockHelpingNowUTC): dpre=preD ) - assert serderK.raw == (b'{"v":"KERI10JSON000301_","vn":[1,0],"i":"DN6WBhWqp6wC08no2iWhgFYTaUgrasnqz6l' - b'lSvWQTWZN","s":"4","p":"EAskHI462CuIMS_gNkcl_QewzrRSKH2p9zHQIO132Z30","d":"E' - b'ANkcl_QewzrRSKH2p9zUskHI462CuIMS_HQIO132Z30","f":"4","dt":"2021-01-01T00:00:' - b'00.000000+00:00","et":"ixn","kt":"1","k":["DN6WBhWqp6wC08no2iWhgFYTaUgrasnqz' - b'6llSvWQTWZN"],"nt":"1","n":["EDDOarj1lzr8pqG5a-SSnM2cc_3JgstRRjmzrrA_Bibg"],' - b'"bt":"2","b":["BGhCNcrRBR6mlBduhbuCYL7Bwc3gbuyaGo9opZsd0D8F","BO7x6ctSA7FllJ' - b'x39hlObnetizGFjuZT1jq0geno0NRK","BK7isi_2-A-RE6Pbtdg7S1NSeinNQkJ4oCFASqwRc_9' - b'W"],"c":[],"ee":{"s":"3","d":"EAskHI462CuIMS_gNkcl_QewzrRSKH2p9zHQIO132Z30",' - b'"br":["BDU5LLVHxQSb9EdSKDTYyqViusxGT8Y4DHOyktkOv5Rt"],"ba":["BK7isi_2-A-RE6P' - b'btdg7S1NSeinNQkJ4oCFASqwRc_9W"]},"di":"DBs-gd3nJGtF0Ch2jn7NLaUKsCKB7l3nLs-99' - b'3_s5Ie1"}') - - assert serderK.said == 'EANkcl_QewzrRSKH2p9zUskHI462CuIMS_HQIO132Z30' - assert serderK.pre == preC == 'DN6WBhWqp6wC08no2iWhgFYTaUgrasnqz6llSvWQTWZN' - assert serderK.sn == 4 + raw = ksr._asjson() + + assert raw == (b'{"v":"KERI10JSON000000_","vn":[1,0],"i":"DN6WBhWqp6wC08no2iWhgFYTaUgrasnqz6l' + b'lSvWQTWZN","s":"4","p":"EAskHI462CuIMS_gNkcl_QewzrRSKH2p9zHQIO132Z30","d":"E' + b'ANkcl_QewzrRSKH2p9zUskHI462CuIMS_HQIO132Z30","f":"4","dt":"2021-01-01T00:00:' + b'00.000000+00:00","et":"ixn","kt":"1","k":["DN6WBhWqp6wC08no2iWhgFYTaUgrasnqz' + b'6llSvWQTWZN"],"nt":"1","n":["EDDOarj1lzr8pqG5a-SSnM2cc_3JgstRRjmzrrA_Bibg"],' + b'"bt":"2","b":["BGhCNcrRBR6mlBduhbuCYL7Bwc3gbuyaGo9opZsd0D8F","BO7x6ctSA7FllJ' + b'x39hlObnetizGFjuZT1jq0geno0NRK","BK7isi_2-A-RE6Pbtdg7S1NSeinNQkJ4oCFASqwRc_9' + b'W"],"c":[],"ee":{"s":"3","d":"EAskHI462CuIMS_gNkcl_QewzrRSKH2p9zHQIO132Z30",' + b'"br":["BDU5LLVHxQSb9EdSKDTYyqViusxGT8Y4DHOyktkOv5Rt"],"ba":["BK7isi_2-A-RE6P' + b'btdg7S1NSeinNQkJ4oCFASqwRc_9W"]},"di":"DBs-gd3nJGtF0Ch2jn7NLaUKsCKB7l3nLs-99' + b'3_s5Ie1"}') + + assert ksr.d == 'EANkcl_QewzrRSKH2p9zUskHI462CuIMS_HQIO132Z30' + assert ksr.i == preC == 'DN6WBhWqp6wC08no2iWhgFYTaUgrasnqz6llSvWQTWZN' + assert ksr.s == '4' # create endorsed ksn with nontrans endorser # create nontrans key pair for endorder of KSN @@ -1746,24 +1752,24 @@ def test_state(mockHelpingNowUTC): assert preE == 'BMrwi0a-Zblpqe5Hg7w7iz9JCKnMgWKu_W9w4aNUL64y' # create endorsed ksn - cigarE = signerE.sign(ser=serderK.raw) - assert signerE.verfer.verify(sig=cigarE.raw, ser=serderK.raw) - msg = messagize(serderK, cigars=[cigarE]) - assert msg == (b'{"v":"KERI10JSON000301_","vn":[1,0],"i":"DN6WBhWqp6wC08no2iWhgFY' - b'TaUgrasnqz6llSvWQTWZN","s":"4","p":"EAskHI462CuIMS_gNkcl_QewzrRS' - b'KH2p9zHQIO132Z30","d":"EANkcl_QewzrRSKH2p9zUskHI462CuIMS_HQIO132' - b'Z30","f":"4","dt":"2021-01-01T00:00:00.000000+00:00","et":"ixn",' - b'"kt":"1","k":["DN6WBhWqp6wC08no2iWhgFYTaUgrasnqz6llSvWQTWZN"],"n' - b't":"1","n":["EDDOarj1lzr8pqG5a-SSnM2cc_3JgstRRjmzrrA_Bibg"],"bt"' - b':"2","b":["BGhCNcrRBR6mlBduhbuCYL7Bwc3gbuyaGo9opZsd0D8F","BO7x6c' - b'tSA7FllJx39hlObnetizGFjuZT1jq0geno0NRK","BK7isi_2-A-RE6Pbtdg7S1N' - b'SeinNQkJ4oCFASqwRc_9W"],"c":[],"ee":{"s":"3","d":"EAskHI462CuIMS' - b'_gNkcl_QewzrRSKH2p9zHQIO132Z30","br":["BDU5LLVHxQSb9EdSKDTYyqViu' - b'sxGT8Y4DHOyktkOv5Rt"],"ba":["BK7isi_2-A-RE6Pbtdg7S1NSeinNQkJ4oCF' - b'ASqwRc_9W"]},"di":"DBs-gd3nJGtF0Ch2jn7NLaUKsCKB7l3nLs-993_s5Ie1"' - b'}-CABBMrwi0a-Zblpqe5Hg7w7iz9JCKnMgWKu_W9w4aNUL64y0BBTNCmYMYJNNQd' - b'QN9irkUaL_RBdztUlykS6P-fxDUofmfWuTL7Hb0XHjtcT-wJMCYO7G1i5IbuhSHf' - b'o-maDh4EG') + cigarE = signerE.sign(ser=raw) + assert signerE.verfer.verify(sig=cigarE.raw, ser=raw) + #msg = messagize(serderK, cigars=[cigarE]) + #assert msg == (b'{"v":"KERI10JSON000301_","vn":[1,0],"i":"DN6WBhWqp6wC08no2iWhgFY' + #b'TaUgrasnqz6llSvWQTWZN","s":"4","p":"EAskHI462CuIMS_gNkcl_QewzrRS' + #b'KH2p9zHQIO132Z30","d":"EANkcl_QewzrRSKH2p9zUskHI462CuIMS_HQIO132' + #b'Z30","f":"4","dt":"2021-01-01T00:00:00.000000+00:00","et":"ixn",' + #b'"kt":"1","k":["DN6WBhWqp6wC08no2iWhgFYTaUgrasnqz6llSvWQTWZN"],"n' + #b't":"1","n":["EDDOarj1lzr8pqG5a-SSnM2cc_3JgstRRjmzrrA_Bibg"],"bt"' + #b':"2","b":["BGhCNcrRBR6mlBduhbuCYL7Bwc3gbuyaGo9opZsd0D8F","BO7x6c' + #b'tSA7FllJx39hlObnetizGFjuZT1jq0geno0NRK","BK7isi_2-A-RE6Pbtdg7S1N' + #b'SeinNQkJ4oCFASqwRc_9W"],"c":[],"ee":{"s":"3","d":"EAskHI462CuIMS' + #b'_gNkcl_QewzrRSKH2p9zHQIO132Z30","br":["BDU5LLVHxQSb9EdSKDTYyqViu' + #b'sxGT8Y4DHOyktkOv5Rt"],"ba":["BK7isi_2-A-RE6Pbtdg7S1NSeinNQkJ4oCF' + #b'ASqwRc_9W"]},"di":"DBs-gd3nJGtF0Ch2jn7NLaUKsCKB7l3nLs-993_s5Ie1"' + #b'}-CABBMrwi0a-Zblpqe5Hg7w7iz9JCKnMgWKu_W9w4aNUL64y0BBTNCmYMYJNNQd' + #b'QN9irkUaL_RBdztUlykS6P-fxDUofmfWuTL7Hb0XHjtcT-wJMCYO7G1i5IbuhSHf' + #b'o-maDh4EG') # create endorsed ksn with trans endorser # create trans key pair for endorder of KSN @@ -1778,25 +1784,25 @@ def test_state(mockHelpingNowUTC): d='EAuNWHss_H_kH4cG7Li1jn2DXfrEaqN7zhqTEhkeDZ2z') # create endorsed ksn - sigerE = signerE.sign(ser=serderK.raw, index=0) - assert signerE.verfer.verify(sig=sigerE.raw, ser=serderK.raw) - msg = messagize(serderK, sigers=[sigerE], seal=seal) - assert msg == (b'{"v":"KERI10JSON000301_","vn":[1,0],"i":"DN6WBhWqp6wC08no2iWhgFY' - b'TaUgrasnqz6llSvWQTWZN","s":"4","p":"EAskHI462CuIMS_gNkcl_QewzrRS' - b'KH2p9zHQIO132Z30","d":"EANkcl_QewzrRSKH2p9zUskHI462CuIMS_HQIO132' - b'Z30","f":"4","dt":"2021-01-01T00:00:00.000000+00:00","et":"ixn",' - b'"kt":"1","k":["DN6WBhWqp6wC08no2iWhgFYTaUgrasnqz6llSvWQTWZN"],"n' - b't":"1","n":["EDDOarj1lzr8pqG5a-SSnM2cc_3JgstRRjmzrrA_Bibg"],"bt"' - b':"2","b":["BGhCNcrRBR6mlBduhbuCYL7Bwc3gbuyaGo9opZsd0D8F","BO7x6c' - b'tSA7FllJx39hlObnetizGFjuZT1jq0geno0NRK","BK7isi_2-A-RE6Pbtdg7S1N' - b'SeinNQkJ4oCFASqwRc_9W"],"c":[],"ee":{"s":"3","d":"EAskHI462CuIMS' - b'_gNkcl_QewzrRSKH2p9zHQIO132Z30","br":["BDU5LLVHxQSb9EdSKDTYyqViu' - b'sxGT8Y4DHOyktkOv5Rt"],"ba":["BK7isi_2-A-RE6Pbtdg7S1NSeinNQkJ4oCF' - b'ASqwRc_9W"]},"di":"DBs-gd3nJGtF0Ch2jn7NLaUKsCKB7l3nLs-993_s5Ie1"' - b'}-FABDMrwi0a-Zblpqe5Hg7w7iz9JCKnMgWKu_W9w4aNUL64y0AAAAAAAAAAAAAA' - b'AAAAAAAAAEAuNWHss_H_kH4cG7Li1jn2DXfrEaqN7zhqTEhkeDZ2z-AABAABTNCm' - b'YMYJNNQdQN9irkUaL_RBdztUlykS6P-fxDUofmfWuTL7Hb0XHjtcT-wJMCYO7G1i' - b'5IbuhSHfo-maDh4EG') + sigerE = signerE.sign(ser=raw, index=0) + assert signerE.verfer.verify(sig=sigerE.raw, ser=raw) + #msg = messagize(serderK, sigers=[sigerE], seal=seal) + #assert msg == (b'{"v":"KERI10JSON000301_","vn":[1,0],"i":"DN6WBhWqp6wC08no2iWhgFY' + #b'TaUgrasnqz6llSvWQTWZN","s":"4","p":"EAskHI462CuIMS_gNkcl_QewzrRS' + #b'KH2p9zHQIO132Z30","d":"EANkcl_QewzrRSKH2p9zUskHI462CuIMS_HQIO132' + #b'Z30","f":"4","dt":"2021-01-01T00:00:00.000000+00:00","et":"ixn",' + #b'"kt":"1","k":["DN6WBhWqp6wC08no2iWhgFYTaUgrasnqz6llSvWQTWZN"],"n' + #b't":"1","n":["EDDOarj1lzr8pqG5a-SSnM2cc_3JgstRRjmzrrA_Bibg"],"bt"' + #b':"2","b":["BGhCNcrRBR6mlBduhbuCYL7Bwc3gbuyaGo9opZsd0D8F","BO7x6c' + #b'tSA7FllJx39hlObnetizGFjuZT1jq0geno0NRK","BK7isi_2-A-RE6Pbtdg7S1N' + #b'SeinNQkJ4oCFASqwRc_9W"],"c":[],"ee":{"s":"3","d":"EAskHI462CuIMS' + #b'_gNkcl_QewzrRSKH2p9zHQIO132Z30","br":["BDU5LLVHxQSb9EdSKDTYyqViu' + #b'sxGT8Y4DHOyktkOv5Rt"],"ba":["BK7isi_2-A-RE6Pbtdg7S1NSeinNQkJ4oCF' + #b'ASqwRc_9W"]},"di":"DBs-gd3nJGtF0Ch2jn7NLaUKsCKB7l3nLs-993_s5Ie1"' + #b'}-FABDMrwi0a-Zblpqe5Hg7w7iz9JCKnMgWKu_W9w4aNUL64y0AAAAAAAAAAAAAA' + #b'AAAAAAAAAEAuNWHss_H_kH4cG7Li1jn2DXfrEaqN7zhqTEhkeDZ2z-AABAABTNCm' + #b'YMYJNNQdQN9irkUaL_RBdztUlykS6P-fxDUofmfWuTL7Hb0XHjtcT-wJMCYO7G1i' + #b'5IbuhSHfo-maDh4EG') """Done Test""" @@ -2133,23 +2139,23 @@ def test_kever(mockHelpingNowUTC): assert kever.sn == kever.sner.num # sn property assert [verfer.qb64 for verfer in kever.verfers] == [skp0.verfer.qb64] assert kever.digs == nxt - state = Serder(ked=kever.db.states.getDict(keys=kever.prefixer.qb64)) - assert state.sn == kever.sner.num == 0 + state = kever.db.states.get(keys=kever.prefixer.qb64) + assert state.s == kever.sner.numh == '0' feqner = kever.db.fons.get(keys=(kever.prefixer.qb64, kever.serder.said)) assert feqner.sn == kever.sn - serderK = kever.state() - assert serderK.ked == state.ked - assert serderK.pre == kever.prefixer.qb64 - assert serderK.sn == kever.sn - assert ([verfer.qb64 for verfer in serderK.verfers] == + ksr = kever.state() # key state record + assert ksr == state + assert ksr.i == kever.prefixer.qb64 + assert ksr.s == kever.sner.numh + assert ([key for key in ksr.k] == [verfer.qb64 for verfer in kever.verfers]) - assert serderK.raw == (b'{"v":"KERI10JSON0001c1_","vn":[1,0],"i":"DAUDqkmn-hqlQKD8W-FAEa5JUvJC2I9yarE' - b'em-AAEg3e","s":"0","p":"","d":"EBTCANzIfUThxmM1z1SFxQuwooGdF4QwtotRS01vZGqi"' - b',"f":"0","dt":"2021-01-01T00:00:00.000000+00:00","et":"icp","kt":"1","k":["D' - b'AUDqkmn-hqlQKD8W-FAEa5JUvJC2I9yarEem-AAEg3e"],"nt":"1","n":["EAKUR-LmLHWMwXT' - b'LWQ1QjxHrihBmwwrV2tYaSG7hOrWj"],"bt":"0","b":[],"c":[],"ee":{"s":"0","d":"EB' - b'TCANzIfUThxmM1z1SFxQuwooGdF4QwtotRS01vZGqi","br":[],"ba":[]},"di":""}') + assert ksr._asjson() == (b'{"v":"KERI10JSON000000_","vn":[1,0],"i":"DAUDqkmn-hqlQKD8W-FAEa5JUvJC2I9yarE' + b'em-AAEg3e","s":"0","p":"","d":"EBTCANzIfUThxmM1z1SFxQuwooGdF4QwtotRS01vZGqi"' + b',"f":"0","dt":"2021-01-01T00:00:00.000000+00:00","et":"icp","kt":"1","k":["D' + b'AUDqkmn-hqlQKD8W-FAEa5JUvJC2I9yarEem-AAEg3e"],"nt":"1","n":["EAKUR-LmLHWMwXT' + b'LWQ1QjxHrihBmwwrV2tYaSG7hOrWj"],"bt":"0","b":[],"c":[],"ee":{"s":"0","d":"EB' + b'TCANzIfUThxmM1z1SFxQuwooGdF4QwtotRS01vZGqi","br":[],"ba":[]},"di":""}') # test exposeds raw = b"raw salt to test" @@ -4791,18 +4797,18 @@ def test_reload_kever(mockHelpingNowUTC): assert serder.said == natHab.kever.serder.said nstate = natHab.kever.state() - state = Serder(ked=natHab.db.states.getDict(keys=natHab.pre)) # Serder instance - assert state.raw == (b'{"v":"KERI10JSON0002a9_","vn":[1,0],"i":"EBm9JqQKS4a3EYv5I7BmAPiwhdSQvFAOpqe' - b'0dgk3kgH_","s":"6","p":"ED_HpKSCQJoeGxHYjPRD2tgUhbIrLf6fH3e3xJFSq2dL","d":"E' - b'A3QbTpV15MvLSXHSedm4lRYdQhmYXqXafsD4i75B_yo","f":"6","dt":"2021-01-01T00:00:' - b'00.000000+00:00","et":"ixn","kt":"2","k":["DCORPGaoMtI_RyJFUTIzk0xdza_z6sBQ2' - b'e2wzYtEAs3s","DNjSHBbYJaaUKJuPd34n7SRYiZHirwvW-QiHRtfRvBh4","DN-hL9CKn6WdsIN' - b'EG207T4pSdjaMIxU9SKhfeeHCwfvT"],"nt":"2","n":["EGZ9WHJPgrvDpe08gJpEZ8Gz-rcy7' - b'2ZG7Tey0PS2CrXY","EO_z0OFTUZ1pmfxj-VnQJcsYFdIVq2tWkN9nUWRxQab_","EMeWMAZpVy7' - b'IX6yl4F2t-WoUCaRFZ-0g5dx_LLoEywhx"],"bt":"0","b":[],"c":[],"ee":{"s":"2","d"' - b':"EJ7s1vk30hWK_l-exQtzj4P5u_wIzki1drVR4FAKDbEW","br":[],"ba":[]},"di":""}') - assert state.ked["f"] == '6' - assert state.ked == nstate.ked + state =natHab.db.states.get(keys=natHab.pre) # key state record + assert state._asjson() == (b'{"v":"KERI10JSON000000_","vn":[1,0],"i":"EBm9JqQKS4a3EYv5I7BmAPiwhdSQvFAOpqe' + b'0dgk3kgH_","s":"6","p":"ED_HpKSCQJoeGxHYjPRD2tgUhbIrLf6fH3e3xJFSq2dL","d":"E' + b'A3QbTpV15MvLSXHSedm4lRYdQhmYXqXafsD4i75B_yo","f":"6","dt":"2021-01-01T00:00:' + b'00.000000+00:00","et":"ixn","kt":"2","k":["DCORPGaoMtI_RyJFUTIzk0xdza_z6sBQ2' + b'e2wzYtEAs3s","DNjSHBbYJaaUKJuPd34n7SRYiZHirwvW-QiHRtfRvBh4","DN-hL9CKn6WdsIN' + b'EG207T4pSdjaMIxU9SKhfeeHCwfvT"],"nt":"2","n":["EGZ9WHJPgrvDpe08gJpEZ8Gz-rcy7' + b'2ZG7Tey0PS2CrXY","EO_z0OFTUZ1pmfxj-VnQJcsYFdIVq2tWkN9nUWRxQab_","EMeWMAZpVy7' + b'IX6yl4F2t-WoUCaRFZ-0g5dx_LLoEywhx"],"bt":"0","b":[],"c":[],"ee":{"s":"2","d"' + b':"EJ7s1vk30hWK_l-exQtzj4P5u_wIzki1drVR4FAKDbEW","br":[],"ba":[]},"di":""}') + assert state.f == '6' + assert state == nstate # now create new Kever with state kever = eventing.Kever(state=state, db=natHby.db) @@ -4812,16 +4818,16 @@ def test_reload_kever(mockHelpingNowUTC): assert kever.serder.said == natHab.kever.serder.said kstate = kever.state() - assert kstate.ked == state.ked - assert state.raw == (b'{"v":"KERI10JSON0002a9_","vn":[1,0],"i":"EBm9JqQKS4a3EYv5I7BmAPiwhdSQvFAOpqe' - b'0dgk3kgH_","s":"6","p":"ED_HpKSCQJoeGxHYjPRD2tgUhbIrLf6fH3e3xJFSq2dL","d":"E' - b'A3QbTpV15MvLSXHSedm4lRYdQhmYXqXafsD4i75B_yo","f":"6","dt":"2021-01-01T00:00:' - b'00.000000+00:00","et":"ixn","kt":"2","k":["DCORPGaoMtI_RyJFUTIzk0xdza_z6sBQ2' - b'e2wzYtEAs3s","DNjSHBbYJaaUKJuPd34n7SRYiZHirwvW-QiHRtfRvBh4","DN-hL9CKn6WdsIN' - b'EG207T4pSdjaMIxU9SKhfeeHCwfvT"],"nt":"2","n":["EGZ9WHJPgrvDpe08gJpEZ8Gz-rcy7' - b'2ZG7Tey0PS2CrXY","EO_z0OFTUZ1pmfxj-VnQJcsYFdIVq2tWkN9nUWRxQab_","EMeWMAZpVy7' - b'IX6yl4F2t-WoUCaRFZ-0g5dx_LLoEywhx"],"bt":"0","b":[],"c":[],"ee":{"s":"2","d"' - b':"EJ7s1vk30hWK_l-exQtzj4P5u_wIzki1drVR4FAKDbEW","br":[],"ba":[]},"di":""}') + assert kstate == state + assert state._asjson() == (b'{"v":"KERI10JSON000000_","vn":[1,0],"i":"EBm9JqQKS4a3EYv5I7BmAPiwhdSQvFAOpqe' + b'0dgk3kgH_","s":"6","p":"ED_HpKSCQJoeGxHYjPRD2tgUhbIrLf6fH3e3xJFSq2dL","d":"E' + b'A3QbTpV15MvLSXHSedm4lRYdQhmYXqXafsD4i75B_yo","f":"6","dt":"2021-01-01T00:00:' + b'00.000000+00:00","et":"ixn","kt":"2","k":["DCORPGaoMtI_RyJFUTIzk0xdza_z6sBQ2' + b'e2wzYtEAs3s","DNjSHBbYJaaUKJuPd34n7SRYiZHirwvW-QiHRtfRvBh4","DN-hL9CKn6WdsIN' + b'EG207T4pSdjaMIxU9SKhfeeHCwfvT"],"nt":"2","n":["EGZ9WHJPgrvDpe08gJpEZ8Gz-rcy7' + b'2ZG7Tey0PS2CrXY","EO_z0OFTUZ1pmfxj-VnQJcsYFdIVq2tWkN9nUWRxQab_","EMeWMAZpVy7' + b'IX6yl4F2t-WoUCaRFZ-0g5dx_LLoEywhx"],"bt":"0","b":[],"c":[],"ee":{"s":"2","d"' + b':"EJ7s1vk30hWK_l-exQtzj4P5u_wIzki1drVR4FAKDbEW","br":[],"ba":[]},"di":""}') assert not os.path.exists(natHby.ks.path) assert not os.path.exists(natHby.db.path) diff --git a/tests/core/test_keystate.py b/tests/core/test_keystate.py index fe90771ea..d3dd379fc 100644 --- a/tests/core/test_keystate.py +++ b/tests/core/test_keystate.py @@ -82,21 +82,21 @@ def test_keystate(mockHelpingNowUTC): iserder = coring.Serder(raw=bytearray(bobIcp)) wesHab.receipt(serder=iserder) - # Get ksn from Bob and verify - ksn = bobHab.kever.state() - assert ksn.pre == bobHab.pre - assert ksn.sn == 0 - assert ksn.ked["d"] == bobHab.kever.serder.said + # Get key state record (ksr) from Bob and verify + ksr = bobHab.kever.state() + assert ksr.i == bobHab.pre + assert ksr.s == '0' + assert ksr.d == bobHab.kever.serder.said - # Get ksn from Wes and verify + # Get key state record (ksr) from Wes and verify bobKeverFromWes = wesHab.kevers[bobHab.pre] - ksn = bobKeverFromWes.state() - assert ksn.pre == bobHab.pre - assert ksn.sn == 0 - assert ksn.ked["d"] == bobHab.kever.serder.said + ksr = bobKeverFromWes.state() + assert ksr.i == bobHab.pre + assert ksr.s == '0' + assert ksr.d == bobHab.kever.serder.said - msg = wesHab.reply(route="/ksn/" + wesHab.pre, data=ksn.ked) + msg = wesHab.reply(route="/ksn/" + wesHab.pre, data=ksr._asdict()) bamRtr = routing.Router() bamRvy = routing.Revery(db=bamHby.db, rtr=bamRtr) @@ -107,7 +107,7 @@ def test_keystate(mockHelpingNowUTC): assert len(bamKvy.cues) == 1 cue = bamKvy.cues.popleft() assert cue["kin"] == "keyStateSaved" - assert cue["serder"].pre == bobHab.pre + assert cue["serder"].ked['a']["i"] == bobHab.pre msgs = bytearray() # outgoing messages for msg in wesHby.db.clonePreIter(pre=bobHab.pre, fn=0): @@ -143,21 +143,21 @@ def test_keystate(mockHelpingNowUTC): parsing.Parser().parse(ims=bytearray(bobIcp), kvy=wesKvy) assert bobHab.pre in wesHab.kevers - # Get ksn from Bob and verify - ksn = bobHab.kever.state() - assert ksn.pre == bobHab.pre - assert ksn.sn == 0 - assert ksn.ked["d"] == bobHab.kever.serder.said + # Get ksr key state record from Bob and verify + ksr = bobHab.kever.state() + assert ksr.i == bobHab.pre + assert ksr.s == '0' + assert ksr.d == bobHab.kever.serder.said - # Get ksn from Wes and verify + # Get ksr key state record from Wes and verify bobKeverFromWes = wesHab.kevers[bobHab.pre] - ksn = bobKeverFromWes.state() - assert ksn.pre == bobHab.pre - assert ksn.sn == 0 - assert ksn.ked["d"] == bobHab.kever.serder.said + ksr = bobKeverFromWes.state() + assert ksr.i == bobHab.pre + assert ksr.s == '0' + assert ksr.d == bobHab.kever.serder.said - msg = wesHab.reply(route="/ksn/" + wesHab.pre, data=ksn.ked) + msg = wesHab.reply(route="/ksn/" + wesHab.pre, data=ksr._asdict()) #bamHab = habbing.Habitat(name="bam", ks=bamKS, db=bamDB, isith='1', icount=1, #transferable=True, temp=True) @@ -177,7 +177,7 @@ def test_keystate(mockHelpingNowUTC): assert len(bamKvy.cues) == 1 cue = bamKvy.cues.popleft() assert cue["kin"] == "keyStateSaved" - assert cue["serder"].pre == bobHab.pre + assert cue["serder"].ked["a"]["i"] == bobHab.pre msgs = bytearray() # outgoing messages for msg in wesHby.db.clonePreIter(pre=bobHab.pre, fn=0): @@ -212,20 +212,20 @@ def test_keystate(mockHelpingNowUTC): parsing.Parser().parse(ims=bytearray(bobIcp), kvy=wesKvy) assert bobHab.pre in wesHab.kevers - # Get ksn from Bob and verify - ksn = bobHab.kever.state() - assert ksn.pre == bobHab.pre - assert ksn.sn == 0 - assert ksn.ked["d"] == bobHab.kever.serder.said + # Get ksr key state record from Bob and verify + ksr = bobHab.kever.state() + assert ksr.i == bobHab.pre + assert ksr.s == '0' + assert ksr.d == bobHab.kever.serder.said - # Get ksn from Wes and verify + # Get ksr key state record from Wes and verify bobKeverFromWes = wesHab.kevers[bobHab.pre] - ksn = bobKeverFromWes.state() - assert ksn.pre == bobHab.pre - assert ksn.sn == 0 - assert ksn.ked["d"] == bobHab.kever.serder.said + ksr = bobKeverFromWes.state() + assert ksr.i == bobHab.pre + assert ksr.s == '0' + assert ksr.d == bobHab.kever.serder.said - msg = wesHab.reply(route="/ksn/" + wesHab.pre, data=ksn.ked) + msg = wesHab.reply(route="/ksn/" + wesHab.pre, data=ksr._asdict()) bamKvy = eventing.Kevery(db=bamHby.db, lax=False, local=False) parsing.Parser().parse(ims=bytearray(msg), kvy=bamKvy) @@ -243,22 +243,22 @@ def test_keystate(mockHelpingNowUTC): bobHab = bobHby.makeHab(name="bob", isith='1', icount=1, transferable=True) assert bobHab.pre == bobpre - # Get ksn from Bob and verify - ksn = bobHab.kever.state() - assert ksn.pre == bobHab.pre - assert ksn.sn == 0 - assert ksn.ked["d"] == bobHab.kever.serder.said + # Get ksr key state record from Bob and verify + ksr = bobHab.kever.state() + assert ksr.i == bobHab.pre + assert ksr.s == '0' + assert ksr.d == bobHab.kever.serder.said for _ in range(3): bobHab.rotate() - # Get ksn from Bob and verify - ksn = bobHab.kever.state() - assert ksn.pre == bobHab.pre - assert ksn.sn == 3 - assert ksn.ked["d"] == bobHab.kever.serder.said + # Get ksr key state record from Bob and verify + ksr = bobHab.kever.state() + assert ksr.i == bobHab.pre + assert ksr.s == '3' + assert ksr.d == bobHab.kever.serder.said - staleKsn = bobHab.reply(route="/ksn/" + bobHab.pre, data=ksn.ked) + staleKsn = bobHab.reply(route="/ksn/" + bobHab.pre, data=ksr._asdict()) bamRtr = routing.Router() bamRvy = routing.Revery(db=bamHby.db, rtr=bamRtr) @@ -270,12 +270,12 @@ def test_keystate(mockHelpingNowUTC): bobHab.rotate() # Get ksn from Bob and verify - ksn = bobHab.kever.state() - assert ksn.pre == bobHab.pre - assert ksn.sn == 8 - assert ksn.ked["d"] == bobHab.kever.serder.said + ksr = bobHab.kever.state() + assert ksr.i == bobHab.pre + assert ksr.s == '8' + assert ksr.d == bobHab.kever.serder.said - liveKsn = bobHab.reply(route="/ksn/" + bobHab.pre, data=ksn.ked) + liveKsn = bobHab.reply(route="/ksn/" + bobHab.pre, data=ksr._asdict()) parsing.Parser().parse(ims=bytearray(liveKsn), kvy=bamKvy, rvy=bamRvy) msgs = bytearray() # outgoing messages @@ -293,7 +293,7 @@ def test_keystate(mockHelpingNowUTC): saider = bamHby.db.knas.get(keys=keys) assert saider.qb64 == bobHab.kever.serder.said latest = bamHby.db.ksns.get(keys=(saider.qb64,)) - assert latest.sn == 8 + assert latest.s == '8' """End Test""" diff --git a/tests/db/test_basing.py b/tests/db/test_basing.py index ab839b004..5303e1758 100644 --- a/tests/db/test_basing.py +++ b/tests/db/test_basing.py @@ -5,7 +5,7 @@ """ import json import os -from dataclasses import asdict +from dataclasses import dataclass, asdict import lmdb import pytest @@ -1745,7 +1745,7 @@ def test_clean_baser(): fn, dts = natHab.kever.logEvent(serder=badsrdr, first=True) natHab.db.states.pin(keys=natHab.pre, val=datify(KeyStateRecord, - natHab.kever.state().ked)) + natHab.kever.state())) assert fn == 7 # verify garbage event in database @@ -1971,6 +1971,40 @@ def test_usebaser(): """ End Test """ +def test_rawrecord(): + """ + Test RawRecord dataclass + """ + @dataclass + class TestRecord(basing.RawRecord): + x: str = "" + y: int = 0 + + record = TestRecord() + + assert isinstance(record, TestRecord) + assert isinstance(record, basing.RawRecord) + + assert "x" in record + assert "y" in record + + assert record.x == '' + assert record.y == 0 + + record = TestRecord(x="hi", y=3) + + assert record.x == 'hi' + assert record.y == 3 + + assert record._asdict() == {'x': 'hi', 'y': 3} + assert record._asjson() == b'{"x":"hi","y":3}' + assert record._ascbor() == b'\xa2axbhiay\x03' + assert record._asmgpk() == b'\x82\xa1x\xa2hi\xa1y\x03' + + """End Test""" + + + def test_keystaterecord(): """ Test KeyStateRecord dataclass @@ -2002,12 +2036,30 @@ def test_keystaterecord(): 'di': '' } + assert ksr._asdict() == ksn + assert ksr._asjson() == (b'{"v":"","vn":[],"i":"","s":"0","p":"","d":"","f":"0","dt":"","et":"","kt":"0' + b'","k":[],"nt":"0","n":[],"bt":"0","b":[],"c":[],"ee":{},"di":""}') + assert ksr._ascbor() == (b'\xb2av`bvn\x80ai`asa0ap`ad`afa0bdt`bet`bkta0ak\x80bnta0an\x80bbta0ab' + b'\x80ac\x80bee\xa0bdi`') + assert ksr._asmgpk() == (b'\xde\x00\x12\xa1v\xa0\xa2vn\x90\xa1i\xa0\xa1s\xa10\xa1p\xa0\xa1d\xa0\xa1' + b'f\xa10\xa2dt\xa0\xa2et\xa0\xa2kt\xa10\xa1k\x90\xa2nt\xa10\xa1n\x90\xa2' + b'bt\xa10\xa1b\x90\xa1c\x90\xa2ee\x80\xa2di\xa0') + + assert str(ksr) == repr(ksr) == ("KeyStateRecord(v='', vn=[], i='', s='0'," + " p='', d='', f='0', dt='', et='', " + "kt='0', k=[], nt='0', n=[], bt='0', b=[], " + "c=[], ee={}, di='')") + dksn = dictify(ksr) assert dksn == ksn dksr = datify(basing.KeyStateRecord, ksn) assert dksr == ksr + nksr = basing.KeyStateRecord._fromdict(ksn) + assert nksr == ksr + assert nksr._asdict() == ksn + """End Test""" @@ -2077,22 +2129,23 @@ def test_dbdict(): db.putEvt(key=dgkey, val=serder.raw) assert db.getEvt(key=dgkey) is not None - db.states.pin(keys=pre, val=datify(KeyStateRecord, - state.ked)) # put state in database - assert db.states.getDict(keys=pre) is not None + db.states.pin(keys=pre, val=state) # put state in database + dbstate = db.states.get(keys=pre) + assert dbstate is not None + assert dbstate == state kever = eventing.Kever(state=state, db=db) - assert kever.state().ked == state.ked + assert kever.state() == state dkever = dbd[pre] # read through cache works here dstate = dkever.state() - assert dstate.ked == state.ked + assert dstate == state del dbd[pre] # not in dbd memory assert pre in dbd # read through cache works dkever = dbd[pre] dstate = dkever.state() - assert dstate.ked == state.ked + assert dstate == state db.states.rem(keys=pre) assert pre in dbd # still in memory