commit c222f0e8b09187200ee3f4f4a787849ca904d0d7
parent 34d7d1bfdaf328171810834234bcacd72a53d29c
Author: William Casarin <jb55@jb55.com>
Date: Sun, 24 Sep 2023 15:16:43 -0700
test: test profile updates
This seems to be working, so maybe there is an ingestion problem when
updating profiles on the Damus iOS side?
Diffstat:
2 files changed, 49 insertions(+), 2 deletions(-)
diff --git a/test.c b/test.c
@@ -77,11 +77,56 @@ static void test_profile_search(struct ndb *ndb)
ndb_end_query(&txn);
}
+static void test_profile_updates()
+{
+ static const int alloc_size = 1024 * 1024;
+ char *json = malloc(alloc_size);
+ struct ndb *ndb;
+ size_t mapsize, len;
+ void *record;
+ int written, ingester_threads;
+ struct ndb_txn txn;
+ uint64_t key;
+
+ mapsize = 1024 * 1024 * 100;
+ ingester_threads = 1;
+
+ assert(ndb_init(&ndb, test_dir, mapsize, ingester_threads, 0));
+
+ read_file("testdata/profile-updates.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, 0));
+
+ 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
+ };
+ record = ndb_get_profile_by_pubkey(&txn, pk, &len, &key);
+
+ assert(record);
+ int res = NdbProfileRecord_verify_as_root(record, len);
+ assert(res == 0);
+
+ NdbProfileRecord_table_t profile_record = NdbProfileRecord_as_root(record);
+ NdbProfile_table_t profile = NdbProfileRecord_profile_get(profile_record);
+ const char *name = NdbProfile_name_get(profile);
+
+ assert(!strcmp(name, "c"));
+
+ ndb_destroy(ndb);
+}
+
static void test_load_profiles()
{
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;
@@ -115,7 +160,6 @@ static void test_load_profiles()
ndb_destroy(ndb);
free(json);
- free(buf);
}
static void test_fuzz_events() {
diff --git a/testdata/profile-updates.json b/testdata/profile-updates.json
@@ -0,0 +1,3 @@
+["EVENT","a",{"id": "9b2861dda8fc602ec2753f92f1a443c9565de606e0c8f4fd2db4f2506a3b13ca","pubkey": "87fbc6d59831a823a45d101f86942c41cde29023f4092024a27c50103c154001","created_at": 1695593347,"kind": 0,"tags": [],"content": "{\"name\":\"a\"}","sig": "f48da228f8967d33c3caf0a78f853b5144631eb86c7777fd25949123a5272a92765a0963d4686dd0efe05b7a9b986bfac8d43070b234153acbae5006d5a90f31"}]
+["EVENT","b",{"id": "a44eb8fb6931d6155b04038bef0624407e46c85c61e5758392cbb615f00184ca","pubkey": "87fbc6d59831a823a45d101f86942c41cde29023f4092024a27c50103c154001","created_at": 1695593354,"kind": 0,"tags": [],"content": "{\"name\":\"b\"}","sig": "7540bbde4b4479275e20d95acaa64027359a73989927f878825093cba2f468bd8e195919a77b4c230acecddf92e6b4bee26918b0c0842f84ec7c1fae82453906"}]
+["EVENT","c",{"id": "3090cdba2889acf1279efbf598e7e1cc701259c329cb11309a495f6c5204a7f6","pubkey": "87fbc6d59831a823a45d101f86942c41cde29023f4092024a27c50103c154001","created_at": 1695593357,"kind": 0,"tags": [],"content": "{\"name\":\"c\"}","sig": "f143edd4a8e60d882b0a19c7a4ee896a0c99da285fceab1ea704c5a9b6110f7b6983fe3c4a0a316c8ab1aa971323639a6049033c253a8c3684f99f76e781aa7c"}]