Skip to content

Commit

Permalink
tests: Store the CPFP priv_key in cpfp_secret
Browse files Browse the repository at this point in the history
Also adds the `with_cpfp` flag to disable the CPFP in tests where
it's not needed
  • Loading branch information
danielabrozzoni committed Dec 10, 2021
1 parent f82ea23 commit b834a5d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 13 deletions.
17 changes: 13 additions & 4 deletions tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,13 @@ def revaultd_stakeholder(bitcoind, directory):
datadir = os.path.join(directory, "revaultd")
os.makedirs(datadir, exist_ok=True)
(stks, cosigs, mans, _, _, _) = get_participants(2, 3)
# TODO: implement CPFP
cpfp_xprivs = [
bytes.fromhex(
"0435839400000000000000000060499f801b896d83179a4374aeb7822aaeaceaa0db1f85ee3e904c4defbd9689004b03d6fc340455b363f51020ad3ecca4f0850280cf436c70c727923f6db46c3e",
)
]
cpfp_xpubs = [
"tpubDFaf3f5ukV7mGPGzniLKNdd34AZiwtLPnawjqcGSsmqsx5Yzr7V1yBugayF8nrjZ6GZfeunZ7fzQcMixLEDY6cPozKNg3V9v2nwPZD3xShx"
"tpubD6NzVbkrYhZ4XJDrzRvuxHEyQaPd1mwwdDofEJwekX18tAdsqeKfxss79AJzg1431FybXg5rfpTrJF4iAhyR7RubberdzEQXiRmXGADH2eA"
]
stks_xpubs = [stk.get_xpub() for stk in stks]
cosigs_keys = []
Expand Down Expand Up @@ -176,9 +180,13 @@ def revaultd_manager(bitcoind, directory):
datadir = os.path.join(directory, "revaultd")
os.makedirs(datadir, exist_ok=True)
(stks, cosigs, mans, _, _, _) = get_participants(2, 3)
# TODO: implement CPFP
cpfp_xprivs = [
bytes.fromhex(
"0435839400000000000000000060499f801b896d83179a4374aeb7822aaeaceaa0db1f85ee3e904c4defbd9689004b03d6fc340455b363f51020ad3ecca4f0850280cf436c70c727923f6db46c3e",
)
]
cpfp_xpubs = [
"tpubDFaf3f5ukV7mGPGzniLKNdd34AZiwtLPnawjqcGSsmqsx5Yzr7V1yBugayF8nrjZ6GZfeunZ7fzQcMixLEDY6cPozKNg3V9v2nwPZD3xShx"
"tpubD6NzVbkrYhZ4XJDrzRvuxHEyQaPd1mwwdDofEJwekX18tAdsqeKfxss79AJzg1431FybXg5rfpTrJF4iAhyR7RubberdzEQXiRmXGADH2eA"
]
stks_xpubs = [stk.get_xpub() for stk in stks]
cosigs_keys = []
Expand Down Expand Up @@ -208,6 +216,7 @@ def revaultd_manager(bitcoind, directory):
bitcoind.rpcport,
bitcoind_cookie,
man_config=man_config,
cpfp_priv=cpfp_xprivs[0],
)
revaultd.start()

Expand Down
2 changes: 1 addition & 1 deletion tests/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pytest==6.2
pytest-xdist==1.31.0
pytest-timeout==1.3.4
ephemeral_port_reserve==1.1.1
bip32~=2.0
bip32~=2.1
psycopg2-binary==2.9
pynacl==1.4

Expand Down
15 changes: 11 additions & 4 deletions tests/test_framework/revault_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def deploy(
managers_threshold=None,
with_cosigs=True,
with_watchtowers=True,
with_cpfp=True,
bitcoind_rpc_mocks=[],
):
"""
Expand Down Expand Up @@ -104,11 +105,15 @@ def deploy(
csv = random.randint(1, 26784)
self.csv = csv

# TODO: implement CPFP
cpfp_xpubs = [
bip32.BIP32.from_seed(os.urandom(32), network="test").get_xpub()
for _ in range(len(mans_keychains))
man_cpfp_privs = [
bip32.BIP32.from_seed(os.urandom(32), network="test")
for _ in range(len(manonly_keychains))
]
stkman_cpfp_privs = [
bip32.BIP32.from_seed(os.urandom(32), network="test")
for _ in range(len(stkman_man_keychains))
]
cpfp_xpubs = [c.get_xpub() for c in man_cpfp_privs + stkman_cpfp_privs]
stks_xpubs = [stk.get_xpub() for stk in stks_keychains]
cosigs_keys = [cosig.get_static_key().hex() for cosig in cosigs_keychains]
mans_xpubs = [man.get_xpub() for man in mans_keychains]
Expand Down Expand Up @@ -363,6 +368,7 @@ def deploy(
stk_config,
man_config,
wt_process=miradord if with_watchtowers else None,
cpfp_priv=stkman_cpfp_privs[i].get_xpriv_bytes() if with_cpfp else None,
)
start_jobs.append(self.executor.submit(revaultd.start))
self.stkman_wallets.append(revaultd)
Expand Down Expand Up @@ -398,6 +404,7 @@ def deploy(
bitcoind_rpcport,
bitcoind_cookie,
man_config,
man_cpfp_privs[i].get_xpriv_bytes() if with_cpfp else None,
)
start_jobs.append(self.executor.submit(daemon.start))
self.man_wallets.append(daemon)
Expand Down
21 changes: 17 additions & 4 deletions tests/test_framework/revaultd.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def __init__(
stk_config=None,
man_config=None,
wt_process=None,
cpfp_priv=None,
):
# set descriptors
self.cpfp_desc = cpfp_desc
Expand All @@ -52,6 +53,11 @@ def __init__(
with open(noise_secret_file, "wb") as f:
f.write(noise_priv)

if cpfp_priv is not None:
cpfp_secret_file = os.path.join(self.datadir_with_network, "cpfp_secret")
with open(cpfp_secret_file, "wb") as f:
f.write(cpfp_priv)

with open(self.conf_file, "w") as f:
f.write(f"data_dir = '{datadir}'\n")
f.write("daemon = false\n")
Expand Down Expand Up @@ -170,6 +176,7 @@ def __init__(
bitcoind_rpc,
bitcoind_cookie,
man_config,
cpfp_priv,
):
"""The wallet daemon for a manager.
Needs to know all xpubs, and needs to be able to connect to the
Expand All @@ -185,7 +192,10 @@ def __init__(
coordinator_port,
bitcoind_rpc,
bitcoind_cookie,
stk_config=None,
man_config=man_config,
wt_process=None,
cpfp_priv=cpfp_priv,
)
assert self.man_keychain is not None

Expand Down Expand Up @@ -219,9 +229,10 @@ def __init__(
coordinator_port,
bitcoind_rpc,
bitcoind_cookie,
stk_config,
stk_config=stk_config,
man_config=None,
wt_process=wt_process,
cpfp_priv=None,
)
assert self.stk_keychain is not None

Expand All @@ -241,6 +252,7 @@ def __init__(
stk_config,
man_config,
wt_process,
cpfp_priv,
):
"""A revaultd instance that is both stakeholder and manager."""
super(StkManRevaultd, self).__init__(
Expand All @@ -253,7 +265,8 @@ def __init__(
coordinator_port,
bitcoind_rpc,
bitcoind_cookie,
stk_config,
man_config,
wt_process,
stk_config=stk_config,
man_config=man_config,
wt_process=wt_process,
cpfp_priv=cpfp_priv,
)

0 comments on commit b834a5d

Please sign in to comment.