[qa] Add tests verifychain, lockunspent, getbalance, listsinceblock

Github-Pull: #7702
Rebased-From: fa4a52254178655f50e73b50153730a60ffafd32
This commit is contained in:
MarcoFalke 2016-03-06 18:30:51 +01:00
parent 331655253d
commit f23cb7c944
4 changed files with 23 additions and 2 deletions

View File

@ -28,6 +28,7 @@ class BlockchainTest(BitcoinTestFramework):
Test blockchain-related RPC calls: Test blockchain-related RPC calls:
- gettxoutsetinfo - gettxoutsetinfo
- verifychain
""" """
@ -44,6 +45,7 @@ class BlockchainTest(BitcoinTestFramework):
def run_test(self): def run_test(self):
self._test_gettxoutsetinfo() self._test_gettxoutsetinfo()
self._test_getblockheader() self._test_getblockheader()
self.nodes[0].verifychain(4, 0)
def _test_gettxoutsetinfo(self): def _test_gettxoutsetinfo(self):
node = self.nodes[0] node = self.nodes[0]

View File

@ -38,7 +38,6 @@ class MempoolLimitTest(BitcoinTestFramework):
self.nodes[0].settxfee(0) # return to automatic fee selection self.nodes[0].settxfee(0) # return to automatic fee selection
txFS = self.nodes[0].signrawtransaction(txF['hex']) txFS = self.nodes[0].signrawtransaction(txF['hex'])
txid = self.nodes[0].sendrawtransaction(txFS['hex']) txid = self.nodes[0].sendrawtransaction(txFS['hex'])
self.nodes[0].lockunspent(True, [us0])
relayfee = self.nodes[0].getnetworkinfo()['relayfee'] relayfee = self.nodes[0].getnetworkinfo()['relayfee']
base_fee = relayfee*100 base_fee = relayfee*100

View File

@ -7,6 +7,7 @@
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 COIN
MAX_ANCESTORS = 25 MAX_ANCESTORS = 25
MAX_DESCENDANTS = 25 MAX_DESCENDANTS = 25

View File

@ -60,6 +60,15 @@ class WalletTest (BitcoinTestFramework):
self.nodes[0].generate(1) self.nodes[0].generate(1)
self.sync_all() self.sync_all()
# Exercise locking of unspent outputs
unspent_0 = self.nodes[2].listunspent()[0]
unspent_0 = {"txid": unspent_0["txid"], "vout": unspent_0["vout"]}
self.nodes[2].lockunspent(False, [unspent_0])
assert_raises(JSONRPCException, self.nodes[2].sendtoaddress, self.nodes[2].getnewaddress(), 20)
assert_equal([unspent_0], self.nodes[2].listlockunspent())
self.nodes[2].lockunspent(True, [unspent_0])
assert_equal(len(self.nodes[2].listlockunspent()), 0)
# Have node1 generate 100 blocks (so node0 can recover the fee) # Have node1 generate 100 blocks (so node0 can recover the fee)
self.nodes[1].generate(100) self.nodes[1].generate(100)
self.sync_all() self.sync_all()
@ -149,6 +158,10 @@ class WalletTest (BitcoinTestFramework):
assert(txid1 in self.nodes[3].getrawmempool()) assert(txid1 in self.nodes[3].getrawmempool())
# Exercise balance rpcs
assert_equal(self.nodes[0].getwalletinfo()["unconfirmed_balance"], 1)
assert_equal(self.nodes[0].getunconfirmedbalance(), 1)
#check if we can list zero value tx as available coins #check if we can list zero value tx as available coins
#1. create rawtx #1. create rawtx
#2. hex-changed one output to 0.0 #2. hex-changed one output to 0.0
@ -252,7 +265,7 @@ class WalletTest (BitcoinTestFramework):
#check if wallet or blochchain maintenance changes the balance #check if wallet or blochchain maintenance changes the balance
self.sync_all() self.sync_all()
self.nodes[0].generate(1) blocks = self.nodes[0].generate(2)
self.sync_all() self.sync_all()
balance_nodes = [self.nodes[i].getbalance() for i in range(3)] balance_nodes = [self.nodes[i].getbalance() for i in range(3)]
@ -270,6 +283,12 @@ class WalletTest (BitcoinTestFramework):
self.nodes = start_nodes(3, self.options.tmpdir, [[m]] * 3) self.nodes = start_nodes(3, self.options.tmpdir, [[m]] * 3)
assert_equal(balance_nodes, [self.nodes[i].getbalance() for i in range(3)]) assert_equal(balance_nodes, [self.nodes[i].getbalance() for i in range(3)])
# Exercise listsinceblock with the last two blocks
coinbase_tx_1 = self.nodes[0].listsinceblock(blocks[0])
assert_equal(coinbase_tx_1["lastblock"], blocks[1])
assert_equal(len(coinbase_tx_1["transactions"]), 1)
assert_equal(coinbase_tx_1["transactions"][0]["blockhash"], blocks[1])
assert_equal(len(self.nodes[0].listsinceblock(blocks[1])["transactions"]), 0)
if __name__ == '__main__': if __name__ == '__main__':
WalletTest ().main () WalletTest ().main ()