Verify poll SQL failures preserve history, reactions, roots and events
This commit is contained in:
1 parent
638e849df0
commit
d1eac6ff6e
1 file changed
+53
@@ -86,6 +86,58 @@ static char* command(struct UTUN_INSTANCE* inst, const char* text, int expected)
|
||||
assert(json_number(inst->topo_sqlite_db, "{\"valid\":1}", "$.valid") == 1); return result;
|
||||
}
|
||||
|
||||
static int message_count(struct UTUN_INSTANCE* inst, const char* channel) {
|
||||
char sql[128]; snprintf(sql, sizeof(sql), "SELECT count(*) FROM msg_%s", channel); sqlite3_stmt* st = NULL;
|
||||
assert(sqlite3_prepare_v2(inst->topo_sqlite_db, sql, -1, &st, NULL) == SQLITE_OK && sqlite3_step(st) == SQLITE_ROW);
|
||||
int count = sqlite3_column_int(st, 0); assert(sqlite3_finalize(st) == SQLITE_OK); return count;
|
||||
}
|
||||
|
||||
/* Ошибка SQL не становится отсутствующим полем/пустой сводкой и не публикует команду. */
|
||||
static void sql_faults(struct UTUN_INSTANCE* inst, const char* channel, const char* hex, const uint8_t message[32]) {
|
||||
char react[512], vote[512], create[512]; uint8_t before[32], after[32]; unsigned cases = 0;
|
||||
snprintf(react, sizeof(react), "{\"cmd\":\"react\",\"ch\":\"%s\",\"message_id\":\"%s\",\"emoji\":0}", channel, hex);
|
||||
snprintf(vote, sizeof(vote), "{\"cmd\":\"vote\",\"ch\":\"%s\",\"message_id\":\"%s\",\"choices\":[0]}", channel, hex);
|
||||
snprintf(create, sizeof(create), "{\"cmd\":\"poll_create\",\"ch\":\"%s\",\"question\":\"SQL retry\","
|
||||
"\"mode\":\"single\",\"options\":[\"one\",\"two\"]}", channel);
|
||||
chat_event_set_handler(inst, poll_event);
|
||||
for (enum poll_query operation = P_VALID; operation <= P_OPTIONS; operation++) {
|
||||
unsigned occurrences = operation == P_FIELD ? 6 : 1;
|
||||
for (unsigned occurrence = 1; occurrence <= occurrences; occurrence++) {
|
||||
for (enum poll_fault point = P_PREPARE; point <= P_FINALIZE; point++) {
|
||||
unsigned bindings = point == P_BIND && (operation == P_FIELD || operation == P_CHOICES) ? 2 : 1;
|
||||
for (unsigned bind = 1; bind <= bindings; bind++) {
|
||||
struct chat_feedback_record saved, actual;
|
||||
assert(chat_feedback_get(inst, channel, message, inst->node_id, CHAT_FEEDBACK_REACTION, &saved) == 1);
|
||||
assert(!merkle_sync_read_hash(inst, MT_DATA_FEEDBACK, channel, 0, 0, before));
|
||||
unsigned events = changed_events; int messages = message_count(inst, channel);
|
||||
query = operation; query_number = occurrence; matching_queries = 0; fault_statement = NULL;
|
||||
fault_bind = bind; fault = point; char* result = NULL;
|
||||
const char* request = operation == P_CHOICES ? vote : operation == P_OPTIONS ? create : react;
|
||||
if (operation == P_SNAPSHOT) {
|
||||
assert(chat_feedback_snapshot(inst, channel, message, &result) < 0 && !result);
|
||||
} else { result = command(inst, request, -1); u_free(result); }
|
||||
assert(fault == P_NONE && !fault_statement && changed_events == events && message_count(inst, channel) == messages);
|
||||
assert(!merkle_sync_read_hash(inst, MT_DATA_FEEDBACK, channel, 0, 0, after) && !memcmp(before, after, 32));
|
||||
assert(chat_feedback_get(inst, channel, message, inst->node_id, CHAT_FEEDBACK_REACTION, &actual) == 1);
|
||||
assert(actual.ver == saved.ver && actual.data_len == saved.data_len && !memcmp(actual.data, saved.data, saved.data_len));
|
||||
assert(!memcmp(actual.signature, saved.signature, 64));
|
||||
if (operation == P_SNAPSHOT) assert(!chat_feedback_snapshot(inst, channel, message, &result) && result);
|
||||
else result = command(inst, request, 0);
|
||||
u_free(result); cases++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
struct chat_feedback_record saved, actual;
|
||||
assert(chat_feedback_get(inst, channel, message, inst->node_id, CHAT_FEEDBACK_REACTION, &saved) == 1);
|
||||
snprintf(react, sizeof(react), "{\"cmd\":\"react\",\"ch\":\"%s\",\"message_id\":\"%s\",\"emoji\":\"👍\\u0000tail\"}", channel, hex);
|
||||
char* result = command(inst, react, -1); u_free(result);
|
||||
assert(chat_feedback_get(inst, channel, message, inst->node_id, CHAT_FEEDBACK_REACTION, &actual) == 1 && actual.ver == saved.ver);
|
||||
assert(actual.data_len == saved.data_len && !memcmp(actual.data, saved.data, saved.data_len));
|
||||
chat_event_set_handler(inst, NULL);
|
||||
printf("PASS: %u poll SQL faults preserve messages, reactions, Merkle root and events; retries succeed; emoji must be complete text\n", cases);
|
||||
}
|
||||
|
||||
/* Проверяем границы, каноничность и невозможность интерпретации битого UTF-8. */
|
||||
static void codecs(void) {
|
||||
struct chat_poll poll = { .mode = CHAT_POLL_SINGLE, .allow_custom_answer = 1, .option_count = 2 }, decoded;
|
||||
@@ -172,6 +224,7 @@ int main(void) {
|
||||
result = command(inst, request, 0); assert(json_number(db, result, "$.reactions[0].count") == 0);
|
||||
assert(json_number(db, result, "$.reaction_ver") == 5); u_free(result);
|
||||
puts("PASS: selecting another emoji replaces the previous one; unselected withdrawal is inert; repeat click cancels");
|
||||
sql_faults(inst, channel, id, message_id);
|
||||
snprintf(request, sizeof(request),
|
||||
"{\"cmd\":\"poll_create\",\"ch\":\"%s\",\"question\":\"Выбор\",\"mode\":\"multiple\","
|
||||
"\"options\":[\"Первый\",\"Второй\"],\"allow_custom_answer\":true}", channel);
|
||||
|
||||
Reference in new issue
Block a user