Changeset View
Changeset View
Standalone View
Standalone View
test/functional/wallet.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2014-2016 The Bitcoin Core developers | # Copyright (c) 2014-2016 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 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 * | |||||
class WalletTest(BitcoinTestFramework): | class WalletTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.num_nodes = 4 | self.num_nodes = 4 | ||||
self.setup_clean_chain = True | self.setup_clean_chain = True | ||||
self.extra_args = [ | self.extra_args = [ | ||||
['-usehd={:d}'.format(i % 2 == 0)] for i in range(4)] | ['-usehd={:d}'.format(i % 2 == 0)] for i in range(4)] | ||||
▲ Show 20 Lines • Show All 132 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
self.nodes[1].generate(1) | self.nodes[1].generate(1) | ||||
self.sync_all([self.nodes[0:3]]) | self.sync_all([self.nodes[0:3]]) | ||||
assert_equal(self.nodes[0].getbalance(), 0) | assert_equal(self.nodes[0].getbalance(), 0) | ||||
assert_equal(self.nodes[2].getbalance(), 94) | assert_equal(self.nodes[2].getbalance(), 94) | ||||
assert_equal(self.nodes[2].getbalance("from1"), 94 - 21) | assert_equal(self.nodes[2].getbalance("from1"), 94 - 21) | ||||
# Send 10 BTC normal | # Send 10 BTC normal | ||||
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]]) | ||||
node_2_bal = self.check_fee_amount(self.nodes[2].getbalance(), Decimal( | ctx = FromHex(CTransaction(), self.nodes[2].getrawtransaction(txid)) | ||||
'84'), fee_per_byte, count_bytes(self.nodes[2].getrawtransaction(txid))) | node_2_bal = self.check_fee_amount(self.nodes[2].getbalance(), old_balance - Decimal('10'), | ||||
fee_per_byte, ctx.billable_size()) | |||||
assert_equal(self.nodes[0].getbalance(), Decimal('10')) | assert_equal(self.nodes[0].getbalance(), Decimal('10')) | ||||
# Send 10 BTC with subtract fee from amount | # Send 10 BTC 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].getrawtransaction(txid))) | ||||
# Sendmany 10 BTC | # Sendmany 10 BTC | ||||
txid = self.nodes[2].sendmany('from1', {address: 10}, 0, "", []) | txid = self.nodes[2].sendmany('from1', {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)) | |||||
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, count_bytes(self.nodes[2].getrawtransaction(txid))) | ), 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 BTC with subtract fee from amount | # Sendmany 10 BTC with subtract fee from amount | ||||
txid = self.nodes[2].sendmany('from1', {address: 10}, 0, "", [address]) | txid = self.nodes[2].sendmany('from1', {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)) | |||||
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, count_bytes(self.nodes[2].getrawtransaction(txid))) | ), node_0_bal + Decimal('10'), fee_per_byte, ctx.billable_size()) | ||||
# Test ResendWalletTransactions: | # Test ResendWalletTransactions: | ||||
# Create a couple of transactions, then start up a fourth | # Create a couple of transactions, then start up a fourth | ||||
# node (nodes[3]) and ask nodes[0] to rebroadcast. | # node (nodes[3]) and ask nodes[0] to rebroadcast. | ||||
# EXPECT: nodes[3] should have those transactions in its mempool. | # EXPECT: nodes[3] should have those transactions in its mempool. | ||||
txid1 = self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 1) | txid1 = self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 1) | ||||
txid2 = self.nodes[1].sendtoaddress(self.nodes[0].getnewaddress(), 1) | txid2 = self.nodes[1].sendtoaddress(self.nodes[0].getnewaddress(), 1) | ||||
sync_mempools(self.nodes[0:2]) | sync_mempools(self.nodes[0:2]) | ||||
▲ Show 20 Lines • Show All 267 Lines • Show Last 20 Lines |