nostrdb

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

commit e12e6d18a1a821b5a43bc3e52ab5545e1617c146
parent a57aac8a3edf245b1a36dc409272c619eed8231f
Author: William Casarin <jb55@jb55.com>
Date:   Sat, 26 Aug 2023 16:51:52 -0700

add failing damus test... yet curiously it works

Diffstat:
Mtest.c | 37+++++++++++++++++++++++++++++++++++++
Atestdata/random.json | 5+++++
2 files changed, 42 insertions(+), 0 deletions(-)

diff --git a/test.c b/test.c @@ -244,6 +244,40 @@ static void test_parse_contact_list() free(buf); } +static void test_fetch_last_noteid() +{ + static const int alloc_size = 1024 * 1024; + char *json = malloc(alloc_size); + unsigned char *buf = malloc(alloc_size); + struct ndb *ndb; + size_t mapsize; + int written, ingester_threads; + + mapsize = 1024 * 1024 * 100; + ingester_threads = 1; + assert(ndb_init(&ndb, test_dir, mapsize, ingester_threads)); + + read_file("testdata/random.json", (unsigned char*)json, alloc_size, &written); + assert(ndb_process_events(ndb, json, written)); + + ndb_destroy(ndb); + + assert(ndb_init(&ndb, test_dir, mapsize, ingester_threads)); + + unsigned char id[32] = { 0xdc, 0x96, 0x4f, 0x4c, 0x89, 0x83, 0x64, + 0x13, 0x8e, 0x81, 0x96, 0xf0, 0xc7, 0x33, 0x38, 0xc8, 0xcc, + 0x3e, 0xbf, 0xa3, 0xaf, 0xdd, 0xbc, 0x7d, 0xd1, 0x58, 0xb4, + 0x84, 0x7c, 0x1e, 0xbf, 0xa0 }; + + struct ndb_note *note = ndb_get_note_by_id(ndb, id); + assert(note != NULL); + + ndb_destroy(ndb); + + free(json); + free(buf); +} + static void test_parse_contact_event() { int written; @@ -550,6 +584,9 @@ int main(int argc, const char *argv[]) { test_content_len(); test_fuzz_events(); + // note fetching + test_fetch_last_noteid(); + // protected queue tests test_queue_init_pop_push(); test_queue_thread_safety(); diff --git a/testdata/random.json b/testdata/random.json @@ -0,0 +1,5 @@ +["EVENT","s",{"id":"d12c17bde3094ad32f4ab862a6cc6f5c289cfe7d5802270bdf34904df585f349","pubkey":"32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245","created_at":1650049978,"kind":0,"tags":[],"content":"{\"name\":\"jb55\",\"picture\":\"http://cdn.jb55.com/img/red-me.jpg\",\"about\":\"bitcoin, lightning and nostr dev\",\"nip05\":\"jb55.com\"}","sig":"1315045da793c4825de1517149172bf35a6da39d91b7787afb3263721e07bc816cb898996ed8d69af05d6efcd1c926a089bd66cad870bcc361405c11ba302c51"}] +["EVENT","s",{"id":"b2e03951843b191b5d9d1969f48db0156b83cc7dbd841f543f109362e24c4a9c","pubkey":"32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245","created_at":1650050002,"kind":1,"tags":[],"content":"hello, this is my new key","sig":"4342eff1d78a82b42522cd26ec66a5293eca997f81d4b80efd02230d3d27317fb63d42656e8f32383562f075a2b6d999b60dcf70e2df18cf5e8b3801faeb0bd6"}] +["EVENT","s",{"id":"00000e1253a8888a195da04ebc528d2b44a3d4e2788e79b85ec1a2c61eef3733","pubkey":"32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245","created_at":1650051200,"kind":1,"tags":[["nonce","2255367"]],"content":"I am a robot beep boop! This note took 4 seconds to mine 20 bits after 2255367 tries!\n\nThis was generated with https://github.com/jb55/nostril","sig":"97aa14e528c3bef66ebfc767592c5e1488f191b949862b7ca9f061839698d3c2048ba252fa767ab688aafc81107a1d1a81f4ae74ff6d7e2dfe4460807dfab98a"}] +["EVENT","s",{"id":"a4b73fc5b901b74f4d96c6f7104fc58472deae474a225fa172eccaf88df50505","pubkey":"32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245","created_at":1650053582,"kind":1,"tags":[["p","6cad545430904b84a8101c5783b65043f19ae29d2da1076b8fc3e64892736f03","wss://nostr-relay.untethr.me"]],"content":"I made a robot friend that mines nostr events: #[0] ","sig":"d9104549d77ca9b4966b68659d1eddd6dc0c8056642ab013f95a434454311b0110b4eb3bfeee7411f63a784059b03214116186023b03f34701441894ba838eb7"}] +["EVENT","s",{"id":"dc964f4c898364138e8196f0c73338c8cc3ebfa3afddbc7dd158b4847c1ebfa0","pubkey":"32e1827635450ebb3c5a7d12c1f8e7b2b514439ac10a67eef3d9fd9c5c68e245","created_at":1650054135,"kind":1,"tags":[["p","fd3fdb0d0d8d6f9a7667b53211de8ae3c5246b79bdaf64ebac849d5148b5615f"],["p","8c0da4862130283ff9e67d889df264177a508974e2feb96de139804ea66d6168","wss://nostr-relay.untethr.me"],["e","8bc0f167205a099454f6638043c3747b474b16bca77966a0f0c09dfaec0768bf"],["e","f78f0480da11b55fd04211268814e3e285ff7d19a40463e304e98cb49a2ec849"]],"content":"I'm at this account now","sig":"3011b712245b9633405e7b9c901311ef98d61e2bcccac95e554d87870a1a4a974d64191170b39e474ffe8e2746efe704761c13d7b22c19005e69d51cf188453f"}]