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 a30670031..2273e0dfc 100644 --- a/src/keri/core/eventing.py +++ b/src/keri/core/eventing.py @@ -2046,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 @@ -2095,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)) @@ -3482,6 +3478,7 @@ def removeStaleReplyEndRole(self, saider): """ pass + def removeStaleReplyLocScheme(self, saider): """ Process reply escrow at saider for route "/loc/scheme" @@ -3500,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): """ @@ -3688,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 @@ -3760,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) + 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 kserder.ked: - raise ValidationError("Missing element = {} from {} msg." - " ksn = {}.".format(k, Ilks.ksn, - serder.pretty())) + #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, @@ -3804,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 @@ -3815,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): @@ -3858,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 @@ -3879,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) @@ -3889,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. @@ -3897,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) """ @@ -3905,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: @@ -3918,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) @@ -3933,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) @@ -3956,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: @@ -3987,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. @@ -4059,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 82b06ced0..a3bef068a 100644 --- a/src/keri/db/basing.py +++ b/src/keri/db/basing.py @@ -97,6 +97,13 @@ class RawRecord: 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)) @@ -167,8 +174,6 @@ class KeyStateRecord(RawRecord): # baser.state - - @dataclass class HabitatRecord: # baser.habs """ @@ -900,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) @@ -1019,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) @@ -1039,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 59d3260e4..048fd736e 100644 --- a/tests/core/test_eventing.py +++ b/tests/core/test_eventing.py @@ -2139,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" @@ -4797,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) @@ -4818,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 83d63fa29..5303e1758 100644 --- a/tests/db/test_basing.py +++ b/tests/db/test_basing.py @@ -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 @@ -2056,6 +2056,10 @@ def test_keystaterecord(): dksr = datify(basing.KeyStateRecord, ksn) assert dksr == ksr + nksr = basing.KeyStateRecord._fromdict(ksn) + assert nksr == ksr + assert nksr._asdict() == ksn + """End Test"""