Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/test/wallet_tests.cpp
Show First 20 Lines • Show All 358 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(LoadReceiveRequests) { | ||||
m_wallet.AddDestData(dest, "rr1", "val_rr1"); | m_wallet.AddDestData(dest, "rr1", "val_rr1"); | ||||
auto values = m_wallet.GetDestValues("rr"); | auto values = m_wallet.GetDestValues("rr"); | ||||
BOOST_CHECK_EQUAL(values.size(), 2U); | BOOST_CHECK_EQUAL(values.size(), 2U); | ||||
BOOST_CHECK_EQUAL(values[0], "val_rr0"); | BOOST_CHECK_EQUAL(values[0], "val_rr0"); | ||||
BOOST_CHECK_EQUAL(values[1], "val_rr1"); | BOOST_CHECK_EQUAL(values[1], "val_rr1"); | ||||
} | } | ||||
// Test some watch-only wallet methods by the procedure of loading | |||||
// (LoadWatchOnly), checking (HaveWatchOnly), getting (GetWatchPubKey) and | |||||
// removing (RemoveWatchOnly) a given PubKey, resp. its corresponding P2PK | |||||
// Script. Results of the the impact on the address -> PubKey map is dependent | |||||
// on whether the PubKey is a point on the curve | |||||
static void TestWatchOnlyPubKey(CWallet &wallet, const CPubKey &add_pubkey) { | |||||
CScript p2pk = GetScriptForRawPubKey(add_pubkey); | |||||
CKeyID add_address = add_pubkey.GetID(); | |||||
CPubKey found_pubkey; | |||||
LOCK(wallet.cs_wallet); | |||||
// all Scripts (i.e. also all PubKeys) are added to the general watch-only | |||||
// set | |||||
BOOST_CHECK(!wallet.HaveWatchOnly(p2pk)); | |||||
wallet.LoadWatchOnly(p2pk); | |||||
BOOST_CHECK(wallet.HaveWatchOnly(p2pk)); | |||||
// only PubKeys on the curve shall be added to the watch-only address -> | |||||
// PubKey map | |||||
bool is_pubkey_fully_valid = add_pubkey.IsFullyValid(); | |||||
if (is_pubkey_fully_valid) { | |||||
BOOST_CHECK(wallet.GetWatchPubKey(add_address, found_pubkey)); | |||||
BOOST_CHECK(found_pubkey == add_pubkey); | |||||
} else { | |||||
BOOST_CHECK(!wallet.GetWatchPubKey(add_address, found_pubkey)); | |||||
// passed key is unchanged | |||||
BOOST_CHECK(found_pubkey == CPubKey()); | |||||
} | |||||
wallet.RemoveWatchOnly(p2pk); | |||||
BOOST_CHECK(!wallet.HaveWatchOnly(p2pk)); | |||||
if (is_pubkey_fully_valid) { | |||||
BOOST_CHECK(!wallet.GetWatchPubKey(add_address, found_pubkey)); | |||||
// passed key is unchanged | |||||
BOOST_CHECK(found_pubkey == add_pubkey); | |||||
} | |||||
} | |||||
// Cryptographically invalidate a PubKey whilst keeping length and first byte | |||||
static void PollutePubKey(CPubKey &pubkey) { | |||||
std::vector<uint8_t> pubkey_raw(pubkey.begin(), pubkey.end()); | |||||
std::fill(pubkey_raw.begin() + 1, pubkey_raw.end(), 0); | |||||
pubkey = CPubKey(pubkey_raw); | |||||
assert(!pubkey.IsFullyValid()); | |||||
assert(pubkey.IsValid()); | |||||
} | |||||
// Test watch-only wallet logic for PubKeys | |||||
BOOST_AUTO_TEST_CASE(WatchOnlyPubKeys) { | |||||
CKey key; | |||||
CPubKey pubkey; | |||||
BOOST_CHECK(!m_wallet.HaveWatchOnly()); | |||||
// uncompressed valid PubKey | |||||
key.MakeNewKey(false); | |||||
pubkey = key.GetPubKey(); | |||||
assert(!pubkey.IsCompressed()); | |||||
TestWatchOnlyPubKey(m_wallet, pubkey); | |||||
// uncompressed cryptographically invalid PubKey | |||||
PollutePubKey(pubkey); | |||||
TestWatchOnlyPubKey(m_wallet, pubkey); | |||||
// compressed valid PubKey | |||||
key.MakeNewKey(true); | |||||
pubkey = key.GetPubKey(); | |||||
assert(pubkey.IsCompressed()); | |||||
TestWatchOnlyPubKey(m_wallet, pubkey); | |||||
// compressed cryptographically invalid PubKey | |||||
PollutePubKey(pubkey); | |||||
TestWatchOnlyPubKey(m_wallet, pubkey); | |||||
// invalid empty PubKey | |||||
pubkey = CPubKey(); | |||||
TestWatchOnlyPubKey(m_wallet, pubkey); | |||||
} | |||||
class ListCoinsTestingSetup : public TestChain100Setup { | class ListCoinsTestingSetup : public TestChain100Setup { | ||||
public: | public: | ||||
ListCoinsTestingSetup() { | ListCoinsTestingSetup() { | ||||
CreateAndProcessBlock({}, | CreateAndProcessBlock({}, | ||||
GetScriptForRawPubKey(coinbaseKey.GetPubKey())); | GetScriptForRawPubKey(coinbaseKey.GetPubKey())); | ||||
wallet = | wallet = | ||||
std::make_unique<CWallet>(Params(), m_chain.get(), WalletLocation(), | std::make_unique<CWallet>(Params(), m_chain.get(), WalletLocation(), | ||||
WalletDatabase::CreateMock()); | WalletDatabase::CreateMock()); | ||||
▲ Show 20 Lines • Show All 137 Lines • Show Last 20 Lines |