Skip to content

Commit 97d8373

Browse files
committed
Merge pull request bitcoin#7153
7632cf6 [Tests] Refactor some shared functions (Jonas Schnelli) 110ff11 [Tests] Add mempool_limit.py test (Jonas Schnelli)
2 parents a1c185b + 7632cf6 commit 97d8373

File tree

4 files changed

+116
-49
lines changed

4 files changed

+116
-49
lines changed

qa/pull-tester/rpc-tests.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
'rest.py',
8686
'mempool_spendcoinbase.py',
8787
'mempool_reorg.py',
88+
'mempool_limit.py',
8889
'httpbasics.py',
8990
'multi_rpc.py',
9091
'zapwallettxes.py',

qa/rpc-tests/mempool_limit.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env python2
2+
# Copyright (c) 2014-2015 The Bitcoin Core developers
3+
# Distributed under the MIT software license, see the accompanying
4+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
6+
# Test mempool limiting together/eviction with the wallet
7+
8+
from test_framework.test_framework import BitcoinTestFramework
9+
from test_framework.util import *
10+
11+
class MempoolLimitTest(BitcoinTestFramework):
12+
13+
def __init__(self):
14+
# Some pre-processing to create a bunch of OP_RETURN txouts to insert into transactions we create
15+
# So we have big transactions (and therefore can't fit very many into each block)
16+
# create one script_pubkey
17+
script_pubkey = "6a4d0200" #OP_RETURN OP_PUSH2 512 bytes
18+
for i in xrange (512):
19+
script_pubkey = script_pubkey + "01"
20+
# concatenate 128 txouts of above script_pubkey which we'll insert before the txout for change
21+
self.txouts = "81"
22+
for k in xrange(128):
23+
# add txout value
24+
self.txouts = self.txouts + "0000000000000000"
25+
# add length of script_pubkey
26+
self.txouts = self.txouts + "fd0402"
27+
# add script_pubkey
28+
self.txouts = self.txouts + script_pubkey
29+
30+
def setup_network(self):
31+
self.nodes = []
32+
self.nodes.append(start_node(0, self.options.tmpdir, ["-maxmempool=5", "-spendzeroconfchange=0", "-debug"]))
33+
self.is_network_split = False
34+
self.sync_all()
35+
self.relayfee = self.nodes[0].getnetworkinfo()['relayfee']
36+
37+
def setup_chain(self):
38+
print("Initializing test directory "+self.options.tmpdir)
39+
initialize_chain_clean(self.options.tmpdir, 2)
40+
41+
def run_test(self):
42+
txids = []
43+
utxos = create_confirmed_utxos(self.relayfee, self.nodes[0], 90)
44+
45+
#create a mempool tx that will be evicted
46+
us0 = utxos.pop()
47+
inputs = [{ "txid" : us0["txid"], "vout" : us0["vout"]}]
48+
outputs = {self.nodes[0].getnewaddress() : 0.0001}
49+
tx = self.nodes[0].createrawtransaction(inputs, outputs)
50+
txF = self.nodes[0].fundrawtransaction(tx)
51+
txFS = self.nodes[0].signrawtransaction(txF['hex'])
52+
txid = self.nodes[0].sendrawtransaction(txFS['hex'])
53+
self.nodes[0].lockunspent(True, [us0])
54+
55+
relayfee = self.nodes[0].getnetworkinfo()['relayfee']
56+
base_fee = relayfee*100
57+
for i in xrange (4):
58+
txids.append([])
59+
txids[i] = create_lots_of_big_transactions(self.nodes[0], self.txouts, utxos[30*i:30*i+30], (i+1)*base_fee)
60+
61+
# by now, the tx should be evicted, check confirmation state
62+
assert(txid not in self.nodes[0].getrawmempool())
63+
txdata = self.nodes[0].gettransaction(txid);
64+
assert(txdata['confirmations'] == 0) #confirmation should still be 0
65+
66+
if __name__ == '__main__':
67+
MempoolLimitTest().main()

qa/rpc-tests/prioritise_transaction.py

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -42,62 +42,15 @@ def setup_network(self):
4242
self.nodes.append(start_node(0, self.options.tmpdir, ["-debug", "-printpriority=1"]))
4343
self.relayfee = self.nodes[0].getnetworkinfo()['relayfee']
4444

