From b1064e030914d3a3fea4ba0f44488c55dd209712 Mon Sep 17 00:00:00 2001
From: Matt Morehouse <mattmorehouse@gmail.com>
Date: Mon, 21 Aug 2023 15:40:53 -0500
Subject: [PATCH] fuzz: target for error

Fuzz the decoding and encoding of error.
---
 tests/fuzz/fuzz-wire-error.c | 38 ++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
 create mode 100644 tests/fuzz/fuzz-wire-error.c

diff --git a/tests/fuzz/fuzz-wire-error.c b/tests/fuzz/fuzz-wire-error.c
new file mode 100644
index 000000000..e39bfb140
--- /dev/null
+++ b/tests/fuzz/fuzz-wire-error.c
@@ -0,0 +1,38 @@
+#include "config.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 error {
+	struct channel_id channel_id;
+	u8 *data;
+};
+
+static void *encode(const tal_t *ctx, const struct error *s)
+{
+	return towire_error(ctx, &s->channel_id, s->data);
+}
+
+static struct error *decode(const tal_t *ctx, const void *p)
+{
+	struct error *s = tal(ctx, struct error);
+
+	if (fromwire_error(s, p, &s->channel_id, &s->data))
+		return s;
+	return tal_free(s);
+}
+
+static bool equal(const struct error *x, const struct error *y)
+{
+	if (!channel_id_eq(&x->channel_id, &y->channel_id))
+		return false;
+	return memeq(x->data, tal_bytelen(x->data), y->data,
+		     tal_bytelen(y->data));
+}
+
+void run(const u8 *data, size_t size)
+{
+	test_decode_encode(data, size, WIRE_ERROR, struct error);
+}