Skip to content

Commit 37ae000

Browse files
committed
Merge #256: work towards bringing mininode.py up to date with the main node
3c21411 work towards bringing mininode.py up to date with the main node and towards re-enabling rpc tests (Arvid Norberg)
2 parents 8a61c33 + 3c21411 commit 37ae000

File tree

5 files changed

+203
-127
lines changed

5 files changed

+203
-127
lines changed

qa/rpc-tests/listtransactions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from test_framework.test_framework import BitcoinTestFramework
99
from test_framework.util import *
10-
from test_framework.mininode import CTransaction, setCTxOutValue, CTxOutValue, COIN
10+
from test_framework.mininode import CTransaction, COIN
1111
from io import BytesIO
1212
import binascii
1313

qa/rpc-tests/p2p-compactblocks.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def build_block_on_tip(self, node, segwit=False):
131131
height = node.getblockcount()
132132
tip = node.getbestblockhash()
133133
mtp = node.getblockheader(tip)['mediantime']
134-
block = create_block(int(tip, 16), create_coinbase(height + 1), mtp + 1)
134+
block = create_block(int(tip, 16), create_coinbase(height + 1), mtp + 1, height + 1)
135135
block.nVersion = 4
136136
if segwit:
137137
add_witness_commitment(block)
@@ -146,12 +146,12 @@ def make_utxos(self):
146146
assert(int(self.nodes[0].getbestblockhash(), 16) == block.sha256)
147147
self.nodes[0].generate(100)
148148

149-
total_value = block.vtx[0].vout[0].nValue
150-
out_value = total_value // 10
149+
total_value = block.vtx[0].vout[0].nValue.getAmount()
150+
out_value = total_value
151151
tx = CTransaction()
152152
tx.vin.append(CTxIn(COutPoint(block.vtx[0].sha256, 0), b''))
153153
for i in range(10):
154-
tx.vout.append(CTxOut(out_value, CScript([OP_TRUE])))
154+
tx.vout.append(CTxOut(CTxOutValue(out_value), CScript([OP_TRUE])))
155155
tx.rehash()
156156

157157
block2 = self.build_block_on_tip(self.nodes[0])
@@ -458,7 +458,7 @@ def build_block_with_transactions(self, node, utxo, num_transactions):
458458
for i in range(num_transactions):
459459
tx = CTransaction()
460460
tx.vin.append(CTxIn(COutPoint(utxo[0], utxo[1]), b''))
461-
tx.vout.append(CTxOut(utxo[2] - 1000, CScript([OP_TRUE])))
461+
tx.vout.append(CTxOut(CTxOutValue(utxo[2].getAmount() - 1000), CScript([OP_TRUE])))
462462
tx.rehash()
463463
utxo = [tx.sha256, 0, tx.vout[0].nValue]
464464
block.vtx.append(tx)

qa/rpc-tests/test_framework/blocktools.py

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,19 @@
88
from .script import CScript, OP_TRUE, OP_CHECKSIG, OP_RETURN
99

1010
# Create a block (with regtest difficulty)
11-
def create_block(hashprev, coinbase, nTime=None):
11+
def create_block(hashprev, coinbase, nTime=None, height=0):
1212
block = CBlock()
1313
if nTime is None:
1414
import time
1515
block.nTime = int(time.time()+600)
1616
else:
1717
block.nTime = nTime
1818
block.hashPrevBlock = hashprev
19-
block.nBits = 0x207fffff # Will break after a difficulty adjustment...
2019
block.vtx.append(coinbase)
2120
block.hashMerkleRoot = block.calc_merkle_root()
21+
block.nHeight = height
22+
block.proof.challenge = CScript([OP_TRUE])
23+
block.proof.solution = b''
2224
block.calc_sha256()
2325
return block
2426

@@ -39,39 +41,28 @@ def add_witness_commitment(block, nonce=0):
3941

4042
# witness commitment is the last OP_RETURN output in coinbase
4143
output_data = WITNESS_COMMITMENT_HEADER + ser_uint256(witness_commitment)
42-
block.vtx[0].vout.append(CTxOut(0, CScript([OP_RETURN, output_data])))
44+
block.vtx[0].vout.append(CTxOut(CTxOutValue(0), CScript([OP_RETURN, output_data])))
4345
block.vtx[0].rehash()
4446
block.hashMerkleRoot = block.calc_merkle_root()
4547
block.rehash()
4648

47-
48-
def serialize_script_num(value):
49-
r = bytearray(0)
50-
if value == 0:
51-
return r
52-
neg = value < 0
53-
absvalue = -value if neg else value
54-
while (absvalue):
55-
r.append(int(absvalue & 0xff))
56-
absvalue >>= 8
57-
if r[-1] & 0x80:
58-
r.append(0x80 if neg else 0)
59-
elif neg:
60-
r[-1] |= 0x80
61-
return r
62-
6349
# Create a coinbase transaction, assuming no miner fees.
6450
# If pubkey is passed in, the coinbase output will be a P2PK output;
6551
# otherwise an anyone-can-spend output.
66-
def create_coinbase(height, pubkey = None):
52+
def create_coinbase(height, pubkey = None, amount = 0):
6753
coinbase = CTransaction()
68-
coinbase.vin.append(CTxIn(COutPoint(0, 0xffffffff),
69-
ser_string(serialize_script_num(height)), 0xffffffff))
54+
# coinbase transaction scriptsigs must be at least 2 bytes
55+
coinbase.vin.append(CTxIn(COutPoint(0, 0xffffffff),
56+
CScript([height, OP_TRUE]), 0xffffffff))
7057
coinbaseoutput = CTxOut()
71-
coinbaseoutput.nValue = 50 * COIN
72-
halvings = int(height/150) # regtest
73-
coinbaseoutput.nValue >>= halvings
74-
if (pubkey != None):
58+
59+
coinbaseoutput.nValue.setToAmount(amount)
60+
coinbaseoutput.nAsset.setToAsset(b'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
61+
62+
if amount == 0:
63+
# zero utxo's must be made unspendable
64+
coinbaseoutput.scriptPubKey = CScript([OP_RETURN])
65+
elif pubkey != None:
7566
coinbaseoutput.scriptPubKey = CScript([pubkey, OP_CHECKSIG])
7667
else:
7768
coinbaseoutput.scriptPubKey = CScript([OP_TRUE])
@@ -85,7 +76,7 @@ def create_transaction(prevtx, n, sig, value, scriptPubKey=CScript()):
8576
tx = CTransaction()
8677
assert(n < len(prevtx.vout))
8778
tx.vin.append(CTxIn(COutPoint(prevtx.sha256, n), sig, 0xffffffff))
88-
tx.vout.append(CTxOut(value, scriptPubKey))
79+
tx.vout.append(CTxOut(CTxOutValue(value), scriptPubKey))
8980
tx.calc_sha256()
9081
return tx
9182

0 commit comments

Comments
 (0)