| 17 | BOOST_FIXTURE_TEST_SUITE(ismine_tests, BasicTestingSetup) |
| 18 | |
| 19 | BOOST_AUTO_TEST_CASE(ismine_standard) |
| 20 | { |
| 21 | CKey keys[2]; |
| 22 | CPubKey pubkeys[2]; |
| 23 | for (int i = 0; i < 2; i++) { |
| 24 | keys[i].MakeNewKey(true); |
| 25 | pubkeys[i] = keys[i].GetPubKey(); |
| 26 | } |
| 27 | |
| 28 | CKey uncompressedKey; |
| 29 | uncompressedKey.MakeNewKey(false); |
| 30 | CPubKey uncompressedPubkey = uncompressedKey.GetPubKey(); |
| 31 | std::unique_ptr<interfaces::Chain>& chain = m_node.chain; |
| 32 | |
| 33 | CScript scriptPubKey; |
| 34 | isminetype result; |
| 35 | |
| 36 | // P2PK compressed |
| 37 | { |
| 38 | CWallet keystore(chain.get(), "", m_args, CreateDummyWalletDatabase()); |
| 39 | keystore.SetupLegacyScriptPubKeyMan(); |
| 40 | LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); |
| 41 | scriptPubKey = GetScriptForRawPubKey(pubkeys[0]); |
| 42 | |
| 43 | // Keystore does not have key |
| 44 | result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey); |
| 45 | BOOST_CHECK_EQUAL(result, ISMINE_NO); |
| 46 | |
| 47 | // Keystore has key |
| 48 | BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0])); |
| 49 | result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey); |
| 50 | BOOST_CHECK_EQUAL(result, ISMINE_SPENDABLE); |
| 51 | } |
| 52 | |
| 53 | // P2PK uncompressed |
| 54 | { |
| 55 | CWallet keystore(chain.get(), "", m_args, CreateDummyWalletDatabase()); |
| 56 | keystore.SetupLegacyScriptPubKeyMan(); |
| 57 | LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); |
| 58 | scriptPubKey = GetScriptForRawPubKey(uncompressedPubkey); |
| 59 | |
| 60 | // Keystore does not have key |
| 61 | result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey); |
| 62 | BOOST_CHECK_EQUAL(result, ISMINE_NO); |
| 63 | |
| 64 | // Keystore has key |
| 65 | BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey)); |
| 66 | result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey); |
| 67 | BOOST_CHECK_EQUAL(result, ISMINE_SPENDABLE); |
| 68 | } |
| 69 | |
| 70 | // P2PKH compressed |
| 71 | { |
| 72 | CWallet keystore(chain.get(), "", m_args, CreateDummyWalletDatabase()); |
| 73 | keystore.SetupLegacyScriptPubKeyMan(); |
| 74 | LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); |
| 75 | scriptPubKey = GetScriptForDestination(PKHash(pubkeys[0])); |
| 76 |
nothing calls this directly
no test coverage detected