Skip to content

Conversation

@moisesPompilio
Copy link
Collaborator

What is the purpose of this pull request?

  • Bug fix
  • Documentation update
  • New feature
  • Test
  • Other:

Which crates are being modified?

  • floresta-chain
  • floresta-common
  • floresta-compact-filters
  • floresta-electrum
  • floresta-node
  • floresta-rpc
  • floresta-watch-only
  • floresta-wire
  • bin/florestad
  • bin/floresta-cli
  • Other: test-rust

Description and Notes

This PR migrates the existing Python functional tests to Rust to align with the project’s ecosystem and take advantage of Rust’s testing capabilities. Since Floresta and its supporting components are written in Rust, keeping tests in Python added unnecessary complexity and dependency management.

The new Rust-based functional test suite can automatically instantiate a bitcoind, utreexod, and florestad node, simulating full regtest integration. It validates the interoperability between these nodes and verifies that Floresta’s RPC responses match those of Bitcoin Core, essential since Floresta aims to maintain RPC compatibility with Core.

A shared static setup, SHARED_FLORESTAD_BITCOIND_UTREEXOD_WITH_BLOCKS, is provided for tests that require a pre-initialized chain with blocks, improving runtime performance by avoiding repeated setup overhead.

The following RPC endpoints are covered:

  • add_node
  • get_best_block_hash
  • get_block
  • get_blockchain_info
  • get_block_count
  • get_block_hash
  • get_block_header
  • get_memory_info
  • get_peer_info
  • get_roots
  • get_rpc_info
  • get_tx_out
  • ping
  • stop
  • uptime

The tests use the electrsd crate to manage the bitcoind node. This library (also used by BDK and LDK) automatically downloads and launches a bitcoind binary matching the desired version, simplifying setup and communication via RPC.

In CI, a preparation step was added to download the Bitcoin binaries and build utreexod, placing them under /tmp/floresta-func-tests/bin. The CI uses prebuilt binaries for Linux and macOS to reduce build time (Linux only for now).

Additionally, the minimum Rust version was updated to 1.90.0, as some dependencies required a newer compiler. This update aligns the project with the latest stable toolchain.

Tests are isolated behind the functional-tests feature to prevent them from running as part of the standard test suite, since they require external binaries and setup.

Note: Each test spawns a florestad instance, which can cause high parallel load and timeouts if run with too many threads. Recommended command for running them:

cargo test --features=functional-tests -p test-functional -- --test-threads=1

On release builds, all tests complete in roughly 100 seconds using one thread.

This PR depends on #689 #688 #683 #682

How to verify the changes you have done?

Run the functional test suite with the following:

cargo test --features=functional-tests -p test-functional -- --test-threads=1

Alternatively, use prepare.sh to download and prepare the required binaries before running. The tests will automatically start bitcoind, utreexod, and florestad instances and validate RPC responses against bitcoind.

- Fix strippedsize to correctly calculate and return the block size excluding witness data (previously returned total block size)
- Ensure bits, chainwork, and version_hex fields return data in big-endian hex order for proper serialization
- Adjust difficulty to use the appropriate calculation method for accurate float representation
- Add target field to include the block's target value in big-endian hex, which was missing before
Make the fields in GetMemInfoStats and MemInfoLocked public to allow implementations using floresta_rpc to access getmemoryinfo in the rpc
Make the fields in ActiveCommand and GetRpcInfoRes public to allow implementations to access RPC information details via the getrpcinfo method.
…tegration

- Created a new workspace member `test-rust` for functional testing.
- Added `Cargo.toml` for `test-rust` with dependencies for testing.
- Implemented a basic `main.rs` file for the test project.
- Developed common utilities for setting up Bitcoind and Florestad nodes.
- Implemented Utreexod setup and RPC client for interaction with the Utreexod node.
- Added tests for Bitcoind and Florestad integration, including peer connection checks.
- Created functions to generate blocks and manage node interactions.
- Established a shared setup for tests to optimize resource usage.
These tests ensure that Floresta's RPC responses align with Bitcoin Core's RPC for maintaining consensus.
Introduce Rust functional tests in the CI workflow using a matrix strategy for parallel execution with Python tests. Add scripts to prepare and compile necessary binaries for Utreexod and Bitcoind
@moisesPompilio
Copy link
Collaborator Author

I opened this PR initially as a draft to validate the overall approach and confirm that the direction taken meets expectations. Please feel free to share any feedback or suggestions, particularly about the test structure, CI setup, or integration strategy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants