Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace a few cairo 0 contracts in tests vol. 2 #1424

Merged
merged 75 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from 72 commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
dd83220
Merge branch 'kkawula/1334-remove-unnecessary-cairo-0-tests'
kkawula Jul 30, 2024
7009e4f
Migrate tests to use cairo 1 ERC20 contract
kkawula Jul 30, 2024
9c1e645
Remove ERC20 contract cairo code and fixtures
kkawula Jul 30, 2024
9a01051
Adapt tests to the cairo 1
kkawula Aug 5, 2024
966f950
Merge 'development'
kkawula Aug 5, 2024
8c4418f
Merge 'development'
kkawula Aug 5, 2024
f43673a
Fix test in Serilization Guide
kkawula Aug 5, 2024
3b1658c
Fix typo in 'test_abi_parsing'
kkawula Aug 5, 2024
2adc084
Fix after merge
kkawula Aug 5, 2024
82e7242
Remove 'constructor_with_arguments.cairo' and 'constructor_without_ar…
kkawula Aug 5, 2024
301a8d4
Add 'constructor_with_arguments.cairo' contract and update test_throw…
kkawula Aug 6, 2024
74e9360
Update 'test_constructor_arguments_contract_deploy'
kkawula Aug 6, 2024
50bad80
Add skiping test while cairo v1 test dir is triggered
kkawula Aug 6, 2024
46f4e6e
Update 'test_create_deployment_call_raw_supports_seed_0' and 'test_cr…
kkawula Aug 6, 2024
ad05ad8
Remove old 'constructor_with_arguments' fixture
kkawula Aug 6, 2024
a0db46f
Update 'test_deploying_with_udc'
kkawula Aug 6, 2024
c735a0d
Update 'constructor_with_arguments_abi' and 'constructor_with_argumen…
kkawula Aug 6, 2024
02c1647
Update docs example
kkawula Aug 6, 2024
c7152f2
Add 'map' contract implementation in cairo 1
kkawula Aug 6, 2024
e1dceb2
Add fixtures for new contract
kkawula Aug 6, 2024
518eafa
Remove 'map_contract_declare_hahs' fixutre
kkawula Aug 6, 2024
a1c69b4
Replace old 'map_contract' fixture
kkawula Aug 6, 2024
e5d6b71
Replace old 'map_class_hash' fixture
kkawula Aug 6, 2024
964a289
Update a few tests
kkawula Aug 6, 2024
a7d664c
Update 'test_deploying_in_multicall'
kkawula Aug 6, 2024
2b8520b
Remove 'Simple declare and deploy' paragraph from docs
kkawula Aug 6, 2024
bf0be0d
Update docs example 'Quickstart - Using Account'
kkawula Aug 6, 2024
dc814a2
Update docs example 'Guide - test_simple_deploy
kkawula Aug 6, 2024
8e9b904
Remove fixtures 'map_source_code' and 'map_compiled_contract'
kkawula Aug 6, 2024
44fb7c2
Fix PriceUnit assertion in 'test_account_estimate_fee_for_declare_tra…
kkawula Aug 6, 2024
a02e663
Add docs test to skip because of redeclaration :(
kkawula Aug 6, 2024
04c5850
Remove map.cairo
kkawula Aug 6, 2024
6f57a8d
Remove 'replace_class.cairo' conatract and fixture
kkawula Aug 6, 2024
7d163b0
Remove unused fixture 'fixture_balance_contract'
kkawula Aug 6, 2024
adfc532
Upadte 'test_estimate_fee_for_multiple_transactions'
kkawula Aug 7, 2024
b01371f
Update 'test_simulate_transactions_declare'
kkawula Aug 7, 2024
7939061
Remove 'test_simulate_transactions_declare'
kkawula Aug 7, 2024
7506f57
Update 'simple_storage_with_event' contract to cairo 1
kkawula Aug 7, 2024
a134d21
Add test to skip reason='Some cairo 1 contracts compiled with v1 comp…
kkawula Aug 7, 2024
c27654a
Merge branch 'development' into kkawula/1334-replace-cairo-0-contracts
kkawula Aug 8, 2024
d4dd60b
Merge 'kkawula/1334-replace-cairo-0-contracts'
kkawula Aug 8, 2024
bc2f6a4
Remove deprecated cairo 0 fixture 'simple_storage_with_event_compiled…
kkawula Aug 8, 2024
823f96c
Remove cairo v1 version of 'simple_storage_with_event.cairo' contract
kkawula Aug 8, 2024
5e0ff7d
Remove cairo v1 contracts that have events
kkawula Aug 8, 2024
f6f15f0
Remove removed contracts from lib.cairo
kkawula Aug 8, 2024
73332dc
Fix 'test_deserialize_abi' v1
kkawula Aug 8, 2024
8995741
Fix 'test_evenet_serialization_v1'
kkawula Aug 8, 2024
1a5db99
Fix 'test_throws_when_cairo1_without_compiled_contract_casm_and_class…
kkawula Aug 8, 2024
dd2785e
Merge branch 'development' into kkawula/1334-replace-cairo-0-contracts
kkawula Aug 8, 2024
3656a44
Merge branch 'kkawula/1334-replace-cairo-0-contracts' into 'kkawula/1…
kkawula Aug 9, 2024
db09b19
Fix 'test_throws_when_cairo1_without_compiled_contract_casm_and_class…
kkawula Aug 9, 2024
0ce876b
Merge branch 'development' into kkawula/1334-replace-cairo-0-contracts
kkawula Aug 21, 2024
e8da73f
Update starknet_py/tests/e2e/deploy/deployer_test.py
kkawula Aug 21, 2024
fa43f2c
Add newline
kkawula Aug 21, 2024
222e702
Update test skip conditio to '--contract_dir=v2 not in sys.argv'
kkawula Aug 21, 2024
b21be50
Add newline
kkawula Aug 21, 2024
580eb5d
Change example in docs - declare_v3 uses casm
kkawula Aug 21, 2024
62ffc08
Merge branch 'kkawula/1334-replace-cairo-0-contracts' into kkawula/re…
kkawula Aug 21, 2024
8b3da08
Add empty line for readability
kkawula Aug 26, 2024
099e7b8
Remove unused assert
kkawula Aug 26, 2024
b86199c
Fix docs-start
kkawula Aug 26, 2024
9588d81
Fix typo 'devnet-rs' -> 'starknet-devnet-rs'
kkawula Aug 26, 2024
84802f9
Update starknet_py/tests/e2e/docs/guide/test_declaring_contracts.py
kkawula Aug 26, 2024
51bb720
Scarb fmt
kkawula Aug 26, 2024
5d91ee4
Scarb fmt
kkawula Aug 26, 2024
1f39a12
Merge branch 'refs/heads/kkawula/1334-replace-cairo-0-contracts' into…
kkawula Aug 26, 2024
34e1b83
Rename fixture 'cairo1_map_contract_abi' -> 'map_abi'
kkawula Aug 26, 2024
2653501
Move abi_v1 constatnt to abi fixture file
kkawula Aug 27, 2024
e05cd0e
Merge branch 'refs/heads/development' into kkawula/replace-cairo-0-co…
kkawula Aug 27, 2024
51d82a0
Fix 'test_get_block_with_txs_latest'
kkawula Aug 27, 2024
d72a94e
Fix 'test_get_block_with_txs_latest'
kkawula Aug 27, 2024
bb987c8
Add TODO to 'test_get_block_with_txs_latest'
kkawula Aug 27, 2024
839ccb9
Fix typo
kkawula Aug 27, 2024
79f8da3
Update starknet_py/tests/e2e/fixtures/contracts_v1.py
kkawula Aug 27, 2024
6cc8ab4
Update starknet_py/tests/e2e/fixtures/contracts_v1.py
kkawula Aug 27, 2024
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
11 changes: 0 additions & 11 deletions docs/guide/deploying_contracts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,6 @@ Here's an example how to use it.
:dedent: 4


Simple declare and deploy
-------------------------

The simplest way of declaring and deploying contracts on the Starknet is to use the :ref:`Contract` class.
Under the hood, this flow first sends ``Declare`` transaction and then sends ``Invoke``
through Universal Deployment Contract (UDC) to deploy a contract.

.. codesnippet:: ../../starknet_py/tests/e2e/docs/guide/test_simple_declare_and_deploy.py
:language: python
:dedent: 4

Simple deploy
-------------

Expand Down
4 changes: 2 additions & 2 deletions starknet_py/abi/v1/schemas_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
"contract_name",
[
"Account",
"ERC20",
"Hello",
"HelloStarknet",
"MinimalContract",
"TestContract",
"TokenBridge",
"TestEnum",
],
)
def test_deserialize_abi(contract_name):
Expand Down
6 changes: 2 additions & 4 deletions starknet_py/serialization/serialization_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
serializer_for_function,
)
from starknet_py.serialization.tuple_dataclass import TupleDataclass
from starknet_py.tests.e2e.fixtures.abi_v1_structures import event_abi_v1
from starknet_py.tests.e2e.fixtures.constants import CONTRACTS_COMPILED_V0_DIR
from starknet_py.tests.e2e.fixtures.misc import (
ContractVersion,
Expand Down Expand Up @@ -110,10 +111,7 @@ class Education(NamedTuple):
)
parsed_abi = AbiParserV0(abi).parse()

