Skip to content

Commit 9f82dc7

Browse files
Update to Starknet 0.12.0 (#1101)
* Remove PENDING tx status * Update .gitignore * Use Cairo v2.0.0-rc5 * Use cairo-lang 0.12.0a0 * Add compile_contracts_v2.sh * Add new syntax contracts * Add complex abi v1 contract * Bump devnet * Add more new syntax contracts * Add more v2 syntax contracts * Remove unused contract * Update tests * Use devnet 0.5.5a0 * Use devnet 0.5.5 * Use Cairo v2.0.0 * Update contracts to Cairo v2.0.0 * Update tests * Extend hello2.cairo * Format * Add abi_types.cairo * V1_DIR -> V2_DIR * Shape + Schemas * AbiParserV2 * Lint, Format, Typecheck * Compile v1.1.0 contracts on CI * Remove unused variables * Remove cache-rust * Fix typing * Update checks.yml * Run tests on v1 and v2 contracts * Export manifest path * Update checks.yml * Update checks.yml * Add compiled contracts * Download artifacts * Clean up * Deprecate `wait_for_accept` parameter in `Client.wait_for_tx` (#1102) * deprecated wait_for_transaction parameter * added poe precommit task * added note in migration guide * migration guide fix * logic change * logic change * formatting * added retries below 0 check * typos * fixed logic * docstring fix * deprecated wait_for_transaction parameter * added poe precommit task * added note in migration guide * migration guide fix * logic change * logic change * formatting * added retries below 0 check * typos * fixed logic * docstring fix * Handle no status in RPC --------- Co-authored-by: drknzz <kamil.jankowski.x@gmail.com> * Fix v2 nested types * Remove unused _get_struct * Remove wait_for_tx NOT_RECEIVED tests * Fix nested types v2 tests * Fix nested types v1 * Fix template structs * Update migration guide --------- Co-authored-by: Tomasz Miśkowicz <tomasz.miskowicz@swmansion.com>
1 parent 4c60216 commit 9f82dc7

File tree

114 files changed

+132053
-404
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+132053
-404
lines changed

.github/workflows/checks.yml

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ jobs:
109109
run: |
110110
poetry run poe compile_contracts
111111
112+
- name: Upload contracts
113+
uses: actions/upload-artifact@v3
114+
with:
115+
name: contract-artifacts
116+
path: starknet_py/tests/e2e/mock/
117+
112118
# ====================== CAIRO SETUP ====================== #
113119

114120
- name: Install rust
@@ -120,7 +126,7 @@ jobs:
120126
with:
121127
repository: starkware-libs/cairo
122128
persist-credentials: false
123-
ref: v1.1.0
129+
ref: v2.0.0
124130
path: cairo
125131

126132
- name: Cache rust dependencies
@@ -151,26 +157,6 @@ jobs:
151157
run: |
152158
readlink -f cairo/Cargo.toml >> starknet_py/tests/e2e/manifest-path
153159
154-
# ====================== CONTRACTS v1 ====================== #
155-
156-
- name: Cache Cairo1 contracts
157-
id: cache-contracts-v1
158-
uses: actions/cache@v3
159-
with:
160-
path: starknet_py/tests/e2e/mock/contracts_compiled_v1
161-
key: ${{ runner.os }}-contracts-v1-${{ hashFiles('starknet_py/tests/e2e/mock/contracts_v1', 'poetry.lock') }}
162-
163-
- name: Compile Cairo1 contracts
164-
if: steps.cache-contracts-v1.outputs.cache-hit != 'true'
165-
run: |
166-
poetry run poe compile_contracts_v1
167-
168-
- name: Upload contracts
169-
uses: actions/upload-artifact@v3
170-
with:
171-
name: contract-artifacts
172-
path: starknet_py/tests/e2e/mock/
173-
174160
# ---------------------------------------------------------- #
175161
# ........................RUN-TESTS......................... #
176162
# ---------------------------------------------------------- #
@@ -228,8 +214,10 @@ jobs:
228214
229215
- name: Run tests
230216
run: |
231-
poetry run poe test_ci_gateway
232-
poetry run poe test_ci_full_node
217+
poetry run poe test_ci_full_node_v2
218+
poetry run poe test_ci_full_node_v1
219+
poetry run poe test_ci_gateway_v2
220+
poetry run poe test_ci_gateway_v1
233221
234222
- name: Generate coverage in XML
235223
run: |
@@ -254,7 +242,8 @@ jobs:
254242
steps:
255243
- uses: actions/checkout@v3
256244

257-
- uses: actions/download-artifact@v3
245+
- name: Download contracts
246+
uses: actions/download-artifact@v3
258247
with:
259248
name: contract-artifacts
260249
path: starknet_py/tests/e2e/mock/
@@ -312,8 +301,10 @@ jobs:
312301
313302
- name: Run tests
314303
run: |
315-
poetry run poe test_ci_gateway
316-
poetry run poe test_ci_full_node
304+
poetry run poe test_ci_full_node_v2
305+
poetry run poe test_ci_full_node_v1
306+
poetry run poe test_ci_gateway_v2
307+
poetry run poe test_ci_gateway_v1
317308
318309
- name: Generate coverage in XML
319310
run: |
@@ -375,8 +366,10 @@ jobs:
375366

376367
- name: Run tests
377368
run: |
378-
poetry run poe test_ci_docs_gateway
379-
poetry run poe test_ci_docs_full_node
369+
poetry run poe test_ci_docs_full_node_v2
370+
poetry run poe test_ci_docs_full_node_v1
371+
poetry run poe test_ci_docs_gateway_v2
372+
poetry run poe test_ci_docs_gateway_v1
380373
381374
- name: Generate coverage in XML
382375
run: |
@@ -401,7 +394,8 @@ jobs:
401394
steps:
402395
- uses: actions/checkout@v3
403396

404-
- uses: actions/download-artifact@v3
397+
- name: Download contracts
398+
uses: actions/download-artifact@v3
405399
with:
406400
name: contract-artifacts
407401
path: starknet_py/tests/e2e/mock/
@@ -455,8 +449,10 @@ jobs:
455449

456450
- name: Run tests
457451
run: |
458-
poetry run poe test_ci_docs_gateway
459-
poetry run poe test_ci_docs_full_node
452+
poetry run poe test_ci_docs_full_node_v2
453+
poetry run poe test_ci_docs_full_node_v1
454+
poetry run poe test_ci_docs_gateway_v2
455+
poetry run poe test_ci_docs_gateway_v1
460456
461457
- name: Generate coverage in XML
462458
run: |

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ cython_debug/
147147

148148
# Compiled contracts
149149
/starknet_py/tests/e2e/mock/contracts_compiled/*
150-
/starknet_py/tests/e2e/mock/contracts_compiled_v1/*
151150

152151
# Allow precompiled contracts
153152
!/starknet_py/tests/e2e/mock/contracts_compiled/precompiled/

docs/migration_guide.rst

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,10 @@ Migration guide
55
0.17.0 Migration guide
66
**********************
77

8-
.. currentmodule:: starknet_py.net.full_node_client
9-
10-
:class:`FullNodeClient` RPC specification has been updated from `v0.3.0-rc1 <https://github.com/starkware-libs/starknet-specs/releases/tag/v0.3.0-rc1>`_ to `v0.3.0 <https://github.com/starkware-libs/starknet-specs/releases/tag/v0.3.0>`_.
11-
12-
.. currentmodule:: starknet_py.contract
13-
14-
Also, four methods were added to its interface:
15-
16-
- :meth:`FullNodeClient.get_block_number`
17-
- :meth:`FullNodeClient.get_block_hash_and_number`
18-
- :meth:`FullNodeClient.get_chain_id`
19-
- :meth:`FullNodeClient.get_syncing_status`
8+
With Starknet 0.12.0, the ``PENDING`` transaction status has been removed.
209

2110

22-
:class:`Contract` now *initially* supports contracts written in **Cairo1**.
11+
:class:`Contract` now supports contracts written in **Cairo1** in both old and new syntax.
2312

2413
To create an instance of such contract, a keyword parameter ``cairo_version=1`` in the Contract constructor is required.
2514

@@ -35,6 +24,20 @@ To create an instance of such contract, a keyword parameter ``cairo_version=1``
3524
As a result, :class:`GatewayClient` won't work and will eventually be removed. Consider migrating to :ref:`FullNodeClient`.
3625

3726

27+
.. currentmodule:: starknet_py.net.full_node_client
28+
29+
:class:`FullNodeClient` RPC specification has been updated from `v0.3.0-rc1 <https://github.com/starkware-libs/starknet-specs/releases/tag/v0.3.0-rc1>`_ to `v0.3.0 <https://github.com/starkware-libs/starknet-specs/releases/tag/v0.3.0>`_.
30+
31+
.. currentmodule:: starknet_py.contract
32+
33+
Also, four methods were added to its interface:
34+
35+
- :meth:`FullNodeClient.get_block_number`
36+
- :meth:`FullNodeClient.get_block_hash_and_number`
37+
- :meth:`FullNodeClient.get_chain_id`
38+
- :meth:`FullNodeClient.get_syncing_status`
39+
40+
3841
Breaking changes
3942
----------------
4043

@@ -44,6 +47,8 @@ Breaking changes
4447

4548
2. Removed deprecated ``Deployer.create_deployment_call`` and ``Deployer.create_deployment_call_raw`` in favor of :meth:`Deployer.create_contract_deployment` and :meth:`Deployer.create_contract_deployment_raw`.
4649

50+
3. Removed ``PENDING`` transaction status.
51+
4752

4853
Minor changes
4954
-------------
@@ -74,6 +79,18 @@ RPC related changes:
7479

7580
9. :class:`StarknetChainId` changed from ``Enum`` to ``IntEnum``.
7681

82+
.. currentmodule:: starknet_py.net.client
83+
84+
10. :meth:`Client.wait_for_tx` has a new parameter ``retries`` describing the amount of retries before a time out when querying for a transaction.
85+
86+
87+
Deprecations
88+
------------
89+
.. currentmodule:: starknet_py.net.client
90+
91+
1. `wait_for_accept` parameter in :meth:`Client.wait_for_tx` and :meth:`SentTransaction.wait_for_acceptance` has been deprecated.
92+
93+
7794
Bugfixes
7895
--------
7996

poetry.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,23 @@ pytest-rerunfailures = "^11.1"
4949

5050

5151
[tool.poetry.group.py39-dev.dependencies]
52-
cairo-lang = { version = "^0.11.2", python= ">=3.9, <3.10" }
53-
starknet-devnet = {version = "0.5.4", python = ">=3.9,<3.10"}
52+
cairo-lang = { version = "0.12.0", python= ">=3.9, <3.10" }
53+
starknet-devnet = { version = "0.5.5", python= ">=3.9, <3.10" }
5454

5555
[tool.poe.tasks]
5656
test.shell = "pytest -n auto -v --reruns 10 --only-rerun aiohttp.client_exceptions.ClientConnectorError --cov=starknet_py starknet_py"
5757

58-
test_ci = ["test_ci_gateway", "test_ci_full_node"]
59-
test_ci_gateway.shell = "coverage run -m pytest --client=gateway -v --reruns 5 --only-rerun aiohttp.client_exceptions.ClientConnectorError starknet_py --ignore=starknet_py/tests/e2e/docs --ignore=starknet_py/tests/e2e/core"
60-
test_ci_full_node.shell = "coverage run -m pytest --client=full_node -v --reruns 5 --only-rerun aiohttp.client_exceptions.ClientConnectorError starknet_py --ignore=starknet_py/tests/e2e/docs --ignore=starknet_py/tests/e2e/core"
58+
test_ci = ["test_ci_gateway_v1", "test_ci_full_node_v1", "test_ci_gateway_v2", "test_ci_full_node_v2"]
59+
test_ci_gateway_v1.shell = "coverage run -m pytest --client=gateway --contract_dir=v1 -v --reruns 5 --only-rerun aiohttp.client_exceptions.ClientConnectorError starknet_py --ignore=starknet_py/tests/e2e/docs --ignore=starknet_py/tests/e2e/core"
60+
test_ci_full_node_v1.shell = "coverage run -m pytest --client=full_node --contract_dir=v1 -v --reruns 5 --only-rerun aiohttp.client_exceptions.ClientConnectorError starknet_py --ignore=starknet_py/tests/e2e/docs --ignore=starknet_py/tests/e2e/core"
61+
test_ci_gateway_v2.shell = "coverage run -m pytest --client=gateway --contract_dir=v2 -v --reruns 5 --only-rerun aiohttp.client_exceptions.ClientConnectorError starknet_py --ignore=starknet_py/tests/e2e/docs --ignore=starknet_py/tests/e2e/core"
62+
test_ci_full_node_v2.shell = "coverage run -m pytest --client=full_node --contract_dir=v2 -v --reruns 5 --only-rerun aiohttp.client_exceptions.ClientConnectorError starknet_py --ignore=starknet_py/tests/e2e/docs --ignore=starknet_py/tests/e2e/core"
6163

62-
test_ci_docs = ["test_ci_docs_gateway", "test_ci_docs_full_node"]
63-
test_ci_docs_gateway.shell = "coverage run -m pytest --client=gateway -v --reruns 5 --only-rerun aiohttp.client_exceptions.ClientConnectorError starknet_py/tests/e2e/docs"
64-
test_ci_docs_full_node.shell = "coverage run -m pytest --client=full_node -v --reruns 5 --only-rerun aiohttp.client_exceptions.ClientConnectorError starknet_py/tests/e2e/docs"
64+
test_ci_docs = ["test_ci_docs_gateway_v1", "test_ci_docs_full_node_v1", "test_ci_docs_gateway_v2", "test_ci_docs_full_node_v2"]
65+
test_ci_docs_gateway_v1.shell = "coverage run -m pytest --client=gateway --contract_dir=v1 -v --reruns 5 --only-rerun aiohttp.client_exceptions.ClientConnectorError starknet_py/tests/e2e/docs"
66+
test_ci_docs_full_node_v1.shell = "coverage run -m pytest --client=full_node --contract_dir=v1 -v --reruns 5 --only-rerun aiohttp.client_exceptions.ClientConnectorError starknet_py/tests/e2e/docs"
67+
test_ci_docs_gateway_v2.shell = "coverage run -m pytest --client=gateway --contract_dir=v2 -v --reruns 5 --only-rerun aiohttp.client_exceptions.ClientConnectorError starknet_py/tests/e2e/docs"
68+
test_ci_docs_full_node_v2.shell = "coverage run -m pytest --client=full_node --contract_dir=v2 -v --reruns 5 --only-rerun aiohttp.client_exceptions.ClientConnectorError starknet_py/tests/e2e/docs"
6569

6670
test_unit.shell = "pytest -n auto -v starknet_py --ignore=starknet_py/tests/e2e"
6771
test_e2e.shell = "pytest -n auto -v starknet_py/tests/e2e --ignore=starknet_py/tests/e2e/docs"
@@ -78,8 +82,11 @@ format_diff.shell = "isort --diff . && black --diff ."
7882
typecheck = "pyright starknet_py"
7983
compile_contracts = "bash starknet_py/tests/e2e/mock/compile_contracts.sh"
8084
compile_contracts_v1 = "bash starknet_py/tests/e2e/mock/compile_contracts_v1.sh"
85+
compile_contracts_v2 = "bash starknet_py/tests/e2e/mock/compile_contracts_v2.sh"
8186
circular_imports_check.shell = "poetry run pytest circular.py"
8287
ci = ["lint", "format_check", "typecheck", "test_ci"]
88+
precommit.sequence = ["format", "lint", "typecheck"]
89+
precommit.ignore_fail = true
8390

8491
[tool.poetry.build]
8592
generate-setup-file = true

starknet_py/abi/parser_test.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import starknet_py.tests.e2e.fixtures.abi_structures as fixtures
66
from starknet_py.abi.parser import AbiParser, AbiParsingError
77
from starknet_py.cairo.type_parser import UnknownCairoTypeError
8+
from starknet_py.tests.e2e.fixtures.constants import CONTRACTS_COMPILED_DIR
89
from starknet_py.tests.e2e.fixtures.misc import read_contract
910

1011

@@ -190,15 +191,19 @@ def test_missing_type_used(missing_name, input_dict):
190191

191192
def test_deserialize_proxy_abi():
192193
# Contains all types of ABI apart from structures
193-
abi = json.loads(read_contract("oz_proxy_abi.json"))
194+
abi = json.loads(
195+
read_contract("oz_proxy_abi.json", directory=CONTRACTS_COMPILED_DIR)
196+
)
194197
deserialized = AbiParser(abi).parse()
195198

196199
assert deserialized == fixtures.oz_proxy_abi
197200

198201

199202
def test_deserialize_balance_struct_event_abi():
200203
# Contains all types of ABI apart from structures
201-
abi = json.loads(read_contract("balance_struct_event_abi.json"))
204+
abi = json.loads(
205+
read_contract("balance_struct_event_abi.json", directory=CONTRACTS_COMPILED_DIR)
206+
)
202207
deserialized = AbiParser(abi).parse()
203208

204209
assert deserialized == fixtures.balance_struct_abi

starknet_py/abi/schemas_test.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
from marshmallow import EXCLUDE
44

55
from starknet_py.abi.schemas import ContractAbiEntrySchema
6+
from starknet_py.tests.e2e.fixtures.constants import CONTRACTS_COMPILED_DIR
67
from starknet_py.tests.e2e.fixtures.misc import read_contract
78

89

910
def test_deserialize_abi():
10-
abi = json.loads(read_contract("balance_struct_event_abi.json"))
11+
abi = json.loads(
12+
read_contract("balance_struct_event_abi.json", directory=CONTRACTS_COMPILED_DIR)
13+
)
1114
deserialized = [
1215
ContractAbiEntrySchema().load(entry, unknown=EXCLUDE) for entry in abi
1316
]

starknet_py/abi/v1/parser_transformer.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ class ParserTransformer(Transformer):
5959
Transforms the lark tree into CairoTypes.
6060
"""
6161

62+
def __init__(self, type_identifiers: Optional[dict] = None) -> None:
63+
if type_identifiers is None:
64+
type_identifiers = {}
65+
self.type_identifiers = type_identifiers
66+
super(Transformer, self).__init__()
67+
6268
# pylint: disable=no-self-use
6369

6470
def __default__(self, data: str, children, meta):
@@ -124,6 +130,8 @@ def type_identifier(self, tokens: List[Token]) -> TypeIdentifier:
124130
We are interested only in the strings because a structure (or enum) name can be built from them.
125131
"""
126132
name = "::".join(token for token in tokens if isinstance(token, str))
133+
if name in self.type_identifiers:
134+
return self.type_identifiers[name]
127135
return TypeIdentifier(name)
128136

129137
def type_contract_address(self, _value: List[Any]) -> FeltType:
@@ -153,6 +161,7 @@ def tuple(self, types: List[CairoType]) -> TupleType:
153161

154162
def parse(
155163
code: str,
164+
type_identifiers,
156165
) -> CairoType:
157166
"""
158167
Parse the given string and return a CairoType.
@@ -164,6 +173,7 @@ def parse(
164173
)
165174
parsed = grammar_parser.parse(code)
166175

167-
transformed = ParserTransformer().transform(parsed)
176+
parser_transformer = ParserTransformer(type_identifiers)
177+
cairo_type = parser_transformer.transform(parsed)
168178

169-
return transformed
179+
return cairo_type

starknet_py/abi/v1/parser_transformer_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66

77
def test_default_parser_transformer():
88
with pytest.raises(TypeError, match="Unable to parse tree node of type wrong."):
9-
ParserTransformer().transform(Tree(data=Token("RULE", "wrong"), children=[]))
9+
ParserTransformer({}).transform(Tree(data=Token("RULE", "wrong"), children=[]))

starknet_py/abi/v2/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)