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

Function main

plugins/test/run-funder_policy.c:489–578  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

487}
488
489int main(int argc, const char *argv[])
490{
491 struct funder_policy *policy;
492 struct node_id id;
493 struct amount_sat empty = AMOUNT_SAT(0), our_funds;
494 bool ok = true;
495 size_t i = 0, flips = 0;
496 struct test_case flipcase, fuzzcase;
497 size_t flipcount = 0;
498 const char *err;
499
500 common_setup(argv[0]);
501 memset(&id, 2, sizeof(struct node_id));
502
503 /* Check the default funder policy, at fixed (0msat) */
504 policy = default_funder_policy(tmpctx, FIXED, 0);
505
506 err = calculate_our_funding(policy, id,
507 AMOUNT_SAT(50000),
508 NULL,
509 AMOUNT_SAT(50000),
510 AMOUNT_SAT(100000),
511 AMOUNT_SAT(100000),
512 &our_funds);
513 assert(amount_sat_eq(empty, our_funds));
514 assert(!err);
515
516 for (i = 0; i < ARRAY_SIZE(cases); i++) {
517 err = calculate_our_funding(&cases[i].policy, id,
518 cases[i].their_funds,
519 cases[i].our_last_funds,
520 cases[i].available_funds,
521 cases[i].channel_max,
522 cases[i].lease_request,
523 &our_funds);
524 if (!amount_sat_eq(cases[i].exp_our_funds, our_funds)) {
525 fprintf(stderr, "FAIL policy: %s. expected %s, got %s\n",
526 funder_policy_desc(NULL, &cases[i].policy),
527 fmt_amount_sat(NULL, cases[i].exp_our_funds),
528 fmt_amount_sat(NULL, our_funds));
529 ok = false;
530 }
531 if (cases[i].expect_err != (err != NULL)) {
532 fprintf(stderr, "FAIL policy: %s. expected %serr,"
533 " got %s\n",
534 funder_policy_desc(NULL, &cases[i].policy),
535 cases[i].expect_err ? "" : "no ",
536 err ? err : "no err");
537 ok = false;
538 }
539 }
540 if (!ok)
541 exit(1);
542
543 /* Try a few fund_probabilitys, we should only fund
544 * 1/10th of the time */
545 flips = 10;
546 flipcase = cases[0];

Callers

nothing calls this directly

Calls 8

common_setupFunction · 0.85
default_funder_policyFunction · 0.85
calculate_our_fundingFunction · 0.85
funder_policy_descFunction · 0.85
check_fuzzingFunction · 0.85
common_shutdownFunction · 0.85
amount_sat_eqFunction · 0.50
fmt_amount_satFunction · 0.50

Tested by

no test coverage detected