mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-05-17 05:30:43 +02:00
test: Check external coin effective value is used in CoinSelection
This commit is contained in:
parent
76b79c1a17
commit
d0d9cf7aea
@ -922,5 +922,52 @@ BOOST_AUTO_TEST_CASE(effective_value_test)
|
|||||||
BOOST_CHECK_EQUAL(output5.GetEffectiveValue(), nValue); // The effective value should be equal to the absolute value if input_bytes is -1
|
BOOST_CHECK_EQUAL(output5.GetEffectiveValue(), nValue); // The effective value should be equal to the absolute value if input_bytes is -1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(SelectCoins_effective_value_test)
|
||||||
|
{
|
||||||
|
// Test that the effective value is used to check whether preset inputs provide sufficient funds when subtract_fee_outputs is not used.
|
||||||
|
// This test creates a coin whose value is higher than the target but whose effective value is lower than the target.
|
||||||
|
// The coin is selected using coin control, with m_allow_other_inputs = false. SelectCoins should fail due to insufficient funds.
|
||||||
|
|
||||||
|
std::unique_ptr<CWallet> wallet = std::make_unique<CWallet>(m_node.chain.get(), "", m_args, CreateMockWalletDatabase());
|
||||||
|
wallet->LoadWallet();
|
||||||
|
LOCK(wallet->cs_wallet);
|
||||||
|
wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
|
||||||
|
wallet->SetupDescriptorScriptPubKeyMans();
|
||||||
|
|
||||||
|
CoinsResult available_coins;
|
||||||
|
{
|
||||||
|
std::unique_ptr<CWallet> dummyWallet = std::make_unique<CWallet>(m_node.chain.get(), "dummy", m_args, CreateMockWalletDatabase());
|
||||||
|
dummyWallet->LoadWallet();
|
||||||
|
LOCK(dummyWallet->cs_wallet);
|
||||||
|
dummyWallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
|
||||||
|
dummyWallet->SetupDescriptorScriptPubKeyMans();
|
||||||
|
|
||||||
|
add_coin(available_coins, *dummyWallet, 100000); // 0.001 BTC
|
||||||
|
}
|
||||||
|
|
||||||
|
CAmount target{99900}; // 0.000999 BTC
|
||||||
|
|
||||||
|
FastRandomContext rand;
|
||||||
|
CoinSelectionParams cs_params{
|
||||||
|
rand,
|
||||||
|
/*change_output_size=*/34,
|
||||||
|
/*change_spend_size=*/148,
|
||||||
|
/*min_change_target=*/1000,
|
||||||
|
/*effective_feerate=*/CFeeRate(3000),
|
||||||
|
/*long_term_feerate=*/CFeeRate(1000),
|
||||||
|
/*discard_feerate=*/CFeeRate(1000),
|
||||||
|
/*tx_noinputs_size=*/0,
|
||||||
|
/*avoid_partial=*/false,
|
||||||
|
};
|
||||||
|
CCoinControl cc;
|
||||||
|
cc.m_allow_other_inputs = false;
|
||||||
|
COutput output = available_coins.All().at(0);
|
||||||
|
cc.SetInputWeight(output.outpoint, 148);
|
||||||
|
cc.SelectExternal(output.outpoint, output.txout);
|
||||||
|
|
||||||
|
const auto result = SelectCoins(*wallet, available_coins, target, cc, cs_params);
|
||||||
|
BOOST_CHECK(!result);
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
} // namespace wallet
|
} // namespace wallet
|
||||||
|
Loading…
Reference in New Issue
Block a user