Skip to content

Commit 66c570a

Browse files
committed
[tests] Don't build the coinbase manually in getblocktemplate test
1 parent 38b38cd commit 66c570a

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

test/functional/getblocktemplate_proposals.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from hashlib import sha256
99
from struct import pack
1010

11+
from test_framework.blocktools import create_coinbase
1112
from test_framework.test_framework import BitcoinTestFramework
1213
from test_framework.util import *
1314

@@ -78,13 +79,13 @@ def run_test(self):
7879
# Mine a block to leave initial block download
7980
node.generate(1)
8081
tmpl = node.getblocktemplate()
81-
if 'coinbasetxn' not in tmpl:
82-
rawcoinbase = encodeUNum(tmpl['height'])
83-
rawcoinbase += b'\x01-'
84-
hexcoinbase = b2x(rawcoinbase)
85-
hexoutval = b2x(pack('<Q', tmpl['coinbasevalue']))
86-
tmpl['coinbasetxn'] = {'data': '01000000' + '01' + '0000000000000000000000000000000000000000000000000000000000000000ffffffff' + ('%02x' % (len(rawcoinbase),)) + hexcoinbase + 'fffffffe' + '01' + hexoutval + '00' + '00000000'}
87-
txlist = list(bytearray(a2b_hex(a['data'])) for a in (tmpl['coinbasetxn'],) + tuple(tmpl['transactions']))
82+
assert 'coinbasetxn' not in tmpl
83+
84+
coinbase_tx = create_coinbase(height=int(tmpl["height"]) + 1)
85+
# sequence numbers must not be max for nLockTime to have effect
86+
coinbase_tx.vin[0].nSequence = 2 ** 32 - 2
87+
tmpl['coinbasetxn'] = {'data': coinbase_tx.serialize()}
88+
txlist = [bytearray(coinbase_tx.serialize())]
8889

8990
self.log.info("getblocktemplate: Test capability advertised")
9091
assert('proposal' in tmpl['capabilities'])

0 commit comments

Comments
 (0)