mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
Extend json unit test with tests for json_tok_bitcoin_amount()
This commit is contained in:
committed by
Christian Decker
parent
82a2d2f0a6
commit
648e4feee2
@@ -4,7 +4,41 @@
|
|||||||
/* AUTOGENERATED MOCKS START */
|
/* AUTOGENERATED MOCKS START */
|
||||||
/* AUTOGENERATED MOCKS END */
|
/* AUTOGENERATED MOCKS END */
|
||||||
|
|
||||||
int main(void)
|
|
||||||
|
// issue #577
|
||||||
|
|
||||||
|
static void do_json_tok_bitcoin_amount(const char* val, uint64_t expected)
|
||||||
|
{
|
||||||
|
uint64_t amount;
|
||||||
|
jsmntok_t tok;
|
||||||
|
|
||||||
|
tok.start = 0;
|
||||||
|
tok.end = strlen(val);
|
||||||
|
|
||||||
|
fprintf(stderr, "do_json_tok_bitcoin_amount(\"%s\", %"PRIu64"): ", val, expected);
|
||||||
|
|
||||||
|
assert(json_tok_bitcoin_amount(val, &tok, &amount) == true);
|
||||||
|
assert(amount == expected);
|
||||||
|
|
||||||
|
fprintf(stderr, "ok\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int test_json_tok_bitcoin_amount(void)
|
||||||
|
{
|
||||||
|
do_json_tok_bitcoin_amount("0.00000001", 1);
|
||||||
|
do_json_tok_bitcoin_amount("0.00000007", 7);
|
||||||
|
do_json_tok_bitcoin_amount("0.00000008", 8);
|
||||||
|
do_json_tok_bitcoin_amount("0.00000010", 10);
|
||||||
|
do_json_tok_bitcoin_amount("0.12345678", 12345678);
|
||||||
|
do_json_tok_bitcoin_amount("0.01234567", 1234567);
|
||||||
|
do_json_tok_bitcoin_amount("123.45678900", 12345678900);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int test_json_escape(void)
|
||||||
{
|
{
|
||||||
struct json_result *result = new_json_result(NULL);
|
struct json_result *result = new_json_result(NULL);
|
||||||
jsmntok_t *toks;
|
jsmntok_t *toks;
|
||||||
@@ -43,3 +77,10 @@ int main(void)
|
|||||||
tal_free(result);
|
tal_free(result);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
test_json_tok_bitcoin_amount();
|
||||||
|
test_json_escape();
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user