Skip to content

Commit ee5e411

Browse files
UPDATE. ensure only bytes values are evaluated for PointerAddress.from_primitive()
1 parent 78df264 commit ee5e411

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

pycardano/address.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
)
2020
from pycardano.hash import VERIFICATION_KEY_HASH_SIZE, ScriptHash, VerificationKeyHash
2121
from pycardano.network import Network
22-
from pycardano.serialization import CBORSerializable
22+
from pycardano.serialization import CBORSerializable, Primitive
2323

2424
__all__ = ["AddressType", "PointerAddress", "Address"]
2525

@@ -160,7 +160,11 @@ def to_primitive(self) -> bytes:
160160
return self.encode()
161161

162162
@classmethod
163-
def from_primitive(cls: Type[PointerAddress], value: bytes) -> PointerAddress:
163+
def from_primitive(cls: Type[PointerAddress], value: Primitive) -> PointerAddress:
164+
if not isinstance(value, bytes):
165+
raise DeserializeException(
166+
f"A bytes value is required for deserialization: {value}"
167+
)
164168
return cls.decode(value)
165169

166170
def __eq__(self, other):

test/pycardano/test_address.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
from pycardano.address import Address
1+
from unittest import TestCase
2+
3+
from pycardano.address import Address, PointerAddress
4+
from pycardano.exception import DeserializeException
25
from pycardano.key import PaymentVerificationKey
36
from pycardano.network import Network
47

@@ -15,3 +18,9 @@ def test_payment_addr():
1518
Address(vk.hash(), network=Network.TESTNET).encode()
1619
== "addr_test1vr2p8st5t5cxqglyjky7vk98k7jtfhdpvhl4e97cezuhn0cqcexl7"
1720
)
21+
22+
23+
class PointerAddressTest(TestCase):
24+
def test_from_primitive_invalid_value(self):
25+
with self.assertRaises(DeserializeException):
26+
PointerAddress.from_primitive(1)

0 commit comments

Comments
 (0)