2016-08-23 05:59:02 +02:00
|
|
|
#include "daemon/channel.c"
|
|
|
|
#include "daemon/htlc.c"
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
/* AUTOGENERATED MOCKS START */
|
|
|
|
/* Generated stub for db_new_htlc */
|
2016-09-01 04:20:32 +02:00
|
|
|
bool db_new_htlc(struct peer *peer UNNEEDED, const struct htlc *htlc UNNEEDED)
|
2016-08-23 05:59:02 +02:00
|
|
|
{ fprintf(stderr, "db_new_htlc called!\n"); abort(); }
|
|
|
|
/* Generated stub for db_update_htlc_state */
|
2016-09-01 04:20:32 +02:00
|
|
|
bool db_update_htlc_state(struct peer *peer UNNEEDED, const struct htlc *htlc UNNEEDED,
|
|
|
|
enum htlc_state oldstate UNNEEDED)
|
2016-08-23 05:59:02 +02:00
|
|
|
{ fprintf(stderr, "db_update_htlc_state called!\n"); abort(); }
|
|
|
|
/* Generated stub for log_ */
|
2016-09-01 04:20:32 +02:00
|
|
|
void log_(struct log *log UNNEEDED, enum log_level level UNNEEDED, const char *fmt UNNEEDED, ...)
|
2016-08-23 05:59:02 +02:00
|
|
|
|
|
|
|
{ fprintf(stderr, "log_ called!\n"); abort(); }
|
|
|
|
/* AUTOGENERATED MOCKS END */
|
|
|
|
|
|
|
|
static void test_maxfee(size_t htlcs, u64 funds)
|
|
|
|
{
|
|
|
|
struct channel_state cstate;
|
|
|
|
uint64_t maxrate;
|
|
|
|
|
|
|
|
cstate.side[LOCAL].pay_msat = funds;
|
|
|
|
cstate.side[LOCAL].fee_msat = 0;
|
|
|
|
cstate.num_nondust = htlcs;
|
|
|
|
|
|
|
|
maxrate = approx_max_feerate(&cstate, LOCAL);
|
|
|
|
assert(fee_by_feerate(tx_bytes(htlcs), maxrate) <= funds);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
size_t htlcs, i;
|
|
|
|
for (htlcs = 0; htlcs < 600; htlcs++) {
|
|
|
|
for (i = 0; i < 32; i++) {
|
|
|
|
test_maxfee(htlcs, i);
|
|
|
|
test_maxfee(htlcs, 1ULL << i);
|
|
|
|
test_maxfee(htlcs, (1ULL << i) - 1);
|
|
|
|
test_maxfee(htlcs, (1ULL << i) + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|