def test_issuer(): """ Test Issuer Class """ issuer = Registry() assert isinstance(issuer, Registry) assert issuer.name == "main" assert issuer.temp is False assert isinstance(issuer.env, lmdb.Environment) assert issuer.path.endswith("keri/db/main") assert issuer.env.path() == issuer.path assert os.path.exists(issuer.path) assert isinstance(issuer.tvts, lmdb._Database) issuer.close(clear=True) assert not os.path.exists(issuer.path) assert not issuer.opened # test not opened on init issuer = Registry(reopen=False) assert isinstance(issuer, Registry) assert issuer.name == "main" assert issuer.temp is False assert issuer.opened is False assert issuer.path is None assert issuer.env is None issuer.reopen() assert issuer.opened assert issuer.path is not None assert isinstance(issuer.env, lmdb.Environment) assert issuer.path.endswith("keri/db/main") assert issuer.env.path() == issuer.path assert os.path.exists(issuer.path) issuer.close(clear=True) assert not os.path.exists(issuer.path) assert not issuer.opened assert isinstance(issuer.tvts, lmdb._Database) with openLMDB(cls=Registry) as issuer: assert isinstance(issuer, Registry) assert issuer.name == "test" assert issuer.temp is True assert isinstance(issuer.env, lmdb.Environment) assert issuer.path.startswith("/tmp/keri_lmdb_") assert issuer.path.endswith("_test/keri/db/test") assert issuer.env.path() == issuer.path assert os.path.exists(issuer.path) assert isinstance(issuer.tvts, lmdb._Database) assert not os.path.exists(issuer.path) ipreb = "DYmJApMvMb8mgiG20BPlPcKLWSfNIUCC21DP0i2_BLjo".encode("utf-8") regb = "EOWdT7a7fZwRz0jiZ0DJxZEM3vsNbLDPEUk-ODnif3O0".encode("utf-8") rarb = "BijzaUuRMwh1ivT5BQrqNhbvx82lB-ofrHVHjL3WADbA".encode("utf-8") # test with registry inception (vcp) event regk = nsKey([ipreb, regb]) assert regk == b'DYmJApMvMb8mgiG20BPlPcKLWSfNIUCC21DP0i2_BLjo:EOWdT7a7fZwRz0jiZ0DJxZEM3vsNbLDPEUk-ODnif3O0' sn = 0 vs = Versify(kind=Serials.json, size=20) vcp = dict(v=vs, i=regk.decode("utf-8"), s="{:x}".format(sn), b=[rarb.decode("utf-8")], t="vcp") vcpb = json.dumps(vcp, separators=(",", ":"), ensure_ascii=False).encode("utf-8") assert vcpb == ( b'{"v":"KERI10JSON000014_",' b'"i":"DYmJApMvMb8mgiG20BPlPcKLWSfNIUCC21DP0i2_BLjo:EOWdT7a7fZwRz0jiZ0DJxZEM3vsNbLDPEUk-ODnif3O0",' b'"s":"0","b":["BijzaUuRMwh1ivT5BQrqNhbvx82lB-ofrHVHjL3WADbA"],"t":"vcp"}' ) vdig = Diger(ser=vcpb) with openLMDB(cls=Registry) as issuer: key = dgKey(regk, vdig.qb64b) assert issuer.getTvt(key) is None assert issuer.delTvt(key) is False assert issuer.putTvt(key, val=vcpb) is True assert issuer.getTvt(key) == vcpb assert issuer.putTvt(key, val=vcpb) is False assert issuer.setTvt(key, val=vcpb) is True assert issuer.getTvt(key) == vcpb assert issuer.delTvt(key) is True assert issuer.getTvt(key) is None telKey = snKey(regk, sn) assert issuer.getTel(telKey) is None assert issuer.delTel(telKey) is False assert issuer.putTel(telKey, val=vdig.qb64b) assert issuer.getTel(telKey) == vdig.qb64b assert issuer.putTel(telKey, val=vdig.qb64b) is False assert issuer.setTel(telKey, val=vdig.qb64b) is True assert issuer.getTel(telKey) == vdig.qb64b assert issuer.delTel(telKey) is True assert issuer.getTel(telKey) is None coupl01 = ( "BPVuWC4Hc0izqPKn2LIwhp72SHJSRgfaL1RhtuiavIy4AAfiKvopJ0O2afOmxb5A6JtdY7Wkl_1uNx1Z8xQkg_" "gMzf-vTfEHDylFdgn2e_u_ppaFajIdvEvONX6dcSYzlfBQ").encode("utf-8") coupl02 = ( "BW1gbapuOJ4TJKwLfKZs5cXEIs9k8EtBqxR1psVxnD7IABrSkjrgPGXdhBiOy6LUZpiqtsHkKHhfLGj_LhT1n6" "EqCIdDjrihzrdM1bm0ZNJDwbDGXoeeZujd7ZYsOsBPzRCw").encode("utf-8") coupl03 = ( "BklrMm7GlYzNrPQunLJHFn_1wWjlUslGkXfs0KyoNOEAAC_6PB5Zre_E_7YLkM9OtRo-uYmwRyFmOH3Xo4JDiP" "jioY7Ycna6ouhSSH0QcKsEjce10HCXIW_XtmEYr9SrB5BA").encode("utf-8") coups = [coupl01, coupl02, coupl03] key = dgKey(regk, vdig.qb64b) assert issuer.getTibs(key) == [] assert issuer.cntTibs(key) == 0 assert issuer.delTibs(key) is False assert issuer.putTibs(key, vals=[coupl01]) is True assert issuer.getTibs(key) == [coupl01] assert issuer.cntTibs(key) == 1 assert issuer.putTibs(key, vals=[coupl01]) is True # add duplicate assert issuer.cntTibs(key) == 1 assert issuer.addTib(key, coupl01) is False assert issuer.addTib(key, coupl02) is True assert issuer.cntTibs(key) == 2 assert issuer.putTibs(key, vals=[coupl02, coupl03]) is True assert issuer.cntTibs(key) == 3 assert issuer.delTibs(key) is True assert issuer.getTibs(key) == [] for c in coups: assert issuer.addTib(key, c) is True assert issuer.cntTibs(key) == 3 assert issuer.getTibs(key) == [coupl01, coupl02, coupl03] for c in issuer.getTibsIter(key): assert issuer.delTibs(key, c) is True assert issuer.getTibs(key) == [] tweKey = snKey(regk, sn) assert issuer.getTwe(tweKey) is None assert issuer.delTwe(tweKey) is False assert issuer.putTwe(tweKey, val=vdig.qb64b) assert issuer.getTwe(tweKey) == vdig.qb64b assert issuer.putTwe(tweKey, val=vdig.qb64b) is False assert issuer.setTwe(tweKey, val=vdig.qb64b) is True assert issuer.getTwe(tweKey) == vdig.qb64b assert issuer.delTwe(tweKey) is True assert issuer.getTwe(tweKey) is None ooKey = snKey(regk, sn) assert issuer.getOot(ooKey) is None assert issuer.delOot(ooKey) is False assert issuer.putOot(ooKey, val=vdig.qb64b) assert issuer.getOot(ooKey) == vdig.qb64b assert issuer.putOot(ooKey, val=vdig.qb64b) is False assert issuer.setOot(ooKey, val=vdig.qb64b) is True assert issuer.getOot(ooKey) == vdig.qb64b assert issuer.delOot(ooKey) is True assert issuer.getOot(ooKey) is None anc01 = ( "DYmJApMvMb8mgiG20BPlPcKLWSfNIUCC21DP0i2_BLjo" "0AAAAAAAAAAAAAAAAAAAAABA" "Ezpq06UecHwzy-K9FpNoRxCJp2wIGM9u2Edk-PLMZ1H4").encode("utf-8") key = dgKey(regk, vdig.qb64b) assert issuer.getAnc(key) is None assert issuer.delAnc(key) is False assert issuer.putAnc(key, val=anc01) assert issuer.getAnc(key) == anc01 assert issuer.putAnc(key, val=anc01) is False assert issuer.setAnc(key, val=anc01) is True assert issuer.getAnc(key) == anc01 assert issuer.delAnc(key) is True assert issuer.getAnc(key) is None # test with verifiable credential issuance (iss) event vcdig = b'EXvR3p8V95W8J7Ui4-mEzZ79S-A1esAnJo1Kmzq80Jkc' vck = nsKey([ipreb, regb, vcdig]) assert vck == ( b'DYmJApMvMb8mgiG20BPlPcKLWSfNIUCC21DP0i2_BLjo:EOWdT7a7fZwRz0jiZ0DJxZEM3vsNbLDPEUk-ODnif3O0' b':EXvR3p8V95W8J7Ui4-mEzZ79S-A1esAnJo1Kmzq80Jkc') sn = 0 vs = Versify(kind=Serials.json, size=20) vcp = dict(v=vs, i=vck.decode("utf-8"), s="{:x}".format(sn), t="iss") issb = json.dumps(vcp, separators=(",", ":"), ensure_ascii=False).encode("utf-8") assert issb == ( b'{"v":"KERI10JSON000014_",' b'"i":"DYmJApMvMb8mgiG20BPlPcKLWSfNIUCC21DP0i2_BLjo:' b'EOWdT7a7fZwRz0jiZ0DJxZEM3vsNbLDPEUk-ODnif3O0:EXvR3p8V95W8J7Ui4-mEzZ79S-A1esAnJo1Kmzq80Jkc",' b'' b'"s":"0","t":"iss"}') idig = Diger(ser=issb) key = dgKey(vck, idig.qb64b) assert issuer.getTvt(key) is None assert issuer.delTvt(key) is False assert issuer.putTvt(key, val=issb) is True assert issuer.getTvt(key) == issb assert issuer.putTvt(key, val=issb) is False assert issuer.setTvt(key, val=issb) is True assert issuer.getTvt(key) == issb assert issuer.delTvt(key) is True assert issuer.getTvt(key) is None telKey = snKey(vck, sn) assert issuer.getTel(telKey) is None assert issuer.delTel(telKey) is False assert issuer.putTel(telKey, val=idig.qb64b) assert issuer.getTel(telKey) == idig.qb64b assert issuer.putTel(telKey, val=idig.qb64b) is False assert issuer.setTel(telKey, val=idig.qb64b) is True assert issuer.getTel(telKey) == idig.qb64b assert issuer.delTel(telKey) is True assert issuer.getTel(telKey) is None """End Test"""
def test_tever_backers(mockHelpingNowUTC): # registry with backer and receipt with basing.openDB() as db, keeping.openKS() as kpr, viring.openReg( ) as reg: valSecret = 'AgjD4nRlycmM5cPcAkfOATAp8wVldRsnc9f1tiwctXlw' # create receipt signer prefixer default code is non-transferable valSigner = Signer(qb64=valSecret, transferable=False) valPrefixer = Prefixer(qb64=valSigner.verfer.qb64) valpre = valPrefixer.qb64 assert valpre == 'B8KY1sKmgyjAiUDdUBPNPyrSz_ad_Qf9yzhDNZlEKiMc' hab = buildHab(db, kpr) vcp = eventing.incept(hab.pre, baks=[valpre], toad=1, cnfg=[], code=MtrDex.Blake3_256) regk = vcp.pre valCigar = valSigner.sign(ser=vcp.raw, index=0) # successfully anchor to a rotation event rseal = SealEvent(i=regk, s=vcp.ked["s"], d=vcp.diger.qb64) rot = hab.rotate(data=[rseal._asdict()]) rotser = Serder(raw=rot) seqner = Seqner(sn=int(rotser.ked["s"], 16)) diger = rotser.diger tev = Tever(serder=vcp, seqner=seqner, diger=diger, bigers=[valCigar], db=db, reger=reg) dgkey = dgKey(pre=regk, dig=vcp.dig) assert reg.getTvt(dgkey) == ( b'{"v":"KERI10JSON0000d7_","i":"EBZR8LxEozgFa6UXwtSAmiXsmdChrT7Hr-jcxc9NFfrU",' b'"ii":"EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY","s":"0","t":"vcp","c":[],' b'"bt":"1",' b'"b":["B8KY1sKmgyjAiUDdUBPNPyrSz_ad_Qf9yzhDNZlEKiMc"]}') assert reg.getAnc( dgkey ) == b'0AAAAAAAAAAAAAAAAAAAAAAQEpWPsFsCcsu5SpVH0416qHx3gvG0CWlrP_i7BVdbmRBg' assert reg.getTel(snKey( pre=regk, sn=0)) == b'EJTWiS0ebp8VSyLr38x73dAHdUqivisUtAaGpEHt5HDc' assert [bytes(tib) for tib in reg.getTibs(dgkey)] == [ b'AAGhpPxAoltsRAnqxf7NsBzWSxWYLZ_ALImVVBiTlzJSdlATxRp_hBK4AbOzu-a900hwRxa0RX-yVWbVJA6oxoBw' ] assert reg.getTwe(snKey(pre=regk, sn=0)) is None debSecret = 'AKUotEE0eAheKdDJh9QvNmSEmO_bjIav8V_GmctGpuCQ' # create receipt signer prefixer default code is non-transferable debSigner = Signer(qb64=debSecret, transferable=False) debPrefixer = Prefixer(qb64=debSigner.verfer.qb64) debpre = debPrefixer.qb64 assert debpre == 'BbWeWTNGXPMQrVuJmScNQn81YF7T2fhh2kXwT8E_NbeI' vrt = eventing.rotate(regk, dig=vcp.dig, baks=[valpre], adds=[debpre]) valCigar = valSigner.sign(ser=vrt.raw, index=0) debCigar = debSigner.sign(ser=vrt.raw, index=1) # successfully anchor to a rotation event rseal = SealEvent(regk, vrt.ked["s"], vrt.diger.qb64) rot = hab.rotate(data=[rseal._asdict()]) rotser = Serder(raw=rot) seqner = Seqner(sn=int(rotser.ked["s"], 16)) diger = rotser.diger tev.update(serder=vrt, seqner=seqner, diger=diger, bigers=[valCigar, debCigar]) assert tev.baks == [ 'B8KY1sKmgyjAiUDdUBPNPyrSz_ad_Qf9yzhDNZlEKiMc', 'BbWeWTNGXPMQrVuJmScNQn81YF7T2fhh2kXwT8E_NbeI' ] vcdig = b'EEBp64Aw2rsjdJpAR0e2qCq3jX7q7gLld3LjAwZgaLXU' bis = eventing.backerIssue(vcdig=vcdig.decode("utf-8"), regk=regk, regsn=tev.sn, regd=tev.serder.dig) valCigar = valSigner.sign(ser=bis.raw, index=0) debCigar = debSigner.sign(ser=bis.raw, index=1) # successfully anchor to a rotation event rseal = SealEvent(bis.ked["i"], bis.ked["s"], bis.diger.qb64) rot = hab.rotate(data=[rseal._asdict()]) rotser = Serder(raw=rot) seqner = Seqner(sn=int(rotser.ked["s"], 16)) diger = rotser.diger tev.update(bis, seqner=seqner, diger=diger, bigers=[valCigar, debCigar]) vci = nsKey([regk, vcdig]) dgkey = dgKey(pre=vci, dig=bis.dig) assert bytes(reg.getTvt(dgkey)) == ( b'{"v":"KERI10JSON00012d_","i":"EEBp64Aw2rsjdJpAR0e2qCq3jX7q7gLld3LjAwZgaLXU",' b'"ii":"EBZR8LxEozgFa6UXwtSAmiXsmdChrT7Hr-jcxc9NFfrU","s":"0","t":"bis","ra":{' b'"i":"EBZR8LxEozgFa6UXwtSAmiXsmdChrT7Hr-jcxc9NFfrU","s":1,"d":"EZH2Cfw3nvcMRg' b'Y31Jyc2zHVh4a0LO_bVZ4EmL4V8Ol8"},"dt":"2021-01-01T00:00:00.000000+00:00"}' )
def test_issuer(): """ Test Issuer Class """ issuer = Registry() assert isinstance(issuer, Registry) assert issuer.name == "main" assert issuer.temp is False assert isinstance(issuer.env, lmdb.Environment) assert issuer.path.endswith("keri/reg/main") assert issuer.env.path() == issuer.path assert os.path.exists(issuer.path) assert isinstance(issuer.tvts, lmdb._Database) issuer.close(clear=True) assert not os.path.exists(issuer.path) assert not issuer.opened # test not opened on init issuer = Registry(reopen=False) assert isinstance(issuer, Registry) assert issuer.name == "main" assert issuer.temp is False assert issuer.opened is False assert issuer.path is None assert issuer.env is None issuer.reopen() assert issuer.opened assert issuer.path is not None assert isinstance(issuer.env, lmdb.Environment) assert issuer.path.endswith("keri/reg/main") assert issuer.env.path() == issuer.path assert os.path.exists(issuer.path) issuer.close(clear=True) assert not os.path.exists(issuer.path) assert not issuer.opened assert isinstance(issuer.tvts, lmdb._Database) with openLMDB(cls=Registry) as issuer: assert isinstance(issuer, Registry) assert issuer.name == "test" assert issuer.temp is True assert isinstance(issuer.env, lmdb.Environment) assert issuer.path.startswith("/tmp/keri_reg_") assert issuer.path.endswith("_test/keri/reg/test") assert issuer.env.path() == issuer.path assert os.path.exists(issuer.path) assert isinstance(issuer.tvts, lmdb._Database) assert not os.path.exists(issuer.path) ipreb = "DYmJApMvMb8mgiG20BPlPcKLWSfNIUCC21DP0i2_BLjo".encode("utf-8") regb = "EOWdT7a7fZwRz0jiZ0DJxZEM3vsNbLDPEUk-ODnif3O0".encode("utf-8") rarb = "BijzaUuRMwh1ivT5BQrqNhbvx82lB-ofrHVHjL3WADbA".encode("utf-8") # test with registry inception (vcp) event regk = nsKey([ipreb, regb]) assert regk == b'DYmJApMvMb8mgiG20BPlPcKLWSfNIUCC21DP0i2_BLjo:EOWdT7a7fZwRz0jiZ0DJxZEM3vsNbLDPEUk-ODnif3O0' sn = 0 vs = Versify(kind=Serials.json, size=20) vcp = dict(v=vs, i=regk.decode("utf-8"), s="{:x}".format(sn), b=[rarb.decode("utf-8")], t="vcp") vcpb = json.dumps(vcp, separators=(",", ":"), ensure_ascii=False).encode("utf-8") assert vcpb == ( b'{"v":"KERI10JSON000014_",' b'"i":"DYmJApMvMb8mgiG20BPlPcKLWSfNIUCC21DP0i2_BLjo:EOWdT7a7fZwRz0jiZ0DJxZEM3vsNbLDPEUk-ODnif3O0",' b'"s":"0","b":["BijzaUuRMwh1ivT5BQrqNhbvx82lB-ofrHVHjL3WADbA"],"t":"vcp"}' ) vdig = Diger(ser=vcpb) with openLMDB(cls=Registry) as issuer: key = dgKey(regk, vdig.qb64b) assert issuer.getTvt(key) is None assert issuer.delTvt(key) is False assert issuer.putTvt(key, val=vcpb) is True assert issuer.getTvt(key) == vcpb assert issuer.putTvt(key, val=vcpb) is False assert issuer.setTvt(key, val=vcpb) is True assert issuer.getTvt(key) == vcpb assert issuer.delTvt(key) is True assert issuer.getTvt(key) is None telKey = snKey(regk, sn) assert issuer.getTel(telKey) is None assert issuer.delTel(telKey) is False assert issuer.putTel(telKey, val=vdig.qb64b) assert issuer.getTel(telKey) == vdig.qb64b assert issuer.putTel(telKey, val=vdig.qb64b) is False assert issuer.setTel(telKey, val=vdig.qb64b) is True assert issuer.getTel(telKey) == vdig.qb64b assert issuer.delTel(telKey) is True assert issuer.getTel(telKey) is None coupl01 = ( "BPVuWC4Hc0izqPKn2LIwhp72SHJSRgfaL1RhtuiavIy4AAfiKvopJ0O2afOmxb5A6JtdY7Wkl_1uNx1Z8xQkg_" "gMzf-vTfEHDylFdgn2e_u_ppaFajIdvEvONX6dcSYzlfBQ").encode("utf-8") coupl02 = ( "BW1gbapuOJ4TJKwLfKZs5cXEIs9k8EtBqxR1psVxnD7IABrSkjrgPGXdhBiOy6LUZpiqtsHkKHhfLGj_LhT1n6" "EqCIdDjrihzrdM1bm0ZNJDwbDGXoeeZujd7ZYsOsBPzRCw").encode("utf-8") coupl03 = ( "BklrMm7GlYzNrPQunLJHFn_1wWjlUslGkXfs0KyoNOEAAC_6PB5Zre_E_7YLkM9OtRo-uYmwRyFmOH3Xo4JDiP" "jioY7Ycna6ouhSSH0QcKsEjce10HCXIW_XtmEYr9SrB5BA").encode("utf-8") coups = [coupl01, coupl02, coupl03] key = dgKey(regk, vdig.qb64b) assert issuer.getTibs(key) == [] assert issuer.cntTibs(key) == 0 assert issuer.delTibs(key) is False assert issuer.putTibs(key, vals=[coupl01]) is True assert issuer.getTibs(key) == [coupl01] assert issuer.cntTibs(key) == 1 assert issuer.putTibs(key, vals=[coupl01]) is True # add duplicate assert issuer.cntTibs(key) == 1 assert issuer.addTib(key, coupl01) is False assert issuer.addTib(key, coupl02) is True assert issuer.cntTibs(key) == 2 assert issuer.putTibs(key, vals=[coupl02, coupl03]) is True assert issuer.cntTibs(key) == 3 assert issuer.delTibs(key) is True assert issuer.getTibs(key) == [] for c in coups: assert issuer.addTib(key, c) is True assert issuer.cntTibs(key) == 3 assert issuer.getTibs(key) == [coupl01, coupl02, coupl03] for c in issuer.getTibsIter(key): assert issuer.delTibs(key, c) is True assert issuer.getTibs(key) == [] tweKey = snKey(regk, sn) assert issuer.getTwe(tweKey) is None assert issuer.delTwe(tweKey) is False assert issuer.putTwe(tweKey, val=vdig.qb64b) assert issuer.getTwe(tweKey) == vdig.qb64b assert issuer.putTwe(tweKey, val=vdig.qb64b) is False assert issuer.setTwe(tweKey, val=vdig.qb64b) is True assert issuer.getTwe(tweKey) == vdig.qb64b assert issuer.delTwe(tweKey) is True assert issuer.getTwe(tweKey) is None ooKey = snKey(regk, sn) assert issuer.getOot(ooKey) is None assert issuer.delOot(ooKey) is False assert issuer.putOot(ooKey, val=vdig.qb64b) assert issuer.getOot(ooKey) == vdig.qb64b assert issuer.putOot(ooKey, val=vdig.qb64b) is False assert issuer.setOot(ooKey, val=vdig.qb64b) is True assert issuer.getOot(ooKey) == vdig.qb64b assert issuer.delOot(ooKey) is True assert issuer.getOot(ooKey) is None anc01 = ( "0AAAAAAAAAAAAAAAAAAAAABA" "Ezpq06UecHwzy-K9FpNoRxCJp2wIGM9u2Edk-PLMZ1H4").encode("utf-8") key = dgKey(regk, vdig.qb64b) assert issuer.getAnc(key) is None assert issuer.delAnc(key) is False assert issuer.putAnc(key, val=anc01) assert issuer.getAnc(key) == anc01 assert issuer.putAnc(key, val=anc01) is False assert issuer.setAnc(key, val=anc01) is True assert issuer.getAnc(key) == anc01 assert issuer.delAnc(key) is True assert issuer.getAnc(key) is None # test with verifiable credential issuance (iss) event vcdig = b'EXvR3p8V95W8J7Ui4-mEzZ79S-A1esAnJo1Kmzq80Jkc' sn = 0 vs = Versify(kind=Serials.json, size=20) vcp = dict(v=vs, i=vcdig.decode("utf-8"), s="{:x}".format(sn), t="iss") issb = json.dumps(vcp, separators=(",", ":"), ensure_ascii=False).encode("utf-8") assert issb == (b'{"v":"KERI10JSON000014_",' b'"i":"EXvR3p8V95W8J7Ui4-mEzZ79S-A1esAnJo1Kmzq80Jkc",' b'' b'"s":"0","t":"iss"}') idig = Diger(ser=issb) key = dgKey(vcdig, idig.qb64b) assert issuer.getTvt(key) is None assert issuer.delTvt(key) is False assert issuer.putTvt(key, val=issb) is True assert issuer.getTvt(key) == issb assert issuer.putTvt(key, val=issb) is False assert issuer.setTvt(key, val=issb) is True assert issuer.getTvt(key) == issb assert issuer.delTvt(key) is True assert issuer.getTvt(key) is None telKey = snKey(vcdig, sn) assert issuer.getTel(telKey) is None assert issuer.delTel(telKey) is False assert issuer.putTel(telKey, val=idig.qb64b) assert issuer.getTel(telKey) == idig.qb64b assert issuer.putTel(telKey, val=idig.qb64b) is False assert issuer.setTel(telKey, val=idig.qb64b) is True assert issuer.getTel(telKey) == idig.qb64b assert issuer.delTel(telKey) is True assert issuer.getTel(telKey) is None rev = dict(v=vs, i=vcdig.decode("utf-8"), s="{:x}".format(sn + 1), t="rev") revb = json.dumps(rev, separators=(",", ":"), ensure_ascii=False).encode("utf-8") assert revb == b'{"v":"KERI10JSON000014_","i":"EXvR3p8V95W8J7Ui4-mEzZ79S-A1esAnJo1Kmzq80Jkc","s":"1","t":"rev"}' rdig = Diger(raw=revb) assert issuer.putTel(snKey(vcdig, sn), val=idig.qb64b) is True assert issuer.putTel(snKey(vcdig, sn + 1), val=rdig.qb64b) is True assert issuer.putTel(snKey(vcdig, sn + 2), val=idig.qb64b) is True assert issuer.putTel(snKey(vcdig, sn + 3), val=rdig.qb64b) is True result = [(sn, dig) for sn, dig in issuer.getTelItemPreIter(vcdig)] assert result == [(0, idig.qb64b), (1, rdig.qb64b), (2, idig.qb64b), (3, rdig.qb64b)] bak1 = b'Bm1Q98kT0HRn9R62lY-LufjjKdbCeL1mqu9arTgOmbqI' bak2 = b'DSEpNJeSJjxo6oAxkNE8eCOJg2HRPstqkeHWBAvN9XNU' bak3 = b'Dvxo-P4W_Z0xXTfoA3_4DMPn7oi0mLCElOWJDpC0nQXw' bak4 = b'BleAn9JkFuEOOwDhfkhnxtGsRQkMh2AH1oGB9QHAvl1U' bak5 = b'Behy5f2BIJbAYdgoy00OcOEZwEyxCGCUDlzbGkbz1RAI' baks = [bak1, bak2, bak3, bak4] # test .baks insertion order dup methods. dup vals are insertion order assert issuer.getBaks(key) == [] assert issuer.cntBaks(key) == 0 assert issuer.delBaks(key) is False assert issuer.putBaks(key, baks) is True assert issuer.getBaks(key) == baks assert issuer.cntBaks(key) == len(baks) == 4 assert issuer.putBaks(key, vals=[bak1]) is False assert issuer.getBaks(key) == baks assert issuer.addBak(key, bak1) is False assert issuer.addBak(key, bak5) is True assert issuer.getBaks(key) == [bak1, bak2, bak3, bak4, bak5] assert [val for val in issuer.getBaksIter(key) ] == [bak1, bak2, bak3, bak4, bak5] assert issuer.delBaks(key) is True assert issuer.getBaks(key) == [] """End Test"""
def test_tever_no_backers(mockHelpingNowUTC): # registry with no backers # registry with backer and receipt with basing.openDB() as db, keeping.openKS() as kpr, viring.openReg( ) as reg: hab = buildHab(db, kpr) vcp = eventing.incept(hab.pre, baks=[], toad=0, cnfg=["NB"], code=MtrDex.Blake3_256) regk = vcp.pre # successfully anchor to a rotation event rseal = SealEvent(i=regk, s=vcp.ked["s"], d=vcp.diger.qb64) rot = hab.rotate(data=[rseal._asdict()]) rotser = Serder(raw=rot) seqner = Seqner(sn=int(rotser.ked["s"], 16)) diger = rotser.diger tev = Tever(serder=vcp, seqner=seqner, diger=diger, db=db, reger=reg) assert tev.prefixer.qb64 == vcp.pre assert tev.sn == 0 dgkey = dgKey(pre=regk, dig=vcp.dig) assert reg.getTvt(dgkey) == ( b'{"v":"KERI10JSON0000ad_","i":"Ezm53Qww2LTJ1yksEL06Wtt-5D23QKdJEGI0egFyLehw",' b'"ii":"EaKJ0FoLxO1TYmyuprguKO7kJ7Hbn0m0Wuk5aMtSrMtY","s":"0","t":"vcp","c":["NB"],"bt":"0","b":[]}' ) assert reg.getAnc(dgkey) == ( b'0AAAAAAAAAAAAAAAAAAAAAAQE-yQ6BjCaJg-u2mNuE-ycVWVTq7IZ8TuN-Ew8soLijSA' ) assert reg.getTel(snKey( pre=regk, sn=0)) == b'ElYstqTocyQixLLz4zYCAs2unaFco_p6LqH0W01loIg4' assert reg.getTibs(dgkey) == [] assert reg.getTwe(snKey(pre=regk, sn=0)) is None # try to rotate a backerless registry vrt = eventing.rotate(regk, dig=vcp.dig) rseal = SealEvent(regk, vrt.ked["s"], vrt.diger.qb64) rot = hab.rotate(data=[rseal._asdict()]) rotser = Serder(raw=rot) seqner = Seqner(sn=int(rotser.ked["s"], 16)) diger = rotser.diger # should raise validation err because rotation is not supported with pytest.raises(ValidationError): tev.update(serder=vrt, seqner=seqner, diger=diger) vcdig = b'EEBp64Aw2rsjdJpAR0e2qCq3jX7q7gLld3LjAwZgaLXU' iss = eventing.issue(vcdig=vcdig.decode("utf-8"), regk=regk) # successfully anchor to a rotation event rseal = SealEvent(iss.ked["i"], iss.ked["s"], iss.diger.qb64) rot = hab.rotate(data=[rseal._asdict()]) rotser = Serder(raw=rot) seqner = Seqner(sn=int(rotser.ked["s"], 16)) diger = rotser.diger tev.update(iss, seqner=seqner, diger=diger) vci = nsKey([regk, vcdig]) dgkey = dgKey(pre=vci, dig=iss.dig) assert bytes(reg.getTvt(dgkey)) == ( b'{"v":"KERI10JSON0000ba_","i":"EEBp64Aw2rsjdJpAR0e2qCq3jX7q7gLld3LjAwZgaLXU",' b'"s":"0","t":"iss","ri":"Ezm53Qww2LTJ1yksEL06Wtt-5D23QKdJEGI0egFyLehw","dt":"' b'2021-01-01T00:00:00.000000+00:00"}') assert bytes( reg.getAnc(dgkey) ) == b'0AAAAAAAAAAAAAAAAAAAAAAwEJLLpuUKPSDIcoOAOArQBzceWc8MoShm-cDL-w81liIw' # revoke vc with no backers rev = eventing.revoke(vcdig=vcdig.decode("utf-8"), regk=regk, dig=iss.dig) # successfully anchor to a rotation event rseal = SealEvent(rev.ked["i"], rev.ked["s"], rev.diger.qb64) rot = hab.rotate(data=[rseal._asdict()]) rotser = Serder(raw=rot) seqner = Seqner(sn=int(rotser.ked["s"], 16)) diger = rotser.diger tev.update(rev, seqner=seqner, diger=diger) dgkey = dgKey(pre=vci, dig=rev.dig) assert bytes(reg.getTvt(dgkey)) == ( b'{"v":"KERI10JSON0000ed_","i":"EEBp64Aw2rsjdJpAR0e2qCq3jX7q7gLld3LjAwZgaLXU",' b'"s":"1","t":"rev","ri":"Ezm53Qww2LTJ1yksEL06Wtt-5D23QKdJEGI0egFyLehw","p":"E' b'C9PffPrvyaKzsn72SWTvgyvWCJ1FbDThvJhsQ9LWo9M","dt":"2021-01-01T00:00:00.00000' b'0+00:00"}')