nostrdb

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

commit 299e2265556f2abefed11e0d0aa2c54ab129a325
parent 53313c747a9399bb9ef2aa03f1bbe13f28a4fa58
Author: William Casarin <jb55@jb55.com>
Date:   Fri, 24 Oct 2025 11:31:41 -0700

test: add initial metadata tests

Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Mtest.c | 44++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+), 0 deletions(-)

diff --git a/test.c b/test.c @@ -51,6 +51,48 @@ static void print_search(struct ndb_txn *txn, struct ndb_search *search) printf("\n"); } +static void test_metadata() +{ + unsigned char buffer[1024]; + union ndb_reaction_str str; + struct ndb_note_meta_builder builder; + struct ndb_note_meta *meta; + struct ndb_note_meta_entry *entry = NULL; + int ok; + + ok = ndb_note_meta_builder_init(&builder, buffer, sizeof(buffer)); + assert(ok); + + entry = ndb_note_meta_add_entry(&builder); + assert(entry); + + ndb_reaction_set(&str, "🏴‍☠️"); + ndb_note_meta_reaction_set(entry, 1337, str); + + ndb_note_meta_build(&builder, &meta); + + assert(ndb_note_meta_entries_count(meta) == 1); + assert(ndb_note_meta_total_size(meta) == 32); + + entry = ndb_note_meta_entries(meta); + assert(ndb_note_meta_reaction_count(entry) == 1337); + + printf("ok test_metadata\n"); +} + +static void test_reaction_encoding() +{ + union ndb_reaction_str reaction; + assert(ndb_reaction_set(&reaction, "👩🏻‍🤝‍👩🏿")); + assert(reaction.binmoji == 0x07D1A7747240B0D0); + assert(ndb_reaction_str_is_emoji(reaction) == 1); + assert(ndb_reaction_set(&reaction, "hello")); + assert(ndb_reaction_str_is_emoji(reaction) == 0); + assert(!strcmp(reaction.packed.str, "hello")); + printf("ok test_reaction_encoding\n"); +} + + static void test_filters() { struct ndb_filter filter, *f; @@ -2083,6 +2125,8 @@ int main(int argc, const char *argv[]) { test_custom_filter(); delete_test_db(); + test_metadata(); + test_reaction_encoding(); test_note_relay_index(); test_filter_search(); test_filter_parse_search_json();