Skip to content

Commit fa7d71f

Browse files
author
MarcoFalke
committed
test: Run pep-8 on touched test
Can be reviewed with --ignore-all-space
1 parent fab7e99 commit fa7d71f

File tree

1 file changed

+41
-39
lines changed

1 file changed

+41
-39
lines changed

test/functional/feature_rbf.py

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
def txToHex(tx):
2121
return tx.serialize().hex()
2222

23+
2324
def make_utxo(node, amount, confirmed=True, scriptPubKey=DUMMY_P2WPKH_SCRIPT):
2425
"""Create a txout with a given amount and scriptPubKey
2526
@@ -28,12 +29,12 @@ def make_utxo(node, amount, confirmed=True, scriptPubKey=DUMMY_P2WPKH_SCRIPT):
2829
confirmed - txouts created will be confirmed in the blockchain;
2930
unconfirmed otherwise.
3031
"""
31-
fee = 1*COIN
32-
while node.getbalance() < satoshi_round((amount + fee)/COIN):
32+
fee = 1 * COIN
33+
while node.getbalance() < satoshi_round((amount + fee) / COIN):
3334
node.generate(COINBASE_MATURITY)
3435

3536
new_addr = node.getnewaddress()
36-
txid = node.sendtoaddress(new_addr, satoshi_round((amount+fee)/COIN))
37+
txid = node.sendtoaddress(new_addr, satoshi_round((amount + fee) / COIN))
3738
tx1 = node.getrawtransaction(txid, 1)
3839
txid = int(txid, 16)
3940
i, _ = next(filter(lambda vout: new_addr == vout[1]['scriptPubKey']['address'], enumerate(tx1['vout'])))
@@ -80,7 +81,7 @@ def skip_test_if_missing_module(self):
8081
self.skip_if_no_wallet()
8182

8283
def run_test(self):
83-
make_utxo(self.nodes[0], 1*COIN)
84+
make_utxo(self.nodes[0], 1 * COIN)
8485

8586
# Ensure nodes are synced
8687
self.sync_all()
@@ -122,7 +123,7 @@ def run_test(self):
122123

123124
def test_simple_doublespend(self):
124125
"""Simple doublespend"""
125-
tx0_outpoint = make_utxo(self.nodes[0], int(1.1*COIN))
126+
tx0_outpoint = make_utxo(self.nodes[0], int(1.1 * COIN))
126127

127128
# make_utxo may have generated a bunch of blocks, so we need to sync
128129
# before we can spend the coins generated, or else the resulting
@@ -164,14 +165,14 @@ def test_simple_doublespend(self):
164165
def test_doublespend_chain(self):
165166
"""Doublespend of a long chain"""
166167

167-
initial_nValue = 50*COIN
168+
initial_nValue = 50 * COIN
168169
tx0_outpoint = make_utxo(self.nodes[0], initial_nValue)
169170

170171
prevout = tx0_outpoint
171172
remaining_value = initial_nValue
172173
chain_txids = []
173-
while remaining_value > 10*COIN:
174-
remaining_value -= 1*COIN
174+
while remaining_value > 10 * COIN:
175+
remaining_value -= 1 * COIN
175176
tx = CTransaction()
176177
tx.vin = [CTxIn(prevout, nSequence=0)]
177178
tx.vout = [CTxOut(remaining_value, CScript([1, OP_DROP] * 15 + [1]))]
@@ -204,10 +205,10 @@ def test_doublespend_chain(self):
204205
def test_doublespend_tree(self):
205206
"""Doublespend of a big tree of transactions"""
206207

207-
initial_nValue = 50*COIN
208+
initial_nValue = 50 * COIN
208209
tx0_outpoint = make_utxo(self.nodes[0], initial_nValue)
209210

210-
def branch(prevout, initial_value, max_txs, tree_width=5, fee=0.0001*COIN, _total_txs=None):
211+
def branch(prevout, initial_value, max_txs, tree_width=5, fee=0.0001 * COIN, _total_txs=None):
211212
if _total_txs is None:
212213
_total_txs = [0]
213214
if _total_txs[0] >= max_txs:
@@ -238,7 +239,7 @@ def branch(prevout, initial_value, max_txs, tree_width=5, fee=0.0001*COIN, _tota
238239
_total_txs=_total_txs):
239240
yield x
240241

