Skip to content

Commit 25940c4

Browse files
committed
Make KeyWallet support deepcopy
1 parent 11f9f7b commit 25940c4

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

iconsdk/wallet/wallet.py

+3
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ def __eq__(self, other: KeyWallet) -> bool:
188188
def __ne__(self, other: KeyWallet) -> bool:
189189
return not self.__eq__(other)
190190

191+
def __deepcopy__(self, memodict={}) -> KeyWallet:
192+
return KeyWallet.load(self.private_key)
193+
191194

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

tests/wallet/test_wallet.py

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import copy
12
from typing import Union, Dict
23

34
import pytest
@@ -61,6 +62,14 @@ def test_to_dict(self):
6162
wallet2 = KeyWallet.from_dict(jso, password)
6263
assert wallet2 == wallet
6364

65+
def test_copy(self):
66+
wallet = KeyWallet.create()
67+
wallet2 = copy.deepcopy(wallet)
68+
assert wallet == wallet2
69+
70+
wallet3 = copy.copy(wallet)
71+
assert wallet == wallet3
72+
6473

6574
def test_public_key_to_address():
6675
wallet: KeyWallet = KeyWallet.create()

0 commit comments

Comments
 (0)