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

Bump devnet version to v0.2.0-rc.1 #1422

Merged
merged 23 commits into from
Aug 8, 2024
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
4 changes: 2 additions & 2 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ jobs:
- name: Install devnet
run: |
$DEVNET_INSTALL_DIR = "$(git rev-parse --show-toplevel)/starknet_py/tests/e2e/devnet"
cargo install --git https://github.com/0xSpaceShard/starknet-devnet-rs.git --locked --rev 3ad81456092a2da939be1f590855cea2c18ce40c --root $DEVNET_INSTALL_DIR
cargo install --git https://github.com/0xSpaceShard/starknet-devnet-rs.git --locked --rev 7e7dbb5 --root $DEVNET_INSTALL_DIR

# ====================== SETUP PYTHON ====================== #

Expand Down Expand Up @@ -515,7 +515,7 @@ jobs:
- name: Install devnet
run: |
$DEVNET_INSTALL_DIR = "$(git rev-parse --show-toplevel)/starknet_py/tests/e2e/devnet"
cargo install --git https://github.com/0xSpaceShard/starknet-devnet-rs.git --locked --rev 3ad81456092a2da939be1f590855cea2c18ce40c --root $DEVNET_INSTALL_DIR
cargo install --git https://github.com/0xSpaceShard/starknet-devnet-rs.git --locked --rev 7e7dbb5 --root $DEVNET_INSTALL_DIR

# ====================== RUN TESTS ====================== #

Expand Down
24 changes: 18 additions & 6 deletions starknet_py/devnet_utils/devnet_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@
PredeployedAccountSchema,
SetTimeResponseSchema,
)
from starknet_py.net.client_models import Hash, PriceUnit
from starknet_py.net.full_node_client import FullNodeClient, _to_rpc_felt
from starknet_py.net.client_models import Hash, PriceUnit, Tag
from starknet_py.net.full_node_client import (
FullNodeClient,
_get_raw_block_identifier,
_to_rpc_felt,
)
from starknet_py.net.http_client import RpcHttpClient
from starknet_py.utils.sync import add_sync_methods

Expand Down Expand Up @@ -142,19 +146,27 @@ async def create_block(self) -> str:

return res["block_hash"]

async def abort_block(self, starting_block_hash: Hash) -> List[str]:
async def abort_block(
self,
block_hash: Optional[Union[Hash, Tag]] = None,
block_number: Optional[Union[int, Tag]] = None,
) -> List[str]:
"""
This functionality allows simulating block abortion that can occur on mainnet.
It is supported in the `--state-archive-capacity full` mode.

:param starting_block_hash: The state of Devnet will be reverted to the state before `starting_block_hash`.
:param block_number: Number of the block which the state of Devnet will be reverted to
or literals `"pending"` or `"latest"`.
:param block_hash: Hash of the block which the state of Devnet will be reverted to
or literals `"pending"` or `"latest"`
"""

res = await self._devnet_client.call(
method_name="abortBlocks",
params={"starting_block_hash": _to_rpc_felt(starting_block_hash)},
params={
"starting_block_id": _get_raw_block_identifier(block_hash, block_number)
},
)

return res["aborted"]

