Skip to content
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

qa: Support using bitcoind in fedpeg test #415

Merged

Conversation

stevenroose
Copy link
Member

@stevenroose stevenroose commented Sep 24, 2018

This ports the functionality from pegging.py to the feature_fedpeg.py
test. The following two commands are not equivalent:

$ ./qa/rpc-tests/pegging.py dir/to/bitcoin
$ ./qa/pull-tester/rpc-tests.py feature_fedpeg --parent_bitcoin \
    --parent_binpath=bin/to/bitcoin/bitcoind

@@ -47,9 +49,30 @@ def __init__(self):
self.setup_clean_chain = True
self.num_nodes = 4

def setup_network(self, split=False):
def add_options(self, parser):
parser.add_option("--bitcoinddir", dest="bitcoinddir", default="",
Copy link
Contributor

Choose a reason for hiding this comment

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

perhaps use --binpath or something directly instead of appending bitcoind in the test?
That way we could also use another elements binary, perhaps an older one to test compatibility or a newer one for testing rebases.
For that we would need to decouple another option --parent_is_bitcoinlike or something of the sort.

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed to --parent_bitcoin and --parent_binpath= :)

] for n in range(2)]

binary = os.path.join(self.options.bitcoinddir, "bitcoind")
self.nodes = start_nodes(2, self.options.tmpdir, self.extra_args[:2], binary=binary, chain="regtest")
Copy link
Contributor

Choose a reason for hiding this comment

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

there's still no -chain=regtest option in normal bitcoind binaries, so in https://github.com/ElementsProject/elements/blob/elements-0.14.1/qa/rpc-tests/test_framework/util.py#L343 you will need to replace '-chain='+chain with just '-regtest' if chain == 'regtest'

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I wanted to try. Is this why it fails? I thought it might just ignore it.

@stevenroose stevenroose changed the title WIP feature_fedpeg with bitoind WIP feature_fedpeg with bitcoind Sep 24, 2018
@stevenroose stevenroose force-pushed the fedpeg-bitcoind branch 4 times, most recently from d6660ac to 4e2ac62 Compare September 24, 2018 17:22
self.nodes = start_nodes(2, self.options.tmpdir, self.extra_args[:2], chain='parent')
chain = None
if self.options.parent_bitcoin:
if self.options.parent_binpath == "":
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't this be filtered in rpc-tests.py as well? This way a top-level arg there could trigger this, or not, safely.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't understand your point..

Copy link
Collaborator

Choose a reason for hiding this comment

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

rpc-tests.py will run all tests in sequence. I'd rather catch this argument error up front instead of waiting for this to be run.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, you can pass these arguments to rpc-tests.py and they are globally set for all tests??

Copy link
Collaborator

Choose a reason for hiding this comment

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

That was my hope, yes

Should be able to just make it some global(?)

Copy link
Member Author

Choose a reason for hiding this comment

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

Euhm, it seems that that's not possible anyway. If you run rpc-tests.py with those arguments, all other tests will complain that they don't know the arguments:

create_cache.py: error: no such option: --parent_bitcoin

Also, I think for now it makes more sense to only use those flags when running this test specifically..

Copy link
Collaborator

Choose a reason for hiding this comment

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

meh ok

args = [ binary, '-chain='+chain, "-datadir="+datadir, "-server", "-keypool=1", "-discover=0", "-rest", "-mocktime="+str(get_mocktime()) ]
args = [ binary, "-datadir="+datadir, "-server", "-keypool=1", "-discover=0", "-rest", "-mocktime="+str(get_mocktime()) ]
if chain != "regtest": #TODO(stevenroose) remove if unnecessary or when bitcoind has -chain
args.append("-chain="+chain)
Copy link
Contributor

Choose a reason for hiding this comment

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

why not?

    # Special case for regtest. Remove if bitcoind gets -chain
    if chain == 'regtest': 
        args.append('-regtest')
    else:
        args.append('-chain=' + chain)

Copy link
Contributor

@jtimon jtimon Sep 24, 2018

Choose a reason for hiding this comment

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

Or perhaps just

args.append('-regtest' if chain == 'regtest' else: '-chain=' + chain)

or some more pythonic way to do it (haven't tried this one, but I know there's something like the '?' keyword in C, java and friends).

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I made it conditional and put a todo to remove it :)

@stevenroose stevenroose changed the title WIP feature_fedpeg with bitcoind qa: Support using bitcoind in fedpeg test Sep 25, 2018
@stevenroose
Copy link
Member Author

Like @jtimon pointed out, this also allows to use a custom elements binary for the parent chain. F.e. any liquid binary.

parser.add_option("--parent_bitcoin", dest="parent_bitcoin", default=False, action="store_true",
help="Parent nodes are Bitcoin")

def start_node(self, idx):
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not so sure this adds a lot of readibility, you could just use:

start_node(n, self.options.tmpdir, self.extra_args[n], chain='sidechain')

in one place and

binary = self.options.parent_binpath if self.options.parent_binpath != "" else None
chain = "regtest" if self.options.parent_bitcoin else "parent"
start_node(n, self.options.tmpdir, self.extra_args[n], binary=binary, chain=chain)

In the other, at least for the sidechains case seems unnecessarily complicated.

Copy link
Member Author

Choose a reason for hiding this comment

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

I also use it to restart the node lateron.

raise Exception("Peg-in with non-matching claim_script should fail.")
except JSONRPCException as e:
print(e.error["message"])
print('ERROR:', e.error)
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you sure removing ['message'] makes the printed error more clear?

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's a bit too noisy imo.

@instagibbs
Copy link
Collaborator

let's set printtoconsole=0 for both bitcoind/elementsd, otherwise 0.17+ nodes make a ton of noise on the test.

