Add testnet4 network support (Bitcoin Core 28.0+)#109
Conversation
- Add testnet4 to NETWORKS dict with same parameters as testnet3 (tb1 addresses, tpub/tprv, same WIF prefix) - Fix liquid.networks.get_network() to check Bitcoin networks before falling back to elementsregtest - Add comprehensive tests for testnet4 and get_network() behavior Fixes diybitcoinhardware#108
|
Related: This PR addresses the root cause of the issue being worked around in cryptoadvance/specter-desktop#2537. specter-desktop currently has to manually map |
|
Some feedback copied from internal chat: Please take this into account and review the PR with that in mind. |
There was a problem hiding this comment.
Pull request overview
Adds first-class support for Bitcoin Core 28.0+ testnet4 chain naming and ensures Liquid’s get_network() resolves testnet4 (and other Bitcoin networks) to Bitcoin network parameters rather than falling back to Liquid regtest defaults.
Changes:
- Added a
testnet4entry toembit.networks.NETWORKS(matching existing testnet parameters, with its own display name). - Adjusted
embit.liquid.networks.get_network()lookup logic/documentation around Bitcoin-network fallback. - Added a new test module validating
testnet4parameters andliquid.networks.get_network()behavior, including fallback behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
tests/tests/test_networks.py |
Adds unit tests for testnet4 and Liquid/Bitcoin network resolution behavior. |
src/embit/networks.py |
Introduces the testnet4 network configuration (Bitcoin Core 28.0+ chain name). |
src/embit/liquid/networks.py |
Updates get_network() resolution order to check Bitcoin networks before falling back. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| class NetworksTest(TestCase): | ||
| """Tests for network configuration.""" | ||
|
|
There was a problem hiding this comment.
These new tests will be collected by pytest, but they won't run in the MicroPython test flow (cd tests && micropython ./run_tests.py) because tests/tests/__init__.py explicitly imports the test modules to execute and currently doesn't import test_networks. If MicroPython support is in scope for this change, add from .test_networks import * (or equivalent) to tests/tests/__init__.py so this coverage runs there too.
| if name in NETWORKS: | ||
| return NETWORKS[name] | ||
| else: | ||
| return NETWORKS["elementsregtest"] | ||
| # Check if it's a known Bitcoin network (added after NETWORKS is defined) | ||
| # This handles testnet4 and other Bitcoin networks correctly | ||
| if name in networks.NETWORKS: | ||
| return networks.NETWORKS[name] | ||
| # Only fall back to elementsregtest for unknown networks |
There was a problem hiding this comment.
In this module, NETWORKS is later populated with all Bitcoin networks via NETWORKS.update(networks.NETWORKS) (see bottom of file). Because of that, the if name in networks.NETWORKS: branch here is effectively dead code: any key in networks.NETWORKS will already be in NETWORKS, so the earlier if name in NETWORKS: would have returned. Consider either removing the redundant second lookup (and updating the docstring/comments), or removing the NETWORKS.update(...) merge and keeping explicit two-stage lookup to match the described behavior.
|
Closing to recreate against develop branch. Will also fix: testnet4 doesn't exist in Liquid - moving that logic to Bitcoin networks only. |
Summary
Bitcoin Core 28.0+ introduces testnet4 with chain name
testnet4(returned bygetblockchaininfo). This PR adds proper support for testnet4.Changes
1. Add testnet4 to
networks.pyAdded testnet4 network configuration with the same address parameters as testnet3:
tb2. Fix
liquid/networks.pyget_network fallback behaviorPreviously,
get_network('testnet4')would silently fall back toelementsregtest(bech32 prefixert), causing applications to generate Liquid addresses instead of testnet addresses.Now the function checks Bitcoin networks before falling back:
3. Add comprehensive tests
New
test_networks.pywith 8 tests covering:get_network()behavior for Bitcoin networksget_network()behavior for liquid networksTesting
All 8 new tests pass. Existing liquid tests also pass.
Fixes #108