Changeset View
Changeset View
Standalone View
Standalone View
test/functional/mining_basic.py
Show All 23 Lines | 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, | ||||
connect_nodes, | connect_nodes, | ||||
) | ) | ||||
from test_framework.script import CScriptNum | |||||
def assert_template(node, block, expect, rehash=True): | def assert_template(node, block, expect, rehash=True): | ||||
if rehash: | if rehash: | ||||
block.hashMerkleRoot = block.calc_merkle_root() | block.hashMerkleRoot = block.calc_merkle_root() | ||||
rsp = node.getblocktemplate( | rsp = node.getblocktemplate( | ||||
template_request={ | template_request={ | ||||
'data': block.serialize().hex(), | 'data': block.serialize().hex(), | ||||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
assert 'proposal' in tmpl['capabilities'] | assert 'proposal' in tmpl['capabilities'] | ||||
next_height = int(tmpl["height"]) | next_height = int(tmpl["height"]) | ||||
coinbase_tx = create_coinbase(height=next_height) | coinbase_tx = create_coinbase(height=next_height) | ||||
# sequence numbers must not be max for nLockTime to have effect | # sequence numbers must not be max for nLockTime to have effect | ||||
coinbase_tx.vin[0].nSequence = 2 ** 32 - 2 | coinbase_tx.vin[0].nSequence = 2 ** 32 - 2 | ||||
coinbase_tx.rehash() | coinbase_tx.rehash() | ||||
# round-trip the encoded bip34 block height commitment | |||||
assert_equal( | |||||
CScriptNum.decode( | |||||
coinbase_tx.vin[0].scriptSig), | |||||
next_height) | |||||
# round-trip negative and multi-byte CScriptNums to catch python | |||||
# regression | |||||
assert_equal( | |||||
CScriptNum.decode( | |||||
CScriptNum.encode( | |||||
CScriptNum(1500))), | |||||
1500) | |||||
assert_equal(CScriptNum.decode( | |||||
CScriptNum.encode(CScriptNum(-1500))), -1500) | |||||
assert_equal(CScriptNum.decode(CScriptNum.encode(CScriptNum(-1))), -1) | |||||
block = CBlock() | block = CBlock() | ||||
block.nVersion = tmpl["version"] | block.nVersion = tmpl["version"] | ||||
block.hashPrevBlock = int(tmpl["previousblockhash"], 16) | block.hashPrevBlock = int(tmpl["previousblockhash"], 16) | ||||
block.nTime = tmpl["curtime"] | block.nTime = tmpl["curtime"] | ||||
block.nBits = int(tmpl["bits"], 16) | block.nBits = int(tmpl["bits"], 16) | ||||
block.nNonce = 0 | block.nNonce = 0 | ||||
block.vtx = [coinbase_tx] | block.vtx = [coinbase_tx] | ||||
▲ Show 20 Lines • Show All 175 Lines • Show Last 20 Lines |