nostrdb

an unfairly fast embedded nostr database backed by lmdb
git clone git://jb55.com/nostrdb
Log | Files | Refs | Submodules | README | LICENSE

commit d05d8dffed9bdb6586bc3596047be7e7a4978d09
parent 6eab55daef7487d546bcab2702dd4faad0f6de00
Author: William Casarin <jb55@jb55.com>
Date:   Wed,  3 Jan 2024 14:40:36 -0800

test: use subscriptions in profile update test

Diffstat:
MTODO | 1+
Mtest.c | 41++++++++++++++++++++++++-----------------
Mtestdata/profile-updates.json | 6+++---
3 files changed, 28 insertions(+), 20 deletions(-)

diff --git a/TODO b/TODO @@ -0,0 +1 @@ +subscription polling diff --git a/test.c b/test.c @@ -287,32 +287,39 @@ static void test_profile_search(struct ndb *ndb) static void test_profile_updates() { static const int alloc_size = 1024 * 1024; - char *json = malloc(alloc_size); - struct ndb *ndb; + static const int num_notes = 3; + char *json; + int written, i; size_t len; - void *record; - int written; - struct ndb_txn txn; - uint64_t key; + struct ndb *ndb; struct ndb_config config; - ndb_default_config(&config); + struct ndb_filter_group group; + struct ndb_txn txn; + uint64_t key, subid; + uint64_t note_ids[num_notes]; + void *record; + + json = malloc(alloc_size); + ndb_default_config(&config); assert(ndb_init(&ndb, test_dir, &config)); - read_file("testdata/profile-updates.json", (unsigned char*)json, alloc_size, &written); + ndb_filter_group_init(&group); + subid = ndb_subscribe(ndb, &group); + ndb_debug("testing profile updates\n"); + read_file("testdata/profile-updates.json", (unsigned char*)json, alloc_size, &written); assert(ndb_process_client_events(ndb, json, written)); - ndb_destroy(ndb); - - assert(ndb_init(&ndb, test_dir, &config)); + for (i = 0; i < num_notes;) + i += ndb_wait_for_notes(ndb, subid, note_ids, num_notes); assert(ndb_begin_query(ndb, &txn)); const unsigned char pk[32] = { - 0x87, 0xfb, 0xc6, 0xd5, 0x98, 0x31, 0xa8, 0x23, 0xa4, 0x5d, - 0x10, 0x1f, 0x86, 0x94, 0x2c, 0x41, 0xcd, 0xe2, 0x90, 0x23, - 0xf4, 0x09, 0x20, 0x24, 0xa2, 0x7c, 0x50, 0x10, 0x3c, 0x15, - 0x40, 0x01 + 0x1c, 0x55, 0x46, 0xe4, 0xf5, 0x93, 0x3b, 0xbe, 0x86, 0x66, + 0x2a, 0x8e, 0xc3, 0x28, 0x9a, 0x29, 0x87, 0xc0, 0x5d, 0xab, + 0x25, 0x6c, 0x06, 0x8b, 0x77, 0x42, 0x9f, 0x0f, 0x08, 0xa7, + 0xa0, 0x90 }; record = ndb_get_profile_by_pubkey(&txn, pk, &len, &key); @@ -1235,8 +1242,8 @@ static void test_subscriptions() assert(ndb_filter_add_int_element(f, 1337)); ndb_filter_end_field(f); - group.filters[0] = f; - group.num_filters = 1; + ndb_filter_group_init(&group); + ndb_filter_group_add(&group, f); assert((subid = ndb_subscribe(ndb, &group))); diff --git a/testdata/profile-updates.json b/testdata/profile-updates.json @@ -1,3 +1,3 @@ -["EVENT",{"id": "9b2861dda8fc602ec2753f92f1a443c9565de606e0c8f4fd2db4f2506a3b13ca","pubkey": "87fbc6d59831a823a45d101f86942c41cde29023f4092024a27c50103c154001","created_at": 1695593347,"kind": 0,"tags": [],"content": "{\"name\":\"a\"}","sig": "f48da228f8967d33c3caf0a78f853b5144631eb86c7777fd25949123a5272a92765a0963d4686dd0efe05b7a9b986bfac8d43070b234153acbae5006d5a90f31"}] -["EVENT",{"id": "a44eb8fb6931d6155b04038bef0624407e46c85c61e5758392cbb615f00184ca","pubkey": "87fbc6d59831a823a45d101f86942c41cde29023f4092024a27c50103c154001","created_at": 1695593354,"kind": 0,"tags": [],"content": "{\"name\":\"b\"}","sig": "7540bbde4b4479275e20d95acaa64027359a73989927f878825093cba2f468bd8e195919a77b4c230acecddf92e6b4bee26918b0c0842f84ec7c1fae82453906"}] -["EVENT",{"id": "3090cdba2889acf1279efbf598e7e1cc701259c329cb11309a495f6c5204a7f6","pubkey": "87fbc6d59831a823a45d101f86942c41cde29023f4092024a27c50103c154001","created_at": 1695593357,"kind": 0,"tags": [],"content": "{\"name\":\"c\"}","sig": "f143edd4a8e60d882b0a19c7a4ee896a0c99da285fceab1ea704c5a9b6110f7b6983fe3c4a0a316c8ab1aa971323639a6049033c253a8c3684f99f76e781aa7c"}] +["EVENT",{"id": "01e4a20005b25308631a3696636b5d3bfa405f96048f12a6e2d710e173e2f172","pubkey": "1c5546e4f5933bbe86662a8ec3289a2987c05dab256c068b77429f0f08a7a090","created_at": 1704321421,"kind": 0,"tags": [],"content": "{\"name\":\"a\"}","sig": "d402c8cbbf9a365b57973bd98a847399db8da99633f4fb48229d60d130be7245f59711694de17b61d1fc3e12ff394e4c6710f522f54d38e889175e392f8b36c2"}] +["EVENT",{"id": "8eec3d4c4c13cb281479585d10c3725cd1b738345eec704875c5e8df10ebc701","pubkey": "1c5546e4f5933bbe86662a8ec3289a2987c05dab256c068b77429f0f08a7a090","created_at": 1704321425,"kind": 0,"tags": [],"content": "{\"name\":\"b\"}","sig": "44b96b630959726b264cf509cbdecf18b0765f065aad1bbb1f45e2a6190356491eb5db9a9bdfb30b409cb97ef9d18f0d7130f4bb390dc70c6c69ace95633b6af"}] +["EVENT",{"id": "593a94d951bec3437695d9873a4adf865ea8d61cfa32ed56bfd82cdd54635e41","pubkey": "1c5546e4f5933bbe86662a8ec3289a2987c05dab256c068b77429f0f08a7a090","created_at": 1704321429,"kind": 0,"tags": [],"content": "{\"name\":\"c\"}","sig": "7c237324183bb7fe9ff21b132dd28d7cfbfa7373de98dc9c84e2bb2f2a3e676d4ff5ed5d2f54a208ded3406f6f241ea3ab8866abc1bd16883813cb0a15873f07"}]