Repository: 0xSpaceShard/starknet-devnet (language: python)

Issue:
DeployAccount does not save contract to self.contracts
**Describe the bug (observed vs expected behavior)**

I've tried to deploy an account through the `DeployAccount` transaction, but I can't call its functions.

I think the problem is in the `starknet_devnet.starknet_wrapper.StarknetWrapper.deploy_account` function.
In the `starknet_devnet.starknet_wrapper.StarknetWrapper.deploy` there is a 
![image](https://user-images.githubusercontent.com/61014013/196700364-c136ea65-b6f8-477b-8034-1efdce1bee05.png)
method used but in the`deploy_account` it is not.

**Not reproducible on alpha-goerli**

- [x] This issue is only present on Devnet and cannot be reproduced on alpha-goerli (check the box if true).

**To Reproduce**
Steps to reproduce the behavior:

Run devnet: `starknet-devnet --accounts=1 --seed=1`

Run the following script:
https://gist.github.com/war-in/41bc2ccdef697c55f4eda17f7e612b62

This is the `account_with_validate_deploy.cairo` file:
https://gist.github.com/war-in/e2d28c0a8c3f06dd70ae905b2b6905d1

**Devnet version**

- I am using Devnet version: v0.3.4
- [ ] This happens with a dockerized Devnet (check the box if true).
- This does not appear on the following Devnet version:

**System specifications**

- OS: macOS
- CPU: Apple M1 Pro
- Memory: 16 GB
- Python version: 3.9.13



Discussion / hints:
Well you found the issue and the cause, not much left for me to do. But I can create a PR with a test so that this doesn't happen in the future.
Thank you very much 🙏 

Fix patch:
diff --git a/starknet_devnet/starknet_wrapper.py b/starknet_devnet/starknet_wrapper.py
index b607e27e5..53f481987 100644
--- a/starknet_devnet/starknet_wrapper.py
+++ b/starknet_devnet/starknet_wrapper.py
@@ -368,6 +368,13 @@ async def deploy_account(self, external_tx: DeployAccount):
         """Deploys account and returns (address, tx_hash)"""
 
         state = self.get_state()
+        account_address = calculate_contract_address_from_hash(
+            salt=external_tx.contract_address_salt,
+            class_hash=external_tx.class_hash,
+            constructor_calldata=external_tx.constructor_calldata,
+            deployer_address=0,
+        )
+
         async with self.__get_transaction_handler() as tx_handler:
             tx_handler.internal_tx = InternalDeployAccount.from_external(
                 external_tx, state.general_config
@@ -377,12 +384,20 @@ async def deploy_account(self, external_tx: DeployAccount):
                 tx_handler.execution_info.call_info.internal_calls
             )
 
-        account_address = calculate_contract_address_from_hash(
-            salt=external_tx.contract_address_salt,
-            class_hash=external_tx.class_hash,
-            constructor_calldata=external_tx.constructor_calldata,
-            deployer_address=0,
-        )
+            contract_class = await state.state.get_contract_class(
+                to_bytes(external_tx.class_hash)
+            )
+            contract = self.__create_contract(
+                contract_class,
+                tx_handler.execution_info.call_info,
+                address=account_address,
+            )
+            await self.store_contract(
+                address=account_address,
+                contract=contract,
+                contract_class=contract_class,
+                tx_hash=tx_handler.internal_tx.hash_value,
+            )
 
         return (
             account_address,
@@ -493,16 +508,26 @@ async def __deploy(self, deploy_tx: InternalDeploy, contract_class: ContractClas
 
         tx_execution_info = await state.execute_tx(tx=deploy_tx)
 
+        return self.__create_contract(
+            contract_class=contract_class,
+            call_info=tx_execution_info.call_info,
+            address=deploy_tx.contract_address,
+        )
+
+    def __create_contract(
+        self, contract_class: ContractClass, call_info: CallInfo, address: int
+    ) -> StarknetContract:
+
         deploy_call_info = StarknetCallInfo.from_internal(
-            call_info=as_non_optional(tx_execution_info.call_info),
+            call_info=as_non_optional(call_info),
             result=(),
             main_call_events=[],
         )
 
         return StarknetContract(
-            state=state,
+            state=self.get_state(),
             abi=get_abi(contract_class=contract_class),
-            contract_address=deploy_tx.contract_address,
+            contract_address=address,
             deploy_call_info=deploy_call_info,
         )
 


Test patch:
diff --git a/test/shared.py b/test/shared.py
index 63abbcf05..2a75abde9 100644
--- a/test/shared.py
+++ b/test/shared.py
@@ -1,5 +1,11 @@
 """Shared values between tests"""
 
+import json
+
+from starkware.starknet.third_party.open_zeppelin.starknet_contracts import (
+    account_contract as oz_account_class,
+)
+
 ARTIFACTS_PATH = "test/artifacts/contracts/cairo"
 CONTRACT_PATH = f"{ARTIFACTS_PATH}/contract.cairo/contract.json"
 ABI_PATH = f"{ARTIFACTS_PATH}/contract.cairo/contract_abi.json"
@@ -11,6 +17,10 @@
 DEPLOYER_CONTRACT_PATH = f"{ARTIFACTS_PATH}/deployer.cairo/deployer.json"
 DEPLOYER_ABI_PATH = f"{ARTIFACTS_PATH}/deployer.cairo/deployer_abi.json"
 
+STARKNET_CLI_ACCOUNT_ABI_PATH = f"{ARTIFACTS_PATH}/starknet_cli_oz_account_abi.json"
+with open(STARKNET_CLI_ACCOUNT_ABI_PATH, "w", encoding="utf-8") as oz_account_abi_file:
+    json.dump(oz_account_class.abi, oz_account_abi_file)
+
 L1L2_CONTRACT_PATH = f"{ARTIFACTS_PATH}/l1l2.cairo/l1l2.json"
 L1L2_ABI_PATH = f"{ARTIFACTS_PATH}/l1l2.cairo/l1l2_abi.json"
 
diff --git a/test/test_deploy.py b/test/test_deploy.py
index 7e0b2f1cd..a9b74cbe2 100644
--- a/test/test_deploy.py
+++ b/test/test_deploy.py
@@ -38,8 +38,9 @@
 from .shared import (
     ABI_PATH,
     CONTRACT_PATH,
-    SUPPORTED_TX_VERSION,
     PREDEPLOY_ACCOUNT_CLI_ARGS,
+    STARKNET_CLI_ACCOUNT_ABI_PATH,
+    SUPPORTED_TX_VERSION,
 )
 
 
@@ -162,6 +163,14 @@ def test_deploy_account():
     tx_after = send_tx(deploy_account_tx, TransactionType.DEPLOY_ACCOUNT)
     assert_tx_status(tx_after["transaction_hash"], "ACCEPTED_ON_L2")
 
+    # assert that contract can be interacted with
+    retrieved_public_key = call(
+        function="get_public_key",
+        address=hex(account_address),
+        abi_path=STARKNET_CLI_ACCOUNT_ABI_PATH,
+    )
+    assert int(retrieved_public_key, 16) == public_key
+
     # deploy a contract for testing
     init_balance = 10
     contract_deploy_info = deploy(contract=CONTRACT_PATH, inputs=[str(init_balance)])
diff --git a/test/util.py b/test/util.py
index 68f34f2d2..994694761 100644
--- a/test/util.py
+++ b/test/util.py
@@ -316,7 +316,7 @@ def estimate_fee(function, inputs, address, abi_path, signature=None, nonce=None
     return extract_fee(output.stdout)
 
 
-def call(function, address, abi_path, inputs=None):
+def call(function: str, address: str, abi_path: str, inputs=None):
     """Wrapper around starknet call"""
     args = [
         "call",