Skip to content

Commit a493c84

Browse files
Chandra Prataprustyrussell
authored andcommitted
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 a796f64 commit a493c84

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
@@ -31,6 +31,24 @@ void init(int *argc, char ***argv)
3131
chainparams = chainparams_for_network("bitcoin");
3232
}
3333

34+
#define MAX_SATS (u64)WALLY_SATOSHI_PER_BTC * WALLY_BTC_MAX
35+
36+
static void test_channel_update_funding(struct channel *channel, const u8 **cursor, size_t *max) {
37+
struct bitcoin_outpoint funding;
38+
struct amount_sat funding_sats;
39+
s64 splice_amnt;
40+
41+
if (*max < sizeof(funding) + sizeof(funding_sats) + sizeof(splice_amnt))
42+
return;
43+
44+
fromwire_bitcoin_outpoint(cursor, max, &funding);
45+
funding_sats = fromwire_amount_sat(cursor, max);
46+
funding_sats.satoshis %= MAX_SATS;
47+
splice_amnt = fromwire_s64(cursor, max) % MAX_SATS;
48+
49+
channel_update_funding(channel, &funding, funding_sats, splice_amnt);
50+
}
51+
3452
void run(const uint8_t *data, size_t size)
3553
{
3654
struct channel_id cid;
@@ -51,7 +69,7 @@ void run(const uint8_t *data, size_t size)
5169
minimum_depth = fromwire_u32(&data, &size);
5270
funding_sats = fromwire_amount_sat(&data, &size);
5371
local_msatoshi = fromwire_amount_msat(&data, &size);
54-
max = AMOUNT_SAT((u32)WALLY_SATOSHI_PER_BTC * WALLY_BTC_MAX);
72+
max = AMOUNT_SAT(MAX_SATS);
5573
if (amount_sat_greater(funding_sats, max))
5674
funding_sats = max;
5775
feerate_per_kw = fromwire_u32(&data, &size);
@@ -95,8 +113,8 @@ void run(const uint8_t *data, size_t size)
95113
channel_type,
96114
wumbo, opener);
97115

98-
/* TODO: make initial_channel_tx() work with ASAN.. */
99-
(void)channel;
116+
if (channel)
117+
test_channel_update_funding(channel, &data, &size);
100118
}
101119

102120
clean_tmpctx();

0 commit comments

Comments
 (0)