Skip to content
This repository has been archived by the owner on Dec 15, 2023. It is now read-only.

Commit

Permalink
Minor modification of #487 (#505)
Browse files Browse the repository at this point in the history
* Keeps the features of the PR but restores the log format
  • Loading branch information
FabijanC authored Jun 16, 2023
1 parent 978b440 commit a5cb1d1
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
12 changes: 8 additions & 4 deletions starknet_devnet/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Account class and its predefined constants.
"""

import sys
from typing import Optional

from starkware.starknet.core.os.contract_address.contract_address import (
calculate_contract_address_from_hash,
Expand All @@ -15,6 +15,7 @@
from starknet_devnet.predeployed_contract_wrapper import PredeployedContractWrapper


# pylint: disable=too-many-instance-attributes
class Account(PredeployedContractWrapper):
"""Account contract wrapper."""

Expand All @@ -26,6 +27,7 @@ def __init__(
public_key: int,
initial_balance: int,
account_class_wrapper: CompiledClassWrapper,
index: Optional[int] = None,
):
self.starknet_wrapper = starknet_wrapper
self.private_key = private_key
Expand All @@ -43,6 +45,9 @@ def __init__(
)
self.initial_balance = initial_balance

self.__index = index
"""Index used when logging/displaying account to user on startup"""

def to_json(self):
"""Return json account"""
return {
Expand All @@ -62,9 +67,8 @@ async def _mimic_constructor(self):
await set_balance(starknet.state, self.address, self.initial_balance)

def print(self):
print("Account:")
print(f"Account #{self.__index}:")
print(f"Address: {hex(self.address)}")
print(f"Public key: {hex(self.public_key)}")
print(f"Private key: {hex(self.private_key)}")
print(f"Initial balance: {self.initial_balance} WEI")
sys.stdout.flush()
print(flush=True)
4 changes: 3 additions & 1 deletion starknet_devnet/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __generate(self):
random_generator = random.Random()
random_generator.seed(self.__seed)

for _ in range(self.__n_accounts):
for i in range(self.__n_accounts):
private_key = random_generator.getrandbits(128)
public_key = private_to_stark_key(private_key)

Expand All @@ -65,11 +65,13 @@ def __generate(self):
public_key=public_key,
initial_balance=self.__initial_balance,
account_class_wrapper=self.__account_class_wrapper,
index=i,
)
)

def __print(self):
"""stdout accounts list"""
print(f"Initial balance of each account: {self.__initial_balance} WEI")
print("Seed to replicate this account sequence:", self.__seed)
warn(
"WARNING: Use these accounts and their keys ONLY for local testing. "
Expand Down
5 changes: 3 additions & 2 deletions starknet_devnet/chargeable_account.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""
Account that is charged with a fee when nobody else can be charged.
Account that can be charged with a fee when nothing else can be charged.
Intended for development and internal testing purposes.
"""

from starknet_devnet.account import Account
Expand All @@ -25,4 +26,4 @@ def __init__(self, starknet_wrapper):
)

def print(self):
pass
"""Since this is a development/testing class, it needn't be logged"""
2 changes: 1 addition & 1 deletion starknet_devnet/predeployed_contract_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@ async def deploy(self):
self.print()

def print(self):
"Prints contract info"
"""Prints contract info"""
raise NotImplementedError()
2 changes: 1 addition & 1 deletion starknet_devnet/starknet_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,7 @@ async def __predeclare_starknet_cli_account(self):
state = self.get_state().state
state.compiled_classes[STARKNET_CLI_ACCOUNT_CLASS_HASH] = oz_account_class
if self.config.verbose or not self.config.hide_predeployed_contracts:
print("Predeclared STARKNET CLI account: ", flush=True)
print("Predeclared Starknet CLI account: ", flush=True)
print(f"Class hash: {hex(STARKNET_CLI_ACCOUNT_CLASS_HASH)}\n", flush=True)

async def __deploy_chargeable_account(self):
Expand Down

0 comments on commit a5cb1d1

Please sign in to comment.