MCPcopy Create free account
hub / github.com/ElementsProject/lightning / test_bip86_newaddr_rpc

Function test_bip86_newaddr_rpc

tests/test_wallet.py:1777–1818  ·  view source on GitHub ↗

Test that BIP86 addresses can be generated via newaddr RPC

(node_factory, chainparams)

Source from the content-addressed store, hash-verified

1775
1776@unittest.skipIf(TEST_NETWORK != 'regtest', "BIP86 tests are regtest-specific")
1777def test_bip86_newaddr_rpc(node_factory, chainparams):
1778 """Test that BIP86 addresses can be generated via newaddr RPC"""
1779 l1 = setup_bip86_node(node_factory)
1780
1781 # Test BIP86 address generation
1782 bip86_addr = l1.rpc.newaddr(addresstype="p2tr")
1783 assert 'p2tr' in bip86_addr
1784 assert 'bech32' not in bip86_addr
1785
1786 # Verify address format (taproot addresses are longer)
1787 p2tr_addr = bip86_addr['p2tr']
1788 assert len(p2tr_addr) > 50
1789
1790 # In regtest, should start with bcrt1p (or appropriate prefix)
1791 assert p2tr_addr.startswith('bcrt1p')
1792
1793 # Test that we're using the correct 64-byte seed from the mnemonic
1794 # Expected seed for "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about":
1795 # "5eb00bbddcf069084889a8ab9155568165f5c453ccb85e70811aaed6f6da5fc19a5ac40b389cd370d086206dec8aa6c43daea6690f20ad3d8d48b2d2ce9e38e4"
1796
1797 # Test that our BIP86 implementation follows the correct derivation path m/86'/0'/0'/0/index
1798 # Generate the same address again and verify it's identical
1799 bip86_addr2 = l1.rpc.newaddr(addresstype="p2tr")
1800 p2tr_addr2 = bip86_addr2['p2tr']
1801
1802 # The second address should be different (next index)
1803 assert p2tr_addr != p2tr_addr2, "Consecutive BIP86 addresses should be different"
1804
1805 # Test against known test vectors for the exact derivation path
1806 # The mainnet test vectors are:
1807 # m/86'/0'/0'/0/0: bc1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxqkedrcr
1808 # m/86'/0'/0'/0/1: bc1p4qhjn9zdvkux4e44uhx8tc55attvtyu358kutcqkudyccelu0was9fqzwh
1809 # m/86'/0'/0'/0/2: bc1p0d0rhyynq0awa9m8cqrcr8f5nxqx3aw29w4ru5u9my3h0sfygnzs9khxz8
1810
1811 # For regtest, the addresses should be the same but with bcrt1p prefix
1812 # Our addresses are for indices 1 and 2, so they should match the regtest versions
1813 expected_regtest_addr_1 = "bcrt1p4qhjn9zdvkux4e44uhx8tc55attvtyu358kutcqkudyccelu0waslcutpz" # index 1
1814 expected_regtest_addr_2 = "bcrt1p0d0rhyynq0awa9m8cqrcr8f5nxqx3aw29w4ru5u9my3h0sfygnzsl8t0dj" # index 2
1815
1816 # Assert on the exact test vectors since we have the correct seed
1817 assert p2tr_addr == expected_regtest_addr_1, f"First address should match test vector for index 1. Expected: {expected_regtest_addr_1}, Got: {p2tr_addr}"
1818 assert p2tr_addr2 == expected_regtest_addr_2, f"Second address should match test vector for index 2. Expected: {expected_regtest_addr_2}, Got: {p2tr_addr2}"
1819
1820
1821@unittest.skipIf(TEST_NETWORK != 'regtest', "BIP86 tests are regtest-specific")

Callers

nothing calls this directly

Calls 2

setup_bip86_nodeFunction · 0.85
newaddrMethod · 0.45

Tested by

no test coverage detected