From 8c1ec659f2946d060a045894f206c3835624de61 Mon Sep 17 00:00:00 2001 From: Brannon King Date: Thu, 12 Mar 2020 13:06:24 -0600 Subject: [PATCH] fix functional tests to work with txindex on by default --- src/txdb.cpp | 1 - src/wallet/rpcwallet.cpp | 3 ++- src/wallet/wallet.cpp | 4 +++- src/wallet/wallet.h | 2 +- test/functional/mempool_accept.py | 1 + test/functional/p2p_invalid_messages.py | 4 ++-- test/functional/rpc_rawtransaction.py | 1 + test/functional/rpc_txoutproof.py | 2 +- test/functional/test_framework/test_node.py | 1 + 9 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/txdb.cpp b/src/txdb.cpp index f609e24f5..1663289c3 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -196,7 +196,6 @@ CBlockTreeDB::CBlockTreeDB(size_t nCacheSize, bool fMemory, bool fWipe) if (fWipe) { db << "DELETE FROM block_file"; db << "DELETE FROM block_info"; - db << "DELETE FROM tx_to_block"; db << "DELETE FROM flag"; } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 420e12751..b8a7cc150 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -321,7 +321,8 @@ static UniValue setlabel(const JSONRPCRequest& request) static CTransactionRef SendMoney(interfaces::Chain::Lock& locked_chain, CWallet * const pwallet, const CTxDestination &address, CAmount nValue, bool fSubtractFeeFromAmount, const CCoinControl& coin_control, mapValue_t mapValue, const CScript& prefix = CScript()) { - CAmount curBalance = pwallet->GetBalance(ISMINE_NO, 0, coin_control.m_avoid_address_reuse).m_mine_trusted; + CAmount maxNeeded = nValue + (fSubtractFeeFromAmount ? 0 : pwallet->m_default_max_tx_fee); + CAmount curBalance = pwallet->GetBalance(ISMINE_NO, 0, coin_control.m_avoid_address_reuse, maxNeeded).m_mine_trusted; // Check amount if (nValue <= 0) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 15ff14d6c..3ab1a65ad 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2465,7 +2465,7 @@ void MaybeResendWalletTxs() */ -CWallet::Balance CWallet::GetBalance(isminefilter filter, const int min_depth, bool avoid_reuse) const +CWallet::Balance CWallet::GetBalance(isminefilter filter, const int min_depth, bool avoid_reuse, CAmount earlyExit) const { Balance ret; if (!avoid_reuse) @@ -2491,6 +2491,8 @@ CWallet::Balance CWallet::GetBalance(isminefilter filter, const int min_depth, b } ret.m_mine_immature += wtx.GetImmatureCredit(*locked_chain); ret.m_watchonly_immature += wtx.GetImmatureWatchOnlyCredit(*locked_chain); + if (earlyExit > 0 && ret.m_mine_trusted >= earlyExit) + break; } } return ret; diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index a2e5d99c5..c2e42f258 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -1132,7 +1132,7 @@ public: CAmount m_watchonly_untrusted_pending{0}; CAmount m_watchonly_immature{0}; }; - Balance GetBalance(isminefilter filter = ISMINE_NO, int min_depth = 0, bool avoid_reuse = true) const; + Balance GetBalance(isminefilter filter = ISMINE_NO, int min_depth = 0, bool avoid_reuse = true, CAmount earlyExit = 0) const; CAmount GetAvailableBalance(const CCoinControl* coinControl = nullptr) const; OutputType TransactionChangeType(OutputType change_type, const std::vector& vecSend); diff --git a/test/functional/mempool_accept.py b/test/functional/mempool_accept.py index f20eeeab6..ed52ae6b8 100644 --- a/test/functional/mempool_accept.py +++ b/test/functional/mempool_accept.py @@ -36,6 +36,7 @@ class MempoolAcceptanceTest(BitcoinTestFramework): self.num_nodes = 1 self.extra_args = [[ '-permitbaremultisig=0', + '-txindex=1' ]] * self.num_nodes self.supports_cli = False diff --git a/test/functional/p2p_invalid_messages.py b/test/functional/p2p_invalid_messages.py index 58c72f89d..3f42a0142 100755 --- a/test/functional/p2p_invalid_messages.py +++ b/test/functional/p2p_invalid_messages.py @@ -153,13 +153,13 @@ class InvalidMessagesTest(BitcoinTestFramework): def test_magic_bytes(self): conn = self.nodes[0].add_p2p_connection(P2PDataStore()) - def swap_magic_bytes(): + async def swap_magic_bytes(): conn._on_data = lambda: None # Need to ignore all incoming messages from now, since they come with "invalid" magic bytes conn.magic_bytes = b'\x00\x11\x22\x32' # Call .result() to block until the atomic swap is complete, otherwise # we might run into races later on - asyncio.run_coroutine_threadsafe(asyncio.coroutine(swap_magic_bytes)(), NetworkThread.network_event_loop).result() + asyncio.run_coroutine_threadsafe(swap_magic_bytes(), NetworkThread.network_event_loop).result() with self.nodes[0].assert_debug_log(['PROCESSMESSAGE: INVALID MESSAGESTART ping']): conn.send_message(messages.msg_ping(nonce=0xff)) diff --git a/test/functional/rpc_rawtransaction.py b/test/functional/rpc_rawtransaction.py index bb2332eb3..2df0468f5 100755 --- a/test/functional/rpc_rawtransaction.py +++ b/test/functional/rpc_rawtransaction.py @@ -48,6 +48,7 @@ class RawTransactionsTest(BitcoinTestFramework): def set_test_params(self): self.setup_clean_chain = True self.num_nodes = 3 + self.extra_args = [['-txindex=1']] * self.num_nodes def skip_test_if_missing_module(self): self.skip_if_no_wallet() diff --git a/test/functional/rpc_txoutproof.py b/test/functional/rpc_txoutproof.py index 468631252..82c02f68a 100755 --- a/test/functional/rpc_txoutproof.py +++ b/test/functional/rpc_txoutproof.py @@ -13,7 +13,7 @@ class MerkleBlockTest(BitcoinTestFramework): self.num_nodes = 4 self.setup_clean_chain = True # Nodes 0/1 are "wallet" nodes, Nodes 2/3 are used for testing - self.extra_args = [[], [], [], []] + self.extra_args = [['-txindex=1']] * self.num_nodes def skip_test_if_missing_module(self): self.skip_if_no_wallet() diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py index 0e1fd0592..ba860f97c 100644 --- a/test/functional/test_framework/test_node.py +++ b/test/functional/test_framework/test_node.py @@ -92,6 +92,7 @@ class TestNode(): "-logtimemicros", "-logthreadnames", "-debug", + "-txindex=0", "-debugexclude=libevent", "-uacomment=testnode%d" % i, ]