Skip to content

Commit 15a3118

Browse files
author
Chandra Pratap
committed
fuzz-tests: Add test for untested function
Currently, `fuzz-initial_channel` doesn't verify the function `channel_update_fundinng()` in its target file, `common/initial_channel.h`. Add a test for it.
1 parent 9a92d82 commit 15a3118

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

tests/fuzz/fuzz-initial_channel.c

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,24 @@ void init(int *argc, char ***argv)
2929
chainparams = chainparams_for_network("bitcoin");
3030
}
3131

32+
#define MAX_SATS (u64)WALLY_SATOSHI_PER_BTC * WALLY_BTC_MAX
33+
34+
static void test_channel_update_funding(struct channel *channel, const u8 **cursor, size_t *max) {
35+
struct bitcoin_outpoint funding;
36+
struct amount_sat funding_sats;
37+
s64 splice_amnt;
38+
39+
if (*max < sizeof(funding) + sizeof(funding_sats) + sizeof(splice_amnt))
40+
return;
41+
42+
fromwire_bitcoin_outpoint(cursor, max, &funding);
43+
funding_sats = fromwire_amount_sat(cursor, max);
44+
funding_sats.satoshis %= MAX_SATS;
45+
splice_amnt = fromwire_s64(cursor, max) % MAX_SATS;
46+
47+
channel_update_funding(channel, &funding, funding_sats, splice_amnt);
48+
}
49+
3250
void run(const uint8_t *data, size_t size)
3351
{
3452
struct channel_id cid;
@@ -49,7 +67,7 @@ void run(const uint8_t *data, size_t size)
4967
minimum_depth = fromwire_u32(&data, &size);
5068
funding_sats = fromwire_amount_sat(&data, &size);
5169
local_msatoshi = fromwire_amount_msat(&data, &size);
52-
max = AMOUNT_SAT((u32)WALLY_SATOSHI_PER_BTC * WALLY_BTC_MAX);
70+
max = AMOUNT_SAT(MAX_SATS);
5371
if (amount_sat_greater(funding_sats, max))
5472
funding_sats = max;
5573
feerate_per_kw = fromwire_u32(&data, &size);
@@ -93,8 +111,8 @@ void run(const uint8_t *data, size_t size)
93111
channel_type,
94112
wumbo, opener);
95113

96-
/* TODO: make initial_channel_tx() work with ASAN.. */
97-
(void)channel;
114+
if (channel)
115+
test_channel_update_funding(channel, &data, &size);
98116
}
99117

100118
clean_tmpctx();

0 commit comments

Comments
 (0)