Antoine Poinsot bb68fb5ec1
Merge #1092: spend: randomized anti-fee sniping
f2791744d8ad3068d12a39bb07f3745012785a5f spend: set locktime for anti-fee sniping (jp1ac4)

Pull request description:

  This is to resolve #44.

  In the first commit, I combine the destinations and change parameters in `spend::create_spend` in order to avoid "too many arguments" error when adding a new parameter. I think these two parameters combine naturally so that `destinations` includes both recipients and change address.

  The second commit sets locktime following the same approach as Bitcoin Core:
  - locktime is set to current tip height, but randomly (about 10% of cases) value is set up to 100 blocks earlier
  - if tip is more than 8 hours old, locktime is set to 0

  For randomness, I'm currently using the current time's milliseconds in order not to add another dependency, which I think is good enough for this use case.

  For consistency, I decided to use "locktime" everywhere instead of "lock time" or "lock-time".

ACKs for top commit:
  darosior:
    ACK f2791744d8ad3068d12a39bb07f3745012785a5f

Tree-SHA512: 69a57cf664e24b32a835c35eaf9016961b2d0f396891a826582044e6302b2ca04dcf5bf2617b5e18dcbfa25cc254a6e8025262718984095677c829ce051a66cc
2024-07-29 12:32:29 +02:00
..
2024-03-28 11:03:15 +00:00
2024-03-28 11:03:15 +00:00

Lianad blackbox tests

Here we test lianad by starting it on a regression testing Bitcoin network, and by then talking to it as an user would, from the outside.

Python scripts are used for the automation, and specifically the pytest framework.

Credits: this test framework was taken and adapted from revaultd, which was itself adapted from C-lightning's test framework.

Building the project for testing

To run the tests, we must build the debug version of lianad. Follow the instructions at doc/BUILD.md but instead of running

$ cargo build --release

Run

$ cargo build

to build the daemon for testing.
The lianad and liana-cli binaries will be in the target/debug directory at the root of the repository.

Test dependencies

Functional tests dependencies can be installed using pip. Use a virtual environment.

# Create a new virtual environment, preferably.
python3 -m venv venv
. venv/bin/activate
# Get the deps
pip install -r tests/requirements.txt

Additionaly you need to have bitcoind installed on your computer, please refer to bitcoincore for installation. You may use a specific bitcoind binary by specifying the BITCOIND_PATH env var.

Running the tests

From the root of the repository:

pytest tests/

For running the tests under Taproot a bitcoind version 26.0 or superior must be used. It can be pointed to using the BITCOIND_PATH variable. For now, one must also compile the taproot_signer Rust program:

(cd tests/tools/taproot_signer && cargo build --release)

Then the test suite can be run by using Taproot descriptors instead of P2WSH descriptors by setting the USE_TAPROOT environment variable to 1.

Tips and tricks

Logging

We use the Live Logging functionality from pytest. It is configured in (pyproject.toml)[../pyproject.toml] to output INFO-level to the console. If a test fails, the entire DEBUG log is output.

You can override the config at runtime with the --log-cli-level option:

pytest -vvv --log-cli-level=DEBUG -k test_startup

Note that we record all logs from daemons, and we start them with log_level = "debug".

Test lints

Just use black.

More

See the environment variables in test_framework/utils.py.