Skip to content

Commit

Permalink
adds test for escrow clear
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Griffin <[email protected]>
  • Loading branch information
m00sey committed Dec 3, 2024
1 parent d750040 commit 22bae1e
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 183 deletions.
159 changes: 0 additions & 159 deletions src/keri/app/cli/commands/escrow.py

This file was deleted.

2 changes: 1 addition & 1 deletion src/keri/app/cli/commands/escrow/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def escrows(tymth, tock=0.0, **opts):
pses = list()
key = ekey = b'' # both start same. when not same means escrows found
while True: # break when done
for ekey, edig in hby.db.getPseItemIter(key=key):
for ekey, edig in hby.db.getPseItemsNextIter(key=key):
pre, sn = dbing.splitSnKey(ekey) # get pre and sn from escrow item

try:
Expand Down
48 changes: 26 additions & 22 deletions src/keri/db/basing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1173,7 +1173,7 @@ def clearEscrows(self):
logger.info(f"KEL: Cleared {count} verified receipt escrows")

count = 0
for (k, _) in self.getPseItemIter():
for (k, _) in self.getPseItemsNextIter():
count += 1
self.delPses(key=k)
logger.info(f"KEL: Cleared {count} partially signed escrows")
Expand Down Expand Up @@ -1203,14 +1203,12 @@ def clearEscrows(self):
logger.info(f"KEL: Cleared {count} likely duplicitous escrows")

count = 0
for ekey, edig in self.getQnfItemsNextIter():
count += 1
pre, _ = splitKey(ekey)
self.delQnf(dgKey(pre, edig), edig)
for k, _ in self.getQnfItemsNextIter():
self.delQnfs(key=k)
logger.info(f"KEL: Cleared {count} query not found escrows")

count = 0
for (key, on, val) in self.getPdesItemsNextIter():
for (key, _) in self.getPdeItemsNextIter():
count += 1
self.delPde(key=key)
logger.info(f"KEL: Cleared {count} partially delegated key event escrows")
Expand All @@ -1224,8 +1222,11 @@ def clearEscrows(self):
('gpse', self.gpse, 'group partial signature escrow'),
('epse', self.epse, 'exchange partial signature escrow'),
('dune', self.dune, 'delegated unanchored escrow')]:
count = 0
for (k, _) in escrow.getItemIter():
count += 1
escrow.trim()
logger.info(f"KEL: Cleared escrow ({name.ljust(5)}): {desc}")
logger.info(f"KEL: Cleared {count} escrows from ({name.ljust(5)}): {desc}")
logger.info("Cleared KEL escrows")

@property
Expand Down Expand Up @@ -2637,18 +2638,6 @@ def getPseLast(self, key):
"""
return self.getIoValLast(self.pses, key)

def getPseItemIter(self, key=b''):
"""
Use sgKey()
Return iterator of partial signed escrowed event dig items at next key after key.
Items is (key, val) where proem has already been stripped from val
If key is b'' empty then returns dup items at first key.
If skip is False and key is not b'' empty then returns dup items at key
Raises StopIteration Error when empty
Duplicates are retrieved in insertion order.
"""
return self.getTopIoDupItemIter(self.pses, key)

def getPseItemsNext(self, key=b'', skip=True):
"""
Use snKey()
Expand Down Expand Up @@ -2728,6 +2717,24 @@ def getPde(self, key):
"""
return self.getVal(self.pdes, key)

def getPdes(self, key):
"""
Use dgKey()
Return list of out of order escrow event dig vals at key
Returns empty list if no entry at key
Duplicates are retrieved in insertion order.
"""
return self.getIoVals(self.pdes, key)

def getPdeItemsNextIter(self, key=b'', skip=True):
"""
Use dgKey()
Return list of witnessed signed escrowed event dig vals at key
Returns empty list if no entry at key
Duplicates are retrieved in insertion order.
"""
return self.getIoItemsNextIter(self.pdes, key, skip)

def delPde(self, key):
"""
Use dgKey()
Expand Down Expand Up @@ -3134,9 +3141,6 @@ def getQnfItemsNextIter(self, key=b'', skip=True):
"""
return self.getIoItemsNextIter(self.qnfs, key, skip)

def getPdesItemsNextIter(self, key=b'', skip=True):
return self.getOnIoDupItemIter(self.pdes, key, skip)

def cntQnfs(self, key):
"""
Use snKey()
Expand Down
73 changes: 72 additions & 1 deletion tests/db/test_basing.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import pytest
from hio.base import doing

