This means we can make sure the compile and run in normal builds. Side note: various tests call common_setup(), which means we called it twice in unit testing mode, so we conditionalize those. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
30 lines
772 B
C
30 lines
772 B
C
#include "config.h"
|
|
|
|
#include <assert.h>
|
|
#include <common/addr.h>
|
|
#include <common/setup.h>
|
|
#include <common/utils.h>
|
|
#include <tests/fuzz/libfuzz.h>
|
|
|
|
void init(int *argc, char ***argv)
|
|
{
|
|
chainparams = chainparams_for_network("bitcoin");
|
|
/* Don't call this if we're in unit-test mode, as libfuzz.c does it */
|
|
if (!tmpctx)
|
|
common_setup("fuzzer");
|
|
}
|
|
|
|
void run(const uint8_t *data, size_t size)
|
|
{
|
|
uint8_t *script_pubkey = tal_dup_arr(tmpctx, uint8_t, data, size, 0);
|
|
|
|
char *addr = encode_scriptpubkey_to_addr(tmpctx, chainparams, script_pubkey);
|
|
if (addr) {
|
|
uint8_t *decoded_script_pubkey;
|
|
assert(decode_scriptpubkey_from_addr(tmpctx, chainparams, addr, &decoded_script_pubkey));
|
|
assert(tal_arr_eq(script_pubkey, decoded_script_pubkey));
|
|
}
|
|
|
|
clean_tmpctx();
|
|
}
|