mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2025-09-09 15:58:48 +00:00
test: loop index size
This commit is contained in:
@@ -39,33 +39,40 @@ def test_nostr_index_size_limits():
|
|||||||
vault = Vault(enc_mgr, tmpdir)
|
vault = Vault(enc_mgr, tmpdir)
|
||||||
entry_mgr = EntryManager(vault, Path(tmpdir))
|
entry_mgr = EntryManager(vault, Path(tmpdir))
|
||||||
|
|
||||||
sizes = [16, 64, 256, 1024, 2048, 4096, 8192]
|
|
||||||
delay = float(os.getenv("NOSTR_TEST_DELAY", "5"))
|
delay = float(os.getenv("NOSTR_TEST_DELAY", "5"))
|
||||||
for size in sizes:
|
size = 16
|
||||||
try:
|
entry_count = 0
|
||||||
|
max_payload = 60 * 1024
|
||||||
|
try:
|
||||||
|
while True:
|
||||||
entry_mgr.add_entry(
|
entry_mgr.add_entry(
|
||||||
website_name=f"site-{size}",
|
website_name=f"site-{entry_count + 1}",
|
||||||
length=12,
|
length=12,
|
||||||
username="u" * size,
|
username="u" * size,
|
||||||
url="https://example.com/" + "a" * size,
|
url="https://example.com/" + "a" * size,
|
||||||
)
|
)
|
||||||
|
entry_count += 1
|
||||||
encrypted = vault.get_encrypted_index()
|
encrypted = vault.get_encrypted_index()
|
||||||
payload_size = len(encrypted) if encrypted else 0
|
payload_size = len(encrypted) if encrypted else 0
|
||||||
published = client.publish_json_to_nostr(encrypted or b"")
|
published = client.publish_json_to_nostr(encrypted or b"")
|
||||||
time.sleep(delay)
|
time.sleep(delay)
|
||||||
retrieved = client.retrieve_json_from_nostr_sync()
|
retrieved = client.retrieve_json_from_nostr_sync()
|
||||||
retrieved_ok = retrieved == encrypted
|
retrieved_ok = retrieved == encrypted
|
||||||
results.append((size, payload_size, published, retrieved_ok))
|
results.append((entry_count, payload_size, published, retrieved_ok))
|
||||||
if not published or not retrieved_ok:
|
if not published or not retrieved_ok or payload_size > max_payload:
|
||||||
break
|
break
|
||||||
except Exception:
|
size *= 2
|
||||||
results.append((size, None, False, False))
|
except Exception:
|
||||||
break
|
results.append((entry_count + 1, None, False, False))
|
||||||
client.close_client_pool()
|
finally:
|
||||||
|
client.close_client_pool()
|
||||||
|
|
||||||
note_kind = Kind.from_std(KindStandard.TEXT_NOTE).as_u16()
|
note_kind = Kind.from_std(KindStandard.TEXT_NOTE).as_u16()
|
||||||
print(f"\nNostr note Kind: {note_kind}")
|
print(f"\nNostr note Kind: {note_kind}")
|
||||||
print(f"Nostr account npub: {npub}")
|
print(f"Nostr account npub: {npub}")
|
||||||
print("Size | Payload Bytes | Published | Retrieved")
|
print("Count | Payload Bytes | Published | Retrieved")
|
||||||
for size, payload, pub, ret in results:
|
for cnt, payload, pub, ret in results:
|
||||||
print(f"{size:>4} | {payload:>13} | {pub} | {ret}")
|
print(f"{cnt:>5} | {payload:>13} | {pub} | {ret}")
|
||||||
|
|
||||||
|
synced = sum(1 for _, _, pub, ret in results if pub and ret)
|
||||||
|
print(f"Successfully synced entries: {synced}")
|
||||||
|
Reference in New Issue
Block a user