Skip to content

Commit

Permalink
Make KeyWallet hashable
Browse files Browse the repository at this point in the history
  • Loading branch information
eunsoo-icon committed Apr 27, 2023
1 parent a4da7e3 commit ee69c20
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions iconsdk/wallet/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 6 additions & 0 deletions tests/wallet/test_wallet.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import copy
from typing import Union, Dict
from copy import deepcopy

import pytest

Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit ee69c20

Please sign in to comment.