@@ -800,30 +800,35 @@ BOOST_FIXTURE_TEST_CASE(ZapSelectTx, TestChain100Setup)
800
800
context.args = &gArgs ;
801
801
context.chain = m_node.chain .get ();
802
802
auto wallet = TestLoadWallet (context);
803
- CKey key;
804
- key.MakeNewKey (true );
805
- AddKey (*wallet, key);
803
+ AddKey (*wallet, coinbaseKey);
806
804
807
- std::string error;
805
+ // rescan to ensure coinbase transactions from test fixture are picked up by the wallet
806
+ {
807
+ WalletRescanReserver reserver (*wallet);
808
+ reserver.reserve ();
809
+ wallet->ScanForWalletTransactions (m_node.chain ->getBlockHash (0 ), 0 , /* max height= */ {}, reserver, /* update= */ true );
810
+ }
811
+ // create one more block to get the first block coinbase to maturity
808
812
m_coinbase_txns.push_back (CreateAndProcessBlock ({}, GetScriptForRawPubKey (coinbaseKey.GetPubKey ())).vtx [0 ]);
809
- auto block_tx = TestSimpleSpend (*m_coinbase_txns[0 ], 0 , coinbaseKey, GetScriptForRawPubKey (key.GetPubKey ()));
810
- CreateAndProcessBlock ({block_tx}, GetScriptForRawPubKey (coinbaseKey.GetPubKey ()));
813
+ // spend first coinbase tx
814
+ auto spend_tx = TestSimpleSpend (*m_coinbase_txns[0 ], 0 , coinbaseKey, GetScriptForRawPubKey (coinbaseKey.GetPubKey ()));
815
+ CreateAndProcessBlock ({spend_tx}, GetScriptForRawPubKey (coinbaseKey.GetPubKey ()));
811
816
812
817
SyncWithValidationInterfaceQueue ();
813
818
814
819
{
815
- auto block_hash = block_tx .GetHash ();
820
+ auto spend_tx_hash = spend_tx .GetHash ();
816
821
auto prev_hash = m_coinbase_txns[0 ]->GetHash ();
817
822
818
823
LOCK (wallet->cs_wallet );
819
824
BOOST_CHECK (wallet->HasWalletSpend (prev_hash));
820
- BOOST_CHECK_EQUAL (wallet->mapWallet .count (block_hash ), 1u );
825
+ BOOST_CHECK_EQUAL (wallet->mapWallet .count (spend_tx_hash ), 1u );
821
826
822
- std::vector<uint256> vHashIn{ block_hash }, vHashOut;
827
+ std::vector<uint256> vHashIn{spend_tx_hash }, vHashOut;
823
828
BOOST_CHECK_EQUAL (wallet->ZapSelectTx (vHashIn, vHashOut), DBErrors::LOAD_OK);
824
829
825
830
BOOST_CHECK (!wallet->HasWalletSpend (prev_hash));
826
- BOOST_CHECK_EQUAL (wallet->mapWallet .count (block_hash ), 0u );
831
+ BOOST_CHECK_EQUAL (wallet->mapWallet .count (spend_tx_hash ), 0u );
827
832
}
828
833
829
834
TestUnloadWallet (std::move (wallet));
0 commit comments