from keri.core.serdering import Serder
from tests.app import openMultiSig
from keri.kering import Versionage
from keri.app import habbing
Expand All @@ -21,7 +22,7 @@
from keri.core.eventing import incept, rotate, interact, Kever
from keri.db import basing
from keri.db import dbing
from keri.db.basing import openDB, Baser, KeyStateRecord
from keri.db.basing import openDB, Baser, KeyStateRecord, OobiRecord
from keri.db.dbing import (dgKey, onKey, snKey)
from keri.db.dbing import openLMDB
from keri.help.helping import datify, dictify
Expand Down Expand Up @@ -2274,6 +2275,76 @@ def test_group_members():
"""End Test"""


def test_clear_escrows():
with openDB() as db:
key = b'A.a'
vals = [b"z", b"m", b"x", b"a"]

db.putUres(key, vals)
db.putVres(key, vals)
db.putPses(key, vals)
db.putPwes(key, vals)
db.putUwes(key, vals)
db.putOoes(key, vals)
db.putLdes(key, vals)
db.putQnfs(key, vals)

preb = 'DAzwEHHzq7K0gzQPYGGwTmuupUhPx5_yZ-Wk1x4ejhcc'.encode("utf-8")
digb = 'EGAPkzNZMtX-QiVgbRbyAIZGoXvbGv9IPb0foWTZvI_4'.encode("utf-8")
key = dgKey(preb, digb)
ssnu1 = b'0AAAAAAAAAAAAAAAAAAAAAAB'
sdig1 = b'EALkveIFUPvt38xhtgYYJRCCpAGO7WjjHVR37Pawv67E'
val1 = ssnu1 + sdig1

db.putPde(key, val1)

pre = 'k'
saider = coring.Saider(qb64b='EGAPkzNZMtX-QiVgbRbyAIZGoXvbGv9IPb0foWTZvI_4')
db.rpes.put(keys=('route',), vals=[saider])
assert db.rpes.cnt(keys=('route',)) == 1

db.eoobi.pin(keys=('url',), val=OobiRecord())
assert db.eoobi.cntAll() == 1

db.gpwe.add(keys=(pre,), val=(coring.Seqner(qb64b=b'0AAAAAAAAAAAAAAAAAAAAAAB'), saider))
assert db.gpwe.cnt(keys=(pre,)) == 1

db.gdee.add(keys=(pre,), val=(coring.Seqner(qb64b=b'0AAAAAAAAAAAAAAAAAAAAAAB'), saider))
assert db.gdee.cnt(keys=(pre,)) == 1

serder = Serder(raw=b'{"v":"KERI10JSON0000cb_","t":"ixn","d":"EG8WAmM29ZBdoXbnb87yiPxQw4Y7gcQjqZS74vBAKsRm","i":"DApYGFaqnrALTyejaJaGAVhNpSCtqyerPqWVK9ZBNZk0","s":"4","p":"EAskHI462CuIMS_gNkcl_QewzrRSKH2p9zHQIO132Z30","a":[]}')
db.dpwe.pin(keys=(pre, 'said'), val=serder)
assert db.dpwe.get(keys=(pre, 'said')) is not None

db.gpse.add(keys=('qb64',), val=(coring.Seqner(qb64b=b'0AAAAAAAAAAAAAAAAAAAAAAB'), saider))
assert db.gpse.cnt(keys=('qb64',)) == 1

db.epse.put(keys=('dig',), val=serder)
assert db.epse.get(keys=('dig',)) is not None

db.dune.pin(keys=(pre, 'said'), val=serder)
assert db.dune.get(keys=(pre, 'said')) is not None

db.clearEscrows()

assert db.getUres(key) == []
assert db.getVres(key) == []
assert db.getPses(key) == []
assert db.getPwes(key) == []
assert db.getUwes(key) == []
assert db.getOoes(key) == []
assert db.getLdes(key) == []
assert db.getQnfs(key) == []
assert db.getPdes(key) == []
assert db.rpes.cnt(keys=('route',)) == 0
assert db.eoobi.cntAll() == 0
assert db.gpwe.cnt(keys=(pre,)) == 0
assert db.gdee.cnt(keys=(pre,)) == 0
assert db.dpwe.get(keys=(pre, 'said')) is None
assert db.gpse.cnt(keys=('qb64',)) == 0
assert db.epse.get(keys=('dig',)) is None
assert db.dune.get(keys=(pre, 'said')) is None

if __name__ == "__main__":
test_baser()
test_clean_baser()
Expand Down

0 comments on commit 22bae1e

Please sign in to comment.