From ee69c20d12ace296aa13736fe11df6d0c3cc9d7a Mon Sep 17 00:00:00 2001 From: Eunsoo Park Date: Thu, 27 Apr 2023 12:27:09 +0900 Subject: [PATCH] Make KeyWallet hashable --- iconsdk/wallet/wallet.py | 3 +++ tests/wallet/test_wallet.py | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/iconsdk/wallet/wallet.py b/iconsdk/wallet/wallet.py index 7bcee0d..8f17b7b 100644 --- a/iconsdk/wallet/wallet.py +++ b/iconsdk/wallet/wallet.py @@ -191,6 +191,9 @@ def __ne__(self, other: KeyWallet) -> bool: def __deepcopy__(self, memodict={}) -> KeyWallet: return KeyWallet.load(self.private_key) + def __hash__(self): + return hash(self._private_key_object.secret) + def public_key_to_address(public_key: bytes) -> str: if not (len(public_key) == 65 and public_key[0] == 4): diff --git a/tests/wallet/test_wallet.py b/tests/wallet/test_wallet.py index 2b3cf27..dbc0ea7 100644 --- a/tests/wallet/test_wallet.py +++ b/tests/wallet/test_wallet.py @@ -1,5 +1,6 @@ import copy from typing import Union, Dict +from copy import deepcopy import pytest @@ -70,6 +71,11 @@ def test_copy(self): wallet3 = copy.copy(wallet) assert wallet == wallet3 + def test_hash(self): + wallet = KeyWallet.create() + wallet_dict = {wallet: wallet.public_key} + assert wallet.public_key == wallet_dict[wallet] + def test_public_key_to_address(): wallet: KeyWallet = KeyWallet.create()