Changeset View
Changeset View
Standalone View
Standalone View
test/functional/mining_basic.py
Show All 12 Lines | |||||
from test_framework.blocktools import ( | from test_framework.blocktools import ( | ||||
create_coinbase, | create_coinbase, | ||||
TIME_GENESIS_BLOCK, | TIME_GENESIS_BLOCK, | ||||
) | ) | ||||
from test_framework.messages import ( | from test_framework.messages import ( | ||||
CBlock, | CBlock, | ||||
CBlockHeader, | CBlockHeader, | ||||
BLOCK_HEADER_SIZE | |||||
Fabien: trailing comma | |||||
) | ) | ||||
from test_framework.mininode import ( | from test_framework.mininode import ( | ||||
P2PDataStore, | P2PDataStore, | ||||
) | ) | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import ( | from test_framework.util import ( | ||||
assert_equal, | assert_equal, | ||||
assert_raises_rpc_error, | assert_raises_rpc_error, | ||||
▲ Show 20 Lines • Show All 134 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
bad_block = copy.deepcopy(block) | bad_block = copy.deepcopy(block) | ||||
bad_block.vtx[0].nLockTime = 2 ** 32 - 1 | bad_block.vtx[0].nLockTime = 2 ** 32 - 1 | ||||
bad_block.vtx[0].rehash() | bad_block.vtx[0].rehash() | ||||
assert_template(node, bad_block, 'bad-txns-nonfinal') | assert_template(node, bad_block, 'bad-txns-nonfinal') | ||||
assert_submitblock(bad_block, 'bad-txns-nonfinal') | assert_submitblock(bad_block, 'bad-txns-nonfinal') | ||||
self.log.info("getblocktemplate: Test bad tx count") | self.log.info("getblocktemplate: Test bad tx count") | ||||
# The tx count is immediately after the block header | # The tx count is immediately after the block header | ||||
TX_COUNT_OFFSET = 80 | |||||
bad_block_sn = bytearray(block.serialize()) | bad_block_sn = bytearray(block.serialize()) | ||||
assert_equal(bad_block_sn[TX_COUNT_OFFSET], 1) | assert_equal(bad_block_sn[BLOCK_HEADER_SIZE], 1) | ||||
bad_block_sn[TX_COUNT_OFFSET] += 1 | bad_block_sn[BLOCK_HEADER_SIZE] += 1 | ||||
assert_raises_rpc_error(-22, "Block decode failed", node.getblocktemplate, { | assert_raises_rpc_error(-22, "Block decode failed", node.getblocktemplate, { | ||||
'data': bad_block_sn.hex(), 'mode': 'proposal'}) | 'data': bad_block_sn.hex(), 'mode': 'proposal'}) | ||||
self.log.info("getblocktemplate: Test bad bits") | self.log.info("getblocktemplate: Test bad bits") | ||||
bad_block = copy.deepcopy(block) | bad_block = copy.deepcopy(block) | ||||
bad_block.nBits = 469762303 # impossible in the real world | bad_block.nBits = 469762303 # impossible in the real world | ||||
assert_template(node, bad_block, 'bad-diffbits') | assert_template(node, bad_block, 'bad-diffbits') | ||||
Show All 16 Lines | def run_test(self): | ||||
bad_block = copy.deepcopy(block) | bad_block = copy.deepcopy(block) | ||||
bad_block.hashPrevBlock = 123 | bad_block.hashPrevBlock = 123 | ||||
assert_template(node, bad_block, 'inconclusive-not-best-prevblk') | assert_template(node, bad_block, 'inconclusive-not-best-prevblk') | ||||
assert_submitblock(bad_block, 'prev-blk-not-found', | assert_submitblock(bad_block, 'prev-blk-not-found', | ||||
'prev-blk-not-found') | 'prev-blk-not-found') | ||||
self.log.info('submitheader tests') | self.log.info('submitheader tests') | ||||
assert_raises_rpc_error(-22, 'Block header decode failed', | assert_raises_rpc_error(-22, 'Block header decode failed', | ||||
lambda: node.submitheader(hexdata='xx' * 80)) | lambda: node.submitheader(hexdata='xx' * BLOCK_HEADER_SIZE)) | ||||
assert_raises_rpc_error(-22, 'Block header decode failed', | assert_raises_rpc_error(-22, 'Block header decode failed', | ||||
lambda: node.submitheader(hexdata='ff' * 78)) | lambda: node.submitheader(hexdata='ff' * (BLOCK_HEADER_SIZE - 2))) | ||||
assert_raises_rpc_error(-25, 'Must submit previous header', | assert_raises_rpc_error(-25, 'Must submit previous header', | ||||
lambda: node.submitheader(hexdata='ff' * 80)) | lambda: node.submitheader(hexdata='ff' * BLOCK_HEADER_SIZE)) | ||||
FabienUnsubmitted Not Done Inline ActionsThat's not what is in the PR Fabien: That's not what is in the PR | |||||
PiRKAuthorUnsubmitted Done Inline ActionsI almost forgot to include the second commit https://github.com/bitcoin/bitcoin/pull/15238/commits/b651ef7e1c39a820089695b29d14a07d910a385a It's fixed now, I squashed the 2 commits. PiRK: I almost forgot to include the second commit https://github. | |||||
block.nTime += 1 | block.nTime += 1 | ||||
block.solve() | block.solve() | ||||
def chain_tip(b_hash, *, status='headers-only', branchlen=1): | def chain_tip(b_hash, *, status='headers-only', branchlen=1): | ||||
return {'hash': b_hash, 'height': 202, | return {'hash': b_hash, 'height': 202, | ||||
'branchlen': branchlen, 'status': status} | 'branchlen': branchlen, 'status': status} | ||||
▲ Show 20 Lines • Show All 80 Lines • Show Last 20 Lines |
trailing comma