Changeset View
Changeset View
Standalone View
Standalone View
test/functional/wallet_basic.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2014-2016 The Bitcoin Core developers | # Copyright (c) 2014-2019 The Bitcoin Core developers | ||||
# Distributed under the MIT software license, see the accompanying | # Distributed under the MIT software license, see the accompanying | ||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
"""Test the wallet.""" | """Test the wallet.""" | ||||
from decimal import Decimal | from decimal import Decimal | ||||
import time | import time | ||||
from test_framework.messages import FromHex, CTransaction | from test_framework.messages import FromHex, CTransaction | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
▲ Show 20 Lines • Show All 178 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
# Send 10 BCH normal | # Send 10 BCH normal | ||||
old_balance = self.nodes[2].getbalance() | old_balance = self.nodes[2].getbalance() | ||||
address = self.nodes[0].getnewaddress("test") | address = self.nodes[0].getnewaddress("test") | ||||
fee_per_byte = Decimal('0.001') / 1000 | fee_per_byte = Decimal('0.001') / 1000 | ||||
self.nodes[2].settxfee(fee_per_byte * 1000) | self.nodes[2].settxfee(fee_per_byte * 1000) | ||||
txid = self.nodes[2].sendtoaddress(address, 10, "", "", False) | txid = self.nodes[2].sendtoaddress(address, 10, "", "", False) | ||||
self.nodes[2].generate(1) | self.nodes[2].generate(1) | ||||
self.sync_all([self.nodes[0:3]]) | self.sync_all([self.nodes[0:3]]) | ||||
ctx = FromHex(CTransaction(), self.nodes[2].getrawtransaction(txid)) | ctx = FromHex(CTransaction(), | ||||
self.nodes[2].gettransaction(txid)['hex']) | |||||
node_2_bal = self.check_fee_amount(self.nodes[2].getbalance(), old_balance - Decimal('10'), | node_2_bal = self.check_fee_amount(self.nodes[2].getbalance(), old_balance - Decimal('10'), | ||||
fee_per_byte, ctx.billable_size()) | fee_per_byte, ctx.billable_size()) | ||||
assert_equal(self.nodes[0].getbalance(), Decimal('10')) | assert_equal(self.nodes[0].getbalance(), Decimal('10')) | ||||
# Send 10 BCH with subtract fee from amount | # Send 10 BCH with subtract fee from amount | ||||
txid = self.nodes[2].sendtoaddress(address, 10, "", "", True) | txid = self.nodes[2].sendtoaddress(address, 10, "", "", True) | ||||
self.nodes[2].generate(1) | self.nodes[2].generate(1) | ||||
self.sync_all([self.nodes[0:3]]) | self.sync_all([self.nodes[0:3]]) | ||||
node_2_bal -= Decimal('10') | node_2_bal -= Decimal('10') | ||||
assert_equal(self.nodes[2].getbalance(), node_2_bal) | assert_equal(self.nodes[2].getbalance(), node_2_bal) | ||||
node_0_bal = self.check_fee_amount(self.nodes[0].getbalance(), Decimal( | node_0_bal = self.check_fee_amount(self.nodes[0].getbalance(), Decimal( | ||||
'20'), fee_per_byte, count_bytes(self.nodes[2].getrawtransaction(txid))) | '20'), fee_per_byte, count_bytes(self.nodes[2].gettransaction(txid)['hex'])) | ||||
# Sendmany 10 BCH | # Sendmany 10 BCH | ||||
txid = self.nodes[2].sendmany('', {address: 10}, 0, "", []) | txid = self.nodes[2].sendmany('', {address: 10}, 0, "", []) | ||||
self.nodes[2].generate(1) | self.nodes[2].generate(1) | ||||
self.sync_all([self.nodes[0:3]]) | self.sync_all([self.nodes[0:3]]) | ||||
node_0_bal += Decimal('10') | node_0_bal += Decimal('10') | ||||
ctx = FromHex(CTransaction(), self.nodes[2].getrawtransaction(txid)) | ctx = FromHex(CTransaction(), | ||||
self.nodes[2].gettransaction(txid)['hex']) | |||||
node_2_bal = self.check_fee_amount(self.nodes[2].getbalance( | node_2_bal = self.check_fee_amount(self.nodes[2].getbalance( | ||||
), node_2_bal - Decimal('10'), fee_per_byte, ctx.billable_size()) | ), node_2_bal - Decimal('10'), fee_per_byte, ctx.billable_size()) | ||||
assert_equal(self.nodes[0].getbalance(), node_0_bal) | assert_equal(self.nodes[0].getbalance(), node_0_bal) | ||||
# Sendmany 10 BCH with subtract fee from amount | # Sendmany 10 BCH with subtract fee from amount | ||||
txid = self.nodes[2].sendmany('', {address: 10}, 0, "", [address]) | txid = self.nodes[2].sendmany('', {address: 10}, 0, "", [address]) | ||||
self.nodes[2].generate(1) | self.nodes[2].generate(1) | ||||
self.sync_all([self.nodes[0:3]]) | self.sync_all([self.nodes[0:3]]) | ||||
node_2_bal -= Decimal('10') | node_2_bal -= Decimal('10') | ||||
assert_equal(self.nodes[2].getbalance(), node_2_bal) | assert_equal(self.nodes[2].getbalance(), node_2_bal) | ||||
ctx = FromHex(CTransaction(), self.nodes[2].getrawtransaction(txid)) | ctx = FromHex(CTransaction(), | ||||
self.nodes[2].gettransaction(txid)['hex']) | |||||
node_0_bal = self.check_fee_amount(self.nodes[0].getbalance( | node_0_bal = self.check_fee_amount(self.nodes[0].getbalance( | ||||
), node_0_bal + Decimal('10'), fee_per_byte, ctx.billable_size()) | ), node_0_bal + Decimal('10'), fee_per_byte, ctx.billable_size()) | ||||
self.start_node(3, self.extra_args[3]) | self.start_node(3, self.extra_args[3]) | ||||
connect_nodes_bi(self.nodes[0], self.nodes[3]) | connect_nodes_bi(self.nodes[0], self.nodes[3]) | ||||
self.sync_all() | self.sync_all() | ||||
# check if we can list zero value tx as available coins | # check if we can list zero value tx as available coins | ||||
▲ Show 20 Lines • Show All 150 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
self.nodes[0].rpc.ensure_ascii = mode | self.nodes[0].rpc.ensure_ascii = mode | ||||
# unicode check: Basic Multilingual Plane, Supplementary Plane | # unicode check: Basic Multilingual Plane, Supplementary Plane | ||||
# respectively | # respectively | ||||
for label in [u'рыба', u'𝅘𝅥𝅯']: | for label in [u'рыба', u'𝅘𝅥𝅯']: | ||||
addr = self.nodes[0].getnewaddress() | addr = self.nodes[0].getnewaddress() | ||||
self.nodes[0].setlabel(addr, label) | self.nodes[0].setlabel(addr, label) | ||||
assert_equal(self.nodes[0].getaddressinfo( | assert_equal(self.nodes[0].getaddressinfo( | ||||
addr)['label'], label) | addr)['label'], label) | ||||
assert(label in self.nodes[0].listlabels()) | assert label in self.nodes[0].listlabels() | ||||
# restore to default | # restore to default | ||||
self.nodes[0].rpc.ensure_ascii = True | self.nodes[0].rpc.ensure_ascii = True | ||||
# maintenance tests | # maintenance tests | ||||
maintenance = [ | maintenance = [ | ||||
'-rescan', | '-rescan', | ||||
'-reindex', | '-reindex', | ||||
'-zapwallettxes=1', | '-zapwallettxes=1', | ||||
▲ Show 20 Lines • Show All 107 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
assert not address_info["isscript"] | assert not address_info["isscript"] | ||||
assert not address_info["ischange"] | assert not address_info["ischange"] | ||||
# Test getaddressinfo 'ischange' field on change address. | # Test getaddressinfo 'ischange' field on change address. | ||||
self.nodes[0].generate(1) | self.nodes[0].generate(1) | ||||
destination = self.nodes[1].getnewaddress() | destination = self.nodes[1].getnewaddress() | ||||
txid = self.nodes[0].sendtoaddress(destination, 0.123) | txid = self.nodes[0].sendtoaddress(destination, 0.123) | ||||
tx = self.nodes[0].decoderawtransaction( | tx = self.nodes[0].decoderawtransaction( | ||||
self.nodes[0].getrawtransaction(txid)) | self.nodes[0].gettransaction(txid)['hex']) | ||||
output_addresses = [vout['scriptPubKey']['addresses'][0] | output_addresses = [vout['scriptPubKey']['addresses'][0] | ||||
for vout in tx["vout"]] | for vout in tx["vout"]] | ||||
assert len(output_addresses) > 1 | assert len(output_addresses) > 1 | ||||
for address in output_addresses: | for address in output_addresses: | ||||
ischange = self.nodes[0].getaddressinfo(address)['ischange'] | ischange = self.nodes[0].getaddressinfo(address)['ischange'] | ||||
assert_equal(ischange, address != destination) | assert_equal(ischange, address != destination) | ||||
if ischange: | if ischange: | ||||
change = address | change = address | ||||
self.nodes[0].setlabel(change, 'foobar') | self.nodes[0].setlabel(change, 'foobar') | ||||
assert_equal(self.nodes[0].getaddressinfo(change)['ischange'], False) | assert_equal(self.nodes[0].getaddressinfo(change)['ischange'], False) | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
WalletTest().main() | WalletTest().main() |