From a4da7f76e0d25f9468ccb100656210afb622cd21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Palmer?= Date: Sun, 28 Jan 2024 17:24:49 +0100 Subject: [PATCH] Tests: use pytezos key in account --- test/python/common.py | 2 +- test/python/utils/account.py | 28 +++++++++++++++++++++------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/test/python/common.py b/test/python/common.py index 4d1805a8..c68ab4d7 100644 --- a/test/python/common.py +++ b/test/python/common.py @@ -10,7 +10,7 @@ DEFAULT_ACCOUNT = Account( "m/44'/1729'/0'/0'", SigScheme.ED25519, - "edpkuXX2VdkdXzkN11oLCb8Aurdo1BTAtQiK8ZY9UPj2YMt3AHEpcY" + "edsk2tUyhVvGj9B1S956ZzmaU4bC9J7t8xVBH52fkAoZL25MHEwacd" ) EMPTY_PATH = BipPath.from_string("m") diff --git a/test/python/utils/account.py b/test/python/utils/account.py index 62535a8f..3c48037c 100644 --- a/test/python/utils/account.py +++ b/test/python/utils/account.py @@ -17,7 +17,7 @@ from enum import IntEnum from typing import Union import base58 -from pytezos import pytezos +import pytezos from bip_utils.bip.bip32.bip32_path import Bip32Path, Bip32PathParser from bip_utils.bip.bip32.bip32_key_data import Bip32KeyIndex from utils.helper import BytesReader @@ -126,23 +126,38 @@ class Account: def __init__(self, path: Union[BipPath, str, bytes], sig_scheme: SigScheme, - public_key: str): + key: str): self.path: BipPath = \ BipPath.from_string(path) if isinstance(path, str) else \ BipPath.from_bytes(path) if isinstance(path, bytes) else \ path self.sig_scheme: SigScheme = sig_scheme - self.public_key: str = public_key + self.key: pytezos.Key = pytezos.pytezos.using(key=key).key + + @property + def public_key_hash(self) -> str: + """public_key_hash of the account.""" + return self.key.public_key_hash() + + @property + def public_key(self) -> str: + """public_key of the account.""" + return self.key.public_key() + + @property + def secret_key(self) -> str: + """secret_key of the account.""" + return self.key.secret_key() def __repr__(self) -> str: - return self.public_key + return self.public_key_hash @property def base58_decoded(self) -> bytes: """base58_decoded of the account.""" # Get the public_key without prefix - public_key = base58.b58decode_check(self.public_key) + public_key = base58.b58decode_check(self.key.public_key()) if self.sig_scheme in [ SigScheme.ED25519, @@ -206,8 +221,7 @@ def check_signature(self, SigScheme.BIP32_ED25519 ] \ else Signature.from_tlv(signature) - ctxt = pytezos.using(key=self.public_key) - assert ctxt.key.verify(signature.value, message), \ + assert self.key.verify(signature.value, message), \ f"Fail to verify signature {signature}, \n\ with account {self} \n\ and message {message.hex()}"