This patch adds tests for bitcoin-cli options -stdin (#7550) and -stdinrpcpass #10997.
Add bitcoin-cli -stdin and -stdinrpcpass functional tests #11125
pull promag wants to merge 6 commits into bitcoin:master from promag:2017-08-stdinrpcpass-functional-test changing 4 files +65 −16-
promag commented at 5:47 PM on August 24, 2017: member
- promag force-pushed on Aug 24, 2017
- laanwj added the label Tests on Aug 24, 2017
-
in test/functional/test_framework/test_node.py:142 in 7162087cc2 outdated
135 | @@ -136,3 +136,7 @@ def node_encrypt_wallet(self, passphrase): 136 | time.sleep(0.1) 137 | self.rpc = None 138 | self.rpc_connected = False 139 | + 140 | + def cli(self, args): 141 | + """Start the cli.""" 142 | + return subprocess.Popen(['bitcoin-cli'] + args, stderr=self.stderr, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
laanwj commented at 6:30 PM on August 24, 2017:We need a way to override what bitcoin-cli to use, akin to
BITCOINDenvironment variable.Which reminds me, didn't we have another PR to add bitcoin-cli testing support at some point? (if so, might be better to do it on top of that)
MarcoFalke commented at 8:13 PM on August 24, 2017:You might be able to hack something up based on
TestNodeCLIfrom currentmasterbranch.
laanwj commented at 6:30 PM on August 24, 2017: memberConcept ACK
promag force-pushed on Aug 25, 2017promag force-pushed on Aug 25, 2017promag renamed this:Add bitcoin-cli -stdinrpcpass functional test
Add bitcoin-cli -stdin and -stdinrpcpass functional tests
on Aug 25, 2017promag force-pushed on Aug 25, 2017jnewbery commented at 3:42 PM on August 25, 2017: memberSee commit here for an alternative way of doing this: https://github.com/jnewbery/bitcoin/commit/5bfd5e0d47f89f4c2e9becf266876c0c6cc62787
A few advantages:
- bitcoin-cli command line arguments are passed in as a string and fed through to
subprocess, rather than being parsed by python - It avoids the cludgy
inputmagic key - it maintains the
-datadirargument, which I think we want to keep (without that, bitcoin-cli won't have access to therpcportvalue in thebitcoin.conffile).
I've proposed that as a test for #10871. Let me know what you think.
jnewbery commented at 6:08 PM on August 25, 2017: memberah sorry, I just looked at the commit at https://github.com/bitcoin/bitcoin/commit/f275cf65018681689e711af6bca202125557c434 and misunderstood how
inputwas used. I'll re-review.MarcoFalke commented at 7:54 PM on August 25, 2017: memberutACK 5b4e3391f6a7dc9e7148eaee05e285f200f46927
in test/functional/bitcoin_cli.py:26 in 5b4e3391f6 outdated
23 | - 24 | assert_equal(cli_get_info, rpc_get_info) 25 | 26 | + self.log.info("Test -stdinrpcpass option") 27 | + user, password = get_auth_cookie(self.nodes[0].datadir) 28 | + block_count = self.nodes[0].cli(rpcuser=user, rpcport=rpc_port(0), stdinrpcpass=None).getblockcount(input=password)
laanwj commented at 7:49 AM on August 28, 2017:I would prefer to make a temporary, empty datadir here instead of make it use the default. The tests should not touch
~/.bitcoin.
jnewbery commented at 2:50 PM on August 28, 2017:It seems weird to me that
inputis an argument to the RPC, rather than an argument to the bitcoin-cli instance.It seems possible that an RPC will have
inputas a parameter. Rather less likely that bitcoin-cli will add an argument calledinput.promag commented at 7:55 AM on August 28, 2017: memberAgree!
in test/functional/test_framework/test_node.py:148 in 5b4e3391f6 outdated
143 | + """Creates a configurable cli for the node. 144 | + 145 | + If arguments is empty then -datadir is set to match the node 146 | + """ 147 | + args = ["-" + str(key) + ("=" + str(value) if value else "") for (key, value) in kwargs.items()] 148 | + if not args:
jnewbery commented at 2:21 PM on August 28, 2017:I think you should add an error here. If args is specified, then
datadirmust be one of the args (otherwisebitcoin-cliwill look in~/.bitcoin).
laanwj commented at 2:56 PM on August 28, 2017:Another option would be to set
datadir=self.datadirif it isn't overridden otherwise. As you say, there is no reason the argument should ever be missing.
jnewbery commented at 6:37 PM on August 29, 2017:I think either approach is fine. Making it an error to not include it in args makes it more explicit to the test writer (ie datadir doesn't get set magically for them).
jnewbery commented at 2:53 PM on August 28, 2017: memberLooks generally good to me. A couple of nits inline.
in test/functional/test_framework/test_node.py:57 in 5b4e3391f6 outdated
50 | @@ -51,8 +51,6 @@ def __init__(self, i, dirname, extra_args, rpchost, timewait, binary, stderr, mo 51 | self.extra_args = extra_args 52 | self.args = [self.binary, "-datadir=" + self.datadir, "-server", "-keypool=1", "-discover=0", "-rest", "-logtimemicros", "-debug", "-debugexclude=libevent", "-debugexclude=leveldb", "-mocktime=" + str(mocktime), "-uacomment=testnode%d" % i] 53 | 54 | - self.cli = TestNodeCLI(os.getenv("BITCOINCLI", "bitcoin-cli"), self.datadir)
MarcoFalke commented at 7:50 PM on August 28, 2017:Thinking more about this, I think we should keep
TestNode.clito be the corresponding interface toTestNode.rpc. The logic to hack a different datadir can be placed in the test that checks for-stdinrpcpass. This makes the TestNode code easier to understand, as the datadir overwrite is rarely needed... Likely only once?
jnewbery commented at 6:43 PM on August 29, 2017:I also think I prefer keeping
TestNode.clias a class (and making it callable as per https://github.com/jnewbery/bitcoin/commit/5bfd5e0d47f89f4c2e9becf266876c0c6cc62787), but I'm happy to be convinced the other way. @MarcoFalke - I'm not sure I fully understand your comment though. As things currently stand with this PR, the interface for changingdatadiris to add an argument toTestNode.cli(). How would you propose to make that different?
MarcoFalke commented at 7:11 AM on August 30, 2017:In python every member is public, so changing the datadir is as easy as
self.nodes[0].cli.datadir = './new' # Overwrite datadir, so we pass in rpcuser and password through stdin
jnewbery commented at 2:01 PM on August 30, 2017:yes, that works. I think I still prefer making
TestNodeCLIcallable and addingdatadiras an argument.
MarcoFalke commented at 2:10 PM on August 30, 2017:It is not like we need to pass in anything to
TestNodeCLI. Thedatadirchange is only needed for the test in this pull.
jnewbery commented at 2:15 PM on August 30, 2017:Have you looked at https://github.com/jnewbery/bitcoin/commit/5bfd5e0d47f89f4c2e9becf266876c0c6cc62787 ? Passing arguments to
TestNodeCLIseems like a good way to passbitcoin-clicommand line arguments.(I'm not arguing forcefully for the change in https://github.com/jnewbery/bitcoin/commit/5bfd5e0d47f89f4c2e9becf266876c0c6cc62787 and I'm happy to be shown a different way to do this)
MarcoFalke commented at 2:25 PM on August 30, 2017:I did not.
This also help with selecting the rpcwallet, so making it callable is more useful than I thought.
in test/functional/test_framework/test_node.py:169 in f275cf6501 outdated
162 | @@ -155,13 +163,16 @@ def dispatcher(*args, **kwargs): 163 | 164 | def send_cli(self, command, *args, **kwargs): 165 | """Run bitcoin-cli command. Deserializes returned string as python object.""" 166 | - 167 | + input = None 168 | + if "input" in kwargs: 169 | + input = kwargs["input"] 170 | + del kwargs["input"]
ryanofsky commented at 6:24 PM on August 29, 2017:In commit "[test] Add support for custom arguments to TestNodeCLI"
You could replace these four lines with
input = kwargs.pop("input", None), or change the function signature todef send_cli(self, command, *args, input=None, **kwargs)to get the same result.Probably though it is better just to pass input to the TestNodeCLI constructor as John suggests.
MarcoFalke commented at 7:41 PM on September 5, 2017: member@promag Are you still working on this. I think what is missing is setting up the temp datadir and addressing @ryanofsky feedback..
promag force-pushed on Sep 6, 2017promag force-pushed on Sep 6, 2017promag force-pushed on Sep 6, 2017promag commented at 3:59 PM on September 6, 2017: memberThanks all for the great feedback. These are the relevant changes:
- keep
-datadir input=...moved to.cli(), although-inputis notbitcoin-cliargument 🙄- added tests for invalid authentication
promag force-pushed on Sep 6, 2017in test/functional/test_framework/util.py:80 in ad730f55b1 outdated
75 | + kwds**: named arguments for the function. 76 | + """ 77 | + try: 78 | + fun(*args, **kwds) 79 | + except CalledProcessError as e: 80 | + if (returncode is not None) and (returncode != e.returncode):
jnewbery commented at 7:14 PM on September 6, 2017:You can remove
(returncode is not None)here and(output is not None)below. The only reason I allowedassert_raises_jsonrpc()callers to not specifyreturncodeoroutputwas to be backwards compatible with existing tests which didn't specify those. As far as I'm concerned, tests should always assert return codes and error messages if they're expecting.(we can probably remove the same from
assert_raises_jsonrpc()as well in a separate PR now)
promag commented at 7:56 PM on September 6, 2017:Great, will do.
in test/functional/test_framework/util.py:10 in ad730f55b1 outdated
6 | @@ -7,6 +7,7 @@ 7 | from base64 import b64encode 8 | from binascii import hexlify, unhexlify 9 | from decimal import Decimal, ROUND_DOWN 10 | +from subprocess import CalledProcessError
jnewbery commented at 7:15 PM on September 6, 2017:nit: my personal preference is for imports to be sorted by module name (ie
from subprocess...should be betweenimport reandimport time)
promag commented at 7:52 PM on September 6, 2017:My bad, that's also my preference.
in test/functional/test_framework/util.py:61 in ad730f55b1 outdated
57 | @@ -57,18 +58,44 @@ def assert_raises_message(exc, message, fun, *args, **kwds): 58 | else: 59 | raise AssertionError("No exception raised") 60 | 61 | +def assert_raises_process(returncode, output, fun, *args, **kwds):
jnewbery commented at 7:17 PM on September 6, 2017:nit: perhaps
assert_raises_process_error()?
promag commented at 7:52 PM on September 6, 2017:No problem.
in test/functional/bitcoin_cli.py:28 in ad730f55b1 outdated
20 | @@ -21,5 +21,15 @@ def run_test(self): 21 | 22 | assert_equal(cli_get_info, rpc_get_info) 23 | 24 | + user, password = get_auth_cookie(self.nodes[0].datadir) 25 | + 26 | + self.log.info("Test -stdinrpcpass option") 27 | + assert_equal(0, self.nodes[0].cli('-rpcuser=%s' % user, '-stdinrpcpass', input=password).getblockcount()) 28 | + assert_raises_process(1, "incorrect rpcuser or rpcpassword", self.nodes[0].cli('-rpcuser=%s' % user, '-stdinrpcpass', input="xpto").echo)
jnewbery commented at 7:19 PM on September 6, 2017:Thanks for teaching me some Portuguese: https://pt.wikipedia.org/wiki/X.P.T.O. 🙂
jnewbery commented at 7:27 PM on September 6, 2017: memberA few nits inline. Tested ACK ad730f55b182549c5e95d6cc09be4474a1c3152a
promag force-pushed on Sep 6, 2017laanwj assigned laanwj on Sep 6, 2017Fix style in -stdin and -stdinrpcpass handling 7696841329[test] Improve assert_raises_jsonrpc docstring e1274947d4[test] Add support for custom arguments to TestNodeCLI 5c18a84b9a[test] Add assert_raises_process_error to assert process errors 232e3e8471[test] Replace check_output with low level version ce379b47b9[test] Add bitcoin-cli -stdin and -stdinrpcpass functional tests 29e1dfbd97promag force-pushed on Sep 6, 2017laanwj merged this on Sep 6, 2017laanwj closed this on Sep 6, 2017laanwj referenced this in commit 645a7ecc0b on Sep 6, 2017MarcoFalke referenced this in commit 812c870043 on Oct 3, 2017MarcoFalke referenced this in commit e0bfd28de2 on Oct 3, 2017MarcoFalke referenced this in commit e38211f5e8 on Oct 3, 2017MarcoFalke referenced this in commit 2b97b36e5d on Oct 3, 2017MarcoFalke referenced this in commit de1d8c04ab on Oct 3, 2017PastaPastaPasta referenced this in commit 74801efebf on Sep 23, 2019PastaPastaPasta referenced this in commit a1b2915923 on Sep 24, 2019PastaPastaPasta referenced this in commit 502b1c0387 on Nov 19, 2019PastaPastaPasta referenced this in commit 7329569cda on Nov 21, 2019PastaPastaPasta referenced this in commit 82035124bf on Dec 9, 2019PastaPastaPasta referenced this in commit e9355f9eec on Jan 1, 2020PastaPastaPasta referenced this in commit 871903f0d2 on Jan 2, 2020PastaPastaPasta referenced this in commit 946eb1599f on Jan 2, 2020PastaPastaPasta referenced this in commit 8aeb9e2f86 on Jan 2, 2020PastaPastaPasta referenced this in commit 9ae12e04e2 on Jan 2, 2020PastaPastaPasta referenced this in commit 39c2079743 on Jan 2, 2020PastaPastaPasta referenced this in commit eac4ea76e4 on Jan 2, 2020PastaPastaPasta referenced this in commit 7214f07e78 on Jan 3, 2020PastaPastaPasta referenced this in commit 3b1696a7e6 on Jan 4, 2020PastaPastaPasta referenced this in commit 09e4b00321 on Jan 12, 2020PastaPastaPasta referenced this in commit 1e1a79a68f on Jan 12, 2020PastaPastaPasta referenced this in commit 5de97013f2 on Jan 12, 2020ckti referenced this in commit 6ae78314c7 on Mar 28, 2021DrahtBot locked this on Sep 8, 2021
github-metadata-mirror
This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-13 15:15 UTC
This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me