45-
def create_confirmed_utxos(self, count):
46-
self.nodes[0].generate(int(0.5*count)+101)
47-
utxos = self.nodes[0].listunspent()
48-
iterations = count - len(utxos)
49-
addr1 = self.nodes[0].getnewaddress()
50-
addr2 = self.nodes[0].getnewaddress()
51-
if iterations <= 0:
52-
return utxos
53-
for i in xrange(iterations):
54-
t = utxos.pop()
55-
fee = self.relayfee
56-
inputs = []
57-
inputs.append({ "txid" : t["txid"], "vout" : t["vout"]})
58-
outputs = {}
59-
send_value = t['amount'] - fee
60-
outputs[addr1] = satoshi_round(send_value/2)
61-
outputs[addr2] = satoshi_round(send_value/2)
62-
raw_tx = self.nodes[0].createrawtransaction(inputs, outputs)
63-
signed_tx = self.nodes[0].signrawtransaction(raw_tx)["hex"]
64-
txid = self.nodes[0].sendrawtransaction(signed_tx)
65-
66-
while (self.nodes[0].getmempoolinfo()['size'] > 0):
67-
self.nodes[0].generate(1)
68-
69-
utxos = self.nodes[0].listunspent()
70-
assert(len(utxos) >= count)
71-
return utxos
72-
73-
def create_lots_of_big_transactions(self, utxos, fee):
74-
addr = self.nodes[0].getnewaddress()
75-
txids = []
76-
for i in xrange(len(utxos)):
77-
t = utxos.pop()
78-
inputs = []
79-
inputs.append({ "txid" : t["txid"], "vout" : t["vout"]})
80-
outputs = {}
81-
send_value = t['amount'] - fee
82-
outputs[addr] = satoshi_round(send_value)
83-
rawtx = self.nodes[0].createrawtransaction(inputs, outputs)
84-
newtx = rawtx[0:92]
85-
newtx = newtx + self.txouts
86-
newtx = newtx + rawtx[94:]
87-
signresult = self.nodes[0].signrawtransaction(newtx, None, None, "NONE")
88-
txid = self.nodes[0].sendrawtransaction(signresult["hex"], True)
89-
txids.append(txid)
90-
return txids
91-
9245
def run_test(self):
93-
utxos = self.create_confirmed_utxos(90)
46+
utxos = create_confirmed_utxos(self.relayfee, self.nodes[0], 90)
9447
base_fee = self.relayfee*100 # our transactions are smaller than 100kb
9548
txids = []
9649

9750
# Create 3 batches of transactions at 3 different fee rate levels
9851
for i in xrange(3):
9952
txids.append([])
100-
txids[i] = self.create_lots_of_big_transactions(utxos[30*i:30*i+30], (i+1)*base_fee)
53+
txids[i] = create_lots_of_big_transactions(self.nodes[0], self.txouts, utxos[30*i:30*i+30], (i+1)*base_fee)
10154

10255
# add a fee delta to something in the cheapest bucket and make sure it gets mined
10356
# also check that a different entry in the cheapest bucket is NOT mined (lower

qa/rpc-tests/test_framework/util.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,3 +409,49 @@ def assert_raises(exc, fun, *args, **kwds):
409409

410410
def satoshi_round(amount):
411411
return Decimal(amount).quantize(Decimal('0.00000001'), rounding=ROUND_DOWN)
412+
413+
def create_confirmed_utxos(fee, node, count):
414+
node.generate(int(0.5*count)+101)
415+
utxos = node.listunspent()
416+
iterations = count - len(utxos)
417+
addr1 = node.getnewaddress()
418+
addr2 = node.getnewaddress()
419+
if iterations <= 0:
420+
return utxos
421+
for i in xrange(iterations):
422+
t = utxos.pop()
423+
inputs = []
424+
inputs.append({ "txid" : t["txid"], "vout" : t["vout"]})
425+
outputs = {}
426+
send_value = t['amount'] - fee
427+
outputs[addr1] = satoshi_round(send_value/2)
428+
outputs[addr2] = satoshi_round(send_value/2)
429+
raw_tx = node.createrawtransaction(inputs, outputs)
430+
signed_tx = node.signrawtransaction(raw_tx)["hex"]
431+
txid = node.sendrawtransaction(signed_tx)
432+
433+
while (node.getmempoolinfo()['size'] > 0):
434+
node.generate(1)
435+
436+
utxos = node.listunspent()
437+
assert(len(utxos) >= count)
438+
return utxos
439+
440+
def create_lots_of_big_transactions(node, txouts, utxos, fee):
441+
addr = node.getnewaddress()
442+
txids = []
443+
for i in xrange(len(utxos)):
444+
t = utxos.pop()
445+
inputs = []
446+
inputs.append({ "txid" : t["txid"], "vout" : t["vout"]})
447+
outputs = {}
448+
send_value = t['amount'] - fee
449+
outputs[addr] = satoshi_round(send_value)
450+
rawtx = node.createrawtransaction(inputs, outputs)
451+
newtx = rawtx[0:92]
452+
newtx = newtx + txouts
453+
newtx = newtx + rawtx[94:]
454+
signresult = node.signrawtransaction(newtx, None, None, "NONE")
455+
txid = node.sendrawtransaction(signresult["hex"], True)
456+
txids.append(txid)
457+
return txids

0 commit comments

Comments
 (0)