Skip to content

tests: add curated list of client test invariants from Bitcoin Core - #606

Merged
tcharding merged 1 commit into
rust-bitcoin:masterfrom
satsfy:add-core-tests
May 26, 2026
Merged

tcharding merged 1 commit into
rust-bitcoin:masterfrom
satsfy:add-core-tests

Conversation

@satsfy

@satsfy satsfy commented May 26, 2026 •

Copy link
Copy Markdown
Contributor

Closes #58.

This PR adds 79 tests corresponding to invariants picked after analyzing Bitcoin Core tests from test/functional folder. Identical test copies from core proved unproductive, extensive, and tested much more than necessary for corepc, so invariants (not tests) needed to be filtered. By putting these tests in tests/, there is no additional effort on Cargo.toml.

The criteria:

  • Not a test of Core's behavior.
  • Only the client layer is tested (meaning the tests apply to the state before the into_model conversion).
  • If a particular assertion failed, that means corepc has a bug.
  • The tests are complementary and do not repeat or collide with existing corepc integration tests.

Main targets:

  • Optional fields to prevent absence failures that the into_model conversions failed to catch.
  • Round trips not exercised or already tested.
  • Optional argument paths.
  • Fragile serde renames.
  • Consistency across fields (such as banned_until == ban_created + ban_duration).
  • Nested structs.
  • Tests that prove the mutual sanity of RPCs, compressing simple RPC tests into one (such as getblockhash tip matches best block, get_deployment_info + get_deployment_info_tip).

All test check corepc honor a particular invariant. Previously untested fields are tested. Many tests contain is_some() because exact value assertions are not necessary, as long as the result parses into a particular type. Comprehensiveness was not a target because we test only what Core has. Flags are checked to be covering only the versions it should.

How LLM was used: I read through Core tests to see what we were missing. Started developing a philosophy for assertions to pick. Realized that copying tests directly wouldn't work, so we would need to pick invariants (some are hard to reproduce, need Core's particulars, or test no meaningful corepc behavior). Asked Claude Opus 4.7 to convert the entire Bitcoin Core surface, and started iterating on it, covering gaps where needed, shaving off useless assertions, and sharpening the philosophy of tests.

I have found various errors (such as rediscovering the inconsistency in numeric types) in RPCs/docs, saving them to investigate and open issues later.

After analyzing countless Bitcoin Core tests from test/functional
folder, invariants were picked for corepc such that if a particular
assertion failed, that means corepc has a bug. The tests are
complementary and do not repeat or collide with existing corepc
integration tests.

Identical test copies from core proved unproductive, extense and
tested much more than necessary for corepc. All existing tests are
derivations centered around checking corepc honors a particular
invariant. Optional fields were specially targeted to prevent absence
failures that into_model() conversions failed to catch. Some setups
exercise previously untested fields.
@tcharding

Copy link
Copy Markdown
Member

Mad, bit sad that we didn't find any bugs ...

@tcharding tcharding left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ACK 6f78f2a

@tcharding
tcharding merged commit c01eb4f into rust-bitcoin:master May 26, 2026
39 checks passed
@tcharding

Copy link
Copy Markdown
Member

Good effort man, this is a ton of work.

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.

Test using Core's test cases

2 participants