Skip to content

Commit

Permalink
qa: Style-only fixes in touched files
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoFalke committed Jan 25, 2019
1 parent 003a47f commit fa21983
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
33 changes: 21 additions & 12 deletions test/functional/wallet_abandonconflict.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@
from decimal import Decimal

from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, assert_raises_rpc_error, connect_nodes, disconnect_nodes, sync_blocks, sync_mempools
from test_framework.util import (
assert_equal,
assert_raises_rpc_error,
connect_nodes,
disconnect_nodes,
sync_blocks,
sync_mempools,
)


class AbandonConflictTest(BitcoinTestFramework):
def set_test_params(self):
Expand All @@ -40,7 +48,7 @@ def run_test(self):

sync_blocks(self.nodes)
newbalance = self.nodes[0].getbalance()
assert(balance - newbalance < Decimal("0.001")) #no more than fees lost
assert balance - newbalance < Decimal("0.001") #no more than fees lost
balance = newbalance

# Disconnect nodes so node0's transactions don't get into node1's mempool
Expand All @@ -51,10 +59,10 @@ def run_test(self):
nB = next(i for i, vout in enumerate(self.nodes[0].getrawtransaction(txB, 1)["vout"]) if vout["value"] == Decimal("10"))
nC = next(i for i, vout in enumerate(self.nodes[0].getrawtransaction(txC, 1)["vout"]) if vout["value"] == Decimal("10"))

inputs =[]
inputs = []
# spend 10btc outputs from txA and txB
inputs.append({"txid":txA, "vout":nA})
inputs.append({"txid":txB, "vout":nB})
inputs.append({"txid": txA, "vout": nA})
inputs.append({"txid": txB, "vout": nB})
outputs = {}

outputs[self.nodes[0].getnewaddress()] = Decimal("14.99998")
Expand All @@ -67,17 +75,17 @@ def run_test(self):

#Create a child tx spending AB1 and C
inputs = []
inputs.append({"txid":txAB1, "vout":nAB})
inputs.append({"txid":txC, "vout":nC})
inputs.append({"txid": txAB1, "vout": nAB})
inputs.append({"txid": txC, "vout": nC})
outputs = {}
outputs[self.nodes[0].getnewaddress()] = Decimal("24.9996")
signed2 = self.nodes[0].signrawtransactionwithwallet(self.nodes[0].createrawtransaction(inputs, outputs))
txABC2 = self.nodes[0].sendrawtransaction(signed2["hex"])

# Create a child tx spending ABC2
signed3_change = Decimal("24.999")
inputs = [ {"txid":txABC2, "vout":0} ]
outputs = { self.nodes[0].getnewaddress(): signed3_change }
inputs = [{"txid": txABC2, "vout": 0}]
outputs = {self.nodes[0].getnewaddress(): signed3_change}
signed3 = self.nodes[0].signrawtransactionwithwallet(self.nodes[0].createrawtransaction(inputs, outputs))
# note tx is never directly referenced, only abandoned as a child of the above
self.nodes[0].sendrawtransaction(signed3["hex"])
Expand Down Expand Up @@ -105,7 +113,7 @@ def run_test(self):
unconfbalance = self.nodes[0].getunconfirmedbalance() + self.nodes[0].getbalance()
assert_equal(unconfbalance, newbalance)
# Also shouldn't show up in listunspent
assert(not txABC2 in [utxo["txid"] for utxo in self.nodes[0].listunspent(0)])
assert not txABC2 in [utxo["txid"] for utxo in self.nodes[0].listunspent(0)]
balance = newbalance

# Abandon original transaction and verify inputs are available again
Expand Down Expand Up @@ -145,8 +153,8 @@ def run_test(self):

# Create a double spend of AB1 by spending again from only A's 10 output
# Mine double spend from node 1
inputs =[]
inputs.append({"txid":txA, "vout":nA})
inputs = []
inputs.append({"txid": txA, "vout": nA})
outputs = {}
outputs[self.nodes[1].getnewaddress()] = Decimal("9.9999")
tx = self.nodes[0].createrawtransaction(inputs, outputs)
Expand All @@ -172,5 +180,6 @@ def run_test(self):
self.log.info("conflicted has not resumed causing its inputs to be seen as spent. See Issue #7315")
self.log.info(str(balance) + " -> " + str(newbalance) + " ?")


if __name__ == '__main__':
AbandonConflictTest().main()
14 changes: 8 additions & 6 deletions test/functional/wallet_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
wait_until,
)


class WalletTest(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 4
Expand Down Expand Up @@ -237,7 +238,7 @@ def run_test(self):
assert_equal(set(relayed), {txid1, txid2})
sync_mempools(self.nodes)

assert(txid1 in self.nodes[3].getrawmempool())
assert txid1 in self.nodes[3].getrawmempool()

# check if we can list zero value tx as available coins
# 1. create raw_tx
Expand All @@ -264,7 +265,7 @@ def run_test(self):
if uTx['txid'] == zero_value_txid:
found = True
assert_equal(uTx['amount'], Decimal('0'))
assert(found)
assert found

# do some -walletbroadcast tests
self.stop_nodes()
Expand Down Expand Up @@ -341,7 +342,7 @@ def run_test(self):
self.nodes[1].importaddress(address_to_import)

# 3. Validate that the imported address is watch-only on node1
assert(self.nodes[1].getaddressinfo(address_to_import)["iswatchonly"])
assert self.nodes[1].getaddressinfo(address_to_import)["iswatchonly"]

# 4. Check that the unspents after import are not spendable
assert_array_result(self.nodes[1].listunspent(),
Expand Down Expand Up @@ -383,7 +384,7 @@ def run_test(self):
addr = self.nodes[0].getnewaddress()
self.nodes[0].setlabel(addr, label)
assert_equal(self.nodes[0].getaddressinfo(addr)['label'], label)
assert(label in self.nodes[0].listlabels())
assert label in self.nodes[0].listlabels()
self.nodes[0].rpc.ensure_ascii = True # restore to default

# maintenance tests
Expand Down Expand Up @@ -442,8 +443,8 @@ def run_test(self):
# Without walletrejectlongchains, we will still generate a txid
# The tx will be stored in the wallet but not accepted to the mempool
extra_txid = self.nodes[0].sendtoaddress(sending_addr, Decimal('0.0001'))
assert(extra_txid not in self.nodes[0].getrawmempool())
assert(extra_txid in [tx["txid"] for tx in self.nodes[0].listtransactions()])
assert extra_txid not in self.nodes[0].getrawmempool()
assert extra_txid in [tx["txid"] for tx in self.nodes[0].listtransactions()]
self.nodes[0].abandontransaction(extra_txid)
total_txs = len(self.nodes[0].listtransactions("*", 99999))

Expand Down Expand Up @@ -491,5 +492,6 @@ def run_test(self):
self.nodes[0].setlabel(change, 'foobar')
assert_equal(self.nodes[0].getaddressinfo(change)['ischange'], False)


if __name__ == '__main__':
WalletTest().main()

0 comments on commit fa21983

Please sign in to comment.