0

I am looking at the some of the Taproot functional tests such as feature_taproot.py to review the open Taproot PR.

I would like to use pdb to debug these tests. Can you provide some guidance on how to do this?

1 Answer 1

0

The Bitcoin Core test documentation provides some guidance on attaching a debugger. The functional tests are in Python so you are correctly choosing pdb (rather than gdb, lldb etc) for the job.

A python debugger can be attached to tests at any point. Just add the line:

import pdb; pdb.set_trace()

anywhere in the test. You will then be able to inspect variables, as well as call methods that interact with the bitcoind nodes-under-test.

If you're unsure where is a good point to attach the debugger one good place is after the random_checksig_style(pubkey) helper is defined in feature_taproot.py. This creates a random CHECKSIG Tapscript that requires only a valid signature on the witness stack.

There is a good video tutorial here from Simeon Franklin on pdb here. There are a large number of pdb commands but the key ones you are most likely to use are:

l(ist)
n(ext)
c(ontinue)
s(tep)
r(eturn)
b(reak)

As Franklin states:

l shows you where you are in your code. n steps to the next line of execution. c leaves debugger control and executes your code normally. s steps into the next line of execution including into function calls if they exist. r steps to the end of the currently executing function and b sets breakpoints. It is important to realize when you are debugging that from the pdb console you can type in any valid Python, changing variables or execution flow of your program and inspecting their values.

(Also p expression for printing an expression value or pp expression for pretty printing an expression value. And whatis expression for printing the type of that expression).

More detailed guidance on using pdb is on python.org but the above should be a good introduction.

Remember that you are making edits to Pieter Wuille's taproot branch locally and will not ever push them to GitHub so you can make whatever changes you want. If you want to revert back to Pieter Wuille's code before you started making edits (and discard all of your edits) you can run

git reset --hard HEAD

and then you should be back to the state before you started experimenting.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.