|
17 | 17 | #include <validation.h> |
18 | 18 | #include <wallet/coincontrol.h> |
19 | 19 | #include <wallet/test/wallet_test_fixture.h> |
| 20 | +#include <policy/policy.h> |
20 | 21 |
|
21 | 22 | #include <boost/test/unit_test.hpp> |
22 | 23 | #include <univalue.h> |
@@ -394,4 +395,47 @@ BOOST_FIXTURE_TEST_CASE(wallet_disableprivkeys, TestChain100Setup) |
394 | 395 | BOOST_CHECK(!wallet->GetKeyFromPool(pubkey, false)); |
395 | 396 | } |
396 | 397 |
|
| 398 | +// Explicit calculation which is used to test the wallet constant |
| 399 | +// We get the same virtual size due to rounding(weight/4) for both use_max_sig values |
| 400 | +static size_t CalculateNestedKeyhashInputSize(bool use_max_sig) |
| 401 | +{ |
| 402 | + // Generate ephemeral valid pubkey |
| 403 | + CKey key; |
| 404 | + key.MakeNewKey(true); |
| 405 | + CPubKey pubkey = key.GetPubKey(); |
| 406 | + |
| 407 | + // Generate pubkey hash |
| 408 | + uint160 key_hash(Hash160(pubkey.begin(), pubkey.end())); |
| 409 | + |
| 410 | + // Create inner-script to enter into keystore. Key hash can't be 0... |
| 411 | + CScript inner_script = CScript() << OP_0 << std::vector<unsigned char>(key_hash.begin(), key_hash.end()); |
| 412 | + |
| 413 | + // Create outer P2SH script for the output |
| 414 | + uint160 script_id(Hash160(inner_script.begin(), inner_script.end())); |
| 415 | + CScript script_pubkey = CScript() << OP_HASH160 << std::vector<unsigned char>(script_id.begin(), script_id.end()) << OP_EQUAL; |
| 416 | + |
| 417 | + // Add inner-script to key store and key to watchonly |
| 418 | + CBasicKeyStore keystore; |
| 419 | + keystore.AddCScript(inner_script); |
| 420 | + keystore.AddKeyPubKey(key, pubkey); |
| 421 | + |
| 422 | + // Fill in dummy signatures for fee calculation. |
| 423 | + SignatureData sig_data; |
| 424 | + |
| 425 | + if (!ProduceSignature(keystore, use_max_sig ? DUMMY_MAXIMUM_SIGNATURE_CREATOR : DUMMY_SIGNATURE_CREATOR, script_pubkey, sig_data)) { |
| 426 | + // We're hand-feeding it correct arguments; shouldn't happen |
| 427 | + assert(false); |
| 428 | + } |
| 429 | + |
| 430 | + CTxIn tx_in; |
| 431 | + UpdateInput(tx_in, sig_data); |
| 432 | + return (size_t)GetVirtualTransactionInputSize(tx_in); |
| 433 | +} |
| 434 | + |
| 435 | +BOOST_FIXTURE_TEST_CASE(dummy_input_size_test, TestChain100Setup) |
| 436 | +{ |
| 437 | + BOOST_CHECK_EQUAL(CalculateNestedKeyhashInputSize(false), DUMMY_NESTED_P2WPKH_INPUT_SIZE); |
| 438 | + BOOST_CHECK_EQUAL(CalculateNestedKeyhashInputSize(true), DUMMY_NESTED_P2WPKH_INPUT_SIZE); |
| 439 | +} |
| 440 | + |
397 | 441 | BOOST_AUTO_TEST_SUITE_END() |
0 commit comments