Skip to content

Testing more types of HDWallet derived Cardano addresses #103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions pycardano/crypto/bip32.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,11 @@ def derive(
Examples:
>>> mnemonic_words = "test walk nut penalty hip pave soap entry language right filter choice"
>>> hdwallet = HDWallet.from_mnemonic(mnemonic_words)
>>> hdwallet = hdwallet.derive(index=1852, hardened=True)
>>> hdwallet = hdwallet.derive(index=1815, hardened=True)
>>> hdwallet = hdwallet.derive(index=0, hardened=True)
>>> hdwallet = hdwallet.derive(index=0)
>>> hdwallet = hdwallet.derive(index=0)
>>> hdwallet = hdwallet.derive(1852, hardened=True)
>>> hdwallet = hdwallet.derive(1815, hardened=True)
>>> hdwallet = hdwallet.derive(0, hardened=True)
>>> hdwallet = hdwallet.derive(0)
>>> hdwallet = hdwallet.derive(0)
>>> hdwallet.public_key.hex()
'73fea80d424276ad0978d4fe5310e8bc2d485f5f6bb3bf87612989f112ad5a7d'
"""
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from pycardano.address import Address
from pycardano.address import Address, PointerAddress
from pycardano.crypto.bip32 import HDWallet
from pycardano.key import PaymentVerificationKey
from pycardano.network import Network
Expand Down Expand Up @@ -88,11 +88,10 @@ def test_payment_address_12_reward():
def test_payment_address_12_reward2_incorrect_index_value():
wrong_index_type = "1815"
with pytest.raises(ValueError):
HDWallet.from_mnemonic(MNEMONIC_12)\
.derive(wrong_index_type, hardened=True)
HDWallet.from_mnemonic(MNEMONIC_12).derive(wrong_index_type, hardened=True)


def test_payment_address_12_reward2():
def test_payment_address_12_reward_full_public_derivation():
hdwallet_stake = (
HDWallet.from_mnemonic(MNEMONIC_12)
.derive(1852, hardened=True)
Expand Down Expand Up @@ -132,17 +131,17 @@ def test_payment_address_12_reward2_full_private_derivation():
stake_vk = PaymentVerificationKey.from_primitive(stake_public_key)

assert (
Address(
payment_part=None, staking_part=stake_vk.hash(), network=Network.TESTNET
).encode()
== "stake_test1uqevw2xnsc0pvn9t9r9c7qryfqfeerchgrlm3ea2nefr9hqp8n5xl"
Address(
payment_part=None, staking_part=stake_vk.hash(), network=Network.TESTNET
).encode()
== "stake_test1uqevw2xnsc0pvn9t9r9c7qryfqfeerchgrlm3ea2nefr9hqp8n5xl"
)

assert (
Address(
payment_part=None, staking_part=stake_vk.hash(), network=Network.MAINNET
).encode()
== "stake1uyevw2xnsc0pvn9t9r9c7qryfqfeerchgrlm3ea2nefr9hqxdekzz"
Address(
payment_part=None, staking_part=stake_vk.hash(), network=Network.MAINNET
).encode()
== "stake1uyevw2xnsc0pvn9t9r9c7qryfqfeerchgrlm3ea2nefr9hqxdekzz"
)


Expand All @@ -167,6 +166,44 @@ def test_payment_address_12_base():
)


def test_payment_address_12_enterprise():
hdwallet = HDWallet.from_mnemonic(MNEMONIC_12)
hdwallet_spend = hdwallet.derive_from_path("m/1852'/1815'/0'/0/0")
spend_public_key = hdwallet_spend.public_key
spend_vk = PaymentVerificationKey.from_primitive(spend_public_key)

assert (
Address(spend_vk.hash(), network=Network.TESTNET).encode()
== "addr_test1vz2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzerspjrlsz"
)

assert (
Address(spend_vk.hash(), network=Network.MAINNET).encode()
== "addr1vx2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzers66hrl8"
)


def test_payment_address_12_pointer():
hdwallet = HDWallet.from_mnemonic(MNEMONIC_12)
hdwallet_spend = hdwallet.derive_from_path("m/1852'/1815'/0'/0/0")
spend_public_key = hdwallet_spend.public_key
spend_vk = PaymentVerificationKey.from_primitive(spend_public_key)

assert (
Address(
spend_vk.hash(), PointerAddress(1, 2, 3), network=Network.TESTNET
).encode()
== "addr_test1gz2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzerspqgpsqe70et"
)

assert (
Address(
spend_vk.hash(), PointerAddress(24157, 177, 42), network=Network.MAINNET
).encode()
== "addr1gx2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzer5ph3wczvf2w8lunk"
)


def test_payment_address_15_base():
hdwallet = HDWallet.from_mnemonic(MNEMONIC_15)
hdwallet_spend = hdwallet.derive_from_path("m/1852'/1815'/0'/0/0")
Expand All @@ -188,6 +225,44 @@ def test_payment_address_15_base():
)


def test_payment_address_15_enterprise():
hdwallet = HDWallet.from_mnemonic(MNEMONIC_15)
hdwallet_spend = hdwallet.derive_from_path("m/1852'/1815'/0'/0/0")
spend_public_key = hdwallet_spend.public_key
spend_vk = PaymentVerificationKey.from_primitive(spend_public_key)

assert (
Address(spend_vk.hash(), network=Network.TESTNET).encode()
== "addr_test1vpu5vlrf4xkxv2qpwngf6cjhtw542ayty80v8dyr49rf5eg57c2qv"
)

assert (
Address(spend_vk.hash(), network=Network.MAINNET).encode()
== "addr1v9u5vlrf4xkxv2qpwngf6cjhtw542ayty80v8dyr49rf5eg0kvk0f"
)


def test_payment_address_15_pointer():
hdwallet = HDWallet.from_mnemonic(MNEMONIC_15)
hdwallet_spend = hdwallet.derive_from_path("m/1852'/1815'/0'/0/0")
spend_public_key = hdwallet_spend.public_key
spend_vk = PaymentVerificationKey.from_primitive(spend_public_key)

assert (
Address(
spend_vk.hash(), PointerAddress(1, 2, 3), network=Network.TESTNET
).encode()
== "addr_test1gpu5vlrf4xkxv2qpwngf6cjhtw542ayty80v8dyr49rf5egpqgpsdhdyc0"
)

assert (
Address(
spend_vk.hash(), PointerAddress(24157, 177, 42), network=Network.MAINNET
).encode()
== "addr1g9u5vlrf4xkxv2qpwngf6cjhtw542ayty80v8dyr49rf5evph3wczvf2kd5vam"
)


def test_payment_address_24_base():
hdwallet = HDWallet.from_mnemonic(MNEMONIC_24)
hdwallet_spend = hdwallet.derive_from_path("m/1852'/1815'/0'/0/0")
Expand All @@ -209,6 +284,44 @@ def test_payment_address_24_base():
)


def test_payment_address_24_enterprise():
hdwallet = HDWallet.from_mnemonic(MNEMONIC_24)
hdwallet_spend = hdwallet.derive_from_path("m/1852'/1815'/0'/0/0")
spend_public_key = hdwallet_spend.public_key
spend_vk = PaymentVerificationKey.from_primitive(spend_public_key)

assert (
Address(spend_vk.hash(), network=Network.TESTNET).encode()
== "addr_test1vqy6nhfyks7wdu3dudslys37v252w2nwhv0fw2nfawemmnqtjtf68"
)

assert (
Address(spend_vk.hash(), network=Network.MAINNET).encode()
== "addr1vyy6nhfyks7wdu3dudslys37v252w2nwhv0fw2nfawemmnqs6l44z"
)


def test_payment_address_24_pointer():
hdwallet = HDWallet.from_mnemonic(MNEMONIC_24)
hdwallet_spend = hdwallet.derive_from_path("m/1852'/1815'/0'/0/0")
spend_public_key = hdwallet_spend.public_key
spend_vk = PaymentVerificationKey.from_primitive(spend_public_key)

assert (
Address(
spend_vk.hash(), PointerAddress(1, 2, 3), network=Network.TESTNET
).encode()
== "addr_test1gqy6nhfyks7wdu3dudslys37v252w2nwhv0fw2nfawemmnqpqgps5mee0p"
)

assert (
Address(
spend_vk.hash(), PointerAddress(24157, 177, 42), network=Network.MAINNET
).encode()
== "addr1gyy6nhfyks7wdu3dudslys37v252w2nwhv0fw2nfawemmnyph3wczvf2dqflgt"
)


def test_payment_address_12_reward_from_entropy():
hdwallet = HDWallet.from_entropy(MNEMONIC_12_ENTROPY)
hdwallet_stake = hdwallet.derive_from_path("m/1852'/1815'/0'/2/0")
Expand Down