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

Adapt to cairo-lang 0.10.1 #307

Merged
merged 20 commits into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions page/docs/guide/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,16 @@ poetry run pytest test/<TEST_FILE>::<TEST_CASE> # for a single test case
./scripts/check_versions.sh
```

## Development - Working with a local version of cairo-lang
## Development - Working with an archive of cairo-lang

In `pyproject.toml` under `[tool.poetry.dependencies]` specify
If you know the URL of the archive (e.g. ZIP) of a new cairo-lang version, you can install it with

```
cairo-lang = { path = "your-cairo-lang-package.zip" }
poetry add <URL>
```

After adding a new cairo-lang version, you will probably want to recompile contract artifacts.

## Development - Updating accounts

1. Set up https://github.com/OpenZeppelin/cairo-contracts/ locally
Expand Down
745 changes: 654 additions & 91 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ keywords = ["starknet", "cairo", "testnet", "local", "server"]
python = ">=3.8,<3.10"
Flask = {extras = ["async"], version = "~2.0.3"}
flask-cors = "~3.0.10"
cairo-lang = "0.10.0"
cairo-lang = "0.10.1"
Werkzeug = "~2.0.3"
cloudpickle = "~2.1.0"
crypto-cpp-py = "~1.0.4"
Expand Down
7 changes: 7 additions & 0 deletions starknet_devnet/blueprints/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ async def add_transaction():
)
response_dict["class_hash"] = hex(contract_class_hash)

elif tx_type == TransactionType.DEPLOY_ACCOUNT:
(
contract_address,
transaction_hash,
) = await state.starknet_wrapper.deploy_account(transaction)
response_dict["address"] = fixed_length_hex(contract_address)

elif tx_type == TransactionType.DEPLOY:
contract_address, transaction_hash = await state.starknet_wrapper.deploy(
transaction
Expand Down
4 changes: 2 additions & 2 deletions starknet_devnet/blueprints/rpc/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ async def add_invoke_transaction(
)

_, transaction_hash = await state.starknet_wrapper.invoke(
invoke_function=invoke_function
external_tx=invoke_function
)
return RpcInvokeTransactionResult(
transaction_hash=rpc_felt(transaction_hash),
Expand Down Expand Up @@ -165,7 +165,7 @@ async def add_declare_transaction(
)

class_hash, transaction_hash = await state.starknet_wrapper.declare(
declare_transaction=declare_transaction
external_tx=declare_transaction
)
return RpcDeclareTransactionResult(
transaction_hash=rpc_felt(transaction_hash),
Expand Down
6 changes: 6 additions & 0 deletions starknet_devnet/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,9 @@
DUMMY_STATE_ROOT = bytes(32)

DEFAULT_TIMEOUT = 60 # seconds

OLD_SUPPORTED_VERSIONS = [0]

OZ_ACCOUNT_CLASS_HASH = (
895370652103566112291566439803611591116951595367594863638369163604569619773
)
8 changes: 7 additions & 1 deletion starknet_devnet/lite_mode/lite_internal_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
from starkware.starknet.business_logic.transaction.objects import InternalTransaction
from starkware.python.utils import to_bytes

from starknet_devnet.constants import OLD_SUPPORTED_VERSIONS

# pylint: disable=too-many-ancestors, arguments-renamed, too-many-arguments
class LiteInternalDeploy(InternalDeploy):
"""
Expand Down Expand Up @@ -76,7 +78,11 @@ def lite_create(
"""
Lite version of create method without hash a calculation.
"""
verify_version(version=version, only_query=False)
verify_version(
version=version,
only_query=False,
old_supported_versions=OLD_SUPPORTED_VERSIONS,
)
class_hash = compute_class_hash(contract_class=contract_class)
contract_address = calculate_contract_address_from_hash(
salt=contract_address_salt,
Expand Down
23 changes: 22 additions & 1 deletion starknet_devnet/sequencer_api_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from starkware.starknet.business_logic.transaction.objects import (
InternalAccountTransaction,
InternalDeclare,
InternalDeployAccount,
InternalInvokeFunction,
InternalTransaction,
)
Expand All @@ -27,10 +28,13 @@
from starkware.starknet.services.api.gateway.transaction import (
AccountTransaction,
Declare,
DeployAccount,
InvokeFunction,
)
from starkware.starkware_utils.config_base import Config

from starknet_devnet.constants import OLD_SUPPORTED_VERSIONS


def format_fee_info(gas_price: int, overall_fee: int) -> FeeEstimationInfo:
"""Construct a FeeEstimationInfo object"""
Expand Down Expand Up @@ -60,6 +64,8 @@ def from_external(
internal_cls = InternalInvokeFunctionForSimulate
elif isinstance(external_tx, Declare):
internal_cls = InternalDeclareForSimulate
elif isinstance(external_tx, DeployAccount):
internal_cls = InternalDeployAccountForSimulate
else:
raise NotImplementedError(f"Unexpected type {type(external_tx).__name__}.")

Expand All @@ -69,7 +75,11 @@ def from_external(
)

def verify_version(self):
verify_version(version=self.version, only_query=True)
verify_version(
version=self.version,
only_query=True,
old_supported_versions=OLD_SUPPORTED_VERSIONS,
)

def charge_fee(
self,
Expand Down Expand Up @@ -103,3 +113,14 @@ class InternalDeclareForSimulate(
"""
Represents an internal declare in the StarkNet network for the simulate transaction API.
"""


class InternalDeployAccountForSimulate(
InternalAccountTransactionForSimulate, InternalDeployAccount
):
"""
Represents an internal deploy account in the StarkNet network for the simulate transaction API.
"""

def verify_version(self):
verify_version(version=self.version, only_query=True, old_supported_versions=[])
Loading