v30.3-roots.1 · Commit 23: [PATCH 23/68] feat(wallet): add transient private-key sweep RPC
src/wallet/test/spend_tests.cpp
Before: src/wallet/test/spend_tests.cpp · After: src/wallet/test/spend_tests.cpp
File metadata
index e295002a51f207aa95c04a30a87f57d9ed662a29..e28272a201d6881216dc990f082b5d191342ee38 100644
Download original patch · Release notes
Diff rows 1–47 of 47. Line numbers refer to the original before/after files.
+ Added− RemovedUnmarked lines are context.
Scroll the code area horizontally to read long lines. The two line-number columns refer to before and after.
src/wallet/test/spend_tests.cpp
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
#include <script/solver.h>
|
|
11
11
|
#include <validation.h>
|
|
12
12
|
#include <wallet/coincontrol.h>
|
|
13
|
+
#include <wallet/fees.h>
|
|
13
14
|
#include <wallet/spend.h>
|
|
14
15
|
#include <wallet/test/util.h>
|
|
15
16
|
#include <wallet/test/wallet_test_fixture.h>
|
|
@@ -48,6 +49,40 @@ BOOST_AUTO_TEST_CASE(anti_fee_sniping_avoids_reserved_policy_locktime)
|
|
|
48
49
|
}
|
|
49
50
|
}
|
|
50
51
|
|
|
52
|
+
BOOST_FIXTURE_TEST_CASE(sweep_transaction_failure_atomicity, TestChain100Setup)
|
|
53
|
+
{
|
|
54
|
+
CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey()));
|
|
55
|
+
auto wallet = CreateSyncedWallet(*m_node.chain, WITH_LOCK(Assert(m_node.chainman)->GetMutex(), return m_node.chainman->ActiveChain()), coinbaseKey);
|
|
56
|
+
const CKey key{GenerateRandomKey()};
|
|
57
|
+
const CScript script{GetScriptForDestination(PKHash{key.GetPubKey()})};
|
|
58
|
+
std::map<COutPoint, Coin> coins;
|
|
59
|
+
coins.emplace(COutPoint{Txid{}, 1}, Coin{CTxOut{COIN, script}, 1, false});
|
|
60
|
+
int broadcasts{0};
|
|
61
|
+
|
|
62
|
+
FlatSigningProvider missing_key;
|
|
63
|
+
auto signing_failure{CreateSweepTransaction(*wallet, missing_key, coins, script, [&](const CTransactionRef&, std::string&) { ++broadcasts; return true; })};
|
|
64
|
+
BOOST_CHECK(!signing_failure);
|
|
65
|
+
BOOST_CHECK_EQUAL(broadcasts, 0);
|
|
66
|
+
|
|
67
|
+
FlatSigningProvider provider;
|
|
68
|
+
provider.keys.emplace(key.GetPubKey().GetID(), key);
|
|
69
|
+
provider.pubkeys.emplace(key.GetPubKey().GetID(), key.GetPubKey());
|
|
70
|
+
auto success{CreateSweepTransaction(*wallet, provider, coins, script, [&](const CTransactionRef&, std::string&) { ++broadcasts; return true; })};
|
|
71
|
+
BOOST_REQUIRE(success);
|
|
72
|
+
BOOST_CHECK_GE(success->fee, GetMinimumFee(*wallet, GetVirtualTransactionSize(*success->tx), CCoinControl{}, nullptr));
|
|
73
|
+
BOOST_CHECK_EQUAL(broadcasts, 1);
|
|
74
|
+
|
|
75
|
+
std::string rejection;
|
|
76
|
+
auto broadcast_failure{CreateSweepTransaction(*wallet, provider, coins, script, [&](const CTransactionRef&, std::string& error) {
|
|
77
|
+
++broadcasts;
|
|
78
|
+
error = "txn-mempool-conflict";
|
|
79
|
+
return false;
|
|
80
|
+
})};
|
|
81
|
+
BOOST_CHECK(!broadcast_failure);
|
|
82
|
+
BOOST_CHECK(util::ErrorString(broadcast_failure).original.find("txn-mempool-conflict") != std::string::npos);
|
|
83
|
+
BOOST_CHECK_EQUAL(broadcasts, 2);
|
|
84
|
+
}
|
|
85
|
+
|
|
51
86
|
BOOST_FIXTURE_TEST_CASE(SubtractFee, TestChain100Setup)
|
|
52
87
|
{
|
|
53
88
|
CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey()));
|