Skip to content

Commit

Permalink
first pass implementing wallet address private key export as a hex st…
Browse files Browse the repository at this point in the history
…ring
  • Loading branch information
Christopher Gerber authored and stat committed Nov 21, 2024
1 parent 550e459 commit a99d22f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cdp/wallet_address.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ def can_sign(self) -> bool:
"""
return self.key is not None

def export(self) -> str:
local_account = self.key

if local_account is None:
raise ValueError("Account is unavailable")

key_bytes = local_account.key

return key_bytes.hex()

def transfer(
self,
amount: Number | Decimal | str,
Expand Down
18 changes: 18 additions & 0 deletions tests/test_wallet_address.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,24 @@ def test_key_setter_raises_error_when_already_set(wallet_address_factory):
wallet_address_with_key.key = new_key


def test_export(wallet_address_factory):
"""Test export method success for a WalletAddress."""
wallet_address_with_key = wallet_address_factory(True)

key_hex = wallet_address_with_key.export()

assert key_hex is not None
assert key_hex is not ""


def test_export_raises_error_when_local_account_is_none(wallet_address_factory):
"""Test export method failure for a WalletAddress with no LocalAccount."""
wallet_address_without_key = wallet_address_factory()

with pytest.raises(ValueError, match="Account is unavailable"):
wallet_address_without_key.export()


@patch("cdp.wallet_address.Transfer")
@patch("cdp.Cdp.api_clients")
@patch("cdp.Cdp.use_server_signer", True)
Expand Down

0 comments on commit a99d22f

Please sign in to comment.