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

Function test_bip86_newaddr_rpc

tests/test_wallet.py:1778–1819  ·  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

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