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
| 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 |
| 436 | static 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 |
| 468 | static void PollutePubKey(CPubKey& pubkey) |
no test coverage detected