diff --git a/test/functional/abc_mining_basic.py b/test/functional/abc_mining_basic.py new file mode 100755 index 000000000..caf63d386 --- /dev/null +++ b/test/functional/abc_mining_basic.py @@ -0,0 +1,85 @@ +#!/usr/bin/env python3 +# Copyright (c) 2020 The Bitcoin developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. +""" +Tests for Bitcoin ABC mining RPCs +""" + +from test_framework.messages import ( + COIN, +) +from test_framework.test_framework import BitcoinTestFramework +from test_framework.util import ( + assert_equal, + assert_greater_than_or_equal, +) + +from decimal import Decimal + +AXION_ACTIVATION_TIME = 2000000600 + + +class AbcMiningRPCTest(BitcoinTestFramework): + def set_test_params(self): + self.num_nodes = 2 + self.extra_args = [[ + '-enableminerfund', + '-axionactivationtime={}'.format(AXION_ACTIVATION_TIME), + ], []] + + def run_test(self): + node = self.nodes[0] + address = node.get_deterministic_priv_key().address + + # Move MTP forward to axion activation + node.setmocktime(AXION_ACTIVATION_TIME) + node.generatetoaddress(6, address) + assert_equal( + node.getblockchaininfo()['mediantime'], + AXION_ACTIVATION_TIME) + + # Assert the results of getblocktemplate have expected values. Keys not + # in 'expected' are not checked. + def assert_getblocktemplate(expected): + blockTemplate = node.getblocktemplate() + for key, value in expected.items(): + assert_equal(blockTemplate[key], value) + + def get_best_coinbase(): + return node.getblock(node.getbestblockhash(), 2)['tx'][0] + + coinbase = get_best_coinbase() + assert_equal(len(coinbase['vout']), 1) + block_reward = coinbase['vout'][0]['value'] + + # We don't need to test all fields in getblocktemplate since many of + # them are covered in mining_basic.py + assert_equal(node.getmempoolinfo()['size'], 0) + assert_getblocktemplate({ + # Although the coinbase value need not necessarily be the same as + # the last block due to halvings and fees, we know this to be true + # since we are not crossing a halving boundary and there are no + # transactions in the mempool. + 'coinbasevalue': block_reward * COIN, + }) + + # First block with the new rules + node.generatetoaddress(1, address) + + # We expect the coinbase to have multiple outputs now + coinbase = get_best_coinbase() + assert_greater_than_or_equal(len(coinbase['vout']), 2) + total = Decimal() + for o in coinbase['vout']: + total += o['value'] + + assert_equal(total, block_reward) + assert_getblocktemplate({ + # Again, we assume the coinbase value is the same as prior blocks. + 'coinbasevalue': block_reward * COIN, + }) + + +if __name__ == '__main__': + AbcMiningRPCTest().main()