MCPcopy Create free account
hub / github.com/ElementsProject/lightning / new_test_case

Function new_test_case

tests/fuzz/fuzz-funder-policy.c:36–98  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34}
35
36static struct test_case *new_test_case(const tal_t *ctx, const u8 **cursor, size_t *max)
37{
38 struct test_case *tcase = tal(ctx, struct test_case);
39 tcase->their_funds = fromwire_amount_sat_bounded(cursor, max);
40 tcase->available_funds = fromwire_amount_sat_bounded(cursor, max);
41
42 /* Read flag for our_last_funds */
43 u8 flag = fromwire_u8(cursor, max);
44
45 /* Handle our_last_funds conditionally */
46 struct amount_sat *our_last_funds_val = tal(ctx, struct amount_sat);
47 if (flag)
48 {
49 *our_last_funds_val = fromwire_amount_sat_bounded(cursor, max);
50 tcase->our_last_funds = our_last_funds_val;
51 }
52 else
53 tcase->our_last_funds = NULL;
54
55 tcase->max_channel_size = fromwire_amount_sat_bounded(cursor, max);
56 tcase->lease_request = fromwire_amount_sat_bounded(cursor, max);
57
58 tcase->policy.opt = (enum funder_opt)(fromwire_u8(cursor, max) % 3);
59 tcase->policy.mod = fromwire_u64(cursor, max);
60 switch (tcase->policy.opt)
61 {
62 case MATCH:
63 tcase->policy.mod %= 201;
64 break;
65 case AVAILABLE:
66 tcase->policy.mod %= 101;
67 break;
68 case FIXED:
69 tcase->policy.mod %= MAX_SATS + 1;
70 break;
71 default:
72 assert(false && "invalid policy");
73 }
74 tcase->policy.min_their_funding = fromwire_amount_sat_bounded(cursor, max);
75 tcase->policy.max_their_funding = fromwire_amount_sat_bounded(cursor, max);
76
77 if (amount_sat_greater(tcase->policy.min_their_funding, tcase->policy.max_their_funding)) {
78 struct amount_sat tmp = tcase->policy.min_their_funding;
79 tcase->policy.min_their_funding = tcase->policy.max_their_funding;
80 tcase->policy.max_their_funding = tmp;
81 }
82
83 tcase->policy.per_channel_max = fromwire_amount_sat_bounded(cursor, max);
84 tcase->policy.per_channel_min = fromwire_amount_sat_bounded(cursor, max);
85
86 if (amount_sat_greater(tcase->policy.per_channel_min, tcase->policy.per_channel_max)) {
87 struct amount_sat tmp = tcase->policy.per_channel_min;
88 tcase->policy.per_channel_min = tcase->policy.per_channel_max;
89 tcase->policy.per_channel_max = tmp;
90 }
91
92 tcase->policy.fuzz_factor = fromwire_u8(cursor, max) % 101;
93 tcase->policy.reserve_tank = fromwire_amount_sat_bounded(cursor, max);

Callers 1

runFunction · 0.85

Calls 4

amount_sat_greaterFunction · 0.85
fromwire_u8Function · 0.50
fromwire_u64Function · 0.50

Tested by

no test coverage detected