Changeset View
Changeset View
Standalone View
Standalone View
test/functional/wallet_abandonconflict.py
Show First 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
inputs = [] | inputs = [] | ||||
# spend 10btc outputs from txA and txB | # spend 10btc outputs from txA and txB | ||||
inputs.append({"txid": txA, "vout": nA}) | inputs.append({"txid": txA, "vout": nA}) | ||||
inputs.append({"txid": txB, "vout": nB}) | inputs.append({"txid": txB, "vout": nB}) | ||||
outputs = {} | outputs = {} | ||||
outputs[self.nodes[0].getnewaddress()] = Decimal("14.99998") | outputs[self.nodes[0].getnewaddress()] = Decimal("14.99998") | ||||
outputs[self.nodes[1].getnewaddress()] = Decimal("5") | outputs[self.nodes[1].getnewaddress()] = Decimal("5") | ||||
signed = self.nodes[0].signrawtransaction( | signed = self.nodes[0].signrawtransactionwithwallet( | ||||
self.nodes[0].createrawtransaction(inputs, outputs)) | self.nodes[0].createrawtransaction(inputs, outputs)) | ||||
txAB1 = self.nodes[0].sendrawtransaction(signed["hex"]) | txAB1 = self.nodes[0].sendrawtransaction(signed["hex"]) | ||||
# Identify the 14.99998btc output | # Identify the 14.99998btc output | ||||
nAB = next(i for i, vout in enumerate(self.nodes[0].getrawtransaction( | nAB = next(i for i, vout in enumerate(self.nodes[0].getrawtransaction( | ||||
txAB1, 1)["vout"]) if vout["value"] == Decimal("14.99998")) | txAB1, 1)["vout"]) if vout["value"] == Decimal("14.99998")) | ||||
# Create a child tx spending AB1 and C | # Create a child tx spending AB1 and C | ||||
inputs = [] | inputs = [] | ||||
# Amount 14.99998 BCH | # Amount 14.99998 BCH | ||||
inputs.append({"txid": txAB1, "vout": nAB}) | inputs.append({"txid": txAB1, "vout": nAB}) | ||||
# Amount 10 BCH | # Amount 10 BCH | ||||
inputs.append({"txid": txC, "vout": nC}) | inputs.append({"txid": txC, "vout": nC}) | ||||
outputs = {} | outputs = {} | ||||
outputs[self.nodes[0].getnewaddress()] = Decimal("24.9996") | outputs[self.nodes[0].getnewaddress()] = Decimal("24.9996") | ||||
signed2 = self.nodes[0].signrawtransaction( | signed2 = self.nodes[0].signrawtransactionwithwallet( | ||||
self.nodes[0].createrawtransaction(inputs, outputs)) | self.nodes[0].createrawtransaction(inputs, outputs)) | ||||
txABC2 = self.nodes[0].sendrawtransaction(signed2["hex"]) | txABC2 = self.nodes[0].sendrawtransaction(signed2["hex"]) | ||||
# Create a child tx spending ABC2 | # Create a child tx spending ABC2 | ||||
signed3_change = Decimal("24.999") | signed3_change = Decimal("24.999") | ||||
inputs = [{"txid": txABC2, "vout": 0}] | inputs = [{"txid": txABC2, "vout": 0}] | ||||
outputs = {self.nodes[0].getnewaddress(): signed3_change} | outputs = {self.nodes[0].getnewaddress(): signed3_change} | ||||
signed3 = self.nodes[0].signrawtransaction( | signed3 = self.nodes[0].signrawtransactionwithwallet( | ||||
self.nodes[0].createrawtransaction(inputs, outputs)) | self.nodes[0].createrawtransaction(inputs, outputs)) | ||||
# note tx is never directly referenced, only abandoned as a child of the above | # note tx is never directly referenced, only abandoned as a child of the above | ||||
self.nodes[0].sendrawtransaction(signed3["hex"]) | self.nodes[0].sendrawtransaction(signed3["hex"]) | ||||
# In mempool txs from self should increase balance from change | # In mempool txs from self should increase balance from change | ||||
newbalance = self.nodes[0].getbalance() | newbalance = self.nodes[0].getbalance() | ||||
assert_equal(newbalance, balance - Decimal("30") + signed3_change) | assert_equal(newbalance, balance - Decimal("30") + signed3_change) | ||||
balance = newbalance | balance = newbalance | ||||
▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
# Create a double spend of AB1. Spend it again from only A's 10 output. | # Create a double spend of AB1. Spend it again from only A's 10 output. | ||||
# Mine double spend from node 1. | # Mine double spend from node 1. | ||||
inputs = [] | inputs = [] | ||||
inputs.append({"txid": txA, "vout": nA}) | inputs.append({"txid": txA, "vout": nA}) | ||||
outputs = {} | outputs = {} | ||||
outputs[self.nodes[1].getnewaddress()] = Decimal("9.9999") | outputs[self.nodes[1].getnewaddress()] = Decimal("9.9999") | ||||
tx = self.nodes[0].createrawtransaction(inputs, outputs) | tx = self.nodes[0].createrawtransaction(inputs, outputs) | ||||
signed = self.nodes[0].signrawtransaction(tx) | signed = self.nodes[0].signrawtransactionwithwallet(tx) | ||||
self.nodes[1].sendrawtransaction(signed["hex"]) | self.nodes[1].sendrawtransaction(signed["hex"]) | ||||
self.nodes[1].generate(1) | self.nodes[1].generate(1) | ||||
connect_nodes(self.nodes[0], self.nodes[1]) | connect_nodes(self.nodes[0], self.nodes[1]) | ||||
sync_blocks(self.nodes) | sync_blocks(self.nodes) | ||||
# Verify that B and C's 10 BTC outputs are available for spending again because AB1 is now conflicted | # Verify that B and C's 10 BTC outputs are available for spending again because AB1 is now conflicted | ||||
newbalance = self.nodes[0].getbalance() | newbalance = self.nodes[0].getbalance() | ||||
Show All 18 Lines |