Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/test/ismine_tests.cpp
Show All 31 Lines | BOOST_AUTO_TEST_CASE(ismine_standard) { | ||||
std::unique_ptr<interfaces::Chain> chain = | std::unique_ptr<interfaces::Chain> chain = | ||||
interfaces::MakeChain(node, Params()); | interfaces::MakeChain(node, Params()); | ||||
CScript scriptPubKey; | CScript scriptPubKey; | ||||
isminetype result; | isminetype result; | ||||
// P2PK compressed | // P2PK compressed | ||||
{ | { | ||||
CWallet keystore(Params(), chain.get(), WalletLocation(), | CWallet keystore(chain.get(), WalletLocation(), | ||||
WalletDatabase::CreateDummy()); | WalletDatabase::CreateDummy()); | ||||
keystore.SetupLegacyScriptPubKeyMan(); | keystore.SetupLegacyScriptPubKeyMan(); | ||||
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); | LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); | ||||
scriptPubKey = GetScriptForRawPubKey(pubkeys[0]); | scriptPubKey = GetScriptForRawPubKey(pubkeys[0]); | ||||
// Keystore does not have key | // Keystore does not have key | ||||
result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey); | result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey); | ||||
BOOST_CHECK_EQUAL(result, ISMINE_NO); | BOOST_CHECK_EQUAL(result, ISMINE_NO); | ||||
// Keystore has key | // Keystore has key | ||||
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0])); | BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0])); | ||||
result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey); | result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey); | ||||
BOOST_CHECK_EQUAL(result, ISMINE_SPENDABLE); | BOOST_CHECK_EQUAL(result, ISMINE_SPENDABLE); | ||||
} | } | ||||
// P2PK uncompressed | // P2PK uncompressed | ||||
{ | { | ||||
CWallet keystore(Params(), chain.get(), WalletLocation(), | CWallet keystore(chain.get(), WalletLocation(), | ||||
WalletDatabase::CreateDummy()); | WalletDatabase::CreateDummy()); | ||||
keystore.SetupLegacyScriptPubKeyMan(); | keystore.SetupLegacyScriptPubKeyMan(); | ||||
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); | LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); | ||||
scriptPubKey = GetScriptForRawPubKey(uncompressedPubkey); | scriptPubKey = GetScriptForRawPubKey(uncompressedPubkey); | ||||
// Keystore does not have key | // Keystore does not have key | ||||
result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey); | result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey); | ||||
BOOST_CHECK_EQUAL(result, ISMINE_NO); | BOOST_CHECK_EQUAL(result, ISMINE_NO); | ||||
// Keystore has key | // Keystore has key | ||||
BOOST_CHECK( | BOOST_CHECK( | ||||
keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey)); | keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey)); | ||||
result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey); | result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey); | ||||
BOOST_CHECK_EQUAL(result, ISMINE_SPENDABLE); | BOOST_CHECK_EQUAL(result, ISMINE_SPENDABLE); | ||||
} | } | ||||
// P2PKH compressed | // P2PKH compressed | ||||
{ | { | ||||
CWallet keystore(Params(), chain.get(), WalletLocation(), | CWallet keystore(chain.get(), WalletLocation(), | ||||
WalletDatabase::CreateDummy()); | WalletDatabase::CreateDummy()); | ||||
keystore.SetupLegacyScriptPubKeyMan(); | keystore.SetupLegacyScriptPubKeyMan(); | ||||
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); | LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); | ||||
scriptPubKey = GetScriptForDestination(PKHash(pubkeys[0])); | scriptPubKey = GetScriptForDestination(PKHash(pubkeys[0])); | ||||
// Keystore does not have key | // Keystore does not have key | ||||
result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey); | result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey); | ||||
BOOST_CHECK_EQUAL(result, ISMINE_NO); | BOOST_CHECK_EQUAL(result, ISMINE_NO); | ||||
// Keystore has key | // Keystore has key | ||||
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0])); | BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0])); | ||||
result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey); | result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey); | ||||
BOOST_CHECK_EQUAL(result, ISMINE_SPENDABLE); | BOOST_CHECK_EQUAL(result, ISMINE_SPENDABLE); | ||||
} | } | ||||
// P2PKH uncompressed | // P2PKH uncompressed | ||||
{ | { | ||||
CWallet keystore(Params(), chain.get(), WalletLocation(), | CWallet keystore(chain.get(), WalletLocation(), | ||||
WalletDatabase::CreateDummy()); | WalletDatabase::CreateDummy()); | ||||
keystore.SetupLegacyScriptPubKeyMan(); | keystore.SetupLegacyScriptPubKeyMan(); | ||||
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); | LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); | ||||
scriptPubKey = GetScriptForDestination(PKHash(uncompressedPubkey)); | scriptPubKey = GetScriptForDestination(PKHash(uncompressedPubkey)); | ||||
// Keystore does not have key | // Keystore does not have key | ||||
result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey); | result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey); | ||||
BOOST_CHECK_EQUAL(result, ISMINE_NO); | BOOST_CHECK_EQUAL(result, ISMINE_NO); | ||||
// Keystore has key | // Keystore has key | ||||
BOOST_CHECK( | BOOST_CHECK( | ||||
keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey)); | keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey)); | ||||
result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey); | result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey); | ||||
BOOST_CHECK_EQUAL(result, ISMINE_SPENDABLE); | BOOST_CHECK_EQUAL(result, ISMINE_SPENDABLE); | ||||
} | } | ||||
// P2SH | // P2SH | ||||
{ | { | ||||
CWallet keystore(Params(), chain.get(), WalletLocation(), | CWallet keystore(chain.get(), WalletLocation(), | ||||
WalletDatabase::CreateDummy()); | WalletDatabase::CreateDummy()); | ||||
keystore.SetupLegacyScriptPubKeyMan(); | keystore.SetupLegacyScriptPubKeyMan(); | ||||
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); | LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); | ||||
CScript redeemScript = GetScriptForDestination(PKHash(pubkeys[0])); | CScript redeemScript = GetScriptForDestination(PKHash(pubkeys[0])); | ||||
scriptPubKey = GetScriptForDestination(ScriptHash(redeemScript)); | scriptPubKey = GetScriptForDestination(ScriptHash(redeemScript)); | ||||
// Keystore does not have redeemScript or key | // Keystore does not have redeemScript or key | ||||
Show All 9 Lines | // P2SH | ||||
// Keystore has redeemScript and key | // Keystore has redeemScript and key | ||||
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0])); | BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0])); | ||||
result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey); | result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey); | ||||
BOOST_CHECK_EQUAL(result, ISMINE_SPENDABLE); | BOOST_CHECK_EQUAL(result, ISMINE_SPENDABLE); | ||||
} | } | ||||
// (P2PKH inside) P2SH inside P2SH (invalid) | // (P2PKH inside) P2SH inside P2SH (invalid) | ||||
{ | { | ||||
CWallet keystore(Params(), chain.get(), WalletLocation(), | CWallet keystore(chain.get(), WalletLocation(), | ||||
WalletDatabase::CreateDummy()); | WalletDatabase::CreateDummy()); | ||||
keystore.SetupLegacyScriptPubKeyMan(); | keystore.SetupLegacyScriptPubKeyMan(); | ||||
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); | LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); | ||||
CScript redeemscript_inner = | CScript redeemscript_inner = | ||||
GetScriptForDestination(PKHash(pubkeys[0])); | GetScriptForDestination(PKHash(pubkeys[0])); | ||||
CScript redeemscript = | CScript redeemscript = | ||||
GetScriptForDestination(ScriptHash(redeemscript_inner)); | GetScriptForDestination(ScriptHash(redeemscript_inner)); | ||||
scriptPubKey = GetScriptForDestination(ScriptHash(redeemscript)); | scriptPubKey = GetScriptForDestination(ScriptHash(redeemscript)); | ||||
BOOST_CHECK( | BOOST_CHECK( | ||||
keystore.GetLegacyScriptPubKeyMan()->AddCScript(redeemscript)); | keystore.GetLegacyScriptPubKeyMan()->AddCScript(redeemscript)); | ||||
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript( | BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddCScript( | ||||
redeemscript_inner)); | redeemscript_inner)); | ||||
BOOST_CHECK( | BOOST_CHECK( | ||||
keystore.GetLegacyScriptPubKeyMan()->AddCScript(scriptPubKey)); | keystore.GetLegacyScriptPubKeyMan()->AddCScript(scriptPubKey)); | ||||
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0])); | BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0])); | ||||
result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey); | result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey); | ||||
BOOST_CHECK_EQUAL(result, ISMINE_NO); | BOOST_CHECK_EQUAL(result, ISMINE_NO); | ||||
} | } | ||||
// scriptPubKey multisig | // scriptPubKey multisig | ||||
{ | { | ||||
CWallet keystore(Params(), chain.get(), WalletLocation(), | CWallet keystore(chain.get(), WalletLocation(), | ||||
WalletDatabase::CreateDummy()); | WalletDatabase::CreateDummy()); | ||||
keystore.SetupLegacyScriptPubKeyMan(); | keystore.SetupLegacyScriptPubKeyMan(); | ||||
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); | LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); | ||||
scriptPubKey = | scriptPubKey = | ||||
GetScriptForMultisig(2, {uncompressedPubkey, pubkeys[1]}); | GetScriptForMultisig(2, {uncompressedPubkey, pubkeys[1]}); | ||||
// Keystore does not have any keys | // Keystore does not have any keys | ||||
Show All 18 Lines | // scriptPubKey multisig | ||||
keystore.GetLegacyScriptPubKeyMan()->AddCScript(scriptPubKey)); | keystore.GetLegacyScriptPubKeyMan()->AddCScript(scriptPubKey)); | ||||
result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey); | result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey); | ||||
BOOST_CHECK_EQUAL(result, ISMINE_NO); | BOOST_CHECK_EQUAL(result, ISMINE_NO); | ||||
} | } | ||||
// P2SH multisig | // P2SH multisig | ||||
{ | { | ||||
CWallet keystore(Params(), chain.get(), WalletLocation(), | CWallet keystore(chain.get(), WalletLocation(), | ||||
WalletDatabase::CreateDummy()); | WalletDatabase::CreateDummy()); | ||||
keystore.SetupLegacyScriptPubKeyMan(); | keystore.SetupLegacyScriptPubKeyMan(); | ||||
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); | LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); | ||||
BOOST_CHECK( | BOOST_CHECK( | ||||
keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey)); | keystore.GetLegacyScriptPubKeyMan()->AddKey(uncompressedKey)); | ||||
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[1])); | BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[1])); | ||||
CScript redeemScript = | CScript redeemScript = | ||||
GetScriptForMultisig(2, {uncompressedPubkey, pubkeys[1]}); | GetScriptForMultisig(2, {uncompressedPubkey, pubkeys[1]}); | ||||
scriptPubKey = GetScriptForDestination(ScriptHash(redeemScript)); | scriptPubKey = GetScriptForDestination(ScriptHash(redeemScript)); | ||||
// Keystore has no redeemScript | // Keystore has no redeemScript | ||||
result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey); | result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey); | ||||
BOOST_CHECK_EQUAL(result, ISMINE_NO); | BOOST_CHECK_EQUAL(result, ISMINE_NO); | ||||
// Keystore has redeemScript | // Keystore has redeemScript | ||||
BOOST_CHECK( | BOOST_CHECK( | ||||
keystore.GetLegacyScriptPubKeyMan()->AddCScript(redeemScript)); | keystore.GetLegacyScriptPubKeyMan()->AddCScript(redeemScript)); | ||||
result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey); | result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey); | ||||
BOOST_CHECK_EQUAL(result, ISMINE_SPENDABLE); | BOOST_CHECK_EQUAL(result, ISMINE_SPENDABLE); | ||||
} | } | ||||
// OP_RETURN | // OP_RETURN | ||||
{ | { | ||||
CWallet keystore(Params(), chain.get(), WalletLocation(), | CWallet keystore(chain.get(), WalletLocation(), | ||||
WalletDatabase::CreateDummy()); | WalletDatabase::CreateDummy()); | ||||
keystore.SetupLegacyScriptPubKeyMan(); | keystore.SetupLegacyScriptPubKeyMan(); | ||||
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); | LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); | ||||
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0])); | BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0])); | ||||
scriptPubKey.clear(); | scriptPubKey.clear(); | ||||
scriptPubKey << OP_RETURN << ToByteVector(pubkeys[0]); | scriptPubKey << OP_RETURN << ToByteVector(pubkeys[0]); | ||||
result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey); | result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey); | ||||
BOOST_CHECK_EQUAL(result, ISMINE_NO); | BOOST_CHECK_EQUAL(result, ISMINE_NO); | ||||
} | } | ||||
// Nonstandard | // Nonstandard | ||||
{ | { | ||||
CWallet keystore(Params(), chain.get(), WalletLocation(), | CWallet keystore(chain.get(), WalletLocation(), | ||||
WalletDatabase::CreateDummy()); | WalletDatabase::CreateDummy()); | ||||
keystore.SetupLegacyScriptPubKeyMan(); | keystore.SetupLegacyScriptPubKeyMan(); | ||||
LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); | LOCK(keystore.GetLegacyScriptPubKeyMan()->cs_KeyStore); | ||||
BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0])); | BOOST_CHECK(keystore.GetLegacyScriptPubKeyMan()->AddKey(keys[0])); | ||||
scriptPubKey.clear(); | scriptPubKey.clear(); | ||||
scriptPubKey << OP_9 << OP_ADD << OP_11 << OP_EQUAL; | scriptPubKey << OP_9 << OP_ADD << OP_11 << OP_EQUAL; | ||||
result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey); | result = keystore.GetLegacyScriptPubKeyMan()->IsMine(scriptPubKey); | ||||
BOOST_CHECK_EQUAL(result, ISMINE_NO); | BOOST_CHECK_EQUAL(result, ISMINE_NO); | ||||
} | } | ||||
} | } | ||||
BOOST_AUTO_TEST_SUITE_END() | BOOST_AUTO_TEST_SUITE_END() |