Skip to content

Commit eeac05a

Browse files
author
MacroFake
committed
Merge bitcoin#26156: test: check that listdescriptors descriptor strings are sorted
810c3dc doc, rpc: mention that `listdescriptors` result is sorted by string representation (Sebastian Falbesoner) d99af86 test: check that `listdescriptors` descriptor strings are sorted (Sebastian Falbesoner) Pull request description: This small PR adds a test for the change introduced in PR bitcoin#25931 ("rpc: sort listdescriptors result", commit 5099624). The correctness of the test can easily be verified by commenting out the `std::sort` call in the `listdescriptors` RPC implementation: ```diff diff --git a/src/wallet/rpc/backup.cpp b/src/wallet/rpc/backup.cpp index 09c74ea..3ed1a69b26 100644 --- a/src/wallet/rpc/backup.cpp +++ b/src/wallet/rpc/backup.cpp @@ -1829,9 +1829,11 @@ RPCHelpMan listdescriptors() }); } + /* std::sort(wallet_descriptors.begin(), wallet_descriptors.end(), [](const auto& a, const auto& b) { return a.descriptor < b.descriptor; }); + */ UniValue descriptors(UniValue::VARR); for (const WalletDescInfo& info : wallet_descriptors) { ``` leading to a fail of the functional test `wallet_listdescriptors.py`. ACKs for top commit: jarolrod: ACK 810c3dc aureleoules: ACK 810c3dc Tree-SHA512: 31770e3149b8a0251ecfa8662a2270c149f778eb910985f48a91d6a5d288b7b1c2244f9f1b798ebe3f1aa9f0b935cb4d6f12d5d28f78bcde3c4a61af76d11d0a
2 parents f227e15 + 810c3dc commit eeac05a

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/wallet/rpc/backup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1760,7 +1760,7 @@ RPCHelpMan listdescriptors()
17601760
},
17611761
RPCResult{RPCResult::Type::OBJ, "", "", {
17621762
{RPCResult::Type::STR, "wallet_name", "Name of wallet this operation was performed on"},
1763-
{RPCResult::Type::ARR, "descriptors", "Array of descriptor objects",
1763+
{RPCResult::Type::ARR, "descriptors", "Array of descriptor objects (sorted by descriptor string representation)",
17641764
{
17651765
{RPCResult::Type::OBJ, "", "", {
17661766
{RPCResult::Type::STR, "desc", "Descriptor string representation"},

test/functional/wallet_listdescriptors.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ def run_test(self):
5252
assert item['range'] == [0, 0]
5353
assert item['timestamp'] is not None
5454

55+
self.log.info('Test that descriptor strings are returned in lexicographically sorted order.')
56+
descriptor_strings = [descriptor['desc'] for descriptor in result['descriptors']]
57+
assert_equal(descriptor_strings, sorted(descriptor_strings))
58+
5559
self.log.info('Test descriptors with hardened derivations are listed in importable form.')
5660
xprv = 'tprv8ZgxMBicQKsPeuVhWwi6wuMQGfPKi9Li5GtX35jVNknACgqe3CY4g5xgkfDDJcmtF7o1QnxWDRYw4H5P26PXq7sbcUkEqeR4fg3Kxp2tigg'
5761
xpub_acc = 'tpubDCMVLhErorrAGfApiJSJzEKwqeaf2z3NrkVMxgYQjZLzMjXMBeRw2muGNYbvaekAE8rUFLftyEar4LdrG2wXyyTJQZ26zptmeTEjPTaATts'

0 commit comments

Comments
 (0)