From fa4a9c7451ced28afce0aa80305eab8434897668 Mon Sep 17 00:00:00 2001 From: evgeny-stakewise <123374581+evgeny-stakewise@users.noreply.github.com> Date: Mon, 16 Dec 2024 12:32:49 +0300 Subject: [PATCH] Separate validator / account in faker (#133) --- pyproject.toml | 2 +- sw_utils/tests/factories.py | 27 ++++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 6b5bcf7..1e6f155 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "sw-utils" -version = "v0.7.0" +version = "v0.7.1" description = "StakeWise Python utils" authors = ["StakeWise Labs "] license = "GPL-3.0-or-later" diff --git a/sw_utils/tests/factories.py b/sw_utils/tests/factories.py index bde9d7e..848ae6f 100644 --- a/sw_utils/tests/factories.py +++ b/sw_utils/tests/factories.py @@ -2,6 +2,7 @@ import string from secrets import randbits +from eth_typing import ChecksumAddress from faker import Faker from faker.providers import BaseProvider from py_ecc.bls import G2ProofOfPossession @@ -20,7 +21,7 @@ def private_key(self) -> int: private_key = G2ProofOfPossession.KeyGen(seed) return private_key - def eth_address(self) -> str: + def eth_address(self) -> ChecksumAddress: account = w3.eth.account.create() return account.address @@ -29,10 +30,24 @@ def eth_proof(self) -> str: return '0x' + ''.join(random.choices('abcdef' + string.digits, k=64)) def eth_signature(self) -> str: + # Deprecated. Use `validator_signature` or `account_signature`. # 96 bytes return '0x' + ''.join(random.choices('abcdef' + string.digits, k=192)) + def validator_signature(self) -> str: + # BLS signature, 96 bytes + return '0x' + ''.join(random.choices('abcdef' + string.digits, k=192)) + + def account_signature(self) -> str: + # ECDSA signature, 65 bytes + return '0x' + ''.join(random.choices('abcdef' + string.digits, k=130)) + def eth_public_key(self) -> str: + # Deprecated. Use `validator_public_key` or `account_public_key`. + # 48 bytes + return '0x' + ''.join(random.choices('abcdef' + string.digits, k=96)) + + def validator_public_key(self) -> str: # 48 bytes return '0x' + ''.join(random.choices('abcdef' + string.digits, k=96)) @@ -40,6 +55,10 @@ def ecies_public_key(self) -> str: # 64 bytes return '0x' + ''.join(random.choices('abcdef' + string.digits, k=128)) + def account_public_key(self) -> str: + # ECIES public key, 64 bytes + return self.ecies_public_key() + def wei_amount(self) -> Wei: amount = random.randint(Web3.to_wei(1, 'gwei'), Web3.to_wei(100, 'ether')) return Wei(amount) @@ -48,6 +67,12 @@ def eth_amount(self, start: int = 10, stop: int = 1000) -> Wei: eth_value = faker.random_int(start, stop) return w3.to_wei(eth_value, 'ether') + def ipfs_hash(self) -> str: + """ + Returns string of length 59 simulating an IPFS hash v1. + """ + return 'bafk' + ''.join(random.choices(string.ascii_lowercase + string.digits, k=55)) + faker.add_provider(Web3Provider)