Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc-magnetic-anomaly-mining.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2014-2016 The Bitcoin Core developers | # Copyright (c) 2014-2016 The Bitcoin Core developers | ||||
# Distributed under the MIT software license, see the accompanying | # Distributed under the MIT software license, see the accompanying | ||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
""" | """ | ||||
Test that mining RPC continues to supply correct transaction metadata after | Test that mining RPC continues to supply correct transaction metadata after | ||||
the Nov 2018 protocol upgrade which engages canonical transaction ordering | the Nov 2018 protocol upgrade which engages canonical transaction ordering | ||||
""" | """ | ||||
import decimal | import decimal | ||||
import random | import random | ||||
import time | import time | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
# Set test to run with sigops deactivation far in the future. | |||||
SIGOPS_DEACTIVATION_TIME = 2000000000 | |||||
class CTORMiningTest(BitcoinTestFramework): | class CTORMiningTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
# Setup two nodes so we can getblocktemplate | # Setup two nodes so we can getblocktemplate | ||||
# it errors out if it is not connected to other nodes | # it errors out if it is not connected to other nodes | ||||
self.num_nodes = 2 | self.num_nodes = 2 | ||||
self.setup_clean_chain = True | self.setup_clean_chain = True | ||||
self.block_heights = {} | self.block_heights = {} | ||||
self.tip = None | self.tip = None | ||||
self.blocks = {} | self.blocks = {} | ||||
self.mocktime = int(time.time()) - 600 * 100 | self.mocktime = int(time.time()) - 600 * 100 | ||||
extra_arg = ['-spendzeroconfchange=0', '-whitelist=127.0.0.1', | extra_arg = ['-spendzeroconfchange=0', '-whitelist=127.0.0.1'] | ||||
'-phononactivationtime={}'.format(SIGOPS_DEACTIVATION_TIME)] | |||||
self.extra_args = [extra_arg, extra_arg] | self.extra_args = [extra_arg, extra_arg] | ||||
def skip_test_if_missing_module(self): | def skip_test_if_missing_module(self): | ||||
self.skip_if_no_wallet() | self.skip_if_no_wallet() | ||||
def run_test(self): | def run_test(self): | ||||
mining_node = self.nodes[0] | mining_node = self.nodes[0] | ||||
Show All 27 Lines | def run_test(self): | ||||
if len(unspent) == 0: | if len(unspent) == 0: | ||||
break | break | ||||
outputs = {} | outputs = {} | ||||
# Calculate a unique fee for this transaction | # Calculate a unique fee for this transaction | ||||
fee = decimal.Decimal(random.randint( | fee = decimal.Decimal(random.randint( | ||||
1000, 2000)) / decimal.Decimal(1e8) | 1000, 2000)) / decimal.Decimal(1e8) | ||||
# Spend to the same number of outputs as inputs, so we can leave | # Spend to the same number of outputs as inputs, so we can leave | ||||
# the amounts unchanged and avoid rounding errors. | # the amounts unchanged and avoid rounding errors. This also ensures | ||||
# the number of sigops == number of sigchecks. | |||||
# | # | ||||
# NOTE: There will be 1 sigop per output (which equals the number | # NOTE: There will be 1 sigop per output (which equals the number | ||||
# of inputs now). We need this randomization to ensure the | # of inputs now). We need this randomization to ensure the | ||||
# numbers are properly following the transactions in the block | # numbers are properly following the transactions in the block | ||||
# template metadata | # template metadata | ||||
addr = "" | addr = "" | ||||
for _ in range(len(inputs)): | for _ in range(len(inputs)): | ||||
addr = mining_node.getnewaddress() | addr = mining_node.getnewaddress() | ||||
▲ Show 20 Lines • Show All 41 Lines • Show Last 20 Lines |