many of the python functional tests corrected
This commit is contained in:
parent
f632d33912
commit
1f03eb41a8
@ -352,8 +352,8 @@ public:
|
||||
|
||||
consensus.fPowAllowMinDifficultyBlocks = true;
|
||||
consensus.fPowNoRetargeting = true;
|
||||
consensus.nRuleChangeActivationThreshold = 432; // 75% for testchains
|
||||
consensus.nMinerConfirmationWindow = 576; // Faster than normal for regtest (144 instead of 2016)
|
||||
consensus.nRuleChangeActivationThreshold = 108; // 75% for testchains
|
||||
consensus.nMinerConfirmationWindow = 144; // Faster than normal for regtest (144 instead of 2016)
|
||||
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].bit = 28;
|
||||
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nStartTime = 0;
|
||||
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nTimeout = 999999999999ULL;
|
||||
|
||||
@ -104,7 +104,7 @@ class BIP68_112_113Test(ComparisonTestFramework):
|
||||
test.run()
|
||||
|
||||
def send_generic_input_tx(self, node, coinbases):
|
||||
amount = Decimal("49.99")
|
||||
amount = Decimal("99.99")
|
||||
return node.sendrawtransaction(ToHex(self.sign_transaction(node, self.create_transaction(node, node.getblock(coinbases.pop())['tx'][0], self.nodeaddress, amount))))
|
||||
|
||||
def create_transaction(self, node, txid, to_address, amount):
|
||||
|
||||
@ -59,8 +59,7 @@ class BlockchainTest(BitcoinTestFramework):
|
||||
def _test_gettxoutsetinfo(self):
|
||||
node = self.nodes[0]
|
||||
res = node.gettxoutsetinfo()
|
||||
|
||||
assert_equal(res['total_amount'], Decimal('8725.00000000'))
|
||||
assert_equal(res['total_amount'], Decimal('17450.00000000'))
|
||||
assert_equal(res['transactions'], 200)
|
||||
assert_equal(res['height'], 200)
|
||||
assert_equal(res['txouts'], 200)
|
||||
|
||||
@ -51,7 +51,7 @@ class RawTransactionsTest(BitcoinTestFramework):
|
||||
self.sync_all()
|
||||
|
||||
# ensure that setting changePosition in fundraw with an exact match is handled properly
|
||||
rawmatch = self.nodes[2].createrawtransaction([], {self.nodes[2].getnewaddress():50})
|
||||
rawmatch = self.nodes[2].createrawtransaction([], {self.nodes[2].getnewaddress():100})
|
||||
rawmatch = self.nodes[2].fundrawtransaction(rawmatch, {"changePosition":1, "subtractFeeFromOutputs":[0]})
|
||||
assert_equal(rawmatch["changepos"], -1)
|
||||
|
||||
@ -498,7 +498,7 @@ class RawTransactionsTest(BitcoinTestFramework):
|
||||
self.sync_all()
|
||||
|
||||
# make sure funds are received at node1
|
||||
assert_equal(oldBalance+Decimal('51.10000000'), self.nodes[0].getbalance())
|
||||
assert_equal(oldBalance+Decimal('101.10000000'), self.nodes[0].getbalance())
|
||||
|
||||
|
||||
###############################################
|
||||
@ -558,7 +558,7 @@ class RawTransactionsTest(BitcoinTestFramework):
|
||||
self.sync_all()
|
||||
self.nodes[0].generate(1)
|
||||
self.sync_all()
|
||||
assert_equal(oldBalance+Decimal('50.19000000'), self.nodes[0].getbalance()) #0.19+block reward
|
||||
assert_equal(oldBalance+Decimal('100.19000000'), self.nodes[0].getbalance()) #0.19+block reward
|
||||
|
||||
#####################################################
|
||||
# test fundrawtransaction with OP_RETURN and no vin #
|
||||
|
||||
@ -102,7 +102,7 @@ class InvalidBlockRequestTest(ComparisonTestFramework):
|
||||
'''
|
||||
block3 = create_block(self.tip, create_coinbase(height), self.block_time)
|
||||
self.block_time += 1
|
||||
block3.vtx[0].vout[0].nValue = 100 * COIN # Too high!
|
||||
block3.vtx[0].vout[0].nValue = 200 * COIN # Too high!
|
||||
block3.vtx[0].sha256=None
|
||||
block3.vtx[0].calc_sha256()
|
||||
block3.hashMerkleRoot = block3.calc_merkle_root()
|
||||
|
||||
@ -41,15 +41,15 @@ class MempoolCoinbaseTest(BitcoinTestFramework):
|
||||
# and make sure the mempool code behaves correctly.
|
||||
b = [ self.nodes[0].getblockhash(n) for n in range(101, 105) ]
|
||||
coinbase_txids = [ self.nodes[0].getblock(h)['tx'][0] for h in b ]
|
||||
spend_101_raw = create_tx(self.nodes[0], coinbase_txids[1], node1_address, 49.99)
|
||||
spend_102_raw = create_tx(self.nodes[0], coinbase_txids[2], node0_address, 49.99)
|
||||
spend_103_raw = create_tx(self.nodes[0], coinbase_txids[3], node0_address, 49.99)
|
||||
spend_101_raw = create_tx(self.nodes[0], coinbase_txids[1], node1_address, 99.99)
|
||||
spend_102_raw = create_tx(self.nodes[0], coinbase_txids[2], node0_address, 99.99)
|
||||
spend_103_raw = create_tx(self.nodes[0], coinbase_txids[3], node0_address, 99.99)
|
||||
|
||||
# Create a transaction which is time-locked to two blocks in the future
|
||||
timelock_tx = self.nodes[0].createrawtransaction([{"txid": coinbase_txids[0], "vout": 0}], {node0_address: 49.99})
|
||||
timelock_tx = self.nodes[0].createrawtransaction([{"txid": coinbase_txids[0], "vout": 0}], {node0_address: 99.99})
|
||||
# Set the time lock
|
||||
timelock_tx = timelock_tx.replace("ffffffff", "11111191", 1)
|
||||
timelock_tx = timelock_tx[:-8] + hex(self.nodes[0].getblockcount() + 2)[2:] + "000000"
|
||||
timelock_tx = timelock_tx[:-10] + hex(self.nodes[0].getblockcount() + 2)[2:] + "00000000"
|
||||
timelock_tx = self.nodes[0].signrawtransaction(timelock_tx)["hex"]
|
||||
# This will raise an exception because the timelock transaction is too immature to spend
|
||||
assert_raises_jsonrpc(-26, "non-final", self.nodes[0].sendrawtransaction, timelock_tx)
|
||||
@ -62,8 +62,8 @@ class MempoolCoinbaseTest(BitcoinTestFramework):
|
||||
assert_raises_jsonrpc(-26,'non-final', self.nodes[0].sendrawtransaction, timelock_tx)
|
||||
|
||||
# Create 102_1 and 103_1:
|
||||
spend_102_1_raw = create_tx(self.nodes[0], spend_102_id, node1_address, 49.98)
|
||||
spend_103_1_raw = create_tx(self.nodes[0], spend_103_id, node1_address, 49.98)
|
||||
spend_102_1_raw = create_tx(self.nodes[0], spend_102_id, node1_address, 99.98)
|
||||
spend_103_1_raw = create_tx(self.nodes[0], spend_103_id, node1_address, 99.98)
|
||||
|
||||
# Broadcast and mine 103_1:
|
||||
spend_103_1_id = self.nodes[0].sendrawtransaction(spend_103_1_raw)
|
||||
|
||||
@ -31,13 +31,13 @@ class MempoolCoinbaseTest(BitcoinTestFramework):
|
||||
|
||||
b = [ self.nodes[0].getblockhash(n) for n in range(1, 4) ]
|
||||
coinbase_txids = [ self.nodes[0].getblock(h)['tx'][0] for h in b ]
|
||||
spends1_raw = [ create_tx(self.nodes[0], txid, node0_address, 49.99) for txid in coinbase_txids ]
|
||||
spends1_raw = [ create_tx(self.nodes[0], txid, node0_address, 99.99) for txid in coinbase_txids ]
|
||||
spends1_id = [ self.nodes[0].sendrawtransaction(tx) for tx in spends1_raw ]
|
||||
|
||||
blocks = []
|
||||
blocks.extend(self.nodes[0].generate(1))
|
||||
|
||||
spends2_raw = [ create_tx(self.nodes[0], txid, node0_address, 49.98) for txid in spends1_id ]
|
||||
spends2_raw = [ create_tx(self.nodes[0], txid, node0_address, 99.98) for txid in spends1_id ]
|
||||
spends2_id = [ self.nodes[0].sendrawtransaction(tx) for tx in spends2_raw ]
|
||||
|
||||
blocks.extend(self.nodes[0].generate(1))
|
||||
|
||||
@ -34,7 +34,7 @@ class MempoolSpendCoinbaseTest(BitcoinTestFramework):
|
||||
# is too immature to spend.
|
||||
b = [ self.nodes[0].getblockhash(n) for n in range(101, 103) ]
|
||||
coinbase_txids = [ self.nodes[0].getblock(h)['tx'][0] for h in b ]
|
||||
spends_raw = [ create_tx(self.nodes[0], txid, node0_address, 49.99) for txid in coinbase_txids ]
|
||||
spends_raw = [ create_tx(self.nodes[0], txid, node0_address, 99.99) for txid in coinbase_txids ]
|
||||
|
||||
spend_101_id = self.nodes[0].sendrawtransaction(spends_raw[0])
|
||||
|
||||
|
||||
@ -35,9 +35,9 @@ class MerkleBlockTest(BitcoinTestFramework):
|
||||
assert_equal(self.nodes[2].getbalance(), 0)
|
||||
|
||||
node0utxos = self.nodes[0].listunspent(1)
|
||||
tx1 = self.nodes[0].createrawtransaction([node0utxos.pop()], {self.nodes[1].getnewaddress(): 49.99})
|
||||
tx1 = self.nodes[0].createrawtransaction([node0utxos.pop()], {self.nodes[1].getnewaddress(): 99.99})
|
||||
txid1 = self.nodes[0].sendrawtransaction(self.nodes[0].signrawtransaction(tx1)["hex"])
|
||||
tx2 = self.nodes[0].createrawtransaction([node0utxos.pop()], {self.nodes[1].getnewaddress(): 49.99})
|
||||
tx2 = self.nodes[0].createrawtransaction([node0utxos.pop()], {self.nodes[1].getnewaddress(): 99.99})
|
||||
txid2 = self.nodes[0].sendrawtransaction(self.nodes[0].signrawtransaction(tx2)["hex"])
|
||||
# This will raise an exception because the transaction is not yet in a block
|
||||
assert_raises_jsonrpc(-5, "Transaction not yet in block", self.nodes[0].gettxoutproof, [txid1])
|
||||
@ -56,7 +56,7 @@ class MerkleBlockTest(BitcoinTestFramework):
|
||||
assert_equal(self.nodes[2].verifytxoutproof(self.nodes[2].gettxoutproof([txid1, txid2], blockhash)), txlist)
|
||||
|
||||
txin_spent = self.nodes[1].listunspent(1).pop()
|
||||
tx3 = self.nodes[1].createrawtransaction([txin_spent], {self.nodes[0].getnewaddress(): 49.98})
|
||||
tx3 = self.nodes[1].createrawtransaction([txin_spent], {self.nodes[0].getnewaddress(): 99.98})
|
||||
txid3 = self.nodes[0].sendrawtransaction(self.nodes[1].signrawtransaction(tx3)["hex"])
|
||||
self.nodes[0].generate(1)
|
||||
self.sync_all()
|
||||
|
||||
@ -46,7 +46,7 @@ class MultiWalletTest(BitcoinTestFramework):
|
||||
|
||||
# check w1 wallet balance
|
||||
w1_info = w1.getwalletinfo()
|
||||
assert_equal(w1_info['immature_balance'], 50)
|
||||
assert_equal(w1_info['immature_balance'], 100)
|
||||
w1_name = w1_info['walletname']
|
||||
assert_equal(w1_name, "w1")
|
||||
|
||||
@ -64,7 +64,7 @@ class MultiWalletTest(BitcoinTestFramework):
|
||||
assert_equal({"w1", "w2", "w3"}, {w1_name, w2_name, w3_name})
|
||||
|
||||
w1.generate(101)
|
||||
assert_equal(w1.getbalance(), 100)
|
||||
assert_equal(w1.getbalance(), 200)
|
||||
assert_equal(w2.getbalance(), 0)
|
||||
assert_equal(w3.getbalance(), 0)
|
||||
|
||||
|
||||
@ -359,7 +359,7 @@ class FullBlockTest(ComparisonTestFramework):
|
||||
tip(15)
|
||||
b23 = block(23, spend=out[6])
|
||||
tx = CTransaction()
|
||||
script_length = MAX_BLOCK_BASE_SIZE - len(b23.serialize()) - 69
|
||||
script_length = MAX_BLOCK_BASE_SIZE - len(b23.serialize()) - 69 - 1 #subtract 1 for txComment byte
|
||||
script_output = CScript([b'\x00' * script_length])
|
||||
tx.vout.append(CTxOut(0, script_output))
|
||||
tx.vin.append(CTxIn(COutPoint(b23.vtx[1].sha256, 0)))
|
||||
@ -372,7 +372,7 @@ class FullBlockTest(ComparisonTestFramework):
|
||||
# Make the next block one byte bigger and check that it fails
|
||||
tip(15)
|
||||
b24 = block(24, spend=out[6])
|
||||
script_length = MAX_BLOCK_BASE_SIZE - len(b24.serialize()) - 69
|
||||
script_length = MAX_BLOCK_BASE_SIZE - len(b24.serialize()) - 69 - 1 #subtract 1 for txComment byte
|
||||
script_output = CScript([b'\x00' * (script_length+1)])
|
||||
tx.vout = [CTxOut(0, script_output)]
|
||||
b24 = update_block(24, [tx])
|
||||
@ -788,7 +788,7 @@ class FullBlockTest(ComparisonTestFramework):
|
||||
assert_equal(len(b56p2.vtx),6)
|
||||
b56p2 = update_block("b56p2", [tx3, tx4])
|
||||
yield rejected(RejectResult(16, b'bad-txns-duplicate'))
|
||||
|
||||
|
||||
tip("57p2")
|
||||
yield accepted()
|
||||
|
||||
@ -813,10 +813,10 @@ class FullBlockTest(ComparisonTestFramework):
|
||||
b58 = update_block(58, [tx])
|
||||
yield rejected(RejectResult(16, b'bad-txns-inputs-missingorspent'))
|
||||
|
||||
# tx with output value > input value out of range
|
||||
# tx with output value > input value out of range
|
||||
tip(57)
|
||||
b59 = block(59)
|
||||
tx = create_and_sign_tx(out[17].tx, out[17].n, 51*COIN)
|
||||
tx = create_and_sign_tx(out[17].tx, out[17].n, 101*COIN)
|
||||
b59 = update_block(59, [tx])
|
||||
yield rejected(RejectResult(16, b'bad-txns-in-belowout'))
|
||||
|
||||
@ -901,7 +901,7 @@ class FullBlockTest(ComparisonTestFramework):
|
||||
tx = CTransaction()
|
||||
|
||||
# use canonical serialization to calculate size
|
||||
script_length = MAX_BLOCK_BASE_SIZE - len(b64a.normal_serialize()) - 69
|
||||
script_length = MAX_BLOCK_BASE_SIZE - len(b64a.normal_serialize()) - 69 - 1 #subtract 1 for txComment byte
|
||||
script_output = CScript([b'\x00' * script_length])
|
||||
tx.vout.append(CTxOut(0, script_output))
|
||||
tx.vin.append(CTxIn(COutPoint(b64a.vtx[1].sha256, 0)))
|
||||
@ -1250,7 +1250,7 @@ class FullBlockTest(ComparisonTestFramework):
|
||||
for i in range(89, LARGE_REORG_SIZE + 89):
|
||||
b = block(i, spend)
|
||||
tx = CTransaction()
|
||||
script_length = MAX_BLOCK_BASE_SIZE - len(b.serialize()) - 69
|
||||
script_length = MAX_BLOCK_BASE_SIZE - len(b.serialize()) - 69 - 1 #subtract 1 for txComment byte
|
||||
script_output = CScript([b'\x00' * script_length])
|
||||
tx.vout.append(CTxOut(0, script_output))
|
||||
tx.vin.append(CTxIn(COutPoint(b.vtx[1].sha256, 0)))
|
||||
|
||||
@ -758,6 +758,10 @@ class SegWitTest(BitcoinTestFramework):
|
||||
if flags & 1:
|
||||
r += self.wit.serialize()
|
||||
r += struct.pack("<I", self.nLockTime)
|
||||
if self.nVersion >= 2:
|
||||
r += ser_compact_size(len(self.txComment))
|
||||
if len(self.txComment) > 0:
|
||||
r += struct.pack("<s", self.txComment)
|
||||
return r
|
||||
|
||||
tx2 = BrokenCTransaction()
|
||||
|
||||
2
test/functional/test_framework/blocktools.py
Normal file → Executable file
2
test/functional/test_framework/blocktools.py
Normal file → Executable file
@ -73,7 +73,7 @@ def create_coinbase(height, pubkey = None):
|
||||
coinbase.vin.append(CTxIn(COutPoint(0, 0xffffffff),
|
||||
ser_string(serialize_script_num(height)), 0xffffffff))
|
||||
coinbaseoutput = CTxOut()
|
||||
coinbaseoutput.nValue = 50 * COIN
|
||||
coinbaseoutput.nValue = 100 * COIN
|
||||
halvings = int(height/150) # regtest
|
||||
coinbaseoutput.nValue >>= halvings
|
||||
if (pubkey != None):
|
||||
|
||||
@ -427,13 +427,14 @@ class CTxWitness(object):
|
||||
class CTransaction(object):
|
||||
def __init__(self, tx=None):
|
||||
if tx is None:
|
||||
self.nVersion = 1
|
||||
self.nVersion = 2
|
||||
self.vin = []
|
||||
self.vout = []
|
||||
self.wit = CTxWitness()
|
||||
self.nLockTime = 0
|
||||
self.sha256 = None
|
||||
self.hash = None
|
||||
self.txComment = ""
|
||||
else:
|
||||
self.nVersion = tx.nVersion
|
||||
self.vin = copy.deepcopy(tx.vin)
|
||||
@ -442,6 +443,7 @@ class CTransaction(object):
|
||||
self.sha256 = tx.sha256
|
||||
self.hash = tx.hash
|
||||
self.wit = copy.deepcopy(tx.wit)
|
||||
self.txComment = '%s' % tx.txComment
|
||||
|
||||
def deserialize(self, f):
|
||||
self.nVersion = struct.unpack("<i", f.read(4))[0]
|
||||
@ -460,6 +462,12 @@ class CTransaction(object):
|
||||
self.wit.vtxinwit = [CTxInWitness() for i in range(len(self.vin))]
|
||||
self.wit.deserialize(f)
|
||||
self.nLockTime = struct.unpack("<I", f.read(4))[0]
|
||||
if self.nVersion >= 2:
|
||||
tx_comment_len = deser_compact_size(f)
|
||||
if tx_comment_len > 0:
|
||||
self.txComment = struct.unpack("<s", f.read(tx_comment_len))[0]
|
||||
else:
|
||||
self.txComment = ""
|
||||
self.sha256 = None
|
||||
self.hash = None
|
||||
|
||||
@ -469,6 +477,11 @@ class CTransaction(object):
|
||||
r += ser_vector(self.vin)
|
||||
r += ser_vector(self.vout)
|
||||
r += struct.pack("<I", self.nLockTime)
|
||||
if self.nVersion >= 2:
|
||||
r += ser_compact_size(len(self.txComment))
|
||||
if len(self.txComment) > 0:
|
||||
r += struct.pack("<s", self.txComment)
|
||||
|
||||
return r
|
||||
|
||||
# Only serialize with witness when explicitly called for
|
||||
@ -492,6 +505,11 @@ class CTransaction(object):
|
||||
self.wit.vtxinwit.append(CTxInWitness())
|
||||
r += self.wit.serialize()
|
||||
r += struct.pack("<I", self.nLockTime)
|
||||
if self.nVersion >= 2:
|
||||
r += ser_compact_size(len(self.txComment))
|
||||
if len(self.txComment) > 0:
|
||||
r += struct.pack("<s", self.txComment)
|
||||
|
||||
return r
|
||||
|
||||
# Regular serialization is without witness -- must explicitly
|
||||
@ -1674,8 +1692,8 @@ class NodeConn(asyncore.dispatcher):
|
||||
b"blocktxn": msg_blocktxn
|
||||
}
|
||||
MAGIC_BYTES = {
|
||||
"mainnet": b"\xfb\xc0\xb6\xdb", # mainnet
|
||||
"testnet3": b"\xfc\xc1\xb7\xdc", # testnet3
|
||||
"mainnet": b"\xfd\xc0\xa5\xf1", # mainnet
|
||||
"testnet3": b"\xfd\xc0\x5a\xf2", # testnet3
|
||||
"regtest": b"\xfa\xbf\xb5\xda", # regtest
|
||||
}
|
||||
|
||||
|
||||
2
test/functional/test_framework/util.py
Normal file → Executable file
2
test/functional/test_framework/util.py
Normal file → Executable file
@ -24,7 +24,7 @@ logger = logging.getLogger("TestFramework.utils")
|
||||
|
||||
def assert_fee_amount(fee, tx_size, fee_per_kB):
|
||||
"""Assert the fee was in range"""
|
||||
target_fee = tx_size * fee_per_kB / 1000
|
||||
target_fee = round(tx_size * fee_per_kB / 1000,30)
|
||||
if fee < target_fee:
|
||||
raise AssertionError("Fee of %s BTC too low! (Should be %s BTC)" % (str(fee), str(target_fee)))
|
||||
# allow the wallet's estimation to be at most 2 bytes off
|
||||
|
||||
Loading…
Reference in New Issue
Block a user