From b558c68193eef91bbccbe4049608316e209472fe Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Sun, 24 Sep 2023 18:10:41 +0200 Subject: [PATCH] fix spelling --- cashu/core/secret.py | 7 ++++++- cashu/wallet/htlc.py | 6 +++--- tests/test_wallet_htlc.py | 12 ++++++------ tests/test_wallet_p2pk.py | 6 ++++++ 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/cashu/core/secret.py b/cashu/core/secret.py index 72bbd1f9..cca5723c 100644 --- a/cashu/core/secret.py +++ b/cashu/core/secret.py @@ -25,7 +25,12 @@ def __init__(self, tags: Optional[List[List[str]]] = None, **kwargs): self.__root__ = tags or [] def __setitem__(self, key: str, value: str) -> None: - self.__root__.append([key, value]) + if self.get_tag(key) is None: + self.__root__.append([key, value]) + else: + for tag in self.__root__: + if tag[0] == key: + tag.append(value) def __getitem__(self, key: str) -> Union[str, None]: return self.get_tag(key) diff --git a/cashu/wallet/htlc.py b/cashu/wallet/htlc.py index 9ed5dc68..dae24571 100644 --- a/cashu/wallet/htlc.py +++ b/cashu/wallet/htlc.py @@ -22,7 +22,7 @@ async def create_htlc_lock( *, preimage: Optional[str] = None, preimage_hash: Optional[str] = None, - hacklock_pubkey: Optional[str] = None, + hashlock_pubkey: Optional[str] = None, locktime_seconds: Optional[int] = None, locktime_pubkey: Optional[str] = None, ) -> HTLCSecret: @@ -39,8 +39,8 @@ async def create_htlc_lock( assert preimage_hash, "preimage_hash or preimage must be provided" - if hacklock_pubkey: - tags["pubkeys"] = hacklock_pubkey + if hashlock_pubkey: + tags["pubkeys"] = hashlock_pubkey return HTLCSecret( kind=SecretKind.HTLC, diff --git a/tests/test_wallet_htlc.py b/tests/test_wallet_htlc.py index 5128b3ab..37833672 100644 --- a/tests/test_wallet_htlc.py +++ b/tests/test_wallet_htlc.py @@ -117,7 +117,7 @@ async def test_htlc_redeem_with_no_signature(wallet1: Wallet, wallet2: Wallet): pubkey_wallet1 = await wallet1.create_p2pk_pubkey() # preimage_hash = hashlib.sha256(bytes.fromhex(preimage)).hexdigest() secret = await wallet1.create_htlc_lock( - preimage=preimage, hacklock_pubkey=pubkey_wallet1 + preimage=preimage, hashlock_pubkey=pubkey_wallet1 ) # p2pk test _, send_proofs = await wallet1.split_to_send(wallet1.proofs, 8, secret_lock=secret) @@ -137,11 +137,11 @@ async def test_htlc_redeem_with_wrong_signature(wallet1: Wallet, wallet2: Wallet pubkey_wallet1 = await wallet1.create_p2pk_pubkey() # preimage_hash = hashlib.sha256(bytes.fromhex(preimage)).hexdigest() secret = await wallet1.create_htlc_lock( - preimage=preimage, hacklock_pubkey=pubkey_wallet1 + preimage=preimage, hashlock_pubkey=pubkey_wallet1 ) + # p2pk test _, send_proofs = await wallet1.split_to_send(wallet1.proofs, 8, secret_lock=secret) - signatures = await wallet1.sign_p2pk_proofs(send_proofs) for p, s in zip(send_proofs, signatures): p.htlcpreimage = preimage @@ -161,7 +161,7 @@ async def test_htlc_redeem_with_correct_signature(wallet1: Wallet, wallet2: Wall pubkey_wallet1 = await wallet1.create_p2pk_pubkey() # preimage_hash = hashlib.sha256(bytes.fromhex(preimage)).hexdigest() secret = await wallet1.create_htlc_lock( - preimage=preimage, hacklock_pubkey=pubkey_wallet1 + preimage=preimage, hashlock_pubkey=pubkey_wallet1 ) # p2pk test _, send_proofs = await wallet1.split_to_send(wallet1.proofs, 8, secret_lock=secret) @@ -186,7 +186,7 @@ async def test_htlc_redeem_hashlock_wrong_signature_timelock_correct_signature( # preimage_hash = hashlib.sha256(bytes.fromhex(preimage)).hexdigest() secret = await wallet1.create_htlc_lock( preimage=preimage, - hacklock_pubkey=pubkey_wallet2, + hashlock_pubkey=pubkey_wallet2, locktime_seconds=5, locktime_pubkey=pubkey_wallet1, ) @@ -221,7 +221,7 @@ async def test_htlc_redeem_hashlock_wrong_signature_timelock_wrong_signature( # preimage_hash = hashlib.sha256(bytes.fromhex(preimage)).hexdigest() secret = await wallet1.create_htlc_lock( preimage=preimage, - hacklock_pubkey=pubkey_wallet2, + hashlock_pubkey=pubkey_wallet2, locktime_seconds=5, locktime_pubkey=pubkey_wallet1, ) diff --git a/tests/test_wallet_p2pk.py b/tests/test_wallet_p2pk.py index 883e64bd..feade986 100644 --- a/tests/test_wallet_p2pk.py +++ b/tests/test_wallet_p2pk.py @@ -360,6 +360,12 @@ def test_tags(): assert tags["key3"] is None assert tags.get_tag_all("key2") == ["value2", "value2_1", "value3"] + # set multiple values of the same key + tags["key3"] = "value3" + assert tags.get_tag_all("key3") == ["value3"] + tags["key3"] = "value4" + assert tags.get_tag_all("key3") == ["value3", "value4"] + @pytest.mark.asyncio async def test_secret_initialized_with_tags(wallet1: Wallet):