async def dump(self, path: str):
Expand Down
23 changes: 13 additions & 10 deletions starknet_py/tests/e2e/account/account_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,25 +124,26 @@ async def test_account_estimate_fee_for_declare_transaction(


@pytest.mark.asyncio
async def test_account_estimate_fee_for_transactions(
account, map_compiled_contract, map_contract
):
declare_tx = await account.sign_declare_v1(
compiled_contract=map_compiled_contract, max_fee=MAX_FEE
)
async def test_account_estimate_fee_for_transactions(account, map_contract):

invoke_tx = await account.sign_invoke_v3(
invoke_tx_1 = await account.sign_invoke_v3(
calls=Call(map_contract.address, get_selector_from_name("put"), [3, 4]),
l1_resource_bounds=MAX_RESOURCE_BOUNDS_L1,
nonce=(declare_tx.nonce + 1),
nonce=(await account.get_nonce()),
)

invoke_tx_2 = await account.sign_invoke_v3(
calls=Call(map_contract.address, get_selector_from_name("put"), [5, 1]),
l1_resource_bounds=MAX_RESOURCE_BOUNDS_L1,
nonce=(await account.get_nonce() + 1),
)

estimated_fee = await account.estimate_fee(tx=[declare_tx, invoke_tx])
estimated_fee = await account.estimate_fee(tx=[invoke_tx_1, invoke_tx_2])

assert len(estimated_fee) == 2
assert isinstance(estimated_fee[0], EstimatedFee)
assert isinstance(estimated_fee[1], EstimatedFee)
assert estimated_fee[0].unit == PriceUnit.WEI
assert estimated_fee[0].unit == PriceUnit.FRI
assert estimated_fee[1].unit == PriceUnit.FRI
assert isinstance(estimated_fee[0].overall_fee, int)
assert estimated_fee[0].overall_fee > 0
Expand Down Expand Up @@ -659,6 +660,8 @@ async def test_sign_invoke_v3_for_fee_estimation(account, map_contract):
assert estimation.overall_fee > 0


# TODO (#1419): Fix contract redeclaration
@pytest.mark.skip(reason="Redeclaration occurred")
@pytest.mark.asyncio
async def test_sign_declare_v1_for_fee_estimation(account, map_compiled_contract):
transaction = await account.sign_declare_v1(
Expand Down
24 changes: 6 additions & 18 deletions starknet_py/tests/e2e/block_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import pytest

from starknet_py.contract import Contract
from starknet_py.net.account.base_account import BaseAccount
from starknet_py.net.client_models import (
BlockStatus,
L1DAMode,
Expand All @@ -11,31 +9,17 @@
StarknetBlockWithReceipts,
StarknetBlockWithTxHashes,
)
from starknet_py.tests.e2e.fixtures.constants import MAX_FEE


async def declare_contract(account: BaseAccount, compiled_contract: str):
declare_result = await Contract.declare_v1(
account=account,
compiled_contract=compiled_contract,
max_fee=MAX_FEE,
)
await declare_result.wait_for_acceptance()


@pytest.mark.asyncio
async def test_pending_block(account, map_compiled_contract):
await declare_contract(account, map_compiled_contract)

async def test_pending_block(account):
blk = await account.client.get_block(block_number="pending")
assert blk.transactions is not None
assert isinstance(blk, PendingStarknetBlock)


@pytest.mark.asyncio
async def test_latest_block(account, map_compiled_contract):
await declare_contract(account, map_compiled_contract)

async def test_latest_block(account):
blk = await account.client.get_block(block_number="latest")
assert blk.block_hash
assert blk.transactions is not None
Expand All @@ -50,6 +34,8 @@ async def test_block_with_tx_hashes_pending(account):
assert isinstance(blk.transactions, list)


# TODO (#1419): Fix contract redeclaration
@pytest.mark.skip(reason="Redeclaration occurred")
@pytest.mark.asyncio
async def test_block_with_tx_hashes_latest(
account,
Expand Down Expand Up @@ -81,6 +67,8 @@ async def test_get_block_with_txs_pending(account):
assert isinstance(blk.transactions, list)


# TODO (#1419): Fix contract redeclaration
@pytest.mark.skip(reason="Redeclaration occurred")
@pytest.mark.asyncio
async def test_get_block_with_txs_latest(
account,
Expand Down
45 changes: 28 additions & 17 deletions starknet_py/tests/e2e/client/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
)


# TODO (#1419): Fix contract redeclaration
@pytest.mark.skip(reason="Redeclaration occurred")
@pytest.mark.asyncio
async def test_get_declare_transaction(
client, declare_transaction_hash, class_hash, account
Expand All @@ -58,6 +60,8 @@ async def test_get_declare_transaction(
assert transaction.sender_address == account.address


# TODO (#1419): Fix contract redeclaration
@pytest.mark.skip(reason="Redeclaration occurred")
@pytest.mark.asyncio
async def test_get_invoke_transaction(
client,
Expand All @@ -70,6 +74,8 @@ async def test_get_invoke_transaction(
assert transaction.hash == invoke_transaction_hash


# TODO (#1419): Fix contract redeclaration
@pytest.mark.skip(reason="Redeclaration occurred")
@pytest.mark.asyncio
async def test_get_deploy_account_transaction(client, deploy_account_transaction_hash):
transaction = await client.get_transaction(deploy_account_transaction_hash)
Expand All @@ -88,6 +94,8 @@ async def test_get_transaction_raises_on_not_received(client):
await client.get_transaction(tx_hash=0x9999)


# TODO (#1419): Fix contract redeclaration
@pytest.mark.skip(reason="Redeclaration occurred")
@pytest.mark.asyncio
async def test_get_block_by_hash(
client,
Expand All @@ -101,6 +109,8 @@ async def test_get_block_by_hash(
assert len(block.transactions) != 0


# TODO (#1419): Fix contract redeclaration
@pytest.mark.skip(reason="Redeclaration occurred")
@pytest.mark.asyncio
async def test_get_block_by_number(
client,
Expand All @@ -114,6 +124,8 @@ async def test_get_block_by_number(
assert len(block.transactions) != 0


# TODO (#1419): Fix contract redeclaration
@pytest.mark.skip(reason="Redeclaration occurred")
@pytest.mark.asyncio
async def test_get_storage_at(client, contract_address):
storage = await client.get_storage_at(
Expand All @@ -125,6 +137,8 @@ async def test_get_storage_at(client, contract_address):
assert storage == 1234


# TODO (#1419): Fix contract redeclaration
@pytest.mark.skip(reason="Redeclaration occurred")
@pytest.mark.asyncio
async def test_get_transaction_receipt(
client, invoke_transaction_hash, block_with_invoke_number
Expand All @@ -136,6 +150,8 @@ async def test_get_transaction_receipt(
assert receipt.type == TransactionType.INVOKE


# TODO (#1419): Fix contract redeclaration
@pytest.mark.skip(reason="Redeclaration occurred")
@pytest.mark.asyncio
async def test_estimate_fee_invoke(account, contract_address):
invoke_tx = await account.sign_invoke_v1(
Expand All @@ -158,6 +174,8 @@ async def test_estimate_fee_invoke(account, contract_address):
assert estimate_fee.data_gas_consumed > 0


# TODO (#1419): Fix contract redeclaration
@pytest.mark.skip(reason="Redeclaration occurred")
@pytest.mark.asyncio
async def test_estimate_fee_invoke_v3(account, contract_address):
invoke_tx = await account.sign_invoke_v3(
Expand Down Expand Up @@ -215,6 +233,8 @@ async def test_estimate_fee_deploy_account(client, deploy_account_transaction):
assert estimate_fee.data_gas_consumed > 0


# TODO (#1419): Fix contract redeclaration
@pytest.mark.skip(reason="Redeclaration occurred")
@pytest.mark.asyncio
async def test_estimate_fee_for_multiple_transactions(
client, deploy_account_transaction, contract_address, account
Expand Down Expand Up @@ -254,6 +274,8 @@ async def test_estimate_fee_for_multiple_transactions(
assert estimated_fee.data_gas_consumed > 0


# TODO (#1419): Fix contract redeclaration
@pytest.mark.skip(reason="Redeclaration occurred")
@pytest.mark.asyncio
async def test_call_contract(client, contract_address):
call = Call(
Expand Down Expand Up @@ -284,6 +306,8 @@ async def test_add_transaction(map_contract, client, account):
assert transaction_receipt.type == TransactionType.INVOKE


# TODO (#1419): Fix contract redeclaration
@pytest.mark.skip(reason="Redeclaration occurred")
@pytest.mark.asyncio
async def test_get_class_hash_at(client, contract_address, class_hash):
received_class_hash = await client.get_class_hash_at(
Expand All @@ -292,6 +316,8 @@ async def test_get_class_hash_at(client, contract_address, class_hash):
assert received_class_hash == class_hash


# TODO (#1419): Fix contract redeclaration
@pytest.mark.skip(reason="Redeclaration occurred")
@pytest.mark.asyncio
async def test_get_class_by_hash(client, class_hash):
contract_class = await client.get_class_by_hash(class_hash=class_hash)
Expand Down Expand Up @@ -383,23 +409,6 @@ async def test_wait_for_tx_unknown_error(
await client.wait_for_tx(tx_hash="0x2137")


@pytest.mark.asyncio
async def test_declare_contract(account, map_compiled_contract):
declare_tx = await account.sign_declare_v1(
compiled_contract=map_compiled_contract, max_fee=MAX_FEE
)

client = account.client
result = await client.declare(declare_tx)
await client.wait_for_tx(result.transaction_hash)
transaction_receipt = await client.get_transaction_receipt(result.transaction_hash)

assert transaction_receipt.execution_status == TransactionExecutionStatus.SUCCEEDED
assert transaction_receipt.transaction_hash
assert 0 < transaction_receipt.actual_fee.amount <= MAX_FEE
assert transaction_receipt.type == TransactionType.DECLARE


@pytest.mark.asyncio
async def test_custom_session_client(map_contract, devnet):
# We must access protected `_client` to test session
Expand Down Expand Up @@ -506,6 +515,8 @@ async def test_state_update_storage_diffs(
assert isinstance(state_update, BlockStateUpdate)


# TODO (#1419): Fix contract redeclaration
@pytest.mark.skip(reason="Redeclaration occurred")
@pytest.mark.run_on_devnet
@pytest.mark.asyncio
async def test_state_update_deployed_contracts(
Expand Down
6 changes: 6 additions & 0 deletions starknet_py/tests/e2e/client/full_node_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ def _parse_event_name(event: str) -> str:
EVENT_TWO_PARSED_NAME = _parse_event_name("another_put_called")


# TODO (#1419): Fix contract redeclaration
@pytest.mark.skip(reason="Redeclaration occurred")
@pytest.mark.run_on_devnet
@pytest.mark.asyncio
async def test_node_get_declare_transaction_by_block_number_and_index(
Expand All @@ -60,6 +62,8 @@ async def test_node_get_declare_transaction_by_block_number_and_index(
assert tx.version == 1


# TODO (#1419): Fix contract redeclaration
@pytest.mark.skip(reason="Redeclaration occurred")
@pytest.mark.run_on_devnet
@pytest.mark.asyncio
async def test_get_class_at(
Expand Down Expand Up @@ -469,6 +473,8 @@ async def test_simulate_transactions_invoke(account, deployed_balance_contract):
assert simulated_txs[0].transaction_trace.execution_resources is not None


# 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(
Expand Down
2 changes: 1 addition & 1 deletion starknet_py/tests/e2e/client_devnet/general_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async def test_abort_blocks(devnet_client):
for _ in range(5):
await devnet_client.create_block()

aborted_blocks = await devnet_client.abort_block(block_hash)
aborted_blocks = await devnet_client.abort_block(block_hash=block_hash)
assert len(aborted_blocks) == 6


Expand Down
2 changes: 1 addition & 1 deletion starknet_py/tests/e2e/client_devnet/time_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
@pytest.mark.asyncio
async def test_set_and_increase_time(devnet_client):
time = 3384617820
increase_value, error_margin = 100, 2
increase_value, error_margin = 100, 10
kkawula marked this conversation as resolved.
Show resolved Hide resolved

await devnet_client.set_time(time, generate_block=True)
block = await devnet_client.get_block(block_number="latest")
Expand Down
2 changes: 2 additions & 0 deletions starknet_py/tests/e2e/docs/code_examples/test_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ async def test_from_address(account, contract_address):
# docs-end: from_address


# TODO (#1419): Fix contract redeclaration
@pytest.mark.skip(reason="Redeclaration occurred")
@pytest.mark.asyncio
async def test_declare_v2(account):
compiled_contract = load_contract(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ async def test_trace_transaction(client):
# docs-end: trace_transaction


# TODO (#1419): Fix contract redeclaration
@pytest.mark.skip(reason="Redeclaration occurred")
@pytest.mark.asyncio
async def test_simulate_transactions(
account, deployed_balance_contract, deploy_account_transaction
Expand Down
2 changes: 2 additions & 0 deletions starknet_py/tests/e2e/docs/guide/test_declaring_contracts.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import pytest


# TODO (#1419): Fix contract redeclaration
@pytest.mark.skip(reason="Redeclaration occurred")
@pytest.mark.asyncio
async def test_declaring_contracts(account, map_compiled_contract):
contract_compiled = map_compiled_contract
Expand Down
Loading
Loading