Changeset View
Changeset View
Standalone View
Standalone View
test/functional/rpc_fundrawtransaction.py
Show All 21 Lines | for utx in listunspent: | ||||
if utx['amount'] == amount: | if utx['amount'] == amount: | ||||
return utx | return utx | ||||
raise AssertionError( | raise AssertionError( | ||||
'Could not find unspent with amount={}'.format(amount)) | 'Could not find unspent with amount={}'.format(amount)) | ||||
class RawTransactionsTest(BitcoinTestFramework): | class RawTransactionsTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.num_nodes = 4 | self.num_nodes = 5 | ||||
self.setup_clean_chain = True | self.setup_clean_chain = True | ||||
self.extra_args = [[], [], [], [], | |||||
["-deprecatedrpc=fundrawtransaction"]] | |||||
def setup_network(self, split=False): | def setup_network(self, split=False): | ||||
self.setup_nodes() | self.setup_nodes() | ||||
connect_nodes_bi(self.nodes[0], self.nodes[1]) | connect_nodes_bi(self.nodes[0], self.nodes[1]) | ||||
connect_nodes_bi(self.nodes[1], self.nodes[2]) | connect_nodes_bi(self.nodes[1], self.nodes[2]) | ||||
connect_nodes_bi(self.nodes[0], self.nodes[2]) | connect_nodes_bi(self.nodes[0], self.nodes[2]) | ||||
connect_nodes_bi(self.nodes[0], self.nodes[3]) | connect_nodes_bi(self.nodes[0], self.nodes[3]) | ||||
connect_nodes_bi(self.nodes[0], self.nodes[4]) | |||||
def run_test(self): | def run_test(self): | ||||
min_relay_tx_fee = self.nodes[0].getnetworkinfo()['relayfee'] | min_relay_tx_fee = self.nodes[0].getnetworkinfo()['relayfee'] | ||||
# This test is not meant to test fee estimation and we'd like | # This test is not meant to test fee estimation and we'd like | ||||
# to be sure all txs are sent at a consistent desired feerate | # to be sure all txs are sent at a consistent desired feerate | ||||
for node in self.nodes: | for node in self.nodes: | ||||
node.settxfee(min_relay_tx_fee) | node.settxfee(min_relay_tx_fee) | ||||
Show All 21 Lines | def run_test(self): | ||||
watchonly_pubkey = self.nodes[ | watchonly_pubkey = self.nodes[ | ||||
0].validateaddress(watchonly_address)["pubkey"] | 0].validateaddress(watchonly_address)["pubkey"] | ||||
watchonly_amount = Decimal(200) | watchonly_amount = Decimal(200) | ||||
self.nodes[3].importpubkey(watchonly_pubkey, "", True) | self.nodes[3].importpubkey(watchonly_pubkey, "", True) | ||||
watchonly_txid = self.nodes[0].sendtoaddress( | watchonly_txid = self.nodes[0].sendtoaddress( | ||||
watchonly_address, watchonly_amount) | watchonly_address, watchonly_amount) | ||||
self.nodes[0].sendtoaddress( | self.nodes[0].sendtoaddress( | ||||
self.nodes[3].getnewaddress(), watchonly_amount / 10) | self.nodes[3].getnewaddress(), watchonly_amount / 10) | ||||
self.nodes[0].sendtoaddress(self.nodes[4].getnewaddress(), 5.0) | |||||
self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 1.5) | self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 1.5) | ||||
self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 1.0) | self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 1.0) | ||||
self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 5.0) | self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 5.0) | ||||
self.nodes[0].generate(1) | self.nodes[0].generate(1) | ||||
self.sync_all() | self.sync_all() | ||||
▲ Show 20 Lines • Show All 386 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
oldBalance + Decimal('1.10000000'), self.nodes[1].getbalance()) | oldBalance + Decimal('1.10000000'), self.nodes[1].getbalance()) | ||||
# | # | ||||
# locked wallet test | # locked wallet test | ||||
self.stop_node(0) | self.stop_node(0) | ||||
self.nodes[1].node_encrypt_wallet("test") | self.nodes[1].node_encrypt_wallet("test") | ||||
self.stop_node(2) | self.stop_node(2) | ||||
self.stop_node(3) | self.stop_node(3) | ||||
self.stop_node(4) | |||||
self.start_nodes() | self.start_nodes() | ||||
# This test is not meant to test fee estimation and we'd like | # This test is not meant to test fee estimation and we'd like | ||||
# to be sure all txs are sent at a consistent desired feerate | # to be sure all txs are sent at a consistent desired feerate | ||||
for node in self.nodes: | for node in self.nodes: | ||||
node.settxfee(min_relay_tx_fee) | node.settxfee(min_relay_tx_fee) | ||||
connect_nodes_bi(self.nodes[0], self.nodes[1]) | connect_nodes_bi(self.nodes[0], self.nodes[1]) | ||||
connect_nodes_bi(self.nodes[1], self.nodes[2]) | connect_nodes_bi(self.nodes[1], self.nodes[2]) | ||||
connect_nodes_bi(self.nodes[0], self.nodes[2]) | connect_nodes_bi(self.nodes[0], self.nodes[2]) | ||||
connect_nodes_bi(self.nodes[0], self.nodes[3]) | connect_nodes_bi(self.nodes[0], self.nodes[3]) | ||||
connect_nodes_bi(self.nodes[0], self.nodes[4]) | |||||
self.sync_all() | self.sync_all() | ||||
# drain the keypool | # drain the keypool | ||||
self.nodes[1].getnewaddress() | self.nodes[1].getnewaddress() | ||||
self.nodes[1].getrawchangeaddress() | self.nodes[1].getrawchangeaddress() | ||||
inputs = [] | inputs = [] | ||||
outputs = {self.nodes[0].getnewaddress(): 1.1} | outputs = {self.nodes[0].getnewaddress(): 1.1} | ||||
rawTx = self.nodes[1].createrawtransaction(inputs, outputs) | rawTx = self.nodes[1].createrawtransaction(inputs, outputs) | ||||
▲ Show 20 Lines • Show All 178 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
rawTx, {"feeRate": 10 * min_relay_tx_fee}) | rawTx, {"feeRate": 10 * min_relay_tx_fee}) | ||||
# allow this transaction to be underfunded by 10 bytes. This is due | # allow this transaction to be underfunded by 10 bytes. This is due | ||||
# to the first transaction possibly being overfunded by up to .9 | # to the first transaction possibly being overfunded by up to .9 | ||||
# satoshi due to fee ceilings being used. | # satoshi due to fee ceilings being used. | ||||
assert_fee_amount( | assert_fee_amount( | ||||
result3['fee'], FromHex(CTransaction(), result3['hex']).billable_size(), 10 * result_fee_rate, 10) | result3['fee'], FromHex(CTransaction(), result3['hex']).billable_size(), 10 * result_fee_rate, 10) | ||||
# | # | ||||
# DEPRECATED, should be removed in v0.20 | |||||
# Test address reuse option # | # Test address reuse option # | ||||
# | # | ||||
result3 = self.nodes[3].fundrawtransaction( | dInputs = [] | ||||
rawTx, {"reserveChangeKey": False}) | dOutputs = {self.nodes[4].getnewaddress(): 1} | ||||
res_dec = self.nodes[0].decoderawtransaction(result3["hex"]) | dRawTx = self.nodes[4].createrawtransaction(dInputs, dOutputs) | ||||
dResult = self.nodes[4].fundrawtransaction( | |||||
dRawTx, {"reserveChangeKey": False}) | |||||
res_dec = self.nodes[0].decoderawtransaction(dResult["hex"]) | |||||
changeaddress = "" | changeaddress = "" | ||||
for out in res_dec['vout']: | for out in res_dec['vout']: | ||||
if out['value'] > 1.0: | if out['value'] > 1.0: | ||||
changeaddress += out['scriptPubKey']['addresses'][0] | changeaddress += out['scriptPubKey']['addresses'][0] | ||||
assert(changeaddress != "") | assert(changeaddress != "") | ||||
nextaddr = self.nodes[3].getrawchangeaddress() | nextaddr = self.nodes[4].getrawchangeaddress() | ||||
# frt should not have removed the key from the keypool | # frt should not have removed the key from the keypool | ||||
assert(changeaddress == nextaddr) | assert(changeaddress == nextaddr) | ||||
# | |||||
# DEPRECATED, should be removed in v0.20 | |||||
# Test address reuse option does # | |||||
# throws an rpc error when not deprecated # | |||||
# | |||||
assert_raises_rpc_error(-32, "fundrawtransaction -reserveChangeKey " | |||||
+ "is deprecated and will be fully removed " | |||||
+ "in v0.20. To use the -reserveChangeKey " | |||||
+ "option in v0.19, restart bitcoind with " | |||||
+ "-deprecatedrpc=fundrawtransaction.\n" | |||||
+ "Projects should transition to expecting " | |||||
+ "change addresses removed from the keypool " | |||||
+ "before upgrading to v0.20", | |||||
self.nodes[3].fundrawtransaction, rawTx, | |||||
{"reserveChangeKey": False}) | |||||
# | |||||
# Test no address reuse occurs # | |||||
# | |||||
result3 = self.nodes[3].fundrawtransaction(rawTx) | result3 = self.nodes[3].fundrawtransaction(rawTx) | ||||
res_dec = self.nodes[0].decoderawtransaction(result3["hex"]) | res_dec = self.nodes[0].decoderawtransaction(result3["hex"]) | ||||
changeaddress = "" | changeaddress = "" | ||||
for out in res_dec['vout']: | for out in res_dec['vout']: | ||||
if out['value'] > 1.0: | if out['value'] > 1.0: | ||||
changeaddress += out['scriptPubKey']['addresses'][0] | changeaddress += out['scriptPubKey']['addresses'][0] | ||||
assert(changeaddress != "") | assert(changeaddress != "") | ||||
nextaddr = self.nodes[3].getnewaddress() | nextaddr = self.nodes[3].getnewaddress() | ||||
▲ Show 20 Lines • Show All 86 Lines • Show Last 20 Lines |