|
| 1 | +#include "config.h" |
| 2 | +#include <assert.h> |
| 3 | +#include <ccan/mem/mem.h> |
| 4 | +#include <tests/fuzz/libfuzz.h> |
| 5 | +#include <tests/fuzz/wire.h> |
| 6 | +#include <wire/peer_wire.h> |
| 7 | + |
| 8 | +struct closing_complete { |
| 9 | + struct channel_id channel_id; |
| 10 | + u32 locktime; |
| 11 | + struct amount_sat fee_satoshis; |
| 12 | + u8 *closer_scriptpubkey, *closee_scriptpubkey; |
| 13 | + struct tlv_closing_tlvs *tlvs; |
| 14 | +}; |
| 15 | + |
| 16 | +static void *encode(const tal_t *ctx, const struct closing_complete *s) |
| 17 | +{ |
| 18 | + return towire_closing_complete(ctx, &s->channel_id, s->closer_scriptpubkey, |
| 19 | + s->closee_scriptpubkey, s->fee_satoshis, s->locktime, s->tlvs); |
| 20 | +} |
| 21 | + |
| 22 | +static struct closing_complete *decode(const tal_t *ctx, const void *p) |
| 23 | +{ |
| 24 | + struct closing_complete *s = tal(ctx, struct closing_complete); |
| 25 | + |
| 26 | + if (fromwire_closing_complete(s, p, &s->channel_id, &s->closer_scriptpubkey, |
| 27 | + &s->closee_scriptpubkey, &s->fee_satoshis, &s->locktime, &s->tlvs)) |
| 28 | + return s; |
| 29 | + return tal_free(s); |
| 30 | +} |
| 31 | + |
| 32 | +static bool equal(const struct closing_complete *x, |
| 33 | + const struct closing_complete *y) |
| 34 | +{ |
| 35 | + size_t upto_closer_scriptpubkey = (uintptr_t)&x->closer_scriptpubkey - (uintptr_t)x; |
| 36 | + if (memcmp(x, y, upto_closer_scriptpubkey) != 0) |
| 37 | + return false; |
| 38 | + |
| 39 | + assert(tal_arr_eq(x->closer_scriptpubkey, y->closer_scriptpubkey)); |
| 40 | + assert(tal_arr_eq(x->closee_scriptpubkey, y->closee_scriptpubkey)); |
| 41 | + |
| 42 | + assert(x->tlvs && y->tlvs); |
| 43 | + return tal_arr_eq(x->tlvs->closer_and_closee_outputs, y->tlvs->closer_and_closee_outputs); |
| 44 | +} |
| 45 | + |
| 46 | +void run(const u8 *data, size_t size) |
| 47 | +{ |
| 48 | + test_decode_encode(data, size, WIRE_CLOSING_COMPLETE, |
| 49 | + struct closing_complete); |
| 50 | +} |
0 commit comments