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

Function run

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

Source from the content-addressed store, hash-verified

101{}
102
103void run(const u8 *data, size_t size)
104{
105 struct test_case *tcase = new_test_case(tmpctx, &data, &size);
106
107 struct node_id id;
108 memset(&id, 1, sizeof(id));
109 const char *err;
110 struct amount_sat our_funds;
111
112 /* Call the function under test */
113 err = calculate_our_funding(&tcase->policy, id,
114 tcase->their_funds,
115 tcase->our_last_funds,
116 tcase->available_funds,
117 tcase->max_channel_size,
118 tcase->lease_request,
119 &our_funds);
120
121 /* Validate invariants */
122 if (!err)
123 {
124 /* Check total doesn't exceed max_channel_size */
125 struct amount_sat total;
126 if (!amount_sat_add(&total, tcase->their_funds, our_funds)) {
127 fprintf(stderr, "Overflow in total channel capacity\n");
128 abort();
129 }
130 if (amount_sat_greater(total, tcase->max_channel_size)) {
131 fprintf(stderr, "Total channel capacity %"PRIu64" exceeds size %"PRIu64"\n",
132 total.satoshis, tcase->max_channel_size.satoshis); /* Raw: fuzzing */
133 abort();
134 }
135
136 /* Check our_funds is within per-channel limits */
137 if (amount_sat_less(our_funds, tcase->policy.per_channel_min) &&
138 !amount_sat_is_zero(our_funds)) {
139 fprintf(stderr, "our_funds %"PRIu64" < per_channel_min %"PRIu64"\n",
140 our_funds.satoshis, tcase->policy.per_channel_min.satoshis); /* Raw: fuzzing */
141 abort();
142 }
143 if (amount_sat_greater(our_funds, tcase->policy.per_channel_max)) {
144 fprintf(stderr, "our_funds %"PRIu64" > per_max_channel_size %"PRIu64"\n",
145 our_funds.satoshis, tcase->policy.per_channel_max.satoshis); /* Raw: fuzzing */
146 abort();
147 }
148 }
149
150 /* Check available funds constraint */
151 struct amount_sat available_minus_reserve;
152 if (amount_sat_sub(&available_minus_reserve, tcase->available_funds, tcase->policy.reserve_tank)) {
153 if (amount_sat_greater(our_funds, available_minus_reserve)) {
154 fprintf(stderr, "our_funds %"PRIu64" > available %"PRIu64" - reserve %"PRIu64"\n",
155 our_funds.satoshis, tcase->available_funds.satoshis, /* Raw: fuzzing */
156 tcase->policy.reserve_tank.satoshis); /* Raw: fuzzing */
157 abort();
158 }
159 } else if (!amount_sat_eq(our_funds, AMOUNT_SAT(0))) {
160 fprintf(stderr, "Reserve %"PRIu64" >= available %"PRIu64" but our_funds %"PRIu64" != 0\n",

Callers

nothing calls this directly

Calls 10

new_test_caseFunction · 0.85
calculate_our_fundingFunction · 0.85
abortFunction · 0.85
amount_sat_greaterFunction · 0.85
amount_sat_lessFunction · 0.85
amount_sat_is_zeroFunction · 0.85
clean_tmpctxFunction · 0.85
amount_sat_addFunction · 0.50
amount_sat_subFunction · 0.50
amount_sat_eqFunction · 0.50

Tested by

no test coverage detected