2018-12-01 19:00:38 +01:00
|
|
|
#!/usr/bin/env python3
|
2021-07-28 13:57:16 +02:00
|
|
|
# Copyright (c) 2014-2021 The Bitcoin Core developers
|
2018-12-01 19:00:38 +01:00
|
|
|
# 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
|
2022-07-11 20:13:32 +02:00
|
|
|
self.setup_clean_chain = True
|
2018-12-01 19:00:38 +01:00
|
|
|
|
|
|
|
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()
|
2021-08-19 17:10:24 +02:00
|
|
|
self.generatetoaddress(self.nodes[0], 1, address)
|
2018-12-01 19:00:38 +01:00
|
|
|
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
|
2021-08-19 17:10:24 +02:00
|
|
|
self.generate(self.nodes[0], 99)
|
2018-12-01 19:00:38 +01:00
|
|
|
# Coinbase transaction is still immature after 100 confirmations
|
|
|
|
self.assert_category("immature", address, txid, 99)
|
|
|
|
|
|
|
|
# Mine one more block
|
2021-08-19 17:10:24 +02:00
|
|
|
self.generate(self.nodes[0], 1)
|
2018-12-01 19:00:38 +01:00
|
|
|
# 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()
|