help="Parent nodes are Bitcoin")

def start_node(self, idx):
is_parent = idx < 2
Copy link
Collaborator

Choose a reason for hiding this comment

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

this isn't very readable, add a comment or make it more explicit in code?

Copy link
Contributor

Choose a reason for hiding this comment

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

or just get rid of the function as I propose above

def setup_network(self, split=False):
if self.options.parent_bitcoin and self.options.parent_binpath == "":
raise "Can't run with --parent_bitcoin without specifying --parent_binpath"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unexpected exception caught during testing: TypeError('exceptions must derive from BaseException',)

Can we handle this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Just put the quote in Exception()

@instagibbs
Copy link
Collaborator

instagibbs commented Sep 25, 2018

Let's also fix up our handling of 0.17 validateaddress ala #416

@instagibbs
Copy link
Collaborator

I just realized this test isn't setting fedpegscript, which results in the peg-in witness stuff being a kind of a no-op... let's set it in the PR. It can just literally be the script in pegging.py:

fedpeg_key="cPxqWyf1HDGpGFH1dnfjz8HbiWxvwG8WXyetbuAiw4thKXUdXLpR"
fedpeg_script="512103dff4923d778550cc13ce0d887d737553b4b58f4e8e886507fc39f5e447b2186451ae"

no need to import it or anything, just set it.

@instagibbs
Copy link
Collaborator

Here's some suggested fixes: instagibbs@af19891

@instagibbs
Copy link
Collaborator

this too: instagibbs@d084d36

@jtimon
Copy link
Contributor

jtimon commented Sep 26, 2018

Can we squash "qa: Fix bug in feature_fedpeg test script"? it isn't really fixing anything, it works the same before and after the change.
Also, more suggestions https://github.com/jtimon/elements/tree/pr-415
Feel free to take some but not others.

@jtimon
Copy link
Contributor

jtimon commented Sep 26, 2018

Do we really need rpc: "reject non-hex strings for claim_script" here?
We're not calling createrawpegin from the tests (perhaps we should).
Also, it would be nice to test that new error, but it seems orthogonal to the PR.

@instagibbs
Copy link
Collaborator

@jtimon yes we are, claimpegin calls the raw version.

@jtimon
Copy link
Contributor

jtimon commented Sep 26, 2018

Ok, either way I had to call it directly from the test to get the 'Given claim_script is not hex' exception. Updated https://github.com/jtimon/elements/tree/pr-415 with that.

parent_pubkey = parent.validateaddress(parent_chain_addr)["pubkey"]
parent_chain_p2sh_addr = parent.createmultisig(1, [parent_pubkey])["address"]
self.test_pegout(parent_chain_p2sh_addr, sidechain)
# print("Test pegout P2SH")
Copy link
Collaborator

Choose a reason for hiding this comment

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

why?

Copy link
Contributor

Choose a reason for hiding this comment

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

read the commits, perhaps better read the commit tittles in the branch without the squashes: https://github.com/jtimon/elements/tree/pr-415

Copy link
Collaborator

Choose a reason for hiding this comment

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

please don't disable swaths of tests when it's very possible to retain them

jtimon and others added 5 commits September 26, 2018 19:05
This ports the functionality from pegging.py to the feature_fedpeg.py
test.  The following two commands are not equivalent:

$ ./qa/rpc-tests/pegging.py dir/to/bitcoin

$ ./qa/pull-tester/rpc-tests.py feature_fedpeg --parent_bitcoin \
    --parent_binpath=bin/to/bitcoin/bitcoind
@jtimon
Copy link
Contributor

jtimon commented Sep 26, 2018

Updated https://github.com/jtimon/elements/tree/pr-415 with a squashed version that works with 0.17.0

@jtimon
Copy link
Contributor

jtimon commented Sep 26, 2018

Tested ACK 498877e

@jtimon
Copy link
Contributor

jtimon commented Sep 26, 2018

oh, and I guess you can add an extra commit getting rid of pegging.py

@stevenroose
Copy link
Member Author

Done :)

self.extra_args.append([
# '-printtoconsole',
args = [
"-printtoconsole",
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: can we set this to 0?

Copy link
Member Author

Choose a reason for hiding this comment

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

I added a commit to do this. If you want me to squash it with the others, let me know..

Copy link
Collaborator

Choose a reason for hiding this comment

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

You commented out, not put to 0. Bitcoin Core 0.17 defaults to 1.

@instagibbs
Copy link
Collaborator

@stevenroose Sorry I mean explicitly set to 0. Future Core version are 1 by default.

@instagibbs
Copy link
Collaborator

We have no coverage of the cookie auth connection to parent node in this test.

@instagibbs
Copy link
Collaborator

tACK 9545ca3

@instagibbs instagibbs merged commit 9545ca3 into ElementsProject:elements-0.14.1 Sep 26, 2018
instagibbs added a commit that referenced this pull request Sep 26, 2018
9545ca3 qa: Disable -printtoconsole in feature_fedpeg (Steven Roose)
1451e86 qa: Remove pegging.py in favor of feature_fedpeg.py (Steven Roose)
498877e QA: Fix feature_fedpeg.py to work with 0.17.0 (Jorge Timón)
a7736f8 QA: Add test to get 'Given claim_script is not hex' error (Jorge Timón)
35364b6 rpc: reject non-hex strings for claim_script (Gregory Sanders)
07c617b qa: Support using bitcoind in fedpeg test (Steven Roose)
729969d QA: Special case for regtest, expected to be used for binaries that lack -chain (Jorge Timón)
@instagibbs
Copy link
Collaborator

I'll follow-up with cookie auth check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants