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

Commit

Permalink
Replaced inline test resources with artifacts.
Browse files Browse the repository at this point in the history
Replaced inline test resources with compiled contract artifacts,
formatted some files.
  • Loading branch information
bartekryba committed May 18, 2023
1 parent d803bae commit 608621d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 53 deletions.
3 changes: 3 additions & 0 deletions starknet_devnet/blueprints/rpc/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ def __str__(self):

@lru_cache
def felt_pattern_from_schema() -> str:
"""
Load regex pattern of felt from rpc schema.
"""
_, schemas = _load_schemas()

return schemas["FELT"]["pattern"]
Expand Down
3 changes: 2 additions & 1 deletion test/rpc/rpc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from __future__ import annotations

import re
from starknet_devnet.blueprints.rpc.schema import felt_pattern_from_schema
from test.account import declare_and_deploy_with_chargeable, invoke
from test.settings import APP_URL
from test.shared import (
Expand All @@ -18,6 +17,8 @@

import requests

from starknet_devnet.blueprints.rpc.schema import felt_pattern_from_schema


class BackgroundDevnetClient:
"""A thin wrapper for requests, to interact with a background devnet instance"""
Expand Down
69 changes: 18 additions & 51 deletions test/rpc/test_rpc_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from test.account import deploy, send_declare_v2
from test.rpc.rpc_utils import rpc_call
from test.shared import (
ABI_1_PATH,
CONTRACT_1_PATH,
PREDEPLOY_ACCOUNT_CLI_ARGS,
PREDEPLOYED_ACCOUNT_ADDRESS,
PREDEPLOYED_ACCOUNT_PRIVATE_KEY,
Expand Down Expand Up @@ -84,52 +86,21 @@
},
]

EXPECTED_ENTRY_POINTS_CAIRO_1 = {
"EXTERNAL": [
{
"selector": "0x362398bec32bc0ebb411203221a35a0301193a96f317ebe5e40be9f60d15320",
"function_idx": 0,
},
{
"selector": "0x39e11d48192e4333233c7eb19d10ad67c362bb28580c604d67884c85da39695",
"function_idx": 1,
},
],
"L1_HANDLER": [],
"CONSTRUCTOR": [
{
"selector": "0x28ffe4ff0f226a9107253e17a904099aa4f63a02a5621de0576e5aa71bc5194",
"function_idx": 2,
}
],
}

EXPECTED_ABI_CAIRO_1 = [
{
"type": "function",
"name": "constructor",
"inputs": [{"name": "initial_balance", "type": "core::felt252"}],
"outputs": [],
"state_mutability": "external",
},
{
"type": "function",
"name": "increase_balance",
"inputs": [
{"name": "amount1", "type": "core::felt252"},
{"name": "amount2", "type": "core::felt252"},
],
"outputs": [],
"state_mutability": "external",
},
{
"type": "function",
"name": "get_balance",
"inputs": [],
"outputs": [{"type": "core::felt252"}],
"state_mutability": "view",
},
]
def assert_correct_cairo_1_contract(contract_class):
"""
Assert that the provided cairo 1 contract is equal to the expected one.
"""
with open(CONTRACT_1_PATH, mode="r", encoding="utf-8") as expected_contract, open(
ABI_1_PATH, mode="r", encoding="utf-8"
) as expected_abi:
expected_contract_json = json.loads(expected_contract.read())
expected_abi_json = json.loads(expected_abi.read())
assert (
contract_class["entry_points_by_type"]
== expected_contract_json["entry_points_by_type"]
)
assert contract_class["abi"] == json.dumps(expected_abi_json)


@pytest.mark.usefixtures("run_devnet_in_background")
Expand Down Expand Up @@ -182,9 +153,7 @@ def test_get_class():
)

contract_class = resp["result"]

assert contract_class["entry_points_by_type"] == EXPECTED_ENTRY_POINTS_CAIRO_1
assert contract_class["abi"] == json.dumps(EXPECTED_ABI_CAIRO_1)
assert_correct_cairo_1_contract(contract_class)


@devnet_in_background(*PREDEPLOY_ACCOUNT_CLI_ARGS)
Expand Down Expand Up @@ -222,9 +191,7 @@ def test_get_class_at():
)

contract_class = resp["result"]

assert contract_class["entry_points_by_type"] == EXPECTED_ENTRY_POINTS_CAIRO_1
assert contract_class["abi"] == json.dumps(EXPECTED_ABI_CAIRO_1)
assert_correct_cairo_1_contract(contract_class)


@pytest.mark.usefixtures("run_devnet_in_background")
Expand Down
8 changes: 7 additions & 1 deletion test/rpc/test_rpc_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
import pytest
from starkware.starknet.public.abi import get_selector_from_name

from starknet_devnet.blueprints.rpc.schema import _assert_valid_rpc_request, felt_pattern_from_schema
from starknet_devnet.blueprints.rpc.schema import (
_assert_valid_rpc_request,
felt_pattern_from_schema,
)
from starknet_devnet.blueprints.rpc.structures.types import PredefinedRpcErrorCode
from starknet_devnet.blueprints.rpc.utils import rpc_felt

Expand Down Expand Up @@ -336,6 +339,9 @@ def test_schema_with_optional_values():


def test_felt_pattern_from_schema():
"""
Test getting the felt pattern from the rpc spec.
"""
pattern = felt_pattern_from_schema()

assert pattern != ""

0 comments on commit 608621d

Please sign in to comment.