Skip to content

Commit 3d0dfdb

Browse files
committed
Merge #7684: [qa] Extend tests
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)
2 parents a6a8607 + fad8cfb commit 3d0dfdb

16 files changed

+37
-53
lines changed

qa/rpc-tests/bip68-sequence.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from test_framework.mininode import *
1414
from test_framework.blocktools import *
1515

16-
COIN = 100000000
1716
SEQUENCE_LOCKTIME_DISABLE_FLAG = (1<<31)
1817
SEQUENCE_LOCKTIME_TYPE_FLAG = (1<<22) # this means use time (0 means height)
1918
SEQUENCE_LOCKTIME_GRANULARITY = 9 # this is a bit-shift

qa/rpc-tests/invalidblockrequest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ def get_tests(self):
7878
self.block_time += 1
7979

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

8484
block2.vtx.extend([tx1, tx2])
8585
block2.hashMerkleRoot = block2.calc_merkle_root()
@@ -103,7 +103,7 @@ def get_tests(self):
103103
'''
104104
block3 = create_block(self.tip, create_coinbase(height), self.block_time)
105105
self.block_time += 1
106-
block3.vtx[0].vout[0].nValue = 100*100000000 # Too high!
106+
block3.vtx[0].vout[0].nValue = 100 * COIN # Too high!
107107
block3.vtx[0].sha256=None
108108
block3.vtx[0].calc_sha256()
109109
block3.hashMerkleRoot = block3.calc_merkle_root()

qa/rpc-tests/invalidtxrequest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def get_tests(self):
6363

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

6969
# TODO: test further transactions...

qa/rpc-tests/listtransactions.py

Lines changed: 2 additions & 2 deletions
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
10+
from test_framework.mininode import CTransaction, COIN
1111
import cStringIO
1212
import binascii
1313

@@ -192,7 +192,7 @@ def get_unconfirmed_utxo_entry(node, txid_to_match):
192192

193193
# Replace tx3, and check that tx4 becomes unknown
194194
tx3_b = tx3_modified
195-
tx3_b.vout[0].nValue -= 0.004*100000000 # bump the fee
195+
tx3_b.vout[0].nValue -= 0.004 * COIN # bump the fee
196196
tx3_b = binascii.hexlify(tx3_b.serialize()).decode('utf-8')
197197
tx3_b_signed = self.nodes[0].signrawtransaction(tx3_b)['hex']
198198
txid_3b = self.nodes[0].sendrawtransaction(tx3_b_signed, True)

qa/rpc-tests/maxuploadtarget.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def run_test(self):
176176
getdata_request.inv.append(CInv(2, big_old_block))
177177

178178
max_bytes_per_day = 200*1024*1024
179-
daily_buffer = 144 * 1000000
179+
daily_buffer = 144 * MAX_BLOCK_SIZE
180180
max_bytes_available = max_bytes_per_day - daily_buffer
181181
success_count = max_bytes_available / old_block_size
182182

qa/rpc-tests/mempool_packages.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,12 @@ def run_test(self):
5959
descendant_count = 1
6060
descendant_fees = 0
6161
descendant_size = 0
62-
SATOSHIS = 100000000
6362

6463
for x in reversed(chain):
6564
assert_equal(mempool[x]['descendantcount'], descendant_count)
6665
descendant_fees += mempool[x]['fee']
6766
assert_equal(mempool[x]['modifiedfee'], mempool[x]['fee'])
68-
assert_equal(mempool[x]['descendantfees'], SATOSHIS*descendant_fees)
67+
assert_equal(mempool[x]['descendantfees'], descendant_fees * COIN)
6968
descendant_size += mempool[x]['size']
7069
assert_equal(mempool[x]['descendantsize'], descendant_size)
7170
descendant_count += 1
@@ -78,7 +77,7 @@ def run_test(self):
7877
descendant_fees = 0
7978
for x in reversed(chain):
8079
descendant_fees += mempool[x]['fee']
81-
assert_equal(mempool[x]['descendantfees'], SATOSHIS*descendant_fees+1000)
80+
assert_equal(mempool[x]['descendantfees'], descendant_fees * COIN + 1000)
8281

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

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

qa/rpc-tests/mempool_reorg.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,6 @@ def setup_network(self):
2525
self.is_network_split = False
2626
self.sync_all()
2727

28-
def create_tx(self, from_txid, to_address, amount):
29-
inputs = [{ "txid" : from_txid, "vout" : 0}]
30-
outputs = { to_address : amount }
31-
rawtx = self.nodes[0].createrawtransaction(inputs, outputs)
32-
signresult = self.nodes[0].signrawtransaction(rawtx)
33-
assert_equal(signresult["complete"], True)
34-
return signresult["hex"]
35-
3628
def run_test(self):
3729
start_count = self.nodes[0].getblockcount()
3830

@@ -52,9 +44,9 @@ def run_test(self):
5244
# and make sure the mempool code behaves correctly.
5345
b = [ self.nodes[0].getblockhash(n) for n in range(101, 105) ]
5446
coinbase_txids = [ self.nodes[0].getblock(h)['tx'][0] for h in b ]
55-
spend_101_raw = self.create_tx(coinbase_txids[1], node1_address, 49.99)
56-
spend_102_raw = self.create_tx(coinbase_txids[2], node0_address, 49.99)
57-
spend_103_raw = self.create_tx(coinbase_txids[3], node0_address, 49.99)
47+
spend_101_raw = create_tx(self.nodes[0], coinbase_txids[1], node1_address, 49.99)
48+
spend_102_raw = create_tx(self.nodes[0], coinbase_txids[2], node0_address, 49.99)
49+
spend_103_raw = create_tx(self.nodes[0], coinbase_txids[3], node0_address, 49.99)
5850

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

7365
# Create 102_1 and 103_1:
74-
spend_102_1_raw = self.create_tx(spend_102_id, node1_address, 49.98)
75-
spend_103_1_raw = self.create_tx(spend_103_id, node1_address, 49.98)
66+
spend_102_1_raw = create_tx(self.nodes[0], spend_102_id, node1_address, 49.98)
67+
spend_103_1_raw = create_tx(self.nodes[0], spend_103_id, node1_address, 49.98)
7668

7769
# Broadcast and mine 103_1:
7870
spend_103_1_id = self.nodes[0].sendrawtransaction(spend_103_1_raw)

qa/rpc-tests/mempool_resurrect_test.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,6 @@ def setup_network(self):
2121
self.nodes.append(start_node(0, self.options.tmpdir, args))
2222
self.is_network_split = False
2323

24-
def create_tx(self, from_txid, to_address, amount):
25-
inputs = [{ "txid" : from_txid, "vout" : 0}]
26-
outputs = { to_address : amount }
27-
rawtx = self.nodes[0].createrawtransaction(inputs, outputs)
28-
signresult = self.nodes[0].signrawtransaction(rawtx)
29-
assert_equal(signresult["complete"], True)
30-
return signresult["hex"]
31-
3224
def run_test(self):
3325
node0_address = self.nodes[0].getnewaddress()
3426
# Spend block 1/2/3's coinbase transactions
@@ -43,13 +35,13 @@ def run_test(self):
4335

4436
b = [ self.nodes[0].getblockhash(n) for n in range(1, 4) ]
4537
coinbase_txids = [ self.nodes[0].getblock(h)['tx'][0] for h in b ]
46-
spends1_raw = [ self.create_tx(txid, node0_address, 49.99) for txid in coinbase_txids ]
38+
spends1_raw = [ create_tx(self.nodes[0], txid, node0_address, 49.99) for txid in coinbase_txids ]
4739
spends1_id = [ self.nodes[0].sendrawtransaction(tx) for tx in spends1_raw ]
4840

4941
blocks = []
5042
blocks.extend(self.nodes[0].generate(1))
5143

52-
spends2_raw = [ self.create_tx(txid, node0_address, 49.98) for txid in spends1_id ]
44+
spends2_raw = [ create_tx(self.nodes[0], txid, node0_address, 49.98) for txid in spends1_id ]
5345
spends2_id = [ self.nodes[0].sendrawtransaction(tx) for tx in spends2_raw ]
5446

5547
blocks.extend(self.nodes[0].generate(1))

qa/rpc-tests/mempool_spendcoinbase.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,6 @@ def setup_network(self):
2626
self.nodes.append(start_node(0, self.options.tmpdir, args))
2727
self.is_network_split = False
2828

29-
def create_tx(self, from_txid, to_address, amount):
30-
inputs = [{ "txid" : from_txid, "vout" : 0}]
31-
outputs = { to_address : amount }
32-
rawtx = self.nodes[0].createrawtransaction(inputs, outputs)
33-
signresult = self.nodes[0].signrawtransaction(rawtx)
34-
assert_equal(signresult["complete"], True)
35-
return signresult["hex"]
36-
3729
def run_test(self):
3830
chain_height = self.nodes[0].getblockcount()
3931
assert_equal(chain_height, 200)
@@ -44,7 +36,7 @@ def run_test(self):
4436
# is too immature to spend.
4537
b = [ self.nodes[0].getblockhash(n) for n in range(101, 103) ]
4638
coinbase_txids = [ self.nodes[0].getblock(h)['tx'][0] for h in b ]
47-
spends_raw = [ self.create_tx(txid, node0_address, 49.99) for txid in coinbase_txids ]
39+
spends_raw = [ create_tx(self.nodes[0], txid, node0_address, 49.99) for txid in coinbase_txids ]
4840

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

qa/rpc-tests/prioritise_transaction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
from test_framework.test_framework import BitcoinTestFramework
1111
from test_framework.util import *
12+
from test_framework.mininode import COIN
1213

13-
COIN = 100000000
1414

1515
class PrioritiseTransactionTest(BitcoinTestFramework):
1616

0 commit comments

Comments
 (0)