60 lines
2.7 KiB
Python
Executable File
60 lines
2.7 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# Copyright (c) 2020 The Zcash developers
|
|
# Distributed under the MIT software license, see the accompanying
|
|
# file COPYING or https://www.opensource.org/licenses/mit-license.php .
|
|
|
|
from test_framework.test_framework import BitcoinTestFramework
|
|
from test_framework.util import assert_equal, connect_nodes_bi, start_nodes, stop_nodes, sync_blocks, wait_bitcoinds
|
|
from decimal import Decimal
|
|
|
|
# Test wallet address behaviour across network upgrades
|
|
class WalletBroadcastTest(BitcoinTestFramework):
|
|
def run_test(self):
|
|
#do some -walletbroadcast tests
|
|
stop_nodes(self.nodes)
|
|
wait_bitcoinds()
|
|
self.nodes = start_nodes(3, self.options.tmpdir, [["-walletbroadcast=0"],["-walletbroadcast=0"],["-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()
|
|
|
|
txIdNotBroadcasted = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 2)
|
|
txObjNotBroadcasted = self.nodes[0].gettransaction(txIdNotBroadcasted)
|
|
self.sync_all()
|
|
self.nodes[1].generate(1) #mine a block, tx should not be in there
|
|
self.sync_all()
|
|
assert_equal(self.nodes[2].getbalance(), Decimal('250.00000000')) #default should not be changed because tx was not broadcasted
|
|
assert_equal(self.nodes[2].getbalance("*"), Decimal('250.00000000')) #default 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.sync_all()
|
|
self.nodes[1].generate(1)
|
|
self.sync_all()
|
|
txObjNotBroadcasted = self.nodes[0].gettransaction(txIdNotBroadcasted)
|
|
assert_equal(self.nodes[2].getbalance(), Decimal('252.00000000')) #should not be
|
|
assert_equal(self.nodes[2].getbalance("*"), Decimal('252.00000000')) #should not be
|
|
|
|
#create another tx
|
|
txIdNotBroadcasted = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 2)
|
|
|
|
#restart the nodes with -walletbroadcast=1
|
|
stop_nodes(self.nodes)
|
|
wait_bitcoinds()
|
|
self.nodes = start_nodes(3, self.options.tmpdir)
|
|
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)
|
|
|
|
self.nodes[0].generate(1)
|
|
sync_blocks(self.nodes)
|
|
|
|
# tx should be added to balance because after restarting the nodes tx should be broadcast
|
|
assert_equal(self.nodes[2].getbalance(), Decimal('254.00000000'))
|
|
assert_equal(self.nodes[2].getbalance("*"), Decimal('254.00000000'))
|
|
|
|
if __name__ == '__main__':
|
|
WalletBroadcastTest().main()
|