mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 14:42:40 +01:00
fuzz: target for tx_init_rbf
Fuzz the decoding and encoding of tx_init_rbf.
This commit is contained in:
parent
1dda44c351
commit
7ddad8b7df
1 changed files with 48 additions and 0 deletions
48
tests/fuzz/fuzz-wire-tx_init_rbf.c
Normal file
48
tests/fuzz/fuzz-wire-tx_init_rbf.c
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
#include "config.h"
|
||||||
|
#include <assert.h>
|
||||||
|
#include <ccan/mem/mem.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <tests/fuzz/libfuzz.h>
|
||||||
|
#include <tests/fuzz/wire.h>
|
||||||
|
#include <wire/peer_wire.h>
|
||||||
|
|
||||||
|
struct tx_init_rbf {
|
||||||
|
struct channel_id channel_id;
|
||||||
|
u32 locktime;
|
||||||
|
u32 feerate;
|
||||||
|
struct tlv_tx_init_rbf_tlvs *tlvs;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void *encode(const tal_t *ctx, const struct tx_init_rbf *s)
|
||||||
|
{
|
||||||
|
return towire_tx_init_rbf(ctx, &s->channel_id, s->locktime, s->feerate,
|
||||||
|
s->tlvs);
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct tx_init_rbf *decode(const tal_t *ctx, const void *p)
|
||||||
|
{
|
||||||
|
struct tx_init_rbf *s = tal(ctx, struct tx_init_rbf);
|
||||||
|
|
||||||
|
if (fromwire_tx_init_rbf(s, p, &s->channel_id, &s->locktime,
|
||||||
|
&s->feerate, &s->tlvs))
|
||||||
|
return s;
|
||||||
|
return tal_free(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool equal(const struct tx_init_rbf *x, const struct tx_init_rbf *y)
|
||||||
|
{
|
||||||
|
size_t upto_tlvs = (uintptr_t)&x->tlvs - (uintptr_t)x;
|
||||||
|
if (memcmp(x, y, upto_tlvs) != 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
assert(x->tlvs && y->tlvs);
|
||||||
|
return memeq(x->tlvs->funding_output_contribution,
|
||||||
|
tal_bytelen(x->tlvs->funding_output_contribution),
|
||||||
|
y->tlvs->funding_output_contribution,
|
||||||
|
tal_bytelen(y->tlvs->funding_output_contribution));
|
||||||
|
}
|
||||||
|
|
||||||
|
void run(const u8 *data, size_t size)
|
||||||
|
{
|
||||||
|
test_decode_encode(data, size, WIRE_TX_INIT_RBF, struct tx_init_rbf);
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue