Skip to content

Commit

Permalink
Merge #7684: [qa] Extend tests
Browse files Browse the repository at this point in the history
fad8cfb [qa] mininode: Add and use CONSTs (MarcoFalke)
fa8cd46 [qa] Move create_tx() to util.py (MarcoFalke)
fad7dc8 [qa] wallet: speed up tests (MarcoFalke)
fa3a81a [tests] Extend util_ParseMoney test case (MarcoFalke)
  • Loading branch information
laanwj committed Mar 16, 2016
2 parents a6a8607 + fad8cfb commit 3d0dfdb
Show file tree
Hide file tree
Showing 16 changed files with 37 additions and 53 deletions.
1 change: 0 additions & 1 deletion qa/rpc-tests/bip68-sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from test_framework.mininode import *
from test_framework.blocktools import *

COIN = 100000000
SEQUENCE_LOCKTIME_DISABLE_FLAG = (1<<31)
SEQUENCE_LOCKTIME_TYPE_FLAG = (1<<22) # this means use time (0 means height)
SEQUENCE_LOCKTIME_GRANULARITY = 9 # this is a bit-shift
Expand Down
6 changes: 3 additions & 3 deletions qa/rpc-tests/invalidblockrequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ def get_tests(self):
self.block_time += 1

# chr(81) is OP_TRUE
tx1 = create_transaction(self.block1.vtx[0], 0, chr(81), 50*100000000)
tx2 = create_transaction(tx1, 0, chr(81), 50*100000000)
tx1 = create_transaction(self.block1.vtx[0], 0, chr(81), 50 * COIN)
tx2 = create_transaction(tx1, 0, chr(81), 50 * COIN)

