aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rwxr-xr-xtest/functional/feature_maxtipage.py23
-rwxr-xr-xtest/functional/interface_bitcoin_cli.py4
-rwxr-xr-xtest/functional/rpc_rawtransaction.py81
3 files changed, 93 insertions, 15 deletions
diff --git a/test/functional/feature_maxtipage.py b/test/functional/feature_maxtipage.py
index ddc2102542..51f37ef1e0 100755
--- a/test/functional/feature_maxtipage.py
+++ b/test/functional/feature_maxtipage.py
@@ -22,23 +22,24 @@ class MaxTipAgeTest(BitcoinTestFramework):
self.setup_clean_chain = True
self.num_nodes = 2
- def test_maxtipage(self, maxtipage, set_parameter=True):
+ def test_maxtipage(self, maxtipage, set_parameter=True, test_deltas=True):
node_miner = self.nodes[0]
node_ibd = self.nodes[1]
self.restart_node(1, [f'-maxtipage={maxtipage}'] if set_parameter else None)
self.connect_nodes(0, 1)
-
- # tips older than maximum age -> stay in IBD
cur_time = int(time.time())
- node_ibd.setmocktime(cur_time)
- for delta in [5, 4, 3, 2, 1]:
- node_miner.setmocktime(cur_time - maxtipage - delta)
- self.generate(node_miner, 1)
- assert_equal(node_ibd.getblockchaininfo()['initialblockdownload'], True)
+
+ if test_deltas:
+ # tips older than maximum age -> stay in IBD
+ node_ibd.setmocktime(cur_time)
+ for delta in [5, 4, 3, 2, 1]:
+ node_miner.setmocktime(cur_time - maxtipage - delta)
+ self.generate(node_miner, 1)
+ assert_equal(node_ibd.getblockchaininfo()['initialblockdownload'], True)
# tip within maximum age -> leave IBD
- node_miner.setmocktime(cur_time - maxtipage)
+ node_miner.setmocktime(max(cur_time - maxtipage, 0))
self.generate(node_miner, 1)
assert_equal(node_ibd.getblockchaininfo()['initialblockdownload'], False)
@@ -51,6 +52,10 @@ class MaxTipAgeTest(BitcoinTestFramework):
self.log.info(f"Test IBD with maximum tip age of {hours} hours (-maxtipage={maxtipage}).")
self.test_maxtipage(maxtipage)
+ max_long_val = 9223372036854775807
+ self.log.info(f"Test IBD with highest allowable maximum tip age ({max_long_val}).")
+ self.test_maxtipage(max_long_val, test_deltas=False)
+
if __name__ == '__main__':
MaxTipAgeTest().main()
diff --git a/test/functional/interface_bitcoin_cli.py b/test/functional/interface_bitcoin_cli.py
index b1369c2615..90a543b51b 100755
--- a/test/functional/interface_bitcoin_cli.py
+++ b/test/functional/interface_bitcoin_cli.py
@@ -90,6 +90,10 @@ class TestBitcoinCli(BitcoinTestFramework):
assert_raises_rpc_error(-8, "Parameter arg1 specified twice both as positional and named argument", self.nodes[0].cli.echo, 0, 1, arg1=1)
assert_raises_rpc_error(-8, "Parameter arg1 specified twice both as positional and named argument", self.nodes[0].cli.echo, 0, None, 2, arg1=1)
+ self.log.info("Test that later cli named arguments values silently overwrite earlier ones")
+ assert_equal(self.nodes[0].cli("-named", "echo", "arg0=0", "arg1=1", "arg2=2", "arg1=3").send_cli(), ['0', '3', '2'])
+ assert_raises_rpc_error(-8, "Parameter args specified multiple times", self.nodes[0].cli("-named", "echo", "args=[0,1,2,3]", "4", "5", "6", ).send_cli)
+
user, password = get_auth_cookie(self.nodes[0].datadir, self.chain)
self.log.info("Test -stdinrpcpass option")
diff --git a/test/functional/rpc_rawtransaction.py b/test/functional/rpc_rawtransaction.py
index 15fc947eef..b87f3ad6f3 100755
--- a/test/functional/rpc_rawtransaction.py
+++ b/test/functional/rpc_rawtransaction.py
@@ -14,6 +14,7 @@ Test the following RPCs:
from collections import OrderedDict
from decimal import Decimal
+from itertools import product
from test_framework.blocktools import COINBASE_MATURITY
from test_framework.messages import (
@@ -81,6 +82,7 @@ class RawTransactionsTest(BitcoinTestFramework):
self.generate(self.nodes[0], COINBASE_MATURITY + 1)
self.getrawtransaction_tests()
+ self.getrawtransaction_verbosity_tests()
self.createrawtransaction_tests()
self.sendrawtransaction_tests()
self.sendrawtransaction_testmempoolaccept_tests()
@@ -116,6 +118,7 @@ class RawTransactionsTest(BitcoinTestFramework):
# 4. valid parameters - supply txid and 1 for verbose.
# We only check the "hex" field of the output so we don't need to update this test every time the output format changes.
assert_equal(self.nodes[n].getrawtransaction(txId, 1)["hex"], tx['hex'])
+ assert_equal(self.nodes[n].getrawtransaction(txId, 2)["hex"], tx['hex'])
# 5. valid parameters - supply txid and True for non-verbose
assert_equal(self.nodes[n].getrawtransaction(txId, True)["hex"], tx['hex'])
@@ -126,13 +129,14 @@ class RawTransactionsTest(BitcoinTestFramework):
# 6. invalid parameters - supply txid and invalid boolean values (strings) for verbose
for value in ["True", "False"]:
- assert_raises_rpc_error(-3, "not of expected type bool", self.nodes[n].getrawtransaction, txid=txId, verbose=value)
+ assert_raises_rpc_error(-3, "not of expected type number", self.nodes[n].getrawtransaction, txid=txId, verbose=value)
+ assert_raises_rpc_error(-3, "not of expected type number", self.nodes[n].getrawtransaction, txid=txId, verbosity=value)
# 7. invalid parameters - supply txid and empty array
- assert_raises_rpc_error(-3, "not of expected type bool", self.nodes[n].getrawtransaction, txId, [])
+ assert_raises_rpc_error(-3, "not of expected type number", self.nodes[n].getrawtransaction, txId, [])
# 8. invalid parameters - supply txid and empty dict
- assert_raises_rpc_error(-3, "not of expected type bool", self.nodes[n].getrawtransaction, txId, {})
+ assert_raises_rpc_error(-3, "not of expected type number", self.nodes[n].getrawtransaction, txId, {})
# Make a tx by sending, then generate 2 blocks; block1 has the tx in it
tx = self.wallet.send_self_transfer(from_node=self.nodes[2])['txid']
@@ -145,9 +149,10 @@ class RawTransactionsTest(BitcoinTestFramework):
assert_equal(gottx['in_active_chain'], True)
if n == 0:
self.log.info("Test getrawtransaction with -txindex, without blockhash: 'in_active_chain' should be absent")
- gottx = self.nodes[n].getrawtransaction(txid=tx, verbose=True)
- assert_equal(gottx['txid'], tx)
- assert 'in_active_chain' not in gottx
+ for v in [1,2]:
+ gottx = self.nodes[n].getrawtransaction(txid=tx, verbosity=v)
+ assert_equal(gottx['txid'], tx)
+ assert 'in_active_chain' not in gottx
else:
self.log.info("Test getrawtransaction without -txindex, without blockhash: expect the call to raise")
assert_raises_rpc_error(-5, err_msg, self.nodes[n].getrawtransaction, txid=tx, verbose=True)
@@ -172,6 +177,70 @@ class RawTransactionsTest(BitcoinTestFramework):
block = self.nodes[0].getblock(self.nodes[0].getblockhash(0))
assert_raises_rpc_error(-5, "The genesis block coinbase is not considered an ordinary transaction", self.nodes[0].getrawtransaction, block['merkleroot'])
+ def getrawtransaction_verbosity_tests(self):
+ tx = self.wallet.send_self_transfer(from_node=self.nodes[1])['txid']
+ [block1] = self.generate(self.nodes[1], 1)
+ fields = [
+ 'blockhash',
+ 'blocktime',
+ 'confirmations',
+ 'hash',
+ 'hex',
+ 'in_active_chain',
+ 'locktime',
+ 'size',
+ 'time',
+ 'txid',
+ 'vin',
+ 'vout',
+ 'vsize',
+ 'weight',
+ ]
+ prevout_fields = [
+ 'generated',
+ 'height',
+ 'value',
+ 'scriptPubKey',
+ ]
+ script_pub_key_fields = [
+ 'address',
+ 'asm',
+ 'hex',
+ 'type',
+ ]
+ # node 0 & 2 with verbosity 1 & 2
+ for n, v in product([0, 2], [1, 2]):
+ self.log.info(f"Test getrawtransaction_verbosity {v} {'with' if n == 0 else 'without'} -txindex, with blockhash")
+ gottx = self.nodes[n].getrawtransaction(txid=tx, verbosity=v, blockhash=block1)
+ missing_fields = set(fields).difference(gottx.keys())
+ if missing_fields:
+ raise AssertionError(f"fields {', '.join(missing_fields)} are not in transaction")
+
+ assert(len(gottx['vin']) > 0)
+ if v == 1:
+ assert('fee' not in gottx)
+ assert('prevout' not in gottx['vin'][0])
+ if v == 2:
+ assert(isinstance(gottx['fee'], Decimal))
+ assert('prevout' in gottx['vin'][0])
+ prevout = gottx['vin'][0]['prevout']
+ script_pub_key = prevout['scriptPubKey']
+
+ missing_fields = set(prevout_fields).difference(prevout.keys())
+ if missing_fields:
+ raise AssertionError(f"fields {', '.join(missing_fields)} are not in transaction")
+
+ missing_fields = set(script_pub_key_fields).difference(script_pub_key.keys())
+ if missing_fields:
+ raise AssertionError(f"fields {', '.join(missing_fields)} are not in transaction")
+
+ # check verbosity 2 without blockhash but with txindex
+ assert('fee' in self.nodes[0].getrawtransaction(txid=tx, verbosity=2))
+ # check that coinbase has no fee or does not throw any errors for verbosity 2
+ coin_base = self.nodes[1].getblock(block1)['tx'][0]
+ gottx = self.nodes[1].getrawtransaction(txid=coin_base, verbosity=2, blockhash=block1)
+ assert('fee' not in gottx)
+
def createrawtransaction_tests(self):
self.log.info("Test createrawtransaction")
# Test `createrawtransaction` required parameters