241-
fee = int(0.0001*COIN)
242+
fee = int(0.0001 * COIN)
242243
n = MAX_REPLACEMENT_LIMIT
243244
tree_txs = list(branch(tx0_outpoint, initial_nValue, n, fee=fee))
244245
assert_equal(len(tree_txs), n)
@@ -266,8 +267,8 @@ def branch(prevout, initial_value, max_txs, tree_width=5, fee=0.0001*COIN, _tota
266267

267268
# Try again, but with more total transactions than the "max txs
268269
# double-spent at once" anti-DoS limit.
269-
for n in (MAX_REPLACEMENT_LIMIT+1, MAX_REPLACEMENT_LIMIT*2):
270-
fee = int(0.0001*COIN)
270+
for n in (MAX_REPLACEMENT_LIMIT + 1, MAX_REPLACEMENT_LIMIT * 2):
271+
fee = int(0.0001 * COIN)
271272
tx0_outpoint = make_utxo(self.nodes[0], initial_nValue)
272273
tree_txs = list(branch(tx0_outpoint, initial_nValue, n, fee=fee))
273274
assert_equal(len(tree_txs), n)
@@ -285,7 +286,7 @@ def branch(prevout, initial_value, max_txs, tree_width=5, fee=0.0001*COIN, _tota
285286

286287
def test_replacement_feeperkb(self):
287288
"""Replacement requires fee-per-KB to be higher"""
288-
tx0_outpoint = make_utxo(self.nodes[0], int(1.1*COIN))
289+
tx0_outpoint = make_utxo(self.nodes[0], int(1.1 * COIN))
289290

290291
tx1a = CTransaction()
291292
tx1a.vin = [CTxIn(tx0_outpoint, nSequence=0)]
@@ -297,16 +298,16 @@ def test_replacement_feeperkb(self):
297298
# rejected.
298299
tx1b = CTransaction()
299300
tx1b.vin = [CTxIn(tx0_outpoint, nSequence=0)]
300-
tx1b.vout = [CTxOut(int(0.001*COIN), CScript([b'a'*999000]))]
301+
tx1b.vout = [CTxOut(int(0.001 * COIN), CScript([b'a' * 999000]))]
301302
tx1b_hex = txToHex(tx1b)
302303

303304
# This will raise an exception due to insufficient fee
304305
assert_raises_rpc_error(-26, "insufficient fee", self.nodes[0].sendrawtransaction, tx1b_hex, 0)
305306

306307
def test_spends_of_conflicting_outputs(self):
307308
"""Replacements that spend conflicting tx outputs are rejected"""
308-
utxo1 = make_utxo(self.nodes[0], int(1.2*COIN))
309-
utxo2 = make_utxo(self.nodes[0], 3*COIN)
309+
utxo1 = make_utxo(self.nodes[0], int(1.2 * COIN))
310+
utxo2 = make_utxo(self.nodes[0], 3 * COIN)
310311

311312
tx1a = CTransaction()
312313
tx1a.vin = [CTxIn(utxo1, nSequence=0)]
@@ -345,8 +346,8 @@ def test_spends_of_conflicting_outputs(self):
345346

346347
def test_new_unconfirmed_inputs(self):
347348
"""Replacements that add new unconfirmed inputs are rejected"""
348-
confirmed_utxo = make_utxo(self.nodes[0], int(1.1*COIN))
349-
unconfirmed_utxo = make_utxo(self.nodes[0], int(0.1*COIN), False)
349+
confirmed_utxo = make_utxo(self.nodes[0], int(1.1 * COIN))
350+
unconfirmed_utxo = make_utxo(self.nodes[0], int(0.1 * COIN), False)
350351

351352
tx1 = CTransaction()
352353
tx1.vin = [CTxIn(confirmed_utxo)]
@@ -368,13 +369,13 @@ def test_too_many_replacements(self):
368369
# transactions
369370

370371
# Start by creating a single transaction with many outputs
371-
initial_nValue = 10*COIN
372+
initial_nValue = 10 * COIN
372373
utxo = make_utxo(self.nodes[0], initial_nValue)
373-
fee = int(0.0001*COIN)
374-
split_value = int((initial_nValue-fee)/(MAX_REPLACEMENT_LIMIT+1))
374+
fee = int(0.0001 * COIN)
375+
split_value = int((initial_nValue - fee) / (MAX_REPLACEMENT_LIMIT + 1))
375376

376377
outputs = []
377-
for _ in range(MAX_REPLACEMENT_LIMIT+1):
378+
for _ in range(MAX_REPLACEMENT_LIMIT + 1):
378379
outputs.append(CTxOut(split_value, CScript([1])))
379380

380381
splitting_tx = CTransaction()
@@ -386,7 +387,7 @@ def test_too_many_replacements(self):
386387
txid = int(txid, 16)
387388

388389
# Now spend each of those outputs individually
389-
for i in range(MAX_REPLACEMENT_LIMIT+1):
390+
for i in range(MAX_REPLACEMENT_LIMIT + 1):
390391
tx_i = CTransaction()
391392
tx_i.vin = [CTxIn(COutPoint(txid, i), nSequence=0)]
392393
tx_i.vout = [CTxOut(split_value - fee, DUMMY_P2WPKH_SCRIPT)]
@@ -396,9 +397,9 @@ def test_too_many_replacements(self):
396397
# Now create doublespend of the whole lot; should fail.
397398
# Need a big enough fee to cover all spending transactions and have
398399
# a higher fee rate
399-
double_spend_value = (split_value-100*fee)*(MAX_REPLACEMENT_LIMIT+1)
400+
double_spend_value = (split_value - 100 * fee) * (MAX_REPLACEMENT_LIMIT + 1)
400401
inputs = []
401-
for i in range(MAX_REPLACEMENT_LIMIT+1):
402+
for i in range(MAX_REPLACEMENT_LIMIT + 1):
402403
inputs.append(CTxIn(COutPoint(txid, i), nSequence=0))
403404
double_tx = CTransaction()
404405
double_tx.vin = inputs
@@ -417,7 +418,7 @@ def test_too_many_replacements(self):
417418

418419
def test_opt_in(self):
419420
"""Replacing should only work if orig tx opted in"""
420-
tx0_outpoint = make_utxo(self.nodes[0], int(1.1*COIN))
421+
tx0_outpoint = make_utxo(self.nodes[0], int(1.1 * COIN))
421422

422423
# Create a non-opting in transaction
423424
tx1a = CTransaction()
@@ -438,7 +439,7 @@ def test_opt_in(self):
438439
# This will raise an exception
439440
assert_raises_rpc_error(-26, "txn-mempool-conflict", self.nodes[0].sendrawtransaction, tx1b_hex, 0)
440441

441-
tx1_outpoint = make_utxo(self.nodes[0], int(1.1*COIN))
442+
tx1_outpoint = make_utxo(self.nodes[0], int(1.1 * COIN))
442443

443444
# Create a different non-opting in transaction
444445
tx2a = CTransaction()
@@ -466,7 +467,7 @@ def test_opt_in(self):
466467
tx3a = CTransaction()
467468
tx3a.vin = [CTxIn(COutPoint(tx1a_txid, 0), nSequence=0xffffffff),
468469
CTxIn(COutPoint(tx2a_txid, 0), nSequence=0xfffffffd)]
469-
tx3a.vout = [CTxOut(int(0.9*COIN), CScript([b'c'])), CTxOut(int(0.9*COIN), CScript([b'd']))]
470+
tx3a.vout = [CTxOut(int(0.9 * COIN), CScript([b'c'])), CTxOut(int(0.9 * COIN), CScript([b'd']))]
470471
tx3a_hex = txToHex(tx3a)
471472

472473
tx3a_txid = self.nodes[0].sendrawtransaction(tx3a_hex, 0)
@@ -494,7 +495,7 @@ def test_prioritised_transactions(self):
494495
# correctly used by replacement logic
495496

496497
# 1. Check that feeperkb uses modified fees
497-
tx0_outpoint = make_utxo(self.nodes[0], int(1.1*COIN))
498+
tx0_outpoint = make_utxo(self.nodes[0], int(1.1 * COIN))
498499

499500
tx1a = CTransaction()
500501
tx1a.vin = [CTxIn(tx0_outpoint, nSequence=0)]
@@ -505,22 +506,22 @@ def test_prioritised_transactions(self):
505506
# Higher fee, but the actual fee per KB is much lower.
506507
tx1b = CTransaction()
507508
tx1b.vin = [CTxIn(tx0_outpoint, nSequence=0)]
508-
tx1b.vout = [CTxOut(int(0.001*COIN), CScript([b'a'*740000]))]
509+
tx1b.vout = [CTxOut(int(0.001 * COIN), CScript([b'a' * 740000]))]
509510
tx1b_hex = txToHex(tx1b)
510511

511512
# Verify tx1b cannot replace tx1a.
512513
assert_raises_rpc_error(-26, "insufficient fee", self.nodes[0].sendrawtransaction, tx1b_hex, 0)
513514

514515
# Use prioritisetransaction to set tx1a's fee to 0.
515-
self.nodes[0].prioritisetransaction(txid=tx1a_txid, fee_delta=int(-0.1*COIN))
516+
self.nodes[0].prioritisetransaction(txid=tx1a_txid, fee_delta=int(-0.1 * COIN))
516517

517518
# Now tx1b should be able to replace tx1a
518519
tx1b_txid = self.nodes[0].sendrawtransaction(tx1b_hex, 0)
519520

520521
assert tx1b_txid in self.nodes[0].getrawmempool()
521522

522523
# 2. Check that absolute fee checks use modified fee.
523-
tx1_outpoint = make_utxo(self.nodes[0], int(1.1*COIN))
524+
tx1_outpoint = make_utxo(self.nodes[0], int(1.1 * COIN))
524525

525526
tx2a = CTransaction()
526527
tx2a.vin = [CTxIn(tx1_outpoint, nSequence=0)]
@@ -539,7 +540,7 @@ def test_prioritised_transactions(self):
539540
assert_raises_rpc_error(-26, "insufficient fee", self.nodes[0].sendrawtransaction, tx2b_hex, 0)
540541

541542
# Now prioritise tx2b to have a higher modified fee
542-
self.nodes[0].prioritisetransaction(txid=tx2b.hash, fee_delta=int(0.1*COIN))
543+
self.nodes[0].prioritisetransaction(txid=tx2b.hash, fee_delta=int(0.1 * COIN))
543544

544545
# tx2b should now be accepted
545546
tx2b_txid = self.nodes[0].sendrawtransaction(tx2b_hex, 0)
@@ -549,20 +550,20 @@ def test_prioritised_transactions(self):
549550
def test_rpc(self):
550551
us0 = self.nodes[0].listunspent()[0]
551552
ins = [us0]
552-
outs = {self.nodes[0].getnewaddress() : Decimal(1.0000000)}
553+
outs = {self.nodes[0].getnewaddress(): Decimal(1.0000000)}
553554
rawtx0 = self.nodes[0].createrawtransaction(ins, outs, 0, True)
554555
rawtx1 = self.nodes[0].createrawtransaction(ins, outs, 0, False)
555-
json0 = self.nodes[0].decoderawtransaction(rawtx0)
556-
json1 = self.nodes[0].decoderawtransaction(rawtx1)
556+
json0 = self.nodes[0].decoderawtransaction(rawtx0)
557+
json1 = self.nodes[0].decoderawtransaction(rawtx1)
557558
assert_equal(json0["vin"][0]["sequence"], 4294967293)
558559
assert_equal(json1["vin"][0]["sequence"], 4294967295)
559560

560561
rawtx2 = self.nodes[0].createrawtransaction([], outs)
561562
frawtx2a = self.nodes[0].fundrawtransaction(rawtx2, {"replaceable": True})
562563
frawtx2b = self.nodes[0].fundrawtransaction(rawtx2, {"replaceable": False})
563564

564-
json0 = self.nodes[0].decoderawtransaction(frawtx2a['hex'])
565-
json1 = self.nodes[0].decoderawtransaction(frawtx2b['hex'])
565+
json0 = self.nodes[0].decoderawtransaction(frawtx2a['hex'])
566+
json1 = self.nodes[0].decoderawtransaction(frawtx2b['hex'])
566567
assert_equal(json0["vin"][0]["sequence"], 4294967293)
567568
assert_equal(json1["vin"][0]["sequence"], 4294967294)
568569

@@ -623,5 +624,6 @@ def test_no_inherited_signaling(self):
623624
assert_equal(True, self.nodes[0].getmempoolentry(optin_parent_tx['txid'])['bip125-replaceable'])
624625
assert_raises_rpc_error(-26, 'txn-mempool-conflict', self.nodes[0].sendrawtransaction, replacement_child_tx["hex"], 0)
625626

627+
626628
if __name__ == '__main__':
627629
ReplaceByFeeTest().main()

0 commit comments

Comments
 (0)