Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abandonconflict.py
Show All 12 Lines | |||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import * | from test_framework.util import * | ||||
from test_framework.mininode import * | from test_framework.mininode import * | ||||
class AbandonConflictTest(BitcoinTestFramework): | class AbandonConflictTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.num_nodes = 2 | self.num_nodes = 2 | ||||
self.extra_args = [["-minrelaytxfee=0.00001", | self.extra_args = [["-minrelaytxfee=0.00001"], []] | ||||
"-deprecatedrpc=signrawtransaction"], []] | |||||
def run_test(self): | def run_test(self): | ||||
def total_fees(*txids): | def total_fees(*txids): | ||||
total = 0 | total = 0 | ||||
for txid in txids: | for txid in txids: | ||||
ctx = FromHex(CTransaction(), | ctx = FromHex(CTransaction(), | ||||
self.nodes[0].getrawtransaction(txid)) | self.nodes[0].getrawtransaction(txid)) | ||||
total += self.nodes[0].calculate_fee_from_txid(txid) | total += self.nodes[0].calculate_fee_from_txid(txid) | ||||
Show All 32 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 51 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
self.nodes[0].sendrawtransaction(signed2["hex"]) | self.nodes[0].sendrawtransaction(signed2["hex"]) | ||||
newbalance = self.nodes[0].getbalance() | newbalance = self.nodes[0].getbalance() | ||||
assert_equal(newbalance, balance - Decimal("10") - | assert_equal(newbalance, balance - Decimal("10") - | ||||
Decimal("14.99998") + Decimal("24.9996")) | Decimal("14.99998") + Decimal("24.9996")) | ||||
balance = newbalance | balance = newbalance | ||||
# Reset to a higher relay fee so that we abandon a transaction | # Reset to a higher relay fee so that we abandon a transaction | ||||
self.stop_node(0) | self.stop_node(0) | ||||
self.start_node( | self.start_node(0, extra_args=["-minrelaytxfee=0.0001"]) | ||||
0, extra_args=["-minrelaytxfee=0.0001", "-deprecatedrpc=signrawtransaction"]) | |||||
assert_equal(len(self.nodes[0].getrawmempool()), 0) | assert_equal(len(self.nodes[0].getrawmempool()), 0) | ||||
newbalance = self.nodes[0].getbalance() | newbalance = self.nodes[0].getbalance() | ||||
assert_equal(newbalance, balance - Decimal("24.9996")) | assert_equal(newbalance, balance - Decimal("24.9996")) | ||||
balance = newbalance | balance = newbalance | ||||
# 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], 1) | connect_nodes(self.nodes[0], 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 |