Skip to content

test: add ismine test for descriptor ScriptPubKeyMan - #25942

Merged
achow101 merged 1 commit into
bitcoin:masterfrom
w0xlt:add_desc_ismine_test
Nov 30, 2022
Merged

achow101 merged 1 commit into
bitcoin:masterfrom
w0xlt:add_desc_ismine_test

Conversation

@w0xlt

@w0xlt w0xlt commented Aug 27, 2022

Copy link
Copy Markdown
Contributor

Currently src/wallet/test/ismine_tests.cpp has tests for the legacy ScriptPubKeyMan only.
This PR adds tests for the descriptor ScriptPubKeyMan.

@w0xlt
w0xlt force-pushed the add_desc_ismine_test branch from 3a3fb68 to 00d89f4 Compare August 27, 2022 06:17
@DrahtBot DrahtBot added the Tests label Aug 27, 2022
@w0xlt
w0xlt force-pushed the add_desc_ismine_test branch from 00d89f4 to c51a5c0 Compare August 27, 2022 07:58

@furszy furszy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK, good catch.
Strange that this wasn't implemented before.

Comment thread src/wallet/test/ismine_tests.cpp Outdated
Comment on lines 27 to 32

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

BOOST_CHECK(success && parsed_desc);
if (!success) return nullptr;

@w0xlt w0xlt Aug 27, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 1b77db2.
But I changed it to BOOST_CHECK(success == (parsed_desc != nullptr)); since success can be false if Parse function is expected to fail.

Comment thread src/wallet/test/ismine_tests.cpp Outdated
Comment on lines 40 to 44

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as this shouldn't fail, maybe could inline it:

Suggested change
auto spk_manager = keystore.AddWalletDescriptor(w_desc, keys, "", false);
BOOST_CHECK(spk_manager != nullptr);
return spk_manager;
return Assert(keystore.AddWalletDescriptor(w_desc, keys,/*label=*/"", /*internal=*/false));

@w0xlt w0xlt Aug 27, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 1b77db2.

@w0xlt
w0xlt force-pushed the add_desc_ismine_test branch from c51a5c0 to de5f82a Compare August 27, 2022 21:48
@w0xlt

w0xlt commented Aug 27, 2022 •

Copy link
Copy Markdown
Contributor Author

#25942 (review) addressed in 1b77db2.

Tests for combo() and tr() have also been added.

@w0xlt
w0xlt force-pushed the add_desc_ismine_test branch from de5f82a to 8e3685f Compare August 27, 2022 21:56
@w0xlt
w0xlt force-pushed the add_desc_ismine_test branch from 8e3685f to 1b77db2 Compare August 27, 2022 21:59

@ishaanam ishaanam left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK

Comment on lines +227 to +234
// (P2PKH inside) P2SH inside P2SH (invalid) - Descriptor
{
CWallet keystore(chain.get(), "", m_args, CreateDummyWalletDatabase());
std::string desc_str = "sh(sh(" + EncodeSecret(keys[0]) + "))";

auto spk_manager = CreateDescriptor(keystore, desc_str, false);
BOOST_CHECK_EQUAL(spk_manager, nullptr);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is ismine_tests.cpp the right place for this test? It doesn't seem to be testing IsMine. There are a few other places where it seems like IsMine isn't being tested, namely wherever the script is invalid and CreateDescriptor returns a nullptr.

@w0xlt w0xlt Aug 28, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. This happens in the cases below:

  • P2PKH inside P2SH inside P2SH (invalid)
  • P2PKH inside P2SH inside P2WSH (invalid)
  • P2WPKH inside P2WSH (invalid)
  • P2PKH inside P2WSH inside P2WSH (invalid)
  • P2WPKH uncompressed (invalid)
  • P2WSH multisig with uncompressed key (invalid)

These cases cannot be reproduced for descriptor ScriptPubKeyMan, so I added them just for consistency and to make this difference explicit.
I can remove them if the reviewers think this is not necessary.

@furszy furszy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 1b77db2 with a non-blocking comment.

Instead of continue expanding the long ismine_standard test case, what do you think about creating another test case ismine_standard_descriptors?

@DrahtBot

DrahtBot commented Sep 23, 2022 •

Copy link
Copy Markdown
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK furszy, ishaanam, achow101

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

No conflicts as of last run.

@ishaanam

Copy link
Copy Markdown
Contributor

ACK 1b77db2

@achow101

Copy link
Copy Markdown
Member

ACK 1b77db2

@achow101
achow101 merged commit e2bfd41 into bitcoin:master Nov 30, 2022
@w0xlt
w0xlt deleted the add_desc_ismine_test branch December 1, 2022 02:02
@bitcoin bitcoin locked and limited conversation to collaborators Dec 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants