genlayer-test 0.1.0b2__py3-none-any.whl → 0.1.0b3__py3-none-any.whl

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.
@@ -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
@@ -5,14 +5,14 @@ gltest/plugin_config.py,sha256=O9Dx9IejbBJe-CJ9h8iMVtLzjWlzLGcTGOIgJM6gLWc,204
5
5
  gltest/plugin_hooks.py,sha256=cy4-LPm3Q-ZaO94t5vgjbPjQB8MRxYGGRXeDBeJ7buU,399
6
6
  gltest/types.py,sha256=BODmwTr2gAUEiO9FjiuTiWwuKvXgo4xZWstQWNUfnlw,156
7
7
  gltest/artifacts/__init__.py,sha256=QCsQI8BSOHQwGWFxZVDRL-HA0Dyae3Re24E-yAZrflA,86
8
- gltest/artifacts/contract.py,sha256=BhY1m9FPQw_gyBNRXKxgjjCUD5z-i2M4BgjvXuinCNg,1639
8
+ gltest/artifacts/contract.py,sha256=2wmfQF6FAiNuMlr9pePK7ZJjQj5Tl7-3SefeH3OnSRQ,3089
9
9
  gltest/glchain/__init__.py,sha256=wD2Hzdz_wKpu-mCAX5iBINZDCNdKezLVI2lywkSkjvw,400
10
10
  gltest/glchain/account.py,sha256=vOXxcR09NkT6iFw_m49DW1nVC7kP8wf23555iPPXRkw,402
11
11
  gltest/glchain/client.py,sha256=U_JJJQ0V8oLPLeIbGpFcHOtnCVPJIoN9DMlvHSD1C0I,355
12
12
  gltest/glchain/contract.py,sha256=46QFDjwwg6n0qmjMTPXR1wueV2ZdFOc1g2nas0U9C_c,7837
13
13
  gltest_cli/main.py,sha256=Ti2-0Ev1x5_cM0D1UKqdgaDt80CDHEQGtdRne2qLm4M,53
14
- genlayer_test-0.1.0b2.dist-info/METADATA,sha256=WPtruwU-TnN4r2W8DNZTmAmdPkEmWAVe0hFamcKXKrs,3409
15
- genlayer_test-0.1.0b2.dist-info/WHEEL,sha256=pxyMxgL8-pra_rKaQ4drOZAegBVuX-G_4nRHjjgWbmo,91
16
- genlayer_test-0.1.0b2.dist-info/entry_points.txt,sha256=rXhrPVq2IhVsd4uWzxzwCTx7jA1KcQIVNxDCUuxq4f8,89
17
- genlayer_test-0.1.0b2.dist-info/top_level.txt,sha256=GSdrnQbiLcZssmtCpbDgBTygsc8Bt_TPeYjwm0FmpdA,18
18
- genlayer_test-0.1.0b2.dist-info/RECORD,,
14
+ genlayer_test-0.1.0b3.dist-info/METADATA,sha256=zzWsz5KgLuoQO7urlzrLz9BYQMmpP-QOiyZZB3zbeiw,3409
15
+ genlayer_test-0.1.0b3.dist-info/WHEEL,sha256=SmOxYU7pzNKBqASvQJ7DjX3XGUF92lrGhMb3R6_iiqI,91
16
+ genlayer_test-0.1.0b3.dist-info/entry_points.txt,sha256=rXhrPVq2IhVsd4uWzxzwCTx7jA1KcQIVNxDCUuxq4f8,89
17
+ genlayer_test-0.1.0b3.dist-info/top_level.txt,sha256=GSdrnQbiLcZssmtCpbDgBTygsc8Bt_TPeYjwm0FmpdA,18
18
+ genlayer_test-0.1.0b3.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (79.0.0)
2
+ Generator: setuptools (79.0.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,7 +1,11 @@
1
1
  import ast
2
2
  from typing import Optional
3
3
  from dataclasses import dataclass
4
+ from pathlib import Path
4
5
  from gltest.plugin_config import get_contracts_dir
6
+ import io
7
+ import zipfile
8
+ from typing import Union
5
9
 
6
10
 
7
11
  @dataclass
@@ -9,41 +13,74 @@ class ContractDefinition:
9
13
  """Class that represents a contract definition from a .gpy file."""
10
14
 
11
15
  contract_name: str
12
- contract_code: str
13
- source_file: str
14
- ast_node: ast.ClassDef
16
+ contract_code: Union[str, bytes]
17
+ main_file_path: Path
18
+ runner_file_path: Optional[Path]
15
19
 
16
20
 
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
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."""
28
23
  for file_path in contracts_dir.rglob("*.gpy"):
29
24
  try:
30
25
  # Read the file content
31
26
  with open(file_path, "r") as f:
32
27
  content = f.read()
33
-
34
28
  # Parse the content into an AST
35
29
  tree = ast.parse(content)
36
-
37
30
  # Search for class definitions
38
31
  for node in ast.walk(tree):
39
32
  if isinstance(node, ast.ClassDef) and node.name == contract_name:
40
33
  # 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
- )
34
+ return file_path
47
35
  except Exception as e:
48
36
  raise ValueError(f"Error reading file {file_path}: {e}")
49
- return None
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
+ )