mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 18:11:28 +01:00
fuzz: target for shutdown
Fuzz the decoding and encoding of shutdown.
This commit is contained in:
parent
4aa165e7a2
commit
1fff136d66
56
tests/fuzz/fuzz-wire-shutdown.c
Normal file
56
tests/fuzz/fuzz-wire-shutdown.c
Normal file
@ -0,0 +1,56 @@
|
||||
#include "config.h"
|
||||
#include <assert.h>
|
||||
#include <ccan/mem/mem.h>
|
||||
#include <common/channel_id.h>
|
||||
#include <tests/fuzz/libfuzz.h>
|
||||
#include <tests/fuzz/wire.h>
|
||||
#include <wire/peer_wire.h>
|
||||
|
||||
struct shutdown {
|
||||
struct channel_id channel_id;
|
||||
u8 *scriptpubkey;
|
||||
struct tlv_shutdown_tlvs *tlvs;
|
||||
};
|
||||
|
||||
static void *encode(const tal_t *ctx, const struct shutdown *s)
|
||||
{
|
||||
return towire_shutdown(ctx, &s->channel_id, s->scriptpubkey, s->tlvs);
|
||||
}
|
||||
|
||||
static struct shutdown *decode(const tal_t *ctx, const void *p)
|
||||
{
|
||||
struct shutdown *s = tal(ctx, struct shutdown);
|
||||
|
||||
if (fromwire_shutdown(s, p, &s->channel_id, &s->scriptpubkey, &s->tlvs))
|
||||
return s;
|
||||
return tal_free(s);
|
||||
}
|
||||
|
||||
static bool wrong_funding_equal(const struct tlv_shutdown_tlvs_wrong_funding *x,
|
||||
const struct tlv_shutdown_tlvs_wrong_funding *y)
|
||||
{
|
||||
if (!x && !y)
|
||||
return true;
|
||||
if (!x || !y)
|
||||
return false;
|
||||
|
||||
return bitcoin_txid_eq(&x->txid, &y->txid) && x->outnum == y->outnum;
|
||||
}
|
||||
|
||||
static bool equal(const struct shutdown *x, const struct shutdown *y)
|
||||
{
|
||||
if (!channel_id_eq(&x->channel_id, &y->channel_id))
|
||||
return false;
|
||||
if (!memeq(x->scriptpubkey, tal_bytelen(x->scriptpubkey),
|
||||
y->scriptpubkey, tal_bytelen(y->scriptpubkey)))
|
||||
return false;
|
||||
|
||||
assert(x->tlvs && y->tlvs);
|
||||
return wrong_funding_equal(x->tlvs->wrong_funding,
|
||||
y->tlvs->wrong_funding);
|
||||
}
|
||||
|
||||
void run(const u8 *data, size_t size)
|
||||
{
|
||||
test_decode_encode(data, size, WIRE_SHUTDOWN, struct shutdown);
|
||||
}
|
Loading…
Reference in New Issue
Block a user