-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Add bitcoin-cli -stdin and -stdinrpcpass functional tests #11125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add bitcoin-cli -stdin and -stdinrpcpass functional tests #11125
Conversation
bea65ea to
7162087
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need a way to override what bitcoin-cli to use, akin to BITCOIND environment 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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might be able to hack something up based on TestNodeCLI from current master branch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should already be possible with #10798 merged
|
Concept ACK |
|
Concept ACK, but I recommend you build on top of #10798 which already adds |
|
I'll refactor now that #10798 is merged. |
9c28558 to
64c89a9
Compare
|
@jnewbery take a look at f275cf6, it allows to pass Updated PR title and description accordingly. |
64c89a9 to
5b4e339
Compare
|
See commit here for an alternative way of doing this: jnewbery@5bfd5e0 A few advantages:
I've proposed that as a test for #10871. Let me know what you think. |
@jnewbery how do you pass the stdin content? |
|
ah sorry, I just looked at the commit at f275cf6 and misunderstood how |
|
utACK 5b4e3391f6a7dc9e7148eaee05e285f200f46927 |
test/functional/bitcoin_cli.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to make a temporary, empty datadir here instead of make it use the default. The tests should not touch ~/.bitcoin.
|
Agree! |
jnewbery
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks generally good to me. A couple of nits inline.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should add an error here. If args is specified, then datadir must be one of the args (otherwise bitcoin-cli will look in ~/.bitcoin).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another option would be to set datadir=self.datadir if it isn't overridden otherwise. As you say, there is no reason the argument should ever be missing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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).
test/functional/bitcoin_cli.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems weird to me that input is an argument to the RPC, rather than an argument to the bitcoin-cli instance.
It seems possible that an RPC will have input as a parameter. Rather less likely that bitcoin-cli will add an argument called input.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking more about this, I think we should keep TestNode.cli to be the corresponding interface to TestNode.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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also think I prefer keeping TestNode.cli as a class (and making it callable as per jnewbery@5bfd5e0), 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 changing datadir is to add an argument to TestNode.cli(). How would you propose to make that different?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, that works. I think I still prefer making TestNodeCLI callable and adding datadir as an argument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not like we need to pass in anything to TestNodeCLI. The datadir change is only needed for the test in this pull.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you looked at jnewbery@5bfd5e0 ?
Passing arguments to TestNodeCLI seems like a good way to pass bitcoin-cli command line arguments.
(I'm not arguing forcefully for the change in jnewbery@5bfd5e0 and I'm happy to be shown a different way to do this)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not.
This also help with selecting the rpcwallet, so making it callable is more useful than I thought.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 to def 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.
|
@promag Are you still working on this. I think what is missing is setting up the temp datadir and addressing @ryanofsky feedback.. |
95fe4df to
04e0e12
Compare
|
Thanks all for the great feedback. These are the relevant changes:
|
04e0e12 to
ad730f5
Compare
jnewbery
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few nits inline. Tested ACK ad730f55b182549c5e95d6cc09be4474a1c3152a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove (returncode is not None) here and (output is not None) below. The only reason I allowed assert_raises_jsonrpc() callers to not specify returncode or output was 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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, will do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: my personal preference is for imports to be sorted by module name (ie from subprocess... should be between import re and import time)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, that's also my preference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: perhaps assert_raises_process_error()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem.
test/functional/bitcoin_cli.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for teaching me some Portuguese: https://pt.wikipedia.org/wiki/X.P.T.O. 🙂
ad730f5 to
71a13a5
Compare
71a13a5 to
29e1dfb
Compare
29e1dfb [test] Add bitcoin-cli -stdin and -stdinrpcpass functional tests (João Barbosa) ce379b4 [test] Replace check_output with low level version (João Barbosa) 232e3e8 [test] Add assert_raises_process_error to assert process errors (João Barbosa) 5c18a84 [test] Add support for custom arguments to TestNodeCLI (João Barbosa) e127494 [test] Improve assert_raises_jsonrpc docstring (João Barbosa) 7696841 Fix style in -stdin and -stdinrpcpass handling (João Barbosa) Pull request description: This patch adds tests for `bitcoin-cli` options `-stdin` (#7550) and `-stdinrpcpass` #10997. Tree-SHA512: fd8133f44876f2b5b41dfd3762b1988598f6b7bf13fb2385ad95876825d9c0b2b896ce4ea6eeb21012158e1f276907f155d37bb967198b609d2d3dddbfa334c1
Github-Pull: bitcoin#11125 Rebased-From: e127494
Github-Pull: bitcoin#11125 Rebased-From: 5c18a84
Github-Pull: bitcoin#11125 Rebased-From: 232e3e8
Github-Pull: bitcoin#11125 Rebased-From: ce379b4
…nal tests 29e1dfb [test] Add bitcoin-cli -stdin and -stdinrpcpass functional tests (João Barbosa) ce379b4 [test] Replace check_output with low level version (João Barbosa) 232e3e8 [test] Add assert_raises_process_error to assert process errors (João Barbosa) 5c18a84 [test] Add support for custom arguments to TestNodeCLI (João Barbosa) e127494 [test] Improve assert_raises_jsonrpc docstring (João Barbosa) 7696841 Fix style in -stdin and -stdinrpcpass handling (João Barbosa) Pull request description: This patch adds tests for `bitcoin-cli` options `-stdin` (bitcoin#7550) and `-stdinrpcpass` bitcoin#10997. Tree-SHA512: fd8133f44876f2b5b41dfd3762b1988598f6b7bf13fb2385ad95876825d9c0b2b896ce4ea6eeb21012158e1f276907f155d37bb967198b609d2d3dddbfa334c1
…nal tests 29e1dfb [test] Add bitcoin-cli -stdin and -stdinrpcpass functional tests (João Barbosa) ce379b4 [test] Replace check_output with low level version (João Barbosa) 232e3e8 [test] Add assert_raises_process_error to assert process errors (João Barbosa) 5c18a84 [test] Add support for custom arguments to TestNodeCLI (João Barbosa) e127494 [test] Improve assert_raises_jsonrpc docstring (João Barbosa) 7696841 Fix style in -stdin and -stdinrpcpass handling (João Barbosa) Pull request description: This patch adds tests for `bitcoin-cli` options `-stdin` (bitcoin#7550) and `-stdinrpcpass` bitcoin#10997. Tree-SHA512: fd8133f44876f2b5b41dfd3762b1988598f6b7bf13fb2385ad95876825d9c0b2b896ce4ea6eeb21012158e1f276907f155d37bb967198b609d2d3dddbfa334c1 remove duplicate method Signed-off-by: Pasta <[email protected]>
This patch adds tests for
bitcoin-clioptions-stdin(#7550) and-stdinrpcpass#10997.