49 lines
1.6 KiB
C
49 lines
1.6 KiB
C
#include "nostr_url.h"
|
|
#include <glib.h>
|
|
#include <string.h>
|
|
|
|
static const char *exact_npub =
|
|
"npub1rmz9gu6de0m0u4ysrn39crrud099ahvfgs6pvasl4hpjr5ud7yus54xv06";
|
|
|
|
static void test_exact_npub(void) {
|
|
nostr_decoded_entity_t decoded;
|
|
GError *error = NULL;
|
|
g_assert_true(nostr_url_decode(exact_npub, &decoded, &error));
|
|
g_assert_no_error(error);
|
|
g_assert_cmpint(decoded.type, ==, NOSTR_ENTITY_NPUB);
|
|
char *hex = nostr_hex_encode32(decoded.pubkey);
|
|
g_assert_cmpstr(hex, ==,
|
|
"1ec454734dcbf6fe54901ce25c0c7c6bca5edd89443416761fadc321d38df139");
|
|
g_free(hex);
|
|
nostr_decoded_entity_clear(&decoded);
|
|
}
|
|
|
|
static void test_checksum_rejected(void) {
|
|
char *bad = g_strdup(exact_npub);
|
|
bad[strlen(bad) - 1] = bad[strlen(bad) - 1] == 'q' ? 'p' : 'q';
|
|
nostr_decoded_entity_t decoded;
|
|
GError *error = NULL;
|
|
g_assert_false(nostr_url_decode(bad, &decoded, &error));
|
|
g_assert_nonnull(error);
|
|
g_clear_error(&error);
|
|
g_free(bad);
|
|
}
|
|
|
|
static void test_nsec_rejected(void) {
|
|
const char *nsec =
|
|
"nsec1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzqujme";
|
|
nostr_decoded_entity_t decoded;
|
|
GError *error = NULL;
|
|
g_assert_false(nostr_url_decode(nsec, &decoded, &error));
|
|
g_assert_nonnull(error);
|
|
g_clear_error(&error);
|
|
}
|
|
|
|
int main(int argc, char **argv) {
|
|
g_test_init(&argc, &argv, NULL);
|
|
g_test_add_func("/nostr-url/exact-npub", test_exact_npub);
|
|
g_test_add_func("/nostr-url/checksum", test_checksum_rejected);
|
|
g_test_add_func("/nostr-url/nsec", test_nsec_rejected);
|
|
return g_test_run();
|
|
}
|