Skip to content

Commit d5c7ee4

Browse files
author
Chandra Pratap
committed
fuzz-tests: verify round‑trip scriptpubkey <-> addr conversion
Changelog-None: Currently, fuzz-addr only tests encoding via encode_scriptpubkey_to_addr(), without checking decoding. Add a round‑trip assertion: if encoding produces an address, decode it back with decode_scriptpubkey_from_addr() and confirm the result matches the original scriptpubkey.
1 parent 44972b2 commit d5c7ee4

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

tests/fuzz/fuzz-addr.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <common/addr.h>
44
#include <common/setup.h>
55
#include <common/utils.h>
6+
#include <assert.h>
67
#include <tests/fuzz/libfuzz.h>
78

89
void init(int *argc, char ***argv)
@@ -15,7 +16,12 @@ void run(const uint8_t *data, size_t size)
1516
{
1617
uint8_t *script_pubkey = tal_dup_arr(tmpctx, uint8_t, data, size, 0);
1718

18-
encode_scriptpubkey_to_addr(tmpctx, chainparams, script_pubkey);
19+
char *addr = encode_scriptpubkey_to_addr(tmpctx, chainparams, script_pubkey);
20+
if (addr) {
21+
uint8_t *decoded_script_pubkey;
22+
assert(decode_scriptpubkey_from_addr(tmpctx, chainparams, addr, &decoded_script_pubkey));
23+
assert(tal_arr_eq(script_pubkey, decoded_script_pubkey));
24+
}
1925

2026
clean_tmpctx();
2127
}

0 commit comments

Comments
 (0)