Skip to content

Commit

Permalink
Separate validator / account in faker (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeny-stakewise authored Dec 16, 2024
1 parent e1b7925 commit fa4a9c7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "sw-utils"
version = "v0.7.0"
version = "v0.7.1"
description = "StakeWise Python utils"
authors = ["StakeWise Labs <[email protected]>"]
license = "GPL-3.0-or-later"
Expand Down
27 changes: 26 additions & 1 deletion sw_utils/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -29,17 +30,35 @@ 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))

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)
Expand All @@ -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)

Expand Down

0 comments on commit fa4a9c7

Please sign in to comment.