Skip to content

Commit ee69c20

Browse files
committed
Make KeyWallet hashable
1 parent a4da7e3 commit ee69c20

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

iconsdk/wallet/wallet.py

+3
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ def __ne__(self, other: KeyWallet) -> bool:
191191
def __deepcopy__(self, memodict={}) -> KeyWallet:
192192
return KeyWallet.load(self.private_key)
193193

194+
def __hash__(self):
195+
return hash(self._private_key_object.secret)
196+
194197

195198
def public_key_to_address(public_key: bytes) -> str:
196199
if not (len(public_key) == 65 and public_key[0] == 4):

tests/wallet/test_wallet.py

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import copy
22
from typing import Union, Dict
3+
from copy import deepcopy
34

45
import pytest
56

@@ -70,6 +71,11 @@ def test_copy(self):
7071
wallet3 = copy.copy(wallet)
7172
assert wallet == wallet3
7273

74+
def test_hash(self):
75+
wallet = KeyWallet.create()
76+
wallet_dict = {wallet: wallet.public_key}
77+
assert wallet.public_key == wallet_dict[wallet]
78+
7379

7480
def test_public_key_to_address():
7581
wallet: KeyWallet = KeyWallet.create()

0 commit comments

Comments
 (0)