| 997 | } |
| 998 | |
| 999 | static bool test_wallet_outputs(struct lightningd *ld, const tal_t *ctx) |
| 1000 | { |
| 1001 | struct wallet *w = create_test_wallet(ld, ctx); |
| 1002 | struct utxo u; |
| 1003 | struct pubkey pk; |
| 1004 | struct node_id id; |
| 1005 | struct wireaddr_internal addr; |
| 1006 | struct block block; |
| 1007 | struct channel channel; |
| 1008 | struct utxo *one_utxo; |
| 1009 | const struct utxo **utxos; |
| 1010 | CHECK(w); |
| 1011 | |
| 1012 | memset(&u, 0, sizeof(u)); |
| 1013 | u.amount = AMOUNT_SAT(1); |
| 1014 | pubkey_from_der(tal_hexdata(w, "02a1633cafcc01ebfb6d78e39f687a1f0995c62fc95f51ead10a02ee0be551b5dc", 66), 33, &pk); |
| 1015 | node_id_from_pubkey(&id, &pk); |
| 1016 | |
| 1017 | db_begin_transaction(w->db); |
| 1018 | |
| 1019 | /* Should work, it's the first time we add it */ |
| 1020 | CHECK_MSG(wallet_add_utxo(w, &u, p2sh_wpkh), |
| 1021 | "wallet_add_utxo failed on first add"); |
| 1022 | CHECK_MSG(!wallet_err, wallet_err); |
| 1023 | |
| 1024 | /* Should fail, we already have that UTXO */ |
| 1025 | CHECK_MSG(!wallet_add_utxo(w, &u, p2sh_wpkh), |
| 1026 | "wallet_add_utxo succeeded on second add"); |
| 1027 | CHECK_MSG(!wallet_err, wallet_err); |
| 1028 | |
| 1029 | /* Attempt to save an UTXO with close_info set */ |
| 1030 | memset(&u.outpoint, 1, sizeof(u.outpoint)); |
| 1031 | u.close_info = tal(w, struct unilateral_close_info); |
| 1032 | u.close_info->channel_id = 42; |
| 1033 | u.close_info->peer_id = id; |
| 1034 | u.close_info->commitment_point = &pk; |
| 1035 | u.close_info->option_anchor_outputs = false; |
| 1036 | /* Arbitrarily set scriptpubkey len to 20 */ |
| 1037 | u.scriptPubkey = tal_arr(w, u8, 20); |
| 1038 | memset(u.scriptPubkey, 1, 20); |
| 1039 | CHECK_MSG(wallet_add_utxo(w, &u, p2sh_wpkh), |
| 1040 | "wallet_add_utxo with close_info"); |
| 1041 | |
| 1042 | /* Now select them */ |
| 1043 | utxos = tal_arr(w, const struct utxo *, 0); |
| 1044 | while ((one_utxo = wallet_find_utxo(w, w, 100, NULL, 253, |
| 1045 | 0 /* no confirmations required */, |
| 1046 | utxos)) != NULL) { |
| 1047 | tal_arr_expand(&utxos, one_utxo); |
| 1048 | } |
| 1049 | CHECK(tal_count(utxos) == 2); |
| 1050 | |
| 1051 | if (utxos[0]->close_info) |
| 1052 | u = *utxos[0]; |
| 1053 | else |
| 1054 | u = *utxos[1]; |
| 1055 | |
| 1056 | CHECK(u.close_info->channel_id == 42 && |
no test coverage detected