diff --git a/src/keri/core/eventing.py b/src/keri/core/eventing.py index 2273e0dfc..ab19496cf 100644 --- a/src/keri/core/eventing.py +++ b/src/keri/core/eventing.py @@ -20,7 +20,7 @@ from .. import help from .. import kering from ..db import basing, dbing -from ..db.basing import KeyStateRecord +from ..db.basing import KeyStateRecord, StateEERecord from ..db.dbing import dgKey, snKey, fnKey, splitKeySN, splitKey from ..kering import (MissingEntryError, @@ -1035,7 +1035,7 @@ def state(pre, KeyStateDict: { - "v": "KERI10JSON00011c_", + #"v": "KERI10JSON00011c_", "vn": []1,0], "i": "EaU6JR2nmwyZ-i0d8JZAoTNZH3ULvYAfSVPzhzS6b5CM", "s": "2":, @@ -1063,7 +1063,7 @@ def state(pre, "di": "" when not delegated """ - vs = versify(version=version, kind=kind, size=0) + #vs = versify(version=version, kind=kind, size=0) sner = Number(num=sn) # raises InvalidValueError if sn < 0 @@ -1146,7 +1146,6 @@ def state(pre, f"latest est event.") 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 @@ -1164,35 +1163,11 @@ def state(pre, 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 + ee=StateEERecord._fromdict(eevt._asdict()), # latest est event dict di=dpre if dpre is not None else "", ) 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="", replyRoute="", @@ -1731,9 +1706,6 @@ def __init__(self, *, state=None, serder=None, sigers=None, wigers=None, self.dater = Dater(dts=dts) self.db.states.pin(keys=self.prefixer.qb64, val=self.state()) - #self.db.states.pin(keys=self.prefixer.qb64, - #val=helping.datify(basing.KeyStateRecord, - #self.state().ked)) @property @@ -1790,11 +1762,6 @@ def reload(self, state): 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 = Versionage._make(state.vn) self.prefixer = Prefixer(qb64=state.i) self.sner = Number(numh=state.s) # sequence number Number instance hex str @@ -1807,13 +1774,13 @@ def reload(self, state): 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.cuts = state.ee.br + self.adds = state.ee.ba self.estOnly = False 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.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 diff --git a/src/keri/db/basing.py b/src/keri/db/basing.py index a3bef068a..4d8cd1faa 100644 --- a/src/keri/db/basing.py +++ b/src/keri/db/basing.py @@ -130,6 +130,23 @@ def _asmgpk(self): return msgpack.dumps(self._asdict()) +@dataclass +class StateEERecord(RawRecord): + """ + Corresponds to StateEstEvent namedtuple used as sub record in KeyStateRecord + for latest establishment event associated with current key state + + Attributes: + s (str): sequence number of latest est evt lowercase hex no leading zeros + d (str): SAID qb64 of latest est evt + br (list[str]): backer aids qb64 remove list (cuts) from latest est event + ba (list[str]): backer aids qb64 add list (adds) from latest est event + """ + s: str ='0' # sequence number of latest event in KEL as hex str + d: str ='' # latest event digest qb64 + br: list = field(default_factory=list) # backer AID qb64 remove (cut) list + ba: list = field(default_factory=list) # backer AID qb64 add list + @dataclass class KeyStateRecord(RawRecord): # baser.state @@ -139,15 +156,31 @@ class KeyStateRecord(RawRecord): # baser.state (see baser.state at 'stts') Attributes: + vn (list[int]): version list [major, minor] i (str): identifier prefix qb64 s (str): sequence number of latest event in KEL as hex str p (str): prior event digest qb64 d (str): latest event digest qb64 f (str): first seen ordinal number of latest event in KEL as hex str + dt (str): datetime iso-8601 + et (str): latest establishment event packet type + kt (str): signing threshold sith + k (list[str]): signing keys qb64 + nt (str): next prerotated threshold sith + n (list[str]): pre-rotation keys qb64 + bt (str): backer threshold hex num + b (list[str]): backer aids qb64 + c (list[str]): config traits + ee (StateEERecord): instance + corresponds to StateEstEvent namedtuple + s = sn of latest est event as lowercase hex string no leading zeros, + d = SAID digest qb64 of latest establishment event + br = backer (witness) remove list (cuts) from latest est event + ba = backer (witness) add list (adds) from latest est event + di (str): delegator aid qb64 """ - v: str = '' # version string need to remove replace with vn below vn: list[int] = field(default_factory=list) # version number [major, minor] round trip serializable i: str ='' # identifier prefix qb64 s: str ='0' # sequence number of latest event in KEL as hex str @@ -163,7 +196,9 @@ class KeyStateRecord(RawRecord): # baser.state bt: str = '0' # backer threshold hex num str b: list = field(default_factory=list) # backer AID list qb64 c: list[str] = field(default_factory=list) # config trait list - ee: dict = field(default_factory=dict) # latest est event details + ee: StateEERecord = field(default_factory=StateEERecord) + + #field(default_factory=dict) # latest est event details # asdict of StateEstEvent # s = sn of latest est event as lowercase hex string no leading zeros, # d = SAID digest qb64 of latest establishment event diff --git a/tests/core/test_eventing.py b/tests/core/test_eventing.py index 048fd736e..cad801a69 100644 --- a/tests/core/test_eventing.py +++ b/tests/core/test_eventing.py @@ -1588,16 +1588,16 @@ def test_state(mockHelpingNowUTC): ) 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 raw == (b'{"vn":[1,0],"i":"DN6WBhWqp6wC08no2iWhgFYTaUgrasnqz6llSvWQTWZN","s":"4","p":"' + b'EAskHI462CuIMS_gNkcl_QewzrRSKH2p9zHQIO132Z30","d":"EANkcl_QewzrRSKH2p9zUskHI' + b'462CuIMS_HQIO132Z30","f":"4","dt":"2021-01-01T00:00:00.000000+00:00","et":"i' + b'xn","kt":"1","k":["DN6WBhWqp6wC08no2iWhgFYTaUgrasnqz6llSvWQTWZN"],"nt":"1","' + b'n":["EDDOarj1lzr8pqG5a-SSnM2cc_3JgstRRjmzrrA_Bibg"],"bt":"2","b":["BGhCNcrRB' + b'R6mlBduhbuCYL7Bwc3gbuyaGo9opZsd0D8F","BO7x6ctSA7FllJx39hlObnetizGFjuZT1jq0ge' + b'no0NRK","BK7isi_2-A-RE6Pbtdg7S1NSeinNQkJ4oCFASqwRc_9W"],"c":[],"ee":{"s":"3"' + b',"d":"EUskHI462CuIMS_gNkcl_QewzrRSKH2p9zHQIO132Z30","br":["BDU5LLVHxQSb9EdSK' + b'DTYyqViusxGT8Y4DHOyktkOv5Rt"],"ba":["BK7isi_2-A-RE6Pbtdg7S1NSeinNQkJ4oCFASqw' + b'Rc_9W"]},"di":""}') assert ksr.d == 'EANkcl_QewzrRSKH2p9zUskHI462CuIMS_HQIO132Z30' assert ksr.i == preC == 'DN6WBhWqp6wC08no2iWhgFYTaUgrasnqz6llSvWQTWZN' @@ -1727,18 +1727,16 @@ def test_state(mockHelpingNowUTC): ) 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 raw == (b'{"vn":[1,0],"i":"DN6WBhWqp6wC08no2iWhgFYTaUgrasnqz6llSvWQTWZN","s":"4","p":"' + b'EAskHI462CuIMS_gNkcl_QewzrRSKH2p9zHQIO132Z30","d":"EANkcl_QewzrRSKH2p9zUskHI' + b'462CuIMS_HQIO132Z30","f":"4","dt":"2021-01-01T00:00:00.000000+00:00","et":"i' + b'xn","kt":"1","k":["DN6WBhWqp6wC08no2iWhgFYTaUgrasnqz6llSvWQTWZN"],"nt":"1","' + b'n":["EDDOarj1lzr8pqG5a-SSnM2cc_3JgstRRjmzrrA_Bibg"],"bt":"2","b":["BGhCNcrRB' + b'R6mlBduhbuCYL7Bwc3gbuyaGo9opZsd0D8F","BO7x6ctSA7FllJx39hlObnetizGFjuZT1jq0ge' + b'no0NRK","BK7isi_2-A-RE6Pbtdg7S1NSeinNQkJ4oCFASqwRc_9W"],"c":[],"ee":{"s":"3"' + b',"d":"EAskHI462CuIMS_gNkcl_QewzrRSKH2p9zHQIO132Z30","br":["BDU5LLVHxQSb9EdSK' + b'DTYyqViusxGT8Y4DHOyktkOv5Rt"],"ba":["BK7isi_2-A-RE6Pbtdg7S1NSeinNQkJ4oCFASqw' + b'Rc_9W"]},"di":"DBs-gd3nJGtF0Ch2jn7NLaUKsCKB7l3nLs-993_s5Ie1"}') assert ksr.d == 'EANkcl_QewzrRSKH2p9zUskHI462CuIMS_HQIO132Z30' assert ksr.i == preC == 'DN6WBhWqp6wC08no2iWhgFYTaUgrasnqz6llSvWQTWZN' @@ -2150,12 +2148,12 @@ def test_kever(mockHelpingNowUTC): assert ksr.s == kever.sner.numh assert ([key for key in ksr.k] == [verfer.qb64 for verfer in kever.verfers]) - 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":""}') + assert ksr._asjson() == (b'{"vn":[1,0],"i":"DAUDqkmn-hqlQKD8W-FAEa5JUvJC2I9yarEem-AAEg3e","s":"0","p":"' + b'","d":"EBTCANzIfUThxmM1z1SFxQuwooGdF4QwtotRS01vZGqi","f":"0","dt":"2021-01-0' + b'1T00:00:00.000000+00:00","et":"icp","kt":"1","k":["DAUDqkmn-hqlQKD8W-FAEa5JU' + b'vJC2I9yarEem-AAEg3e"],"nt":"1","n":["EAKUR-LmLHWMwXTLWQ1QjxHrihBmwwrV2tYaSG7' + b'hOrWj"],"bt":"0","b":[],"c":[],"ee":{"s":"0","d":"EBTCANzIfUThxmM1z1SFxQuwoo' + b'GdF4QwtotRS01vZGqi","br":[],"ba":[]},"di":""}') # test exposeds raw = b"raw salt to test" @@ -4798,15 +4796,15 @@ def test_reload_kever(mockHelpingNowUTC): nstate = natHab.kever.state() 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._asjson() == (b'{"vn":[1,0],"i":"EBm9JqQKS4a3EYv5I7BmAPiwhdSQvFAOpqe0dgk3kgH_","s":"6","p":"' + b'ED_HpKSCQJoeGxHYjPRD2tgUhbIrLf6fH3e3xJFSq2dL","d":"EA3QbTpV15MvLSXHSedm4lRYd' + b'QhmYXqXafsD4i75B_yo","f":"6","dt":"2021-01-01T00:00:00.000000+00:00","et":"i' + b'xn","kt":"2","k":["DCORPGaoMtI_RyJFUTIzk0xdza_z6sBQ2e2wzYtEAs3s","DNjSHBbYJa' + b'aUKJuPd34n7SRYiZHirwvW-QiHRtfRvBh4","DN-hL9CKn6WdsINEG207T4pSdjaMIxU9SKhfeeH' + b'CwfvT"],"nt":"2","n":["EGZ9WHJPgrvDpe08gJpEZ8Gz-rcy72ZG7Tey0PS2CrXY","EO_z0O' + b'FTUZ1pmfxj-VnQJcsYFdIVq2tWkN9nUWRxQab_","EMeWMAZpVy7IX6yl4F2t-WoUCaRFZ-0g5dx' + b'_LLoEywhx"],"bt":"0","b":[],"c":[],"ee":{"s":"2","d":"EJ7s1vk30hWK_l-exQtzj4' + b'P5u_wIzki1drVR4FAKDbEW","br":[],"ba":[]},"di":""}') assert state.f == '6' assert state == nstate @@ -4819,15 +4817,15 @@ def test_reload_kever(mockHelpingNowUTC): kstate = kever.state() 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 state._asjson() == (b'{"vn":[1,0],"i":"EBm9JqQKS4a3EYv5I7BmAPiwhdSQvFAOpqe0dgk3kgH_","s":"6","p":"' + b'ED_HpKSCQJoeGxHYjPRD2tgUhbIrLf6fH3e3xJFSq2dL","d":"EA3QbTpV15MvLSXHSedm4lRYd' + b'QhmYXqXafsD4i75B_yo","f":"6","dt":"2021-01-01T00:00:00.000000+00:00","et":"i' + b'xn","kt":"2","k":["DCORPGaoMtI_RyJFUTIzk0xdza_z6sBQ2e2wzYtEAs3s","DNjSHBbYJa' + b'aUKJuPd34n7SRYiZHirwvW-QiHRtfRvBh4","DN-hL9CKn6WdsINEG207T4pSdjaMIxU9SKhfeeH' + b'CwfvT"],"nt":"2","n":["EGZ9WHJPgrvDpe08gJpEZ8Gz-rcy72ZG7Tey0PS2CrXY","EO_z0O' + b'FTUZ1pmfxj-VnQJcsYFdIVq2tWkN9nUWRxQab_","EMeWMAZpVy7IX6yl4F2t-WoUCaRFZ-0g5dx' + b'_LLoEywhx"],"bt":"0","b":[],"c":[],"ee":{"s":"2","d":"EJ7s1vk30hWK_l-exQtzj4' + b'P5u_wIzki1drVR4FAKDbEW","br":[],"ba":[]},"di":""}') assert not os.path.exists(natHby.ks.path) assert not os.path.exists(natHby.db.path) diff --git a/tests/db/test_basing.py b/tests/db/test_basing.py index 5303e1758..762ef78cf 100644 --- a/tests/db/test_basing.py +++ b/tests/db/test_basing.py @@ -1717,9 +1717,9 @@ def test_clean_baser(): assert ldig == natHab.kever.serder.saidb serder = coring.Serder(raw=bytes(natHab.db.getEvt(dbing.dgKey(natHab.pre,ldig)))) assert serder.said == natHab.kever.serder.said - state = Serder(ked=natHab.db.states.getDict(keys=natHab.pre)) # Serder instance - assert state.sn == 6 - assert state.ked["f"] == '6' + state = natHab.db.states.get(keys=natHab.pre) # Serder instance + assert state.s == '6' + assert state.f == '6' assert natHab.db.env.stat()['entries'] <= 96 #68 # test reopenDB with reuse (because temp) @@ -1786,9 +1786,9 @@ def test_clean_baser(): # confirm bad event missing from database assert not natHab.db.getEvt(dbing.dgKey(natHab.pre, badsrdr.said)) assert not natHab.db.getFe(dbing.fnKey(natHab.pre, 7)) - state = Serder(ked=natHab.db.states.getDict(keys=natHab.pre)) # Serder instance - assert state.sn == 6 - assert state.ked["f"] == '6' + state = natHab.db.states.get(keys=natHab.pre) # Serder instance + assert state.s == '6' + assert state.f == '6' # verify name pre kom in db data = natHab.db.habs.get(keys=natHab.name) @@ -2009,15 +2009,18 @@ def test_keystaterecord(): """ Test KeyStateRecord dataclass """ + seer = basing.StateEERecord() + assert seer.s == '0' + assert seer.d == '' + assert seer._asdict() == {'s': '0', 'd': '', 'br': [], 'ba': []} + ksr = basing.KeyStateRecord() assert isinstance(ksr, basing.KeyStateRecord) assert ksr.i == '' ksn = asdict(ksr) # key state notice dict - assert ksn == { - 'v': '', - 'vn': [], + assert ksn == {'vn': [], 'i': '', 's': '0', 'p': '', @@ -2032,23 +2035,26 @@ def test_keystaterecord(): 'bt': '0', 'b': [], 'c': [], - 'ee': {}, - 'di': '' - } + 'ee': {'s': '0', 'd': '', 'br': [], 'ba': []}, + '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='')") + assert ksr._asjson() == (b'{"vn":[],"i":"","s":"0","p":"","d":"","f":"0","dt":"","et":"","kt":"0","k":[' + b'],"nt":"0","n":[],"bt":"0","b":[],"c":[],"ee":{"s":"0","d":"","br":[],"ba":[' + b']},"di":""}') + + assert ksr._ascbor() == (b'\xb1bvn\x80ai`asa0ap`ad`afa0bdt`bet`bkta0ak\x80bnta0an\x80bbta0ab\x80ac' + b'\x80bee\xa4asa0ad`bbr\x80bba\x80bdi`') + + assert ksr._asmgpk() == (b'\xde\x00\x11\xa2vn\x90\xa1i\xa0\xa1s\xa10\xa1p\xa0\xa1d\xa0\xa1f\xa10' + b'\xa2dt\xa0\xa2et\xa0\xa2kt\xa10\xa1k\x90\xa2nt\xa10\xa1n\x90\xa2bt\xa1' + b'0\xa1b\x90\xa1c\x90\xa2ee\x84\xa1s\xa10\xa1d\xa0\xa2br\x90\xa2ba\x90\xa2d' + b'i\xa0') + + + assert str(ksr) == repr(ksr) == ("KeyStateRecord(vn=[], i='', s='0', p='', d='', f='0', dt='', et='', kt='0', " + "k=[], nt='0', n=[], bt='0', b=[], c=[], ee=StateEERecord(s='0', d='', br=[], " + "ba=[]), di='')") dksn = dictify(ksr) assert dksn == ksn