| 466 | } |
| 467 | |
| 468 | int main(int argc, const char *argv[]) |
| 469 | { |
| 470 | struct funder_policy *policy; |
| 471 | struct node_id id; |
| 472 | struct amount_sat empty = AMOUNT_SAT(0), our_funds; |
| 473 | bool ok = true; |
| 474 | size_t i = 0, flips = 0; |
| 475 | struct test_case flipcase, fuzzcase; |
| 476 | size_t flipcount = 0; |
| 477 | const char *err; |
| 478 | |
| 479 | common_setup(argv[0]); |
| 480 | memset(&id, 2, sizeof(struct node_id)); |
| 481 | |
| 482 | /* Check the default funder policy, at fixed (0msat) */ |
| 483 | policy = default_funder_policy(tmpctx, FIXED, 0); |
| 484 | |
| 485 | err = calculate_our_funding(policy, id, |
| 486 | AMOUNT_SAT(50000), |
| 487 | AMOUNT_SAT(50000), |
| 488 | AMOUNT_SAT(100000), |
| 489 | AMOUNT_SAT(100000), |
| 490 | &our_funds); |
| 491 | assert(amount_sat_eq(empty, our_funds)); |
| 492 | assert(!err); |
| 493 | |
| 494 | for (i = 0; i < ARRAY_SIZE(cases); i++) { |
| 495 | err = calculate_our_funding(&cases[i].policy, id, |
| 496 | cases[i].their_funds, |
| 497 | cases[i].available_funds, |
| 498 | cases[i].channel_max, |
| 499 | cases[i].lease_request, |
| 500 | &our_funds); |
| 501 | if (!amount_sat_eq(cases[i].exp_our_funds, our_funds)) { |
| 502 | fprintf(stderr, "FAIL policy: %s. expected %s, got %s\n", |
| 503 | funder_policy_desc(NULL, &cases[i].policy), |
| 504 | type_to_string(NULL, struct amount_sat, |
| 505 | &cases[i].exp_our_funds), |
| 506 | type_to_string(NULL, struct amount_sat, |
| 507 | &our_funds)); |
| 508 | ok = false; |
| 509 | } |
| 510 | if (cases[i].expect_err != (err != NULL)) { |
| 511 | fprintf(stderr, "FAIL policy: %s. expected %serr," |
| 512 | " got %s\n", |
| 513 | funder_policy_desc(NULL, &cases[i].policy), |
| 514 | cases[i].expect_err ? "" : "no ", |
| 515 | err ? err : "no err"); |
| 516 | ok = false; |
| 517 | } |
| 518 | } |
| 519 | if (!ok) |
| 520 | exit(1); |
| 521 | |
| 522 | /* Try a few fund_probabilitys, we should only fund |
| 523 | * 1/10th of the time */ |
| 524 | flips = 10; |
| 525 | flipcase = cases[0]; |
nothing calls this directly
no test coverage detected