From 2210c61c7001a737b692b85b9f8a08cad6fd622b Mon Sep 17 00:00:00 2001 From: Big Herc Date: Tue, 28 Feb 2023 12:53:17 +0100 Subject: [PATCH 1/7] Refactor predeployed contract wrapper classes --- starknet_devnet/account.py | 3 ++- starknet_devnet/fee_token.py | 3 ++- starknet_devnet/predeployed_contract_wrapper.py | 9 +++++++++ starknet_devnet/udc.py | 4 +++- 4 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 starknet_devnet/predeployed_contract_wrapper.py diff --git a/starknet_devnet/account.py b/starknet_devnet/account.py index 36c7cb543..f74996093 100644 --- a/starknet_devnet/account.py +++ b/starknet_devnet/account.py @@ -11,9 +11,10 @@ from starknet_devnet.account_util import set_balance from starknet_devnet.contract_class_wrapper import ContractClassWrapper +from starknet_devnet.predeployed_contract_wrapper import PredeployedContractWrapper -class Account: +class Account(PredeployedContractWrapper): """Account contract wrapper.""" # pylint: disable=too-many-arguments diff --git a/starknet_devnet/fee_token.py b/starknet_devnet/fee_token.py index 0e646b453..a2253fe21 100644 --- a/starknet_devnet/fee_token.py +++ b/starknet_devnet/fee_token.py @@ -13,11 +13,12 @@ from starknet_devnet.account_util import get_execute_args from starknet_devnet.chargeable_account import ChargeableAccount from starknet_devnet.constants import SUPPORTED_TX_VERSION +from starknet_devnet.predeployed_contract_wrapper import PredeployedContractWrapper from starknet_devnet.sequencer_api_utils import InternalInvokeFunction from starknet_devnet.util import Uint256, str_to_felt -class FeeToken: +class FeeToken(PredeployedContractWrapper): """Wrapper of token for charging fees.""" CONTRACT_CLASS: ContractClass = None # loaded lazily diff --git a/starknet_devnet/predeployed_contract_wrapper.py b/starknet_devnet/predeployed_contract_wrapper.py new file mode 100644 index 000000000..1a136171c --- /dev/null +++ b/starknet_devnet/predeployed_contract_wrapper.py @@ -0,0 +1,9 @@ +"""Parent for predeployed contract wrapper classes""" + + +class PredeployedContractWrapper: + """Parent class for all predeployed contract wrapper classes""" + + async def deploy(self): + """Deploy the contract wrapper to devnet""" + raise NotImplementedError() diff --git a/starknet_devnet/udc.py b/starknet_devnet/udc.py index 5799dba9a..4deede1f0 100644 --- a/starknet_devnet/udc.py +++ b/starknet_devnet/udc.py @@ -5,8 +5,10 @@ from starkware.starknet.services.api.contract_class import ContractClass from starkware.starknet.testing.starknet import Starknet +from starknet_devnet.predeployed_contract_wrapper import PredeployedContractWrapper -class UDC: + +class UDC(PredeployedContractWrapper): """Universal deployer contract wrapper class""" CONTRACT_CLASS: ContractClass = None # loaded lazily From 69d352e0d76086cb70e3cdc2f49b91e9f0b016b2 Mon Sep 17 00:00:00 2001 From: Big Herc Date: Sat, 4 Mar 2023 19:29:46 +0100 Subject: [PATCH 2/7] Refactor: move common logic to PredeployedContractWrapper --- starknet_devnet/account.py | 8 +- starknet_devnet/fee_token.py | 23 +---- .../predeployed_contract_wrapper.py | 95 ++++++++++++++++++- starknet_devnet/udc.py | 11 --- 4 files changed, 95 insertions(+), 42 deletions(-) diff --git a/starknet_devnet/account.py b/starknet_devnet/account.py index f74996093..927923da4 100644 --- a/starknet_devnet/account.py +++ b/starknet_devnet/account.py @@ -51,14 +51,8 @@ def to_json(self): "address": hex(self.address), } - async def deploy(self) -> StarknetContract: - """Deploy this account and set its balance.""" + async def mimic_constructor(self): starknet: Starknet = self.starknet_wrapper.starknet - contract_class = self.contract_class - await starknet.state.state.set_contract_class( - self.class_hash_bytes, contract_class - ) - await starknet.state.state.deploy_contract(self.address, self.class_hash_bytes) await starknet.state.state.set_storage_at( self.address, get_selector_from_name("Account_public_key"), self.public_key diff --git a/starknet_devnet/fee_token.py b/starknet_devnet/fee_token.py index a2253fe21..1f81a5e9f 100644 --- a/starknet_devnet/fee_token.py +++ b/starknet_devnet/fee_token.py @@ -48,22 +48,8 @@ def get_contract_class(cls): ) return cls.CONTRACT_CLASS - async def deploy(self): - """Deploy token contract for charging fees.""" + async def mimic_constructor(self): starknet: Starknet = self.starknet_wrapper.starknet - contract_class = FeeToken.get_contract_class() - - await starknet.state.state.set_contract_class( - FeeToken.HASH_BYTES, contract_class - ) - - # pylint: disable=protected-access - starknet.state.state.cache._class_hash_writes[ - FeeToken.ADDRESS - ] = FeeToken.HASH_BYTES - # replace with await starknet.state.state.deploy_contract - - # mimic constructor await starknet.state.state.set_storage_at( FeeToken.ADDRESS, get_selector_from_name("ERC20_name"), @@ -85,13 +71,6 @@ async def deploy(self): ChargeableAccount.ADDRESS, ) - self.contract = StarknetContract( - state=starknet.state, - abi=contract_class.abi, - contract_address=FeeToken.ADDRESS, - deploy_call_info=None, - ) - async def get_balance(self, address: int) -> int: """Return the balance of the contract under `address`.""" response = await self.contract.balanceOf(address).call() diff --git a/starknet_devnet/predeployed_contract_wrapper.py b/starknet_devnet/predeployed_contract_wrapper.py index 1a136171c..f21de8b51 100644 --- a/starknet_devnet/predeployed_contract_wrapper.py +++ b/starknet_devnet/predeployed_contract_wrapper.py @@ -1,9 +1,100 @@ """Parent for predeployed contract wrapper classes""" +from abc import ABC, abstractmethod +from starkware.starknet.testing.starknet import Starknet +from starkware.starknet.services.api.contract_class import ContractClass +from starkware.starknet.testing.contract import StarknetContract -class PredeployedContractWrapper: + +class PredeployedContractWrapper(ABC): """Parent class for all predeployed contract wrapper classes""" + # Cannot import it because of circular imports + # from .starknet_wrapper import StarknetWrapper + + starknet_wrapper = NotImplemented + + @property + def address(self) -> int: + try: + return self.ADDRESS + except AttributeError: + try: + return self._address + except AttributeError: + raise NotImplementedError( + "Predeployed contracts should provide an address attribute or an ADDRESS class attribute" + ) + + @address.setter + def address(self, address: int): + self._address = address + + @property + def class_hash_bytes(self) -> bytes: + try: + return self._class_hash_bytes + except AttributeError: + try: + return self.HASH_BYTES + except AttributeError: + raise NotImplementedError( + "Predeployed contracts should provide a class_hash_bytes attribute or a HASH_BYTES class attribute" + ) + + @class_hash_bytes.setter + def class_hash_bytes(self, class_hash_bytes: bytes): + self._class_hash_bytes = class_hash_bytes + + @property + def contract_class(self) -> ContractClass: + try: + return self._contract_class + except AttributeError: + try: + return self.get_contract_class() + except AttributeError: + raise NotImplementedError( + "Predeployed contracts should provide a contract_class attribute or get_contract_class method" + ) + + @contract_class.setter + def contract_class(self, contract_class): + self._contract_class = contract_class + + async def deploy_contract(self): + # pylint: disable=protected-access + starknet: Starknet = self.starknet_wrapper.starknet + starknet.state.state.cache._class_hash_writes[ + self.address + ] = self.class_hash_bytes + # replace with await starknet.state.state.deploy_contract + # await starknet.state.state.deploy_contract(self.address, self.class_hash_bytes) + # For now, it fails for fee token since the address is the same as the + # ETH Token, see: + # https://starkscan.co/token/0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7: + # Requested contract address + # 0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7 + # is unavailable for deployment + + async def mimic_constructor(self): + pass + async def deploy(self): """Deploy the contract wrapper to devnet""" - raise NotImplementedError() + starknet: Starknet = self.starknet_wrapper.starknet + + await starknet.state.state.set_contract_class( + self.class_hash_bytes, self.contract_class + ) + + await self.deploy_contract() + + await self.mimic_constructor() + + self.contract = StarknetContract( + state=starknet.state, + abi=self.contract_class.abi, + contract_address=self.address, + deploy_call_info=None, + ) diff --git a/starknet_devnet/udc.py b/starknet_devnet/udc.py index 4deede1f0..d86955ed2 100644 --- a/starknet_devnet/udc.py +++ b/starknet_devnet/udc.py @@ -34,14 +34,3 @@ def get_contract_class(cls): load_nearby_contract("UDC_OZ_0.5.0") ) return cls.CONTRACT_CLASS - - async def deploy(self): - """Deploy token contract for charging fees.""" - starknet: Starknet = self.starknet_wrapper.starknet - contract_class = UDC.get_contract_class() - - await starknet.state.state.set_contract_class(UDC.HASH_BYTES, contract_class) - - # pylint: disable=protected-access - starknet.state.state.cache._class_hash_writes[UDC.ADDRESS] = UDC.HASH_BYTES - # replace with await starknet.state.state.deploy_contract From c7071958d053055ae56aedee44fded9b7aa62fa7 Mon Sep 17 00:00:00 2001 From: Big Herc Date: Wed, 8 Mar 2023 21:49:46 +0100 Subject: [PATCH 3/7] Refactor: remove ambiguous deploy_contract method --- .../predeployed_contract_wrapper.py | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/starknet_devnet/predeployed_contract_wrapper.py b/starknet_devnet/predeployed_contract_wrapper.py index f21de8b51..b775734ec 100644 --- a/starknet_devnet/predeployed_contract_wrapper.py +++ b/starknet_devnet/predeployed_contract_wrapper.py @@ -62,7 +62,17 @@ def contract_class(self) -> ContractClass: def contract_class(self, contract_class): self._contract_class = contract_class - async def deploy_contract(self): + async def mimic_constructor(self): + pass + + async def deploy(self): + """Deploy the contract wrapper to devnet""" + starknet: Starknet = self.starknet_wrapper.starknet + + await starknet.state.state.set_contract_class( + self.class_hash_bytes, self.contract_class + ) + # pylint: disable=protected-access starknet: Starknet = self.starknet_wrapper.starknet starknet.state.state.cache._class_hash_writes[ @@ -77,19 +87,6 @@ async def deploy_contract(self): # 0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7 # is unavailable for deployment - async def mimic_constructor(self): - pass - - async def deploy(self): - """Deploy the contract wrapper to devnet""" - starknet: Starknet = self.starknet_wrapper.starknet - - await starknet.state.state.set_contract_class( - self.class_hash_bytes, self.contract_class - ) - - await self.deploy_contract() - await self.mimic_constructor() self.contract = StarknetContract( From 8e3b51ff35b4e90631990e8124b29cc19523a988 Mon Sep 17 00:00:00 2001 From: Big Herc Date: Fri, 10 Mar 2023 10:33:20 +0100 Subject: [PATCH 4/7] Refactor: make mimic_constructor private and mandatory --- starknet_devnet/account.py | 2 +- starknet_devnet/fee_token.py | 2 +- starknet_devnet/predeployed_contract_wrapper.py | 6 +++--- starknet_devnet/udc.py | 3 +++ 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/starknet_devnet/account.py b/starknet_devnet/account.py index 927923da4..0c5438b48 100644 --- a/starknet_devnet/account.py +++ b/starknet_devnet/account.py @@ -51,7 +51,7 @@ def to_json(self): "address": hex(self.address), } - async def mimic_constructor(self): + async def _mimic_constructor(self): starknet: Starknet = self.starknet_wrapper.starknet await starknet.state.state.set_storage_at( diff --git a/starknet_devnet/fee_token.py b/starknet_devnet/fee_token.py index 1f81a5e9f..f423447b7 100644 --- a/starknet_devnet/fee_token.py +++ b/starknet_devnet/fee_token.py @@ -48,7 +48,7 @@ def get_contract_class(cls): ) return cls.CONTRACT_CLASS - async def mimic_constructor(self): + async def _mimic_constructor(self): starknet: Starknet = self.starknet_wrapper.starknet await starknet.state.state.set_storage_at( FeeToken.ADDRESS, diff --git a/starknet_devnet/predeployed_contract_wrapper.py b/starknet_devnet/predeployed_contract_wrapper.py index b775734ec..de7c17130 100644 --- a/starknet_devnet/predeployed_contract_wrapper.py +++ b/starknet_devnet/predeployed_contract_wrapper.py @@ -62,8 +62,8 @@ def contract_class(self) -> ContractClass: def contract_class(self, contract_class): self._contract_class = contract_class - async def mimic_constructor(self): - pass + async def _mimic_constructor(self): + raise NotImplementedError() async def deploy(self): """Deploy the contract wrapper to devnet""" @@ -87,7 +87,7 @@ async def deploy(self): # 0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7 # is unavailable for deployment - await self.mimic_constructor() + await self._mimic_constructor() self.contract = StarknetContract( state=starknet.state, diff --git a/starknet_devnet/udc.py b/starknet_devnet/udc.py index d86955ed2..b7ba1f9f6 100644 --- a/starknet_devnet/udc.py +++ b/starknet_devnet/udc.py @@ -34,3 +34,6 @@ def get_contract_class(cls): load_nearby_contract("UDC_OZ_0.5.0") ) return cls.CONTRACT_CLASS + + async def _mimic_constructor(self): + pass From 750accb197f8dcd1257fd14c1a019c4f1e942a27 Mon Sep 17 00:00:00 2001 From: Big Herc Date: Fri, 10 Mar 2023 10:49:37 +0100 Subject: [PATCH 5/7] Refactor: get rid of default property impl for address and class_hash_bytes --- starknet_devnet/fee_token.py | 6 +++ .../predeployed_contract_wrapper.py | 53 ++----------------- starknet_devnet/udc.py | 6 +++ 3 files changed, 16 insertions(+), 49 deletions(-) diff --git a/starknet_devnet/fee_token.py b/starknet_devnet/fee_token.py index f423447b7..7c2fa667e 100644 --- a/starknet_devnet/fee_token.py +++ b/starknet_devnet/fee_token.py @@ -27,10 +27,12 @@ class FeeToken(PredeployedContractWrapper): # HASH = to_bytes(compute_class_hash(contract_class=FeeToken.get_contract_class())) HASH = 0x6A22BF63C7BC07EFFA39A25DFBD21523D211DB0100A0AFD054D172B81840EAF HASH_BYTES = to_bytes(HASH) + class_hash_bytes = HASH_BYTES # Taken from # https://github.com/starknet-community-libs/starknet-addresses/blob/df19b17d2c83f11c30e65e2373e8a0c65446f17c/bridged_tokens/goerli.json ADDRESS = 0x49D36570D4E46F48E99674BD3FCC84644DDD6B96F7C741B1562B82F9E004DC7 + address = ADDRESS SYMBOL = "ETH" NAME = "ether" @@ -48,6 +50,10 @@ def get_contract_class(cls): ) return cls.CONTRACT_CLASS + @property + def contract_class(self) -> ContractClass: + return self.get_contract_class() + async def _mimic_constructor(self): starknet: Starknet = self.starknet_wrapper.starknet await starknet.state.state.set_storage_at( diff --git a/starknet_devnet/predeployed_contract_wrapper.py b/starknet_devnet/predeployed_contract_wrapper.py index de7c17130..0c871bdad 100644 --- a/starknet_devnet/predeployed_contract_wrapper.py +++ b/starknet_devnet/predeployed_contract_wrapper.py @@ -12,55 +12,10 @@ class PredeployedContractWrapper(ABC): # Cannot import it because of circular imports # from .starknet_wrapper import StarknetWrapper - starknet_wrapper = NotImplemented - - @property - def address(self) -> int: - try: - return self.ADDRESS - except AttributeError: - try: - return self._address - except AttributeError: - raise NotImplementedError( - "Predeployed contracts should provide an address attribute or an ADDRESS class attribute" - ) - - @address.setter - def address(self, address: int): - self._address = address - - @property - def class_hash_bytes(self) -> bytes: - try: - return self._class_hash_bytes - except AttributeError: - try: - return self.HASH_BYTES - except AttributeError: - raise NotImplementedError( - "Predeployed contracts should provide a class_hash_bytes attribute or a HASH_BYTES class attribute" - ) - - @class_hash_bytes.setter - def class_hash_bytes(self, class_hash_bytes: bytes): - self._class_hash_bytes = class_hash_bytes - - @property - def contract_class(self) -> ContractClass: - try: - return self._contract_class - except AttributeError: - try: - return self.get_contract_class() - except AttributeError: - raise NotImplementedError( - "Predeployed contracts should provide a contract_class attribute or get_contract_class method" - ) - - @contract_class.setter - def contract_class(self, contract_class): - self._contract_class = contract_class + starknet_wrapper: "StarknetWrapper" + address: int + class_hash_bytes: bytes + contract_class: ContractClass async def _mimic_constructor(self): raise NotImplementedError() diff --git a/starknet_devnet/udc.py b/starknet_devnet/udc.py index b7ba1f9f6..b1bff150d 100644 --- a/starknet_devnet/udc.py +++ b/starknet_devnet/udc.py @@ -17,11 +17,13 @@ class UDC(PredeployedContractWrapper): # HASH = to_bytes(compute_class_hash(contract_class=UDC.get_contract_class())) HASH = 3484004124736344420122298338254154090450773688458934993781007232228755339881 HASH_BYTES = to_bytes(HASH) + class_hash_bytes = HASH_BYTES # Precalculated to fixed address # ADDRESS = calculate_contract_address_from_hash(salt=0, class_hash=HASH, # constructor_calldata=[], deployer_address=0) ADDRESS = 0x41A78E741E5AF2FEC34B695679BC6891742439F7AFB8484ECD7766661AD02BF + address = ADDRESS def __init__(self, starknet_wrapper): self.starknet_wrapper = starknet_wrapper @@ -35,5 +37,9 @@ def get_contract_class(cls): ) return cls.CONTRACT_CLASS + @property + def contract_class(self) -> ContractClass: + return self.get_contract_class() + async def _mimic_constructor(self): pass From 55de14a6f0f6302a9ee4784284faedcc2434828f Mon Sep 17 00:00:00 2001 From: Big Herc Date: Fri, 10 Mar 2023 16:12:16 +0100 Subject: [PATCH 6/7] Refactor: make address and class_hash_bytes instance attrs --- starknet_devnet/fee_token.py | 4 ++-- starknet_devnet/predeployed_contract_wrapper.py | 2 +- starknet_devnet/udc.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/starknet_devnet/fee_token.py b/starknet_devnet/fee_token.py index 7c2fa667e..b937e984c 100644 --- a/starknet_devnet/fee_token.py +++ b/starknet_devnet/fee_token.py @@ -27,12 +27,10 @@ class FeeToken(PredeployedContractWrapper): # HASH = to_bytes(compute_class_hash(contract_class=FeeToken.get_contract_class())) HASH = 0x6A22BF63C7BC07EFFA39A25DFBD21523D211DB0100A0AFD054D172B81840EAF HASH_BYTES = to_bytes(HASH) - class_hash_bytes = HASH_BYTES # Taken from # https://github.com/starknet-community-libs/starknet-addresses/blob/df19b17d2c83f11c30e65e2373e8a0c65446f17c/bridged_tokens/goerli.json ADDRESS = 0x49D36570D4E46F48E99674BD3FCC84644DDD6B96F7C741B1562B82F9E004DC7 - address = ADDRESS SYMBOL = "ETH" NAME = "ether" @@ -40,6 +38,8 @@ class FeeToken(PredeployedContractWrapper): def __init__(self, starknet_wrapper): self.starknet_wrapper = starknet_wrapper + self.address = self.ADDRESS + self.class_hash_bytes = self.HASH_BYTES @classmethod def get_contract_class(cls): diff --git a/starknet_devnet/predeployed_contract_wrapper.py b/starknet_devnet/predeployed_contract_wrapper.py index 0c871bdad..a05bf4c49 100644 --- a/starknet_devnet/predeployed_contract_wrapper.py +++ b/starknet_devnet/predeployed_contract_wrapper.py @@ -1,9 +1,9 @@ """Parent for predeployed contract wrapper classes""" from abc import ABC, abstractmethod -from starkware.starknet.testing.starknet import Starknet from starkware.starknet.services.api.contract_class import ContractClass from starkware.starknet.testing.contract import StarknetContract +from starkware.starknet.testing.starknet import Starknet class PredeployedContractWrapper(ABC): diff --git a/starknet_devnet/udc.py b/starknet_devnet/udc.py index b1bff150d..0b91ac17a 100644 --- a/starknet_devnet/udc.py +++ b/starknet_devnet/udc.py @@ -17,16 +17,16 @@ class UDC(PredeployedContractWrapper): # HASH = to_bytes(compute_class_hash(contract_class=UDC.get_contract_class())) HASH = 3484004124736344420122298338254154090450773688458934993781007232228755339881 HASH_BYTES = to_bytes(HASH) - class_hash_bytes = HASH_BYTES # Precalculated to fixed address # ADDRESS = calculate_contract_address_from_hash(salt=0, class_hash=HASH, # constructor_calldata=[], deployer_address=0) ADDRESS = 0x41A78E741E5AF2FEC34B695679BC6891742439F7AFB8484ECD7766661AD02BF - address = ADDRESS def __init__(self, starknet_wrapper): self.starknet_wrapper = starknet_wrapper + self.address = self.ADDRESS + self.class_hash_bytes = self.HASH_BYTES @classmethod def get_contract_class(cls): From cacad6fb5dbd21e5e5b02da66789f4ef8f657155 Mon Sep 17 00:00:00 2001 From: Big Herc Date: Fri, 10 Mar 2023 16:23:12 +0100 Subject: [PATCH 7/7] Refactor: move contract attr to pranet + docstrings + remove unused imports --- starknet_devnet/account.py | 1 - starknet_devnet/fee_token.py | 4 +--- starknet_devnet/predeployed_contract_wrapper.py | 5 ++++- starknet_devnet/udc.py | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/starknet_devnet/account.py b/starknet_devnet/account.py index 0c5438b48..05758dd8b 100644 --- a/starknet_devnet/account.py +++ b/starknet_devnet/account.py @@ -6,7 +6,6 @@ calculate_contract_address_from_hash, ) from starkware.starknet.public.abi import get_selector_from_name -from starkware.starknet.testing.contract import StarknetContract from starkware.starknet.testing.starknet import Starknet from starknet_devnet.account_util import set_balance diff --git a/starknet_devnet/fee_token.py b/starknet_devnet/fee_token.py index b937e984c..ae913fbdb 100644 --- a/starknet_devnet/fee_token.py +++ b/starknet_devnet/fee_token.py @@ -7,7 +7,6 @@ from starkware.starknet.compiler.compile import get_selector_from_name from starkware.starknet.services.api.contract_class import ContractClass from starkware.starknet.services.api.gateway.transaction import InvokeFunction -from starkware.starknet.testing.contract import StarknetContract from starkware.starknet.testing.starknet import Starknet from starknet_devnet.account_util import get_execute_args @@ -34,8 +33,6 @@ class FeeToken(PredeployedContractWrapper): SYMBOL = "ETH" NAME = "ether" - contract: StarknetContract = None - def __init__(self, starknet_wrapper): self.starknet_wrapper = starknet_wrapper self.address = self.ADDRESS @@ -52,6 +49,7 @@ def get_contract_class(cls): @property def contract_class(self) -> ContractClass: + """Same as `get_contract_class`, used by `PredeployedContractWrapper` parent""" return self.get_contract_class() async def _mimic_constructor(self): diff --git a/starknet_devnet/predeployed_contract_wrapper.py b/starknet_devnet/predeployed_contract_wrapper.py index a05bf4c49..190bb06f9 100644 --- a/starknet_devnet/predeployed_contract_wrapper.py +++ b/starknet_devnet/predeployed_contract_wrapper.py @@ -1,5 +1,5 @@ """Parent for predeployed contract wrapper classes""" -from abc import ABC, abstractmethod +from abc import ABC from starkware.starknet.services.api.contract_class import ContractClass from starkware.starknet.testing.contract import StarknetContract @@ -17,6 +17,9 @@ class PredeployedContractWrapper(ABC): class_hash_bytes: bytes contract_class: ContractClass + # Value will be set by deploy + contract: StarknetContract + async def _mimic_constructor(self): raise NotImplementedError() diff --git a/starknet_devnet/udc.py b/starknet_devnet/udc.py index 0b91ac17a..7f08eef5c 100644 --- a/starknet_devnet/udc.py +++ b/starknet_devnet/udc.py @@ -3,7 +3,6 @@ from starkware.python.utils import to_bytes from starkware.solidity.utils import load_nearby_contract from starkware.starknet.services.api.contract_class import ContractClass -from starkware.starknet.testing.starknet import Starknet from starknet_devnet.predeployed_contract_wrapper import PredeployedContractWrapper @@ -39,6 +38,7 @@ def get_contract_class(cls): @property def contract_class(self) -> ContractClass: + """Same as `get_contract_class`, used by `PredeployedContractWrapper` parent""" return self.get_contract_class() async def _mimic_constructor(self):