block2.vtx.extend([tx1, tx2])
block2.hashMerkleRoot = block2.calc_merkle_root()
Expand All @@ -103,7 +103,7 @@ def get_tests(self):
'''
block3 = create_block(self.tip, create_coinbase(height), self.block_time)
self.block_time += 1
block3.vtx[0].vout[0].nValue = 100*100000000 # Too high!
block3.vtx[0].vout[0].nValue = 100 * COIN # Too high!
block3.vtx[0].sha256=None
block3.vtx[0].calc_sha256()
block3.hashMerkleRoot = block3.calc_merkle_root()
Expand Down
2 changes: 1 addition & 1 deletion qa/rpc-tests/invalidtxrequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def get_tests(self):

# chr(100) is OP_NOTIF
# Transaction will be rejected with code 16 (REJECT_INVALID)
tx1 = create_transaction(self.block1.vtx[0], 0, chr(100), 50*100000000 - 12000)
tx1 = create_transaction(self.block1.vtx[0], 0, chr(100), 50 * COIN - 12000)
yield TestInstance([[tx1, RejectResult(16, 'mandatory-script-verify-flag-failed')]])

# TODO: test further transactions...
Expand Down
4 changes: 2 additions & 2 deletions qa/rpc-tests/listtransactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import *
from test_framework.mininode import CTransaction
from test_framework.mininode import CTransaction, COIN
import cStringIO
import binascii

Expand Down Expand Up @@ -192,7 +192,7 @@ def get_unconfirmed_utxo_entry(node, txid_to_match):

# Replace tx3, and check that tx4 becomes unknown
tx3_b = tx3_modified
tx3_b.vout[0].nValue -= 0.004*100000000 # bump the fee
tx3_b.vout[0].nValue -= 0.004 * COIN # bump the fee
tx3_b = binascii.hexlify(tx3_b.serialize()).decode('utf-8')
tx3_b_signed = self.nodes[0].signrawtransaction(tx3_b)['hex']
txid_3b = self.nodes[0].sendrawtransaction(tx3_b_signed, True)
Expand Down
2 changes: 1 addition & 1 deletion qa/rpc-tests/maxuploadtarget.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def run_test(self):
getdata_request.inv.append(CInv(2, big_old_block))

max_bytes_per_day = 200*1024*1024
daily_buffer = 144 * 1000000
daily_buffer = 144 * MAX_BLOCK_SIZE
max_bytes_available = max_bytes_per_day - daily_buffer
success_count = max_bytes_available / old_block_size

Expand Down
7 changes: 3 additions & 4 deletions qa/rpc-tests/mempool_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,12 @@ def run_test(self):
descendant_count = 1
descendant_fees = 0
descendant_size = 0
SATOSHIS = 100000000

for x in reversed(chain):
assert_equal(mempool[x]['descendantcount'], descendant_count)
descendant_fees += mempool[x]['fee']
assert_equal(mempool[x]['modifiedfee'], mempool[x]['fee'])
assert_equal(mempool[x]['descendantfees'], SATOSHIS*descendant_fees)
assert_equal(mempool[x]['descendantfees'], descendant_fees * COIN)
descendant_size += mempool[x]['size']
assert_equal(mempool[x]['descendantsize'], descendant_size)
descendant_count += 1
Expand All @@ -78,7 +77,7 @@ def run_test(self):
descendant_fees = 0
for x in reversed(chain):
descendant_fees += mempool[x]['fee']
assert_equal(mempool[x]['descendantfees'], SATOSHIS*descendant_fees+1000)
assert_equal(mempool[x]['descendantfees'], descendant_fees * COIN + 1000)

# Adding one more transaction on to the chain should fail.
try:
Expand Down Expand Up @@ -106,7 +105,7 @@ def run_test(self):
descendant_fees += mempool[x]['fee']
if (x == chain[-1]):
assert_equal(mempool[x]['modifiedfee'], mempool[x]['fee']+satoshi_round(0.00002))
assert_equal(mempool[x]['descendantfees'], SATOSHIS*descendant_fees+2000)
assert_equal(mempool[x]['descendantfees'], descendant_fees * COIN + 2000)

# TODO: check that node1's mempool is as expected

Expand Down
18 changes: 5 additions & 13 deletions qa/rpc-tests/mempool_reorg.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@ def setup_network(self):
self.is_network_split = False
self.sync_all()

def create_tx(self, from_txid, to_address, amount):
inputs = [{ "txid" : from_txid, "vout" : 0}]
outputs = { to_address : amount }
rawtx = self.nodes[0].createrawtransaction(inputs, outputs)
signresult = self.nodes[0].signrawtransaction(rawtx)
assert_equal(signresult["complete"], True)
return signresult["hex"]

def run_test(self):
start_count = self.nodes[0].getblockcount()

Expand All @@ -52,9 +44,9 @@ def run_test(self):
# 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 = self.create_tx(coinbase_txids[1], node1_address, 49.99)
spend_102_raw = self.create_tx(coinbase_txids[2], node0_address, 49.99)
spend_103_raw = self.create_tx(coinbase_txids[3], node0_address, 49.99)
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)

# Create a block-height-locked transaction which will be invalid after reorg
timelock_tx = self.nodes[0].createrawtransaction([{"txid": coinbase_txids[0], "vout": 0}], {node0_address: 49.99})
Expand All @@ -71,8 +63,8 @@ def run_test(self):
assert_raises(JSONRPCException, self.nodes[0].sendrawtransaction, timelock_tx)

# Create 102_1 and 103_1:
spend_102_1_raw = self.create_tx(spend_102_id, node1_address, 49.98)
spend_103_1_raw = self.create_tx(spend_103_id, node1_address, 49.98)
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)

# Broadcast and mine 103_1:
spend_103_1_id = self.nodes[0].sendrawtransaction(spend_103_1_raw)
Expand Down
12 changes: 2 additions & 10 deletions qa/rpc-tests/mempool_resurrect_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@ def setup_network(self):
self.nodes.append(start_node(0, self.options.tmpdir, args))
self.is_network_split = False

def create_tx(self, from_txid, to_address, amount):
inputs = [{ "txid" : from_txid, "vout" : 0}]
outputs = { to_address : amount }
rawtx = self.nodes[0].createrawtransaction(inputs, outputs)
signresult = self.nodes[0].signrawtransaction(rawtx)
assert_equal(signresult["complete"], True)
return signresult["hex"]

def run_test(self):
node0_address = self.nodes[0].getnewaddress()
# Spend block 1/2/3's coinbase transactions
Expand All @@ -43,13 +35,13 @@ def run_test(self):

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 = [ self.create_tx(txid, node0_address, 49.99) for txid in coinbase_txids ]
spends1_raw = [ create_tx(self.nodes[0], txid, node0_address, 49.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 = [ self.create_tx(txid, node0_address, 49.98) for txid in spends1_id ]
spends2_raw = [ create_tx(self.nodes[0], txid, node0_address, 49.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))
Expand Down
10 changes: 1 addition & 9 deletions qa/rpc-tests/mempool_spendcoinbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@ def setup_network(self):
self.nodes.append(start_node(0, self.options.tmpdir, args))
self.is_network_split = False

def create_tx(self, from_txid, to_address, amount):
inputs = [{ "txid" : from_txid, "vout" : 0}]
outputs = { to_address : amount }
rawtx = self.nodes[0].createrawtransaction(inputs, outputs)
signresult = self.nodes[0].signrawtransaction(rawtx)
assert_equal(signresult["complete"], True)
return signresult["hex"]

def run_test(self):
chain_height = self.nodes[0].getblockcount()
assert_equal(chain_height, 200)
Expand All @@ -44,7 +36,7 @@ def run_test(self):
# 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 = [ self.create_tx(txid, node0_address, 49.99) for txid in coinbase_txids ]
spends_raw = [ create_tx(self.nodes[0], txid, node0_address, 49.99) for txid in coinbase_txids ]

spend_101_id = self.nodes[0].sendrawtransaction(spends_raw[0])

Expand Down
2 changes: 1 addition & 1 deletion qa/rpc-tests/prioritise_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import *
from test_framework.mininode import COIN

COIN = 100000000

class PrioritiseTransactionTest(BitcoinTestFramework):

Expand Down
1 change: 0 additions & 1 deletion qa/rpc-tests/replace-by-fee.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from test_framework.mininode import *
import binascii

COIN = 100000000
MAX_REPLACEMENT_LIMIT = 100

def satoshi_round(amount):
Expand Down
2 changes: 1 addition & 1 deletion qa/rpc-tests/test_framework/blocktools.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,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*100000000
coinbaseoutput.nValue = 50 * COIN
halvings = int(height/150) # regtest
coinbaseoutput.nValue >>= halvings
if (pubkey != None):
Expand Down
6 changes: 4 additions & 2 deletions qa/rpc-tests/test_framework/mininode.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
MAX_INV_SZ = 50000
MAX_BLOCK_SIZE = 1000000

COIN = 100000000L # 1 btc in satoshis

# Keep our own socket map for asyncore, so that we can track disconnects
# ourselves (to workaround an issue with closing an asyncore socket when
# using select)
Expand Down Expand Up @@ -377,7 +379,7 @@ def serialize(self):

def __repr__(self):
return "CTxOut(nValue=%i.%08i scriptPubKey=%s)" \
% (self.nValue // 100000000, self.nValue % 100000000,
% (self.nValue // COIN, self.nValue % COIN,
binascii.hexlify(self.scriptPubKey))


Expand Down Expand Up @@ -426,7 +428,7 @@ def calc_sha256(self):
def is_valid(self):
self.calc_sha256()
for tout in self.vout:
if tout.nValue < 0 or tout.nValue > 21000000L * 100000000L:
if tout.nValue < 0 or tout.nValue > 21000000 * COIN:
return False
return True

Expand Down
8 changes: 8 additions & 0 deletions qa/rpc-tests/test_framework/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,14 @@ def gen_return_txouts():
txouts = txouts + script_pubkey
return txouts

def create_tx(node, coinbase, to_address, amount):
inputs = [{ "txid" : coinbase, "vout" : 0}]
outputs = { to_address : amount }
rawtx = node.createrawtransaction(inputs, outputs)
signresult = node.signrawtransaction(rawtx)
assert_equal(signresult["complete"], True)
return signresult["hex"]

def create_lots_of_big_transactions(node, txouts, utxos, fee):
addr = node.getnewaddress()
txids = []
Expand Down
4 changes: 0 additions & 4 deletions qa/rpc-tests/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,6 @@ def run_test (self):
stop_nodes(self.nodes)
wait_bitcoinds()
self.nodes = start_nodes(3, self.options.tmpdir, [[m]] * 3)
connect_nodes_bi(self.nodes,0,1)
connect_nodes_bi(self.nodes,1,2)
connect_nodes_bi(self.nodes,0,2)
self.sync_all()
assert_equal(balance_nodes, [self.nodes[i].getbalance() for i in range(3)])


Expand Down
5 changes: 5 additions & 0 deletions src/test/util_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ BOOST_AUTO_TEST_CASE(util_ParseMoney)
BOOST_CHECK_EQUAL(ret, COIN*10);
BOOST_CHECK(ParseMoney("1.00", ret));
BOOST_CHECK_EQUAL(ret, COIN);
BOOST_CHECK(ParseMoney("1", ret));
BOOST_CHECK_EQUAL(ret, COIN);
BOOST_CHECK(ParseMoney("0.1", ret));
BOOST_CHECK_EQUAL(ret, COIN/10);
BOOST_CHECK(ParseMoney("0.01", ret));
Expand All @@ -219,6 +221,9 @@ BOOST_AUTO_TEST_CASE(util_ParseMoney)

// Attempted 63 bit overflow should fail
BOOST_CHECK(!ParseMoney("92233720368.54775808", ret));

// Parsing negative amounts must fail
BOOST_CHECK(!ParseMoney("-1", ret));
}

BOOST_AUTO_TEST_CASE(util_IsHex)
Expand Down

0 comments on commit 3d0dfdb

Please sign in to comment.