genlayer-test 0.1.0b2__tar.gz → 0.1.0b3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (24) hide show
  1. {genlayer_test-0.1.0b2 → genlayer_test-0.1.0b3}/PKG-INFO +1 -1
  2. {genlayer_test-0.1.0b2 → genlayer_test-0.1.0b3}/genlayer_test.egg-info/PKG-INFO +1 -1
  3. genlayer_test-0.1.0b3/gltest/artifacts/contract.py +86 -0
  4. {genlayer_test-0.1.0b2 → genlayer_test-0.1.0b3}/pyproject.toml +1 -1
  5. genlayer_test-0.1.0b2/gltest/artifacts/contract.py +0 -49
  6. {genlayer_test-0.1.0b2 → genlayer_test-0.1.0b3}/README.md +0 -0
  7. {genlayer_test-0.1.0b2 → genlayer_test-0.1.0b3}/genlayer_test.egg-info/SOURCES.txt +0 -0
  8. {genlayer_test-0.1.0b2 → genlayer_test-0.1.0b3}/genlayer_test.egg-info/dependency_links.txt +0 -0
  9. {genlayer_test-0.1.0b2 → genlayer_test-0.1.0b3}/genlayer_test.egg-info/entry_points.txt +0 -0
  10. {genlayer_test-0.1.0b2 → genlayer_test-0.1.0b3}/genlayer_test.egg-info/requires.txt +0 -0
  11. {genlayer_test-0.1.0b2 → genlayer_test-0.1.0b3}/genlayer_test.egg-info/top_level.txt +0 -0
  12. {genlayer_test-0.1.0b2 → genlayer_test-0.1.0b3}/gltest/__init__.py +0 -0
  13. {genlayer_test-0.1.0b2 → genlayer_test-0.1.0b3}/gltest/artifacts/__init__.py +0 -0
  14. {genlayer_test-0.1.0b2 → genlayer_test-0.1.0b3}/gltest/assertions.py +0 -0
  15. {genlayer_test-0.1.0b2 → genlayer_test-0.1.0b3}/gltest/exceptions.py +0 -0
  16. {genlayer_test-0.1.0b2 → genlayer_test-0.1.0b3}/gltest/glchain/__init__.py +0 -0
  17. {genlayer_test-0.1.0b2 → genlayer_test-0.1.0b3}/gltest/glchain/account.py +0 -0
  18. {genlayer_test-0.1.0b2 → genlayer_test-0.1.0b3}/gltest/glchain/client.py +0 -0
  19. {genlayer_test-0.1.0b2 → genlayer_test-0.1.0b3}/gltest/glchain/contract.py +0 -0
  20. {genlayer_test-0.1.0b2 → genlayer_test-0.1.0b3}/gltest/plugin_config.py +0 -0
  21. {genlayer_test-0.1.0b2 → genlayer_test-0.1.0b3}/gltest/plugin_hooks.py +0 -0
  22. {genlayer_test-0.1.0b2 → genlayer_test-0.1.0b3}/gltest/types.py +0 -0
  23. {genlayer_test-0.1.0b2 → genlayer_test-0.1.0b3}/gltest_cli/main.py +0 -0
  24. {genlayer_test-0.1.0b2 → genlayer_test-0.1.0b3}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: genlayer-test
3
- Version: 0.1.0b2
3
+ Version: 0.1.0b3
4
4
  Summary: GenLayer Testing Suite
5
5
  Author: GenLayer
6
6
  License-Expression: MIT
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: genlayer-test
3
- Version: 0.1.0b2
3
+ Version: 0.1.0b3
4
4
  Summary: GenLayer Testing Suite
5
5
  Author: GenLayer
6
6
  License-Expression: MIT
@@ -0,0 +1,86 @@
1
+ import ast
2
+ from typing import Optional
3
+ from dataclasses import dataclass
4
+ from pathlib import Path
5
+ from gltest.plugin_config import get_contracts_dir
6
+ import io
7
+ import zipfile
8
+ from typing import Union
9
+
10
+
11
+ @dataclass
12
+ class ContractDefinition:
13
+ """Class that represents a contract definition from a .gpy file."""
14
+
15
+ contract_name: str
16
+ contract_code: Union[str, bytes]
17
+ main_file_path: Path
18
+ runner_file_path: Optional[Path]
19
+
20
+
21
+ def search_path_by_class_name(contracts_dir: Path, contract_name: str) -> Path:
22
+ """Search for a file by class name in the contracts directory."""
23
+ for file_path in contracts_dir.rglob("*.gpy"):
24
+ try:
25
+ # Read the file content
26
+ with open(file_path, "r") as f:
27
+ content = f.read()
28
+ # Parse the content into an AST
29
+ tree = ast.parse(content)
30
+ # Search for class definitions
31
+ for node in ast.walk(tree):
32
+ if isinstance(node, ast.ClassDef) and node.name == contract_name:
33
+ # Found the contract class
34
+ return file_path
35
+ except Exception as e:
36
+ raise ValueError(f"Error reading file {file_path}: {e}")
37
+ raise FileNotFoundError(f"Contract {contract_name} not found at: {contracts_dir}")
38
+
39
+
40
+ def compute_contract_code(
41
+ main_file_path: Path,
42
+ runner_file_path: Optional[Path] = None,
43
+ ) -> str:
44
+ """Compute the contract code."""
45
+ # Single file contract
46
+ if runner_file_path is None:
47
+ return main_file_path.read_text()
48
+
49
+ # Multifile contract
50
+ main_file_dir = main_file_path.parent
51
+ buffer = io.BytesIO()
52
+
53
+ with zipfile.ZipFile(buffer, mode="w") as zip:
54
+ zip.write(main_file_path, "contract/__init__.py")
55
+ for file_path in main_file_dir.rglob("*"):
56
+ if file_path.name in ["runner.json", "__init__.gpy"]:
57
+ continue
58
+ rel_path = file_path.relative_to(main_file_dir)
59
+ zip.write(file_path, f"contract/{rel_path}")
60
+ zip.write(runner_file_path, "runner.json")
61
+ buffer.flush()
62
+ return buffer.getvalue()
63
+
64
+
65
+ def find_contract_definition(contract_name: str) -> Optional[ContractDefinition]:
66
+ """
67
+ Search in the contracts directory for a contract definition.
68
+ """
69
+ contracts_dir = get_contracts_dir()
70
+ if not contracts_dir.exists():
71
+ raise FileNotFoundError(f"Contracts directory not found at: {contracts_dir}")
72
+ main_file_path = search_path_by_class_name(contracts_dir, contract_name)
73
+ main_file_dir = main_file_path.parent
74
+ runner_file_path = None
75
+ if main_file_path.name == "__init__.gpy":
76
+ # Likely a multifile contract
77
+ runner_file_path = main_file_dir.joinpath("runner.json")
78
+ if not runner_file_path.exists():
79
+ # No runner file, so it's a single file contract
80
+ runner_file_path = None
81
+ return ContractDefinition(
82
+ contract_name=contract_name,
83
+ contract_code=compute_contract_code(main_file_path, runner_file_path),
84
+ main_file_path=main_file_path,
85
+ runner_file_path=runner_file_path,
86
+ )
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "genlayer-test"
7
- version = "0.1.0b2"
7
+ version = "0.1.0b3"
8
8
  description = "GenLayer Testing Suite"
9
9
  authors = [
10
10
  { name = "GenLayer" }
@@ -1,49 +0,0 @@
1
- import ast
2
- from typing import Optional
3
- from dataclasses import dataclass
4
- from gltest.plugin_config import get_contracts_dir
5
-
6
-
7
- @dataclass
8
- class ContractDefinition:
9
- """Class that represents a contract definition from a .gpy file."""
10
-
11
- contract_name: str
12
- contract_code: str
13
- source_file: str
14
- ast_node: ast.ClassDef
15
-
16
-
17
- def find_contract_definition(contract_name: str) -> Optional[ContractDefinition]:
18
- """
19
- Search in the contracts directory for a contract definition.
20
- TODO: Make this more robust to handle imports and other files.
21
- """
22
- contracts_dir = get_contracts_dir()
23
-
24
- if not contracts_dir.exists():
25
- raise FileNotFoundError(f"Contracts directory not found at: {contracts_dir}")
26
-
27
- # Search through all .gpy files in the contracts directory
28
- for file_path in contracts_dir.rglob("*.gpy"):
29
- try:
30
- # Read the file content
31
- with open(file_path, "r") as f:
32
- content = f.read()
33
-
34
- # Parse the content into an AST
35
- tree = ast.parse(content)
36
-
37
- # Search for class definitions
38
- for node in ast.walk(tree):
39
- if isinstance(node, ast.ClassDef) and node.name == contract_name:
40
- # Found the contract class
41
- return ContractDefinition(
42
- contract_name=contract_name,
43
- source_file=str(file_path),
44
- contract_code=content,
45
- ast_node=node,
46
- )
47
- except Exception as e:
48
- raise ValueError(f"Error reading file {file_path}: {e}")
49
- return None