abi_v1 = json.loads(
load_contract(contract_name="ERC20", version=ContractVersion.V1)["sierra"]
)["abi"]
parsed_abi_v1 = AbiParserV1(abi_v1).parse()
parsed_abi_v1 = AbiParserV1(event_abi_v1).parse()

abi_v2 = json.loads(
load_contract(contract_name="NewSyntaxTestContract", version=ContractVersion.V2)[
Expand Down
30 changes: 19 additions & 11 deletions starknet_py/tests/e2e/account/account_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ async def test_get_balance_throws_when_token_not_specified(account):


@pytest.mark.skipif(
"--contract_dir=v2" not in sys.argv,
reason="Some cairo 1 contracts compiled with v1 compiler fail with new starknet-devnet-rs",
"--contract_dir=v1" in sys.argv,
kkawula marked this conversation as resolved.
Show resolved Hide resolved
reason="Contract exists only in v2 directory",
)
@pytest.mark.asyncio
async def test_balance_when_token_specified(account, erc20_contract):
Expand All @@ -68,8 +68,8 @@ async def test_balance_when_token_specified(account, erc20_contract):


@pytest.mark.skipif(
"--contract_dir=v2" not in sys.argv,
reason="Some cairo 1 contracts compiled with v1 compiler fail with new starknet-devnet-rs",
"--contract_dir=v1" in sys.argv,
reason="Contract exists only in v2 directory",
)
@pytest.mark.asyncio
async def test_estimated_fee_greater_than_zero(account, erc20_contract):
Expand All @@ -88,9 +88,14 @@ async def test_estimated_fee_greater_than_zero(account, erc20_contract):


@pytest.mark.asyncio
async def test_estimate_fee_for_declare_transaction(account, map_compiled_contract):
declare_tx = await account.sign_declare_v1(
compiled_contract=map_compiled_contract, max_fee=MAX_FEE
async def test_estimate_fee_for_declare_transaction(
account, map_compiled_contract_and_class_hash
):
(compiled_contract, class_hash) = map_compiled_contract_and_class_hash
declare_tx = await account.sign_declare_v3(
compiled_contract=compiled_contract,
compiled_class_hash=class_hash,
l1_resource_bounds=MAX_RESOURCE_BOUNDS_L1,
)

estimated_fee = await account.client.estimate_fee(tx=declare_tx)
Expand All @@ -106,15 +111,18 @@ async def test_estimate_fee_for_declare_transaction(account, map_compiled_contra

@pytest.mark.asyncio
async def test_account_estimate_fee_for_declare_transaction(
account, map_compiled_contract
account, map_compiled_contract_and_class_hash
):
declare_tx = await account.sign_declare_v1(
compiled_contract=map_compiled_contract, max_fee=MAX_FEE
(compiled_contract, class_hash) = map_compiled_contract_and_class_hash
declare_tx = await account.sign_declare_v3(
compiled_contract=compiled_contract,
compiled_class_hash=class_hash,
l1_resource_bounds=MAX_RESOURCE_BOUNDS_L1,
)

estimated_fee = await account.estimate_fee(tx=declare_tx)

assert estimated_fee.unit == PriceUnit.WEI
assert estimated_fee.unit == PriceUnit.FRI
assert isinstance(estimated_fee.overall_fee, int)
assert estimated_fee.overall_fee > 0
assert (
Expand Down
17 changes: 6 additions & 11 deletions starknet_py/tests/e2e/block_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,12 @@ async def test_block_with_tx_hashes_pending(account):
# TODO (#1419): Fix contract redeclaration
@pytest.mark.skip(reason="Redeclaration occurred")
@pytest.mark.asyncio
async def test_block_with_tx_hashes_latest(
account,
map_contract_declare_hash,
):
async def test_block_with_tx_hashes_latest(account):
blk = await account.client.get_block_with_tx_hashes(block_number="latest")

assert isinstance(blk, StarknetBlockWithTxHashes)
assert isinstance(blk.transactions, list)
assert map_contract_declare_hash in blk.transactions
assert blk.transactions is not None
franciszekjob marked this conversation as resolved.
Show resolved Hide resolved
assert blk.block_hash is not None
assert blk.parent_hash is not None
assert blk.block_number is not None
Expand All @@ -68,17 +65,15 @@ async def test_get_block_with_txs_pending(account):


# TODO (#1419): Fix contract redeclaration
@pytest.mark.skip(reason="Redeclaration occurred")
@pytest.mark.asyncio
async def test_get_block_with_txs_latest(
account,
map_contract_declare_hash,
):
async def test_get_block_with_txs_latest(account, map_class_hash):
# pylint: disable=unused-argument

blk = await account.client.get_block_with_txs(block_number="latest")

assert isinstance(blk, StarknetBlock)
assert isinstance(blk.transactions, list)
assert blk.transactions[0].hash == map_contract_declare_hash
kkawula marked this conversation as resolved.
Show resolved Hide resolved
assert blk.transactions[0].hash is not None
franciszekjob marked this conversation as resolved.
Show resolved Hide resolved
assert blk.block_hash is not None
assert blk.parent_hash is not None
assert blk.block_number is not None
Expand Down
15 changes: 2 additions & 13 deletions starknet_py/tests/e2e/client/client_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# pylint: disable=too-many-arguments
import dataclasses
from typing import Tuple
from unittest.mock import AsyncMock, Mock, patch

Expand Down Expand Up @@ -37,8 +36,7 @@
from starknet_py.net.http_client import RpcHttpClient
from starknet_py.net.models.transaction import DeclareV2
from starknet_py.net.udc_deployer.deployer import Deployer
from starknet_py.tests.e2e.fixtures.constants import CONTRACTS_COMPILED_V0_DIR, MAX_FEE
from starknet_py.tests.e2e.fixtures.misc import read_contract
from starknet_py.tests.e2e.fixtures.constants import MAX_FEE
from starknet_py.transaction_errors import (
TransactionNotReceivedError,
TransactionRejectedError,
Expand Down Expand Up @@ -249,16 +247,7 @@ async def test_estimate_fee_for_multiple_transactions(
)
invoke_tx = await account.sign_for_fee_estimate(invoke_tx)

declare_tx = await account.sign_declare_v1(
compiled_contract=read_contract(
"map_compiled.json", directory=CONTRACTS_COMPILED_V0_DIR
),
max_fee=MAX_FEE,
)
declare_tx = dataclasses.replace(declare_tx, nonce=invoke_tx.nonce + 1)
declare_tx = await account.sign_for_fee_estimate(declare_tx)

transactions = [invoke_tx, declare_tx, deploy_account_transaction]
transactions = [invoke_tx, deploy_account_transaction]

estimated_fees = await client.estimate_fee(tx=transactions, block_number="latest")

Expand Down
33 changes: 2 additions & 31 deletions starknet_py/tests/e2e/client/fixtures/transactions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# pylint: disable=redefined-outer-name
from typing import Tuple, cast
from typing import Tuple

import pytest
import pytest_asyncio
Expand All @@ -12,8 +12,7 @@
from starknet_py.tests.e2e.client.fixtures.prepare_net_for_gateway_test import (
PreparedNetworkData,
)
from starknet_py.tests.e2e.fixtures.constants import CONTRACTS_COMPILED_V0_DIR, MAX_FEE
from starknet_py.tests.e2e.fixtures.misc import read_contract
from starknet_py.tests.e2e.fixtures.constants import MAX_FEE
from starknet_py.tests.e2e.utils import (
get_deploy_account_details,
get_deploy_account_transaction,
Expand Down Expand Up @@ -94,31 +93,3 @@ async def block_with_declare_v2_number(
cairo1_hello_starknet_tx_hash
)
return declare_v2_receipt.block_number


@pytest_asyncio.fixture(scope="function")
async def replaced_class(account: Account, map_class_hash: int) -> Tuple[int, int, int]:
"""
Returns block_number, contract_address and class_hash of transaction replacing implementation.
"""
compiled_contract = read_contract(
"replace_class_compiled.json", directory=CONTRACTS_COMPILED_V0_DIR
)

declare_result = await (
await Contract.declare_v1(account, compiled_contract, max_fee=MAX_FEE)
).wait_for_acceptance()

deploy_result = await (
await declare_result.deploy_v1(max_fee=MAX_FEE)
).wait_for_acceptance()

contract = deploy_result.deployed_contract

resp = await (
await contract.functions["replace_implementation"].invoke_v1(
new_class=map_class_hash, max_fee=MAX_FEE
)
).wait_for_acceptance()

return cast(int, resp.block_number), contract.address, map_class_hash
59 changes: 33 additions & 26 deletions starknet_py/tests/e2e/client/full_node_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import dataclasses
import sys
from unittest.mock import AsyncMock, patch

import pytest
Expand Down Expand Up @@ -26,12 +27,7 @@
)
from starknet_py.net.full_node_client import _to_rpc_felt
from starknet_py.net.models import StarknetChainId
from starknet_py.tests.e2e.fixtures.constants import CONTRACTS_COMPILED_V0_DIR
from starknet_py.tests.e2e.fixtures.misc import (
ContractVersion,
load_contract,
read_contract,
)
from starknet_py.tests.e2e.fixtures.misc import ContractVersion, load_contract
from starknet_py.tests.e2e.utils import create_empty_block


Expand All @@ -40,9 +36,9 @@ def _parse_event_name(event: str) -> str:


FUNCTION_ONE_NAME = "put"
EVENT_ONE_PARSED_NAME = _parse_event_name("put_called")
EVENT_ONE_PARSED_NAME = _parse_event_name("PutCalled")
FUNCTION_TWO_NAME = "another_put"
EVENT_TWO_PARSED_NAME = _parse_event_name("another_put_called")
EVENT_TWO_PARSED_NAME = _parse_event_name("AnotherPutCalled")


# TODO (#1419): Fix contract redeclaration
Expand Down Expand Up @@ -149,14 +145,18 @@ async def test_get_storage_at_incorrect_address_full_node_client(client):
)


@pytest.mark.skipif(
"--contract_dir=v1" in sys.argv,
reason="Contract exists only in v2 directory",
)
@pytest.mark.run_on_devnet
@pytest.mark.asyncio
async def test_get_events_without_following_continuation_token(
client,
simple_storage_with_event_contract: Contract,
):
for i in range(4):
await simple_storage_with_event_contract.functions[FUNCTION_ONE_NAME].invoke_v1(
await simple_storage_with_event_contract.functions[FUNCTION_ONE_NAME].invoke_v3(
i, i, auto_estimate=True
)

Expand All @@ -174,6 +174,10 @@ async def test_get_events_without_following_continuation_token(
assert events_response.continuation_token is not None


@pytest.mark.skipif(
"--contract_dir=v1" in sys.argv,
reason="Contract exists only in v2 directory",
)
@pytest.mark.run_on_devnet
@pytest.mark.asyncio
async def test_get_events_follow_continuation_token(
Expand All @@ -199,6 +203,10 @@ async def test_get_events_follow_continuation_token(
assert events_response.continuation_token is None


@pytest.mark.skipif(
"--contract_dir=v1" in sys.argv,
reason="Contract exists only in v2 directory",
)
@pytest.mark.run_on_devnet
@pytest.mark.asyncio
async def test_get_events_nonexistent_event_name(
Expand All @@ -222,6 +230,10 @@ async def test_get_events_nonexistent_event_name(
assert events_response.continuation_token is None


@pytest.mark.skipif(
"--contract_dir=v1" in sys.argv,
reason="Contract exists only in v2 directory",
)
@pytest.mark.run_on_devnet
@pytest.mark.asyncio
async def test_get_events_with_two_events(
Expand Down Expand Up @@ -271,6 +283,10 @@ async def test_get_events_with_two_events(
assert event_one_two_events_response.continuation_token is None


@pytest.mark.skipif(
"--contract_dir=v1" in sys.argv,
reason="Contract exists only in v2 directory",
)
@pytest.mark.run_on_devnet
@pytest.mark.asyncio
async def test_get_events_start_from_continuation_token(
Expand Down Expand Up @@ -298,6 +314,10 @@ async def test_get_events_start_from_continuation_token(
assert events_response.continuation_token == expected_continuation_token


@pytest.mark.skipif(
"--contract_dir=v1" in sys.argv,
reason="Contract exists only in v2 directory",
)
@pytest.mark.run_on_devnet
@pytest.mark.asyncio
async def test_get_events_no_params(
Expand All @@ -317,6 +337,10 @@ async def test_get_events_no_params(
assert len(events_response.events) == default_chunk_size


@pytest.mark.skipif(
"--contract_dir=v1" in sys.argv,
reason="Contract exists only in v2 directory",
)
@pytest.mark.run_on_devnet
@pytest.mark.asyncio
async def test_get_events_nonexistent_starting_block(
Expand Down Expand Up @@ -475,23 +499,6 @@ async def test_simulate_transactions_invoke(account, deployed_balance_contract):

# TODO (#1419): Fix contract redeclaration
@pytest.mark.skip(reason="Redeclaration occurred")
@pytest.mark.asyncio
async def test_simulate_transactions_declare(account):
compiled_contract = read_contract(
"map_compiled.json", directory=CONTRACTS_COMPILED_V0_DIR
)
declare_tx = await account.sign_declare_v1(compiled_contract, max_fee=int(1e16))

simulated_txs = await account.client.simulate_transactions(
transactions=[declare_tx], block_number="latest"
)

assert isinstance(simulated_txs[0].transaction_trace, DeclareTransactionTrace)
assert simulated_txs[0].fee_estimation.overall_fee > 0
assert simulated_txs[0].transaction_trace.validate_invocation is not None
assert simulated_txs[0].transaction_trace.execution_resources is not None


franciszekjob marked this conversation as resolved.
Show resolved Hide resolved
@pytest.mark.asyncio
async def test_simulate_transactions_two_txs(account, deployed_balance_contract):
assert isinstance(deployed_balance_contract, Contract)
Expand Down
2 changes: 1 addition & 1 deletion starknet_py/tests/e2e/contract_interaction/declare_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async def test_throws_when_cairo1_without_compiled_contract_casm_and_class_hash(
"For Cairo 1.0 contracts, either the 'compiled_class_hash' or the 'compiled_contract_casm' "
"argument must be provided."
)
compiled_contract = load_contract("ERC20")["sierra"]
compiled_contract = load_contract("Map")["sierra"]

with pytest.raises(ValueError, match=error_message):
await Contract.declare_v2(
Expand Down
Loading
Loading