#include "config.h"
#include "../txout_failures.c"
#include "../common/timeout.c"
#include <common/blinding.h>
#include <common/channel_type.h>
#include <common/clock_time.h>
#include <common/daemon_conn.h>
#include <common/ecdh.h>
#include <common/json_stream.h>
#include <common/memleak.h>
#include <common/onionreply.h>
#include <common/sciddir_or_pubkey.h>
#include <common/setup.h>
#include <gossipd/gossip_store.h>
#include <gossipd/queries.h>
#include <stdio.h>

/* AUTOGENERATED MOCKS START */
/* AUTOGENERATED MOCKS END */

int main(int argc, char *argv[])
{
	struct txout_failures *txf;
	struct timer *t;
	struct short_channel_id scid1, scid2;
	struct daemon *daemon;

	common_setup(argv[0]);

	daemon = tal(tmpctx, struct daemon);
	timers_init(&daemon->timers, time_mono());
	txf = txout_failures_new(tmpctx, daemon);

	scid1.u64 = 100;
	scid2.u64 = 200;
	assert(!in_txout_failures(txf, scid1));
	assert(!in_txout_failures(txf, scid2));

	txout_failures_add(txf, scid1);
	assert(in_txout_failures(txf, scid1));
	assert(!in_txout_failures(txf, scid2));
	assert(txf->num == 1);

	txout_failures_add(txf, scid2);
	assert(in_txout_failures(txf, scid1));
	assert(in_txout_failures(txf, scid2));
	assert(txf->num == 2);

	/* Move time forward 1 hour. */
	t = timers_expire(&daemon->timers,
			  timemono_add(time_mono(),
				       time_from_sec(3601)));
	assert(t);
	timer_expired(t);

	/* Still there, just old.  Refresh scid1 */
	assert(txf->num == 0);
	assert(in_txout_failures(txf, scid1));
	assert(txf->num == 1);

	t = timers_expire(&daemon->timers,
			  timemono_add(time_mono(),
				       time_from_sec(3601)));
	assert(t);
	timer_expired(t);

	assert(txf->num == 0);
	assert(in_txout_failures(txf, scid1));
	assert(txf->num == 1);
	assert(!in_txout_failures(txf, scid2));

	tal_free(txf);
	timers_cleanup(&daemon->timers);
	common_shutdown();

	return 0;
}
