Skip to content

Conversation

@promag
Copy link
Contributor

@promag promag commented Aug 24, 2017

This patch adds tests for bitcoin-cli options -stdin (#7550) and -stdinrpcpass #10997.

@promag promag force-pushed the 2017-08-stdinrpcpass-functional-test branch from bea65ea to 7162087 Compare August 24, 2017 17:59
@laanwj laanwj added the Tests label Aug 24, 2017
Copy link
Member

@laanwj laanwj Aug 24, 2017

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)

Copy link
Member

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.

Copy link
Contributor

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

@laanwj
Copy link
Member

laanwj commented Aug 24, 2017

Concept ACK

@jnewbery
Copy link
Contributor

Concept ACK, but I recommend you build on top of #10798 which already adds bitcoin-cli interface to TestNode.

@promag
Copy link
Contributor Author

promag commented Aug 24, 2017

I'll refactor now that #10798 is merged.

@promag promag force-pushed the 2017-08-stdinrpcpass-functional-test branch 2 times, most recently from 9c28558 to 64c89a9 Compare August 25, 2017 03:04
@promag promag changed the title Add bitcoin-cli -stdinrpcpass functional test Add bitcoin-cli -stdin and -stdinrpcpass functional tests Aug 25, 2017
@promag
Copy link
Contributor Author

promag commented Aug 25, 2017

@jnewbery take a look at f275cf6, it allows to pass -stdin and -stdinrpcpass. Also, TestNodeCLI instances are only created when necessary.

Updated PR title and description accordingly.

@promag promag force-pushed the 2017-08-stdinrpcpass-functional-test branch from 64c89a9 to 5b4e339 Compare August 25, 2017 03:17
@jnewbery
Copy link
Contributor

See commit here for an alternative way of doing this: jnewbery@5bfd5e0

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 input magic key
  • it maintains the -datadir argument, which I think we want to keep (without that, bitcoin-cli won't have access to the rpcport value in the bitcoin.conf file).

I've proposed that as a test for #10871. Let me know what you think.

@promag
Copy link
Contributor Author

promag commented Aug 25, 2017

It avoids the cludgy input magic key

@jnewbery how do you pass the stdin content?

@jnewbery
Copy link
Contributor

ah sorry, I just looked at the commit at f275cf6 and misunderstood how input was used. I'll re-review.

@maflcko
Copy link
Member

maflcko commented Aug 25, 2017

utACK 5b4e3391f6a7dc9e7148eaee05e285f200f46927

Copy link
Member

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.

@promag
Copy link
Contributor Author

promag commented Aug 28, 2017

Agree!

Copy link
Contributor

@jnewbery jnewbery left a 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.

Copy link
Contributor

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).

Copy link
Member

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.

Copy link
Contributor

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).

Copy link
Contributor

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.

Copy link
Member

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?

Copy link
Contributor

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?

Copy link
Member

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

Copy link
Contributor

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.

Copy link
Member

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.

Copy link
Contributor

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)

Copy link
Member

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.

Copy link
Contributor

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.

@maflcko
Copy link
Member

maflcko commented Sep 5, 2017

@promag Are you still working on this. I think what is missing is setting up the temp datadir and addressing @ryanofsky feedback..

@promag promag force-pushed the 2017-08-stdinrpcpass-functional-test branch 3 times, most recently from 95fe4df to 04e0e12 Compare September 6, 2017 15:54
@promag
Copy link
Contributor Author

promag commented Sep 6, 2017

Thanks all for the great feedback. These are the relevant changes:

  • keep -datadir
  • input=... moved to .cli(), although -input is not bitcoin-cli argument 🙄
  • added tests for invalid authentication

@promag promag force-pushed the 2017-08-stdinrpcpass-functional-test branch from 04e0e12 to ad730f5 Compare September 6, 2017 16:08
Copy link
Contributor

@jnewbery jnewbery left a 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

Copy link
Contributor

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, will do.

Copy link
Contributor

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)

Copy link
Contributor Author

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.

Copy link
Contributor

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()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@promag promag force-pushed the 2017-08-stdinrpcpass-functional-test branch from ad730f5 to 71a13a5 Compare September 6, 2017 20:28
@laanwj laanwj self-assigned this Sep 6, 2017
@promag promag force-pushed the 2017-08-stdinrpcpass-functional-test branch from 71a13a5 to 29e1dfb Compare September 6, 2017 23:38
@laanwj laanwj merged commit 29e1dfb into bitcoin:master Sep 6, 2017
laanwj added a commit that referenced this pull request Sep 6, 2017
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
maflcko pushed a commit to maflcko/bitcoin-core that referenced this pull request Oct 3, 2017
maflcko pushed a commit to maflcko/bitcoin-core that referenced this pull request Oct 3, 2017
maflcko pushed a commit to maflcko/bitcoin-core that referenced this pull request Oct 3, 2017
maflcko pushed a commit to maflcko/bitcoin-core that referenced this pull request Oct 3, 2017
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Dec 9, 2019
…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
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jan 3, 2020
…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]>
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants