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

ProtostarFixture #566

Merged
merged 46 commits into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
9aeeae1
Initial draft
Radinyn Aug 9, 2022
3616fb0
Removed artifacts
Radinyn Aug 9, 2022
6ac63e4
Cleanup
Radinyn Aug 9, 2022
1237a75
Added protocols
Radinyn Aug 9, 2022
8de3f4f
add compiled_project fixture
kasperski95 Aug 10, 2022
1861fd0
fix project testing environemnet
kasperski95 Aug 10, 2022
8b7a574
rename fixtures
kasperski95 Aug 10, 2022
fd999c2
use constants for fixture names
kasperski95 Aug 10, 2022
205204f
fix importing fixtures
kasperski95 Aug 10, 2022
9cef01d
use module scope
kasperski95 Aug 10, 2022
2ab9625
add declare test
kasperski95 Aug 10, 2022
226cb5d
add tests
kasperski95 Aug 10, 2022
c4df9c0
add more learning tests
kasperski95 Aug 11, 2022
5752227
remove invoke and _add call test
kasperski95 Aug 11, 2022
684ab21
_add test
kasperski95 Aug 11, 2022
3174a72
refine test
kasperski95 Aug 11, 2022
3f859cb
change fixture desired interface
kasperski95 Aug 11, 2022
288fc62
_add protostar fixture
kasperski95 Aug 11, 2022
3732554
add protostar fixture
kasperski95 Aug 11, 2022
3d64e05
use protostar fixture for declare cheatcode
kasperski95 Aug 11, 2022
2a44242
use protostar fixture in gateway facade
kasperski95 Aug 11, 2022
678db3c
remove asyncs
kasperski95 Aug 11, 2022
2521c0a
remove dead code
kasperski95 Aug 11, 2022
42ddd28
use protostar fixture
kasperski95 Aug 11, 2022
cf6d536
make call pass
kasperski95 Aug 11, 2022
4dcebf2
move contract to tests.data
kasperski95 Aug 12, 2022
eb86294
fix creating migration output file
kasperski95 Aug 12, 2022
90dd036
add more tests
kasperski95 Aug 12, 2022
956250c
format
kasperski95 Aug 12, 2022
33b40ea
handle errors
kasperski95 Aug 12, 2022
8a13d88
fix gateway facade tests
kasperski95 Aug 12, 2022
6e9e88b
fix types and format
kasperski95 Aug 12, 2022
a4d3fa0
refine
kasperski95 Aug 12, 2022
1ae2947
fix protostar toml
kasperski95 Aug 12, 2022
436c5f4
fix lint
kasperski95 Aug 12, 2022
b237c83
remove invoke
kasperski95 Aug 16, 2022
e2871d2
remove call cheatcode
kasperski95 Aug 16, 2022
34a1b6c
refine no protostar toml exception
kasperski95 Aug 16, 2022
5a557fe
remove "call" literal type
kasperski95 Aug 17, 2022
f8bd58c
rename type
kasperski95 Aug 17, 2022
f2b6c5c
remove unnecessary log color provider
kasperski95 Aug 17, 2022
265ac19
remove cwd
kasperski95 Aug 17, 2022
e5cf92a
remove cwd
kasperski95 Aug 17, 2022
a548c00
remove type
kasperski95 Aug 17, 2022
556b624
renamed cwd to project root path
kasperski95 Aug 17, 2022
3434ca1
fix e2e tests
kasperski95 Aug 17, 2022
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
15 changes: 4 additions & 11 deletions protostar/commands/init/init_command.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from glob import glob
from pathlib import Path
from typing import List, Optional

from protostar.cli import Command
Expand All @@ -18,13 +17,11 @@ def __init__(
requester: InputRequester,
new_project_creator: NewProjectCreator,
adapted_project_creator: AdaptedProjectCreator,
cwd: Path,
) -> None:
super().__init__()
self._adapted_project_creator = adapted_project_creator
self._new_project_creator = new_project_creator
self._requester = requester
self._cwd = cwd

@property
def name(self) -> str:
Expand Down Expand Up @@ -68,13 +65,9 @@ def init(self, force_adapting_existing_project: bool):
else:
self._new_project_creator.run()

def _can_be_protostar_project(self) -> bool:

files_depth_3 = (
glob(str(self._cwd / "*"))
+ glob(str(self._cwd / "*" / "*"))
+ glob(str(self._cwd / "*" / "*" / "*"))
)
@staticmethod
def _can_be_protostar_project() -> bool:
files_depth_3 = glob("*") + glob("*/*") + glob("*/*/*")
return any(
map(lambda f: f.endswith(".cairo") or f == ".git", files_depth_3)
) and "protostar.toml" not in glob(str(self._cwd / "*"))
) and "protostar.toml" not in glob("*")
9 changes: 4 additions & 5 deletions protostar/composition_root.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from dataclasses import dataclass
from logging import getLogger
from pathlib import Path
from typing import List, Optional
from typing import List

from protostar.cli import Command
from protostar.commands import (
Expand Down Expand Up @@ -55,10 +55,10 @@ class DIContainer:


# pylint: disable=too-many-locals
def build_di_container(script_root: Path, cwd: Optional[Path] = None):
cwd = cwd or Path()
def build_di_container(script_root: Path):
logger = getLogger()
protostar_toml_path = search_upwards_protostar_toml_path(start_path=cwd.resolve())
cwd = Path()
protostar_toml_path = search_upwards_protostar_toml_path(start_path=cwd)
project_root_path = (
protostar_toml_path.parent if protostar_toml_path is not None else cwd
)
Expand Down Expand Up @@ -111,7 +111,6 @@ def build_di_container(script_root: Path, cwd: Optional[Path] = None):
protostar_toml_writer,
version_manager,
),
cwd=cwd,
),
BuildCommand(project_compiler, logger),
InstallCommand(
Expand Down
2 changes: 1 addition & 1 deletion protostar/starknet_gateway/gateway_facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from protostar.starknet_gateway.starknet_request import StarknetRequest
from protostar.utils.log_color_provider import LogColorProvider

GatewayFacadeSupportedInputType = Union[List[int], Dict[str, Any]]
ContractFunctionInputType = Union[List[int], Dict[str, Any]]
kasperski95 marked this conversation as resolved.
Show resolved Hide resolved


class TransactionException(ProtostarException):
Expand Down
2 changes: 1 addition & 1 deletion protostar/starknet_gateway/starknet_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

@dataclass
class StarknetRequest:
Action = Literal["DEPLOY", "DECLARE", "CALL"]
Action = Literal["DEPLOY", "DECLARE"]
Payload = Dict[str, Union[None, str, int, List[int], List[str]]]

action: Action
Expand Down
2 changes: 1 addition & 1 deletion protostar/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


def main(script_root: Path):
container = build_di_container(script_root, cwd=Path())
container = build_di_container(script_root)
arg_parser = build_parser(container.protostar_cli, container.protostar_toml_reader)
args = parse_args(arg_parser)
run_protostar(container.protostar_cli, args, arg_parser)
Expand Down
2 changes: 1 addition & 1 deletion scripts/generate_reference_docs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


def test_instance_matches_cli_reference_docs():
di_container = build_di_container(script_root=Path(), cwd=Path())
di_container = build_di_container(script_root=Path())
new_snapshot = ReferenceDocsGenerator(
di_container.protostar_cli
).generate_cli_reference_markdown()
Expand Down
3 changes: 0 additions & 3 deletions tests/integration/gateway/gateway_facade_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import pytest

from protostar.starknet_gateway.gateway_facade import GatewayFacade
from protostar.utils.log_color_provider import LogColorProvider
from tests.integration.protostar_fixture import ProtostarFixture


Expand All @@ -20,8 +19,6 @@ def compiled_contract_path_fixture(protostar: ProtostarFixture) -> Path:

@pytest.fixture(name="gateway_facade")
def gateway_facade_fixture(devnet_gateway_url: str):
log_color_provider = LogColorProvider()
log_color_provider.is_ci_mode = False
gateway_facade_builder = GatewayFacade.Builder(project_root_path=Path())
gateway_facade_builder.set_network(devnet_gateway_url)
return gateway_facade_builder.build()
Expand Down
8 changes: 6 additions & 2 deletions tests/integration/protostar_fixture.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import os
from argparse import Namespace
from logging import getLogger
from pathlib import Path
Expand Down Expand Up @@ -43,7 +44,11 @@ def project_root_path(self) -> Path:
def init_sync(self):
args = Namespace()
args.existing = False
return asyncio.run(self._init_command.run(args))
cwd = Path().resolve()
os.chdir(self._project_root_path.parent)
result = asyncio.run(self._init_command.run(args))
os.chdir(cwd)
return result

def build_sync(self):
args = Namespace()
Expand Down Expand Up @@ -151,7 +156,6 @@ def request_input(message: str) -> str:
input_requester,
new_project_creator=new_project_creator,
adapted_project_creator=mocker.MagicMock(),
cwd=project_root_path.parent,
)

project_compiler = ProjectCompiler(
Expand Down