| 908 | } |
| 909 | |
| 910 | static struct wallet *create_test_wallet(struct lightningd *ld, const tal_t *ctx, bool bip86) |
| 911 | { |
| 912 | char *dsn, *filename; |
| 913 | int fd = tmpdir_mkstemp(ctx, "ldb-XXXXXX", &filename); |
| 914 | struct wallet *w = tal(ctx, struct wallet); |
| 915 | static unsigned char badseed[BIP32_ENTROPY_LEN_128]; |
| 916 | const struct ext_key *bip32_base = NULL; |
| 917 | CHECK_MSG(fd != -1, "Unable to generate temp filename"); |
| 918 | close(fd); |
| 919 | |
| 920 | dsn = tal_fmt(NULL, "sqlite3://%s", filename); |
| 921 | w->db = db_open(w, dsn, true, true, test_error, ld); |
| 922 | w->db->report_changes_fn = NULL; |
| 923 | tal_free(dsn); |
| 924 | tal_add_destructor2(w, cleanup_test_wallet, filename); |
| 925 | |
| 926 | w->ld = ld; |
| 927 | ld->wallet = w; |
| 928 | |
| 929 | ld->bip32_base = tal(ld, struct ext_key); |
| 930 | CHECK(bip32_key_from_seed(badseed, sizeof(badseed), |
| 931 | BIP32_VER_TEST_PRIVATE, 0, |
| 932 | ld->bip32_base) == WALLY_OK); |
| 933 | if (bip86) { |
| 934 | ld->bip86_base = ld->bip32_base; |
| 935 | ld->bip32_base = NULL; |
| 936 | } else { |
| 937 | ld->bip86_base = NULL; |
| 938 | } |
| 939 | |
| 940 | CHECK_MSG(w->db, "Failed opening the db"); |
| 941 | w->db->data_version = 0; |
| 942 | db_begin_transaction(w->db); |
| 943 | db_migrate(ld, w->db, bip32_base); |
| 944 | db_commit_transaction(w->db); |
| 945 | CHECK_MSG(!wallet_err, wallet_err); |
| 946 | w->max_channel_dbid = 0; |
| 947 | |
| 948 | /* Create fresh channels map */ |
| 949 | ld->channels_by_scid = tal(ld, struct channel_scid_map); |
| 950 | channel_scid_map_init(ld->channels_by_scid); |
| 951 | ld->channels_by_dbid = tal(ld, struct channel_dbid_map); |
| 952 | channel_dbid_map_init(ld->channels_by_dbid); |
| 953 | return w; |
| 954 | } |
| 955 | |
| 956 | static bool test_wallet_outputs(struct lightningd *ld, const tal_t *ctx, bool bip86) |
| 957 | { |
no test coverage detected