From 910dc0c2a609181cb91e1222ab7505d516b360fa Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Fri, 21 Dec 2018 05:56:46 +1300 Subject: [PATCH] Merge #14653: rpcwallet: Add missing transaction categories to rpc helptexts f3f6dde56e Test coinbase category in wallet rpcs (andrewtoth) e982f0b682 Add all category options to wallet rpc help (andrewtoth) Pull request description: The current helptext for `listtransactions`, `listsinceblock` and `gettransaction` only list two of the five possible options for `category`. This incorrectly implies that these are the only two options, and can cause problems if the other three options aren't accounted for. Also, some of the documentation is incorrect when specifying which options are returned for which categories. This PR updates the helptext for these RPCs and adds a functional regression test for the cases when the other three categories are returned. Tree-SHA512: 67dd7ff6269a3b0f17f5d1a61b0ae1fb1f3778f05e1c440bfbb9b3a005c9c6d740abcace20f3d597cf2bd6779c494448690f13fab0bd2340f206213bc7890b51 --- src/wallet/rpcwallet.cpp | 52 +++++++++++------- test/functional/test_runner.py | 1 + test/functional/wallet_coinbase_category.py | 59 +++++++++++++++++++++ 3 files changed, 92 insertions(+), 20 deletions(-) create mode 100755 test/functional/wallet_coinbase_category.py diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 40a3ff3729..31786e4e31 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -1370,17 +1370,18 @@ static UniValue listtransactions(const JSONRPCRequest& request) {RPCResult::Type::STR, "address", "The dash address of the transaction. Not present for\n" "move transactions (category = move)."}, {RPCResult::Type::STR, "category", "The transaction category.\n" - "\"send\" Transactions sent.\n" - "\"receive\" Non-coinbase transactions received.\n" - "\"move\" A local (off blockchain)\n" - "transaction between accounts, and not associated with an address,\n" - "transaction id or block..\n"}, + "\"send\" Transactions sent.\n" + "\"coinjoin\" Transactions sent using CoinJoin funds.\n" + "\"receive\" Non-coinbase transactions received.\n" + "\"generate\" Coinbase transactions received with more than 100 confirmations.\n" + "\"immature\" Coinbase transactions received with 100 or fewer confirmations.\n" + "\"orphan\" Orphaned coinbase transactions received.\n"}, {RPCResult::Type::STR_AMOUNT, "amount", "The amount in " + CURRENCY_UNIT + ". This is negative for the 'send' category, and is positive\n" "for all other categories"}, - {RPCResult::Type::STR, "label", "A comment for the address/transaction, if any"}, - {RPCResult::Type::NUM, "vout", "the vout value"}, - {RPCResult::Type::STR_AMOUNT, "fee", "The amount of the fee in " + CURRENCY_UNIT + ". This is negative and only available for the\n" - "'send' category of transactions."}, + {RPCResult::Type::STR, "label", "A comment for the address/transaction, if any"}, + {RPCResult::Type::NUM, "vout", "the vout value"}, + {RPCResult::Type::STR_AMOUNT, "fee", "The amount of the fee in " + CURRENCY_UNIT + ". This is negative and only available for the\n" + "'send' category of transactions."}, {RPCResult::Type::NUM, "confirmations", "The number of blockchain confirmations for the transaction. Available for 'send' and\n" "'receive' category of transactions. Negative confirmations indicate the\n" "transaction conflicts with the block chain"}, @@ -1495,23 +1496,28 @@ static UniValue listsinceblock(const JSONRPCRequest& request) { {RPCResult::Type::OBJ, "", "", Cat>( { - {RPCResult::Type::STR, "address", "The dash address of the transaction. Not present for move transactions (category = move)."}, - {RPCResult::Type::STR, "category", "The transaction category. 'send' has negative amounts, 'receive' has positive amounts."}, - {RPCResult::Type::NUM, "amount", "The amount in " + CURRENCY_UNIT + ". This is negative for the 'send' category, and for the 'move' category for moves \n" - "outbound. It is positive for the 'receive' category, and for the 'move' category for inbound funds."}, + {RPCResult::Type::STR, "address", "The dash address of the transaction."}, + {RPCResult::Type::STR, "category", "The transaction category.\n" + "\"send\" Transactions sent.\n" + "\"coinjoin\" Transactions sent using CoinJoin funds.\n" + "\"receive\" Non-coinbase transactions received.\n" + "\"generate\" Coinbase transactions received with more than 100 confirmations.\n" + "\"immature\" Coinbase transactions received with 100 or fewer confirmations.\n" + "\"orphan\" Orphaned coinbase transactions received.\n"}, + {RPCResult::Type::STR_AMOUNT, "amount", "The amount in " + CURRENCY_UNIT + ". This is negative for the 'send' category, and is positive\n" + "for all other categories"}, {RPCResult::Type::NUM, "vout", "the vout value"}, {RPCResult::Type::NUM, "fee", "The amount of the fee in " + CURRENCY_UNIT + ". This is negative and only available for the 'send' category of transactions."}, - {RPCResult::Type::NUM, "confirmations", "The number of blockchain confirmations for the transaction. Available for 'send' and 'receive' category of transactions.\n" - "When it's < 0, it means the transaction conflicted that many blocks ago."}, + {RPCResult::Type::NUM, "confirmations", "The number of confirmations for the transaction."}, {RPCResult::Type::BOOL, "instantlock", "Current transaction lock state. Available for 'send' and 'receive' category of transactions."}, {RPCResult::Type::BOOL, "instantlock_internal", "Current internal transaction lock state. Available for 'send' and 'receive' category of transactions."}, {RPCResult::Type::BOOL, "chainlock", "The state of the corresponding block chainlock."}, - {RPCResult::Type::STR_HEX, "blockhash", "The block hash containing the transaction. Available for 'send' and 'receive' category of transactions."}, - {RPCResult::Type::NUM, "blockindex", "The index of the transaction in the block that includes it. Available for 'send' and 'receive' category of transactions."}, + {RPCResult::Type::STR_HEX, "blockhash", "The block hash containing the transaction."}, + {RPCResult::Type::NUM, "blockindex", "The index of the transaction in the block that includes it."}, {RPCResult::Type::NUM_TIME, "blocktime", "The block time in seconds since epoch (1 Jan 1970 GMT)."}, - {RPCResult::Type::STR_HEX, "txid", "The transaction id. Available for 'send' and 'receive' category of transactions."}, + {RPCResult::Type::STR_HEX, "txid", "The transaction id."}, {RPCResult::Type::NUM_TIME, "time", "The transaction time in seconds since epoch (Jan 1 1970 GMT).."}, - {RPCResult::Type::NUM_TIME, "timereceived", "The time received in seconds since epoch (Jan 1 1970 GMT). Available for 'send' and 'receive' category of transactions."}, + {RPCResult::Type::NUM_TIME, "timereceived", "The time received in seconds since epoch (Jan 1 1970 GMT)."}, {RPCResult::Type::BOOL, "abandoned", "'true' if the transaction has been abandoned (inputs are respendable). Only available for the 'send' category of transactions."}, {RPCResult::Type::STR, "comment", "If a comment is associated with the transaction."}, {RPCResult::Type::STR, "label", "A comment for the address/transaction, if any."}, @@ -1676,7 +1682,13 @@ static UniValue gettransaction(const JSONRPCRequest& request) {RPCResult::Type::OBJ, "", "", { {RPCResult::Type::STR, "address", "The dash address involved in the transaction."}, - {RPCResult::Type::STR, "category", "The category, either 'send' or 'receive'.\n"}, + {RPCResult::Type::STR, "category", "The transaction category.\n" + "\"send\" Transactions sent.\n" + "\"coinjoin\" Transactions sent using CoinJoin funds.\n" + "\"receive\" Non-coinbase transactions received.\n" + "\"generate\" Coinbase transactions received with more than 100 confirmations.\n" + "\"immature\" Coinbase transactions received with 100 or fewer confirmations.\n" + "\"orphan\" Orphaned coinbase transactions received.\n"}, {RPCResult::Type::STR_AMOUNT, "amount", "The amount in " + CURRENCY_UNIT}, {RPCResult::Type::STR, "label", "A comment for the address/transaction, if any"}, {RPCResult::Type::NUM, "vout", "the vout value"}, diff --git a/test/functional/test_runner.py b/test/functional/test_runner.py index 0c02398afd..6cfd62803a 100755 --- a/test/functional/test_runner.py +++ b/test/functional/test_runner.py @@ -231,6 +231,7 @@ BASE_SCRIPTS = [ 'rpc_platform_filter.py', 'feature_dip0020_activation.py', 'feature_uacomment.py', + 'wallet_coinbase_category.py', 'feature_filelock.py', 'feature_loadblock.py', 'p2p_blockfilters.py', diff --git a/test/functional/wallet_coinbase_category.py b/test/functional/wallet_coinbase_category.py new file mode 100755 index 0000000000..7aa8b44ebd --- /dev/null +++ b/test/functional/wallet_coinbase_category.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python3 +# Copyright (c) 2014-2018 The Bitcoin Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. +"""Test coinbase transactions return the correct categories. + +Tests listtransactions, listsinceblock, and gettransaction. +""" + +from test_framework.test_framework import BitcoinTestFramework +from test_framework.util import ( + assert_array_result +) + +class CoinbaseCategoryTest(BitcoinTestFramework): + def set_test_params(self): + self.num_nodes = 1 + + def skip_test_if_missing_module(self): + self.skip_if_no_wallet() + + def assert_category(self, category, address, txid, skip): + assert_array_result(self.nodes[0].listtransactions(skip=skip), + {"address": address}, + {"category": category}) + assert_array_result(self.nodes[0].listsinceblock()["transactions"], + {"address": address}, + {"category": category}) + assert_array_result(self.nodes[0].gettransaction(txid)["details"], + {"address": address}, + {"category": category}) + + def run_test(self): + # Generate one block to an address + address = self.nodes[0].getnewaddress() + self.nodes[0].generatetoaddress(1, address) + hash = self.nodes[0].getbestblockhash() + txid = self.nodes[0].getblock(hash)["tx"][0] + + # Coinbase transaction is immature after 1 confirmation + self.assert_category("immature", address, txid, 0) + + # Mine another 99 blocks on top + self.nodes[0].generate(99) + # Coinbase transaction is still immature after 100 confirmations + self.assert_category("immature", address, txid, 99) + + # Mine one more block + self.nodes[0].generate(1) + # Coinbase transaction is now matured, so category is "generate" + self.assert_category("generate", address, txid, 100) + + # Orphan block that paid to address + self.nodes[0].invalidateblock(hash) + # Coinbase transaction is now orphaned + self.assert_category("orphan", address, txid, 100) + +if __name__ == '__main__': + CoinbaseCategoryTest().main()