|
2 | 2 | // Distributed under the MIT software license, see the accompanying
|
3 | 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
4 | 4 |
|
| 5 | +#include <addresstype.h> |
| 6 | +#include <coins.h> |
| 7 | +#include <common/bip352.h> |
5 | 8 | #include <key.h>
|
| 9 | +#include <primitives/transaction.h> |
6 | 10 | #include <test/util/setup_common.h>
|
7 | 11 | #include <script/solver.h>
|
| 12 | +#include <uint256.h> |
8 | 13 | #include <wallet/scriptpubkeyman.h>
|
9 | 14 | #include <wallet/wallet.h>
|
| 15 | +#include <wallet/walletutil.h> |
10 | 16 | #include <wallet/test/util.h>
|
11 | 17 |
|
| 18 | +#include <variant> |
| 19 | + |
12 | 20 | #include <boost/test/unit_test.hpp>
|
13 | 21 |
|
14 | 22 | namespace wallet {
|
@@ -40,5 +48,45 @@ BOOST_AUTO_TEST_CASE(CanProvide)
|
40 | 48 | BOOST_CHECK(keyman.CanProvide(p2sh_script, data));
|
41 | 49 | }
|
42 | 50 |
|
| 51 | +// Test SilentPaymentDescriptorScriptPubKeyMan::GetLabelledSPDestination |
| 52 | +// returns the correct label for the given Taproot spk |
| 53 | +BOOST_AUTO_TEST_CASE(GetLabelledSPDestination) |
| 54 | +{ |
| 55 | + CWallet wallet(m_node.chain.get(), "", CreateMockableWalletDatabase()); |
| 56 | + wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS); |
| 57 | + wallet.SetWalletFlag(WALLET_FLAG_SILENT_PAYMENTS); |
| 58 | + { |
| 59 | + LOCK(wallet.cs_wallet); |
| 60 | + wallet.SetupDescriptorScriptPubKeyMans(); |
| 61 | + } |
| 62 | + SilentPaymentDescriptorScriptPubKeyMan* sp_spk_man = *wallet.GetSilentPaymentsSPKMs().begin(); |
| 63 | + uint64_t index; |
| 64 | + auto labelled_dest = sp_spk_man->GetNewLabelledDestination(index); |
| 65 | + |
| 66 | + CKey private_key = GenerateRandomKey(); |
| 67 | + CPubKey pubkey = private_key.GetPubKey(); |
| 68 | + COutPoint prevout(Txid::FromUint256(*uint256::FromHex("daec98e9311f843277e8c59f9dccb42efd4d40881bff215ae82e5724fa754c50")), 0); |
| 69 | + WitnessV0KeyHash p2wpkh(pubkey); |
| 70 | + CScript scriptPubKey = GetScriptForDestination(p2wpkh); |
| 71 | + CScript scriptSig; |
| 72 | + auto sp_dest = std::get_if<V0SilentPaymentDestination>(&labelled_dest.value()); |
| 73 | + auto destinations = BIP352::GenerateSilentPaymentTaprootDestinations( |
| 74 | + std::map<size_t, V0SilentPaymentDestination>{{0, *sp_dest}}, |
| 75 | + std::vector{private_key}, |
| 76 | + std::vector<KeyPair>(), |
| 77 | + prevout |
| 78 | + ); |
| 79 | + auto taproot_dest = destinations.value()[0]; |
| 80 | + |
| 81 | + CTxIn tx_in(prevout, scriptSig); |
| 82 | + tx_in.scriptWitness.stack.push_back(std::vector<unsigned char>(pubkey.begin(), pubkey.end())); |
| 83 | + auto public_data = BIP352::GetSilentPaymentsPublicData( |
| 84 | + std::vector{tx_in}, |
| 85 | + std::map<COutPoint, Coin>{{prevout, Coin(CTxOut(10000, scriptPubKey), 1, false)}} |
| 86 | + ); |
| 87 | + auto retrieved_labelled_dest = sp_spk_man->GetLabelledSPDestination(taproot_dest, *public_data); |
| 88 | + BOOST_CHECK(*labelled_dest == *retrieved_labelled_dest); |
| 89 | +} |
| 90 | + |
43 | 91 | BOOST_AUTO_TEST_SUITE_END()
|
44 | 92 | } // namespace wallet
|
0 commit comments