Files
palladum-lightning/tests/fuzz/fuzz-wire-closing_complete.c
Chandra Pratap 0b401a92f2 fuzz-tests: Add fuzz target for closing_complete
Changelog-None: 'closing_signed' and 'closing_complete'
are channel closing negotiation messages defined in BOLT #2.

While 'closing_signed' has a wire fuzz test, 'closing_complete'
does not. Add a test to perform a round-trip encoding check
(towire -> fromwire) similar to the other wire fuzzers.
2025-09-15 11:21:25 +09:30

54 lines
1.7 KiB
C

#include "config.h"
#include <assert.h>
#include <ccan/mem/mem.h>
#include <tests/fuzz/libfuzz.h>
#include <tests/fuzz/wire.h>
#include <wire/peer_wire.h>
struct closing_complete {
struct channel_id channel_id;
u32 locktime;
struct amount_sat fee_satoshis;
u8 *closer_scriptpubkey, *closee_scriptpubkey;
struct tlv_closing_tlvs *tlvs;
};
static void *encode(const tal_t *ctx, const struct closing_complete *s)
{
return towire_closing_complete(ctx, &s->channel_id, s->closer_scriptpubkey,
s->closee_scriptpubkey, s->fee_satoshis, s->locktime, s->tlvs);
}
static struct closing_complete *decode(const tal_t *ctx, const void *p)
{
struct closing_complete *s = tal(ctx, struct closing_complete);
if (fromwire_closing_complete(s, p, &s->channel_id, &s->closer_scriptpubkey,
&s->closee_scriptpubkey, &s->fee_satoshis, &s->locktime, &s->tlvs))
return s;
return tal_free(s);
}
static bool equal(const struct closing_complete *x,
const struct closing_complete *y)
{
assert(memcmp(&x->channel_id, &y->channel_id, sizeof(x->channel_id)) == 0);
assert(x->locktime == y->locktime);
assert(memcmp(&x->fee_satoshis, &y->fee_satoshis, sizeof(x->fee_satoshis)) == 0);
assert(tal_arr_eq(x->closer_scriptpubkey, y->closer_scriptpubkey));
assert(tal_arr_eq(x->closee_scriptpubkey, y->closee_scriptpubkey));
assert(x->tlvs && y->tlvs);
assert(tal_arr_eq(x->tlvs->closer_output_only, y->tlvs->closer_output_only));
assert(tal_arr_eq(x->tlvs->closee_output_only, y->tlvs->closee_output_only));
return tal_arr_eq(x->tlvs->closer_and_closee_outputs, y->tlvs->closer_and_closee_outputs);
}
void run(const u8 *data, size_t size)
{
test_decode_encode(data, size, WIRE_CLOSING_COMPLETE,
struct closing_complete);
}