MCPcopy Create free account
hub / github.com/ElementsProject/elements / TestWatchOnlyPubKey

Function TestWatchOnlyPubKey

src/wallet/test/wallet_tests.cpp:436–465  ·  view source on GitHub ↗

Test some watch-only LegacyScriptPubKeyMan 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 impact on the address -> PubKey map is dependent on whether the PubKey is a point on the curve

Source from the content-addressed store, hash-verified

434// given PubKey, resp. its corresponding P2PK Script. Results of the impact on
435// the address -> PubKey map is dependent on whether the PubKey is a point on the curve
436static void TestWatchOnlyPubKey(LegacyScriptPubKeyMan* spk_man, const CPubKey& add_pubkey)
437{
438 CScript p2pk = GetScriptForRawPubKey(add_pubkey);
439 CKeyID add_address = add_pubkey.GetID();
440 CPubKey found_pubkey;
441 LOCK(spk_man->cs_KeyStore);
442
443 // all Scripts (i.e. also all PubKeys) are added to the general watch-only set
444 BOOST_CHECK(!spk_man->HaveWatchOnly(p2pk));
445 spk_man->LoadWatchOnly(p2pk);
446 BOOST_CHECK(spk_man->HaveWatchOnly(p2pk));
447
448 // only PubKeys on the curve shall be added to the watch-only address -> PubKey map
449 bool is_pubkey_fully_valid = add_pubkey.IsFullyValid();
450 if (is_pubkey_fully_valid) {
451 BOOST_CHECK(spk_man->GetWatchPubKey(add_address, found_pubkey));
452 BOOST_CHECK(found_pubkey == add_pubkey);
453 } else {
454 BOOST_CHECK(!spk_man->GetWatchPubKey(add_address, found_pubkey));
455 BOOST_CHECK(found_pubkey == CPubKey()); // passed key is unchanged
456 }
457
458 spk_man->RemoveWatchOnly(p2pk);
459 BOOST_CHECK(!spk_man->HaveWatchOnly(p2pk));
460
461 if (is_pubkey_fully_valid) {
462 BOOST_CHECK(!spk_man->GetWatchPubKey(add_address, found_pubkey));
463 BOOST_CHECK(found_pubkey == add_pubkey); // passed key is unchanged
464 }
465}
466
467// Cryptographically invalidate a PubKey whilst keeping length and first byte
468static void PollutePubKey(CPubKey& pubkey)

Callers 1

BOOST_AUTO_TEST_CASEFunction · 0.85

Calls 8

GetScriptForRawPubKeyFunction · 0.85
HaveWatchOnlyMethod · 0.80
LoadWatchOnlyMethod · 0.80
IsFullyValidMethod · 0.80
GetWatchPubKeyMethod · 0.80
RemoveWatchOnlyMethod · 0.80
CPubKeyClass · 0.50
GetIDMethod · 0.45

Tested by

no test coverage detected