@ -21,11 +21,14 @@ class WalletTest(BitcoinTestFramework):
@@ -21,11 +21,14 @@ class WalletTest(BitcoinTestFramework):
self . extra_args = [ [ ' -usehd= {:d} ' . format ( i % 2 == 0 ) ] for i in range ( 4 ) ]
def setup_network ( self ) :
self . nodes = self . start_nodes ( 3 , self . options . tmpdir , self . extra_args [ : 3 ] )
self . add_nodes ( 4 , self . options . tmpdir , self . extra_args )
self . start_node ( 0 )
self . start_node ( 1 )
self . start_node ( 2 )
connect_nodes_bi ( self . nodes , 0 , 1 )
connect_nodes_bi ( self . nodes , 1 , 2 )
connect_nodes_bi ( self . nodes , 0 , 2 )
self . sync_all ( )
self . sync_all ( [ self . nodes [ 0 : 3 ] ] )
def run_test ( self ) :
@ -42,9 +45,9 @@ class WalletTest(BitcoinTestFramework):
@@ -42,9 +45,9 @@ class WalletTest(BitcoinTestFramework):
assert_equal ( walletinfo [ ' immature_balance ' ] , 50 )
assert_equal ( walletinfo [ ' balance ' ] , 0 )
self . sync_all ( )
self . sync_all ( [ self . nodes [ 0 : 3 ] ] )
self . nodes [ 1 ] . generate ( 101 )
self . sync_all ( )
self . sync_all ( [ self . nodes [ 0 : 3 ] ] )
assert_equal ( self . nodes [ 0 ] . getbalance ( ) , 50 )
assert_equal ( self . nodes [ 1 ] . getbalance ( ) , 50 )
@ -88,7 +91,7 @@ class WalletTest(BitcoinTestFramework):
@@ -88,7 +91,7 @@ class WalletTest(BitcoinTestFramework):
# Have node0 mine a block, thus it will collect its own fee.
self . nodes [ 0 ] . generate ( 1 )
self . sync_all ( )
self . sync_all ( [ self . nodes [ 0 : 3 ] ] )
# Exercise locking of unspent outputs
unspent_0 = self . nodes [ 2 ] . listunspent ( ) [ 0 ]
@ -101,7 +104,7 @@ class WalletTest(BitcoinTestFramework):
@@ -101,7 +104,7 @@ class WalletTest(BitcoinTestFramework):
# Have node1 generate 100 blocks (so node0 can recover the fee)
self . nodes [ 1 ] . generate ( 100 )
self . sync_all ( )
self . sync_all ( [ self . nodes [ 0 : 3 ] ] )
# node0 should end up with 100 btc in block rewards plus fees, but
# minus the 21 plus fees sent to node2
@ -130,7 +133,7 @@ class WalletTest(BitcoinTestFramework):
@@ -130,7 +133,7 @@ class WalletTest(BitcoinTestFramework):
# Have node1 mine a block to confirm transactions:
self . nodes [ 1 ] . generate ( 1 )
self . sync_all ( )
self . sync_all ( [ self . nodes [ 0 : 3 ] ] )
assert_equal ( self . nodes [ 0 ] . getbalance ( ) , 0 )
assert_equal ( self . nodes [ 2 ] . getbalance ( ) , 94 )
@ -142,14 +145,14 @@ class WalletTest(BitcoinTestFramework):
@@ -142,14 +145,14 @@ class WalletTest(BitcoinTestFramework):
self . nodes [ 2 ] . settxfee ( fee_per_byte * 1000 )
txid = self . nodes [ 2 ] . sendtoaddress ( address , 10 , " " , " " , False )
self . nodes [ 2 ] . generate ( 1 )
self . sync_all ( )
self . sync_all ( [ self . nodes [ 0 : 3 ] ] )
node_2_bal = self . check_fee_amount ( self . nodes [ 2 ] . getbalance ( ) , Decimal ( ' 84 ' ) , fee_per_byte , count_bytes ( self . nodes [ 2 ] . getrawtransaction ( txid ) ) )
assert_equal ( self . nodes [ 0 ] . getbalance ( ) , Decimal ( ' 10 ' ) )
# Send 10 BTC with subtract fee from amount
txid = self . nodes [ 2 ] . sendtoaddress ( address , 10 , " " , " " , True )
self . nodes [ 2 ] . generate ( 1 )
self . sync_all ( )
self . sync_all ( [ self . nodes [ 0 : 3 ] ] )
node_2_bal - = Decimal ( ' 10 ' )
assert_equal ( self . nodes [ 2 ] . getbalance ( ) , node_2_bal )
node_0_bal = self . check_fee_amount ( self . nodes [ 0 ] . getbalance ( ) , Decimal ( ' 20 ' ) , fee_per_byte , count_bytes ( self . nodes [ 2 ] . getrawtransaction ( txid ) ) )
@ -157,7 +160,7 @@ class WalletTest(BitcoinTestFramework):
@@ -157,7 +160,7 @@ class WalletTest(BitcoinTestFramework):
# Sendmany 10 BTC
txid = self . nodes [ 2 ] . sendmany ( ' from1 ' , { address : 10 } , 0 , " " , [ ] )
self . nodes [ 2 ] . generate ( 1 )
self . sync_all ( )
self . sync_all ( [ self . nodes [ 0 : 3 ] ] )
node_0_bal + = Decimal ( ' 10 ' )
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 ) ) )
assert_equal ( self . nodes [ 0 ] . getbalance ( ) , node_0_bal )
@ -165,7 +168,7 @@ class WalletTest(BitcoinTestFramework):
@@ -165,7 +168,7 @@ class WalletTest(BitcoinTestFramework):
# Sendmany 10 BTC with subtract fee from amount
txid = self . nodes [ 2 ] . sendmany ( ' from1 ' , { address : 10 } , 0 , " " , [ address ] )
self . nodes [ 2 ] . generate ( 1 )
self . sync_all ( )
self . sync_all ( [ self . nodes [ 0 : 3 ] ] )
node_2_bal - = Decimal ( ' 10 ' )
assert_equal ( self . nodes [ 2 ] . getbalance ( ) , node_2_bal )
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 ) ) )
@ -176,9 +179,9 @@ class WalletTest(BitcoinTestFramework):
@@ -176,9 +179,9 @@ class WalletTest(BitcoinTestFramework):
# EXPECT: nodes[3] should have those transactions in its mempool.
txid1 = self . nodes [ 0 ] . sendtoaddress ( self . nodes [ 1 ] . getnewaddress ( ) , 1 )
txid2 = self . nodes [ 1 ] . sendtoaddress ( self . nodes [ 0 ] . getnewaddress ( ) , 1 )
sync_mempools ( self . nodes )
sync_mempools ( self . nodes [ 0 : 2 ] )
self . nodes . append ( self . start_node ( 3 , self . options . tmpdir , self . extra_args [ 3 ] ) )
self . start_node ( 3 )
connect_nodes_bi ( self . nodes , 0 , 3 )
sync_blocks ( self . nodes )
@ -222,22 +225,24 @@ class WalletTest(BitcoinTestFramework):
@@ -222,22 +225,24 @@ class WalletTest(BitcoinTestFramework):
#do some -walletbroadcast tests
self . stop_nodes ( )
self . nodes = self . start_nodes ( 3 , self . options . tmpdir , [ [ " -walletbroadcast=0 " ] , [ " -walletbroadcast=0 " ] , [ " -walletbroadcast=0 " ] ] )
self . start_node ( 0 , [ " -walletbroadcast=0 " ] )
self . start_node ( 1 , [ " -walletbroadcast=0 " ] )
self . start_node ( 2 , [ " -walletbroadcast=0 " ] )
connect_nodes_bi ( self . nodes , 0 , 1 )
connect_nodes_bi ( self . nodes , 1 , 2 )
connect_nodes_bi ( self . nodes , 0 , 2 )
self . sync_all ( )
self . sync_all ( [ self . nodes [ 0 : 3 ] ] )
txIdNotBroadcasted = self . nodes [ 0 ] . sendtoaddress ( self . nodes [ 2 ] . getnewaddress ( ) , 2 )
txObjNotBroadcasted = self . nodes [ 0 ] . gettransaction ( txIdNotBroadcasted )
self . nodes [ 1 ] . generate ( 1 ) #mine a block, tx should not be in there
self . sync_all ( )
self . sync_all ( [ self . nodes [ 0 : 3 ] ] )
assert_equal ( self . nodes [ 2 ] . getbalance ( ) , node_2_bal ) #should not be changed because tx was not broadcasted
#now broadcast from another node, mine a block, sync, and check the balance
self . nodes [ 1 ] . sendrawtransaction ( txObjNotBroadcasted [ ' hex ' ] )
self . nodes [ 1 ] . generate ( 1 )
self . sync_all ( )
self . sync_all ( [ self . nodes [ 0 : 3 ] ] )
node_2_bal + = 2
txObjNotBroadcasted = self . nodes [ 0 ] . gettransaction ( txIdNotBroadcasted )
assert_equal ( self . nodes [ 2 ] . getbalance ( ) , node_2_bal )
@ -247,14 +252,16 @@ class WalletTest(BitcoinTestFramework):
@@ -247,14 +252,16 @@ class WalletTest(BitcoinTestFramework):
#restart the nodes with -walletbroadcast=1
self . stop_nodes ( )
self . nodes = self . start_nodes ( 3 , self . options . tmpdir )
self . start_node ( 0 )
self . start_node ( 1 )
self . start_node ( 2 )
connect_nodes_bi ( self . nodes , 0 , 1 )
connect_nodes_bi ( self . nodes , 1 , 2 )
connect_nodes_bi ( self . nodes , 0 , 2 )
sync_blocks ( self . nodes )
sync_blocks ( self . nodes [ 0 : 3 ] )
self . nodes [ 0 ] . generate ( 1 )
sync_blocks ( self . nodes )
sync_blocks ( self . nodes [ 0 : 3 ] )
node_2_bal + = 2
#tx should be added to balance because after restarting the nodes tx should be broadcastet
@ -285,7 +292,7 @@ class WalletTest(BitcoinTestFramework):
@@ -285,7 +292,7 @@ class WalletTest(BitcoinTestFramework):
address_to_import = self . nodes [ 2 ] . getnewaddress ( )
txid = self . nodes [ 0 ] . sendtoaddress ( address_to_import , 1 )
self . nodes [ 0 ] . generate ( 1 )
self . sync_all ( )
self . sync_all ( [ self . nodes [ 0 : 3 ] ] )
# 2. Import address from node2 to node1
self . nodes [ 1 ] . importaddress ( address_to_import )
@ -311,15 +318,15 @@ class WalletTest(BitcoinTestFramework):
@@ -311,15 +318,15 @@ class WalletTest(BitcoinTestFramework):
cbAddr = self . nodes [ 1 ] . getnewaddress ( )
blkHash = self . nodes [ 0 ] . generatetoaddress ( 1 , cbAddr ) [ 0 ]
cbTxId = self . nodes [ 0 ] . getblock ( blkHash ) [ ' tx ' ] [ 0 ]
self . sync_all ( )
self . sync_all ( [ self . nodes [ 0 : 3 ] ] )
# Check that the txid and balance is found by node1
self . nodes [ 1 ] . gettransaction ( cbTxId )
# check if wallet or blockchain maintenance changes the balance
self . sync_all ( )
self . sync_all ( [ self . nodes [ 0 : 3 ] ] )
blocks = self . nodes [ 0 ] . generate ( 2 )
self . sync_all ( )
self . sync_all ( [ self . nodes [ 0 : 3 ] ] )
balance_nodes = [ self . nodes [ i ] . getbalance ( ) for i in range ( 3 ) ]
block_count = self . nodes [ 0 ] . getblockcount ( )
@ -350,7 +357,9 @@ class WalletTest(BitcoinTestFramework):
@@ -350,7 +357,9 @@ class WalletTest(BitcoinTestFramework):
self . log . info ( " check " + m )
self . stop_nodes ( )
# set lower ancestor limit for later
self . nodes = self . start_nodes ( 3 , self . options . tmpdir , [ [ m , " -limitancestorcount= " + str ( chainlimit ) ] ] * 3 )
self . start_node ( 0 , [ m , " -limitancestorcount= " + str ( chainlimit ) ] )
self . start_node ( 1 , [ m , " -limitancestorcount= " + str ( chainlimit ) ] )
self . start_node ( 2 , [ m , " -limitancestorcount= " + str ( chainlimit ) ] )
while m == ' -reindex ' and [ block_count ] * 3 != [ self . nodes [ i ] . getblockcount ( ) for i in range ( 3 ) ] :
# reindex will leave rpc warm up "early"; Wait for it to finish
time . sleep ( 0.1 )
@ -398,7 +407,7 @@ class WalletTest(BitcoinTestFramework):
@@ -398,7 +407,7 @@ class WalletTest(BitcoinTestFramework):
# Try with walletrejectlongchains
# Double chain limit but require combining inputs, so we pass SelectCoinsMinConf
self . stop_node ( 0 )
self . nodes [ 0 ] = self . start_node ( 0 , self . options . tmpdir , [ " -walletrejectlongchains " , " -limitancestorcount= " + str ( 2 * chainlimit ) ] )
self . start_node ( 0 , extra_args = [ " -walletrejectlongchains " , " -limitancestorcount= " + str ( 2 * chainlimit ) ] )
# wait for loadmempool
timeout = 10