mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-01 17:47:30 +01:00
tests/fuzz: update for fmt_amount changes, create pseudorand for fuzzing.
Reported-by: Christian Reitter Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
b366453c6a
commit
4e2410742a
2 changed files with 19 additions and 6 deletions
|
@ -43,15 +43,15 @@ void run(const uint8_t *data, size_t size)
|
|||
/* Format should inconditionally produce valid amount strings according to our
|
||||
* parser */
|
||||
|
||||
fmt_msat = fmt_amount_msat(NULL, &msat);
|
||||
fmt_msatbtc = fmt_amount_msat_btc(NULL, &msat, true);
|
||||
fmt_msat = fmt_amount_msat(NULL, msat);
|
||||
fmt_msatbtc = fmt_amount_msat_btc(NULL, msat, true);
|
||||
assert(parse_amount_msat(&msat, fmt_msat, tal_count(fmt_msat)));
|
||||
assert(parse_amount_msat(&msat, fmt_msatbtc, tal_count(fmt_msatbtc)));
|
||||
tal_free(fmt_msat);
|
||||
tal_free(fmt_msatbtc);
|
||||
|
||||
fmt_sat = fmt_amount_sat(NULL, &sat);
|
||||
fmt_satbtc = fmt_amount_sat_btc(NULL, &sat, true);
|
||||
fmt_sat = fmt_amount_sat(NULL, sat);
|
||||
fmt_satbtc = fmt_amount_sat_btc(NULL, sat, true);
|
||||
assert(parse_amount_sat(&sat, fmt_sat, tal_count(fmt_sat)));
|
||||
assert(parse_amount_sat(&sat, fmt_satbtc, tal_count(fmt_satbtc)));
|
||||
tal_free(fmt_sat);
|
||||
|
|
|
@ -1,15 +1,28 @@
|
|||
#include <tests/fuzz/libfuzz.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <ccan/tal/tal.h>
|
||||
#include <ccan/isaac/isaac64.h>
|
||||
#include <common/pseudorand.h>
|
||||
#include <common/utils.h>
|
||||
#include <string.h>
|
||||
|
||||
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
|
||||
int LLVMFuzzerInitialize(int *argc, char ***argv);
|
||||
|
||||
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
run(data, size);
|
||||
/* Provide a non-random pseudo-random function to speed fuzzing. */
|
||||
static isaac64_ctx isaac64;
|
||||
|
||||
uint64_t pseudorand(uint64_t max)
|
||||
{
|
||||
assert(max);
|
||||
return isaac64_next_uint(&isaac64, max);
|
||||
}
|
||||
|
||||
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
isaac64_init(&isaac64, NULL, 0);
|
||||
|
||||
run(data, size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue