genlayer-test 0.1.0b1__tar.gz → 0.1.0b2__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.
- {genlayer_test-0.1.0b1 → genlayer_test-0.1.0b2}/PKG-INFO +1 -1
- {genlayer_test-0.1.0b1 → genlayer_test-0.1.0b2}/genlayer_test.egg-info/PKG-INFO +1 -1
- {genlayer_test-0.1.0b1 → genlayer_test-0.1.0b2}/genlayer_test.egg-info/SOURCES.txt +5 -2
- genlayer_test-0.1.0b2/genlayer_test.egg-info/entry_points.txt +5 -0
- {genlayer_test-0.1.0b1 → genlayer_test-0.1.0b2}/genlayer_test.egg-info/top_level.txt +1 -0
- {genlayer_test-0.1.0b1 → genlayer_test-0.1.0b2}/gltest/artifacts/contract.py +4 -7
- {genlayer_test-0.1.0b1 → genlayer_test-0.1.0b2}/gltest/glchain/contract.py +45 -21
- genlayer_test-0.1.0b2/gltest/plugin_config.py +12 -0
- genlayer_test-0.1.0b2/gltest/plugin_hooks.py +16 -0
- genlayer_test-0.1.0b2/gltest/types.py +7 -0
- {genlayer_test-0.1.0b1 → genlayer_test-0.1.0b2}/pyproject.toml +5 -2
- genlayer_test-0.1.0b1/genlayer_test.egg-info/entry_points.txt +0 -2
- {genlayer_test-0.1.0b1 → genlayer_test-0.1.0b2}/README.md +0 -0
- {genlayer_test-0.1.0b1 → genlayer_test-0.1.0b2}/genlayer_test.egg-info/dependency_links.txt +0 -0
- {genlayer_test-0.1.0b1 → genlayer_test-0.1.0b2}/genlayer_test.egg-info/requires.txt +0 -0
- {genlayer_test-0.1.0b1 → genlayer_test-0.1.0b2}/gltest/__init__.py +0 -0
- {genlayer_test-0.1.0b1 → genlayer_test-0.1.0b2}/gltest/artifacts/__init__.py +0 -0
- {genlayer_test-0.1.0b1 → genlayer_test-0.1.0b2}/gltest/assertions.py +0 -0
- {genlayer_test-0.1.0b1 → genlayer_test-0.1.0b2}/gltest/exceptions.py +0 -0
- {genlayer_test-0.1.0b1 → genlayer_test-0.1.0b2}/gltest/glchain/__init__.py +0 -0
- {genlayer_test-0.1.0b1 → genlayer_test-0.1.0b2}/gltest/glchain/account.py +0 -0
- {genlayer_test-0.1.0b1 → genlayer_test-0.1.0b2}/gltest/glchain/client.py +0 -0
- /genlayer_test-0.1.0b1/gltest/cli.py → /genlayer_test-0.1.0b2/gltest_cli/main.py +0 -0
- {genlayer_test-0.1.0b1 → genlayer_test-0.1.0b2}/setup.cfg +0 -0
@@ -8,11 +8,14 @@ genlayer_test.egg-info/requires.txt
|
|
8
8
|
genlayer_test.egg-info/top_level.txt
|
9
9
|
gltest/__init__.py
|
10
10
|
gltest/assertions.py
|
11
|
-
gltest/cli.py
|
12
11
|
gltest/exceptions.py
|
12
|
+
gltest/plugin_config.py
|
13
|
+
gltest/plugin_hooks.py
|
14
|
+
gltest/types.py
|
13
15
|
gltest/artifacts/__init__.py
|
14
16
|
gltest/artifacts/contract.py
|
15
17
|
gltest/glchain/__init__.py
|
16
18
|
gltest/glchain/account.py
|
17
19
|
gltest/glchain/client.py
|
18
|
-
gltest/glchain/contract.py
|
20
|
+
gltest/glchain/contract.py
|
21
|
+
gltest_cli/main.py
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import ast
|
2
|
-
from pathlib import Path
|
3
2
|
from typing import Optional
|
4
3
|
from dataclasses import dataclass
|
4
|
+
from gltest.plugin_config import get_contracts_dir
|
5
5
|
|
6
6
|
|
7
7
|
@dataclass
|
@@ -14,21 +14,18 @@ class ContractDefinition:
|
|
14
14
|
ast_node: ast.ClassDef
|
15
15
|
|
16
16
|
|
17
|
-
def find_contract_definition(
|
18
|
-
contract_name: str, relative_contracts_dir: str = "contracts"
|
19
|
-
) -> Optional[ContractDefinition]:
|
17
|
+
def find_contract_definition(contract_name: str) -> Optional[ContractDefinition]:
|
20
18
|
"""
|
21
19
|
Search in the contracts directory for a contract definition.
|
22
20
|
TODO: Make this more robust to handle imports and other files.
|
23
21
|
"""
|
24
|
-
|
25
|
-
contracts_dir = Path.cwd() / relative_contracts_dir
|
22
|
+
contracts_dir = get_contracts_dir()
|
26
23
|
|
27
24
|
if not contracts_dir.exists():
|
28
25
|
raise FileNotFoundError(f"Contracts directory not found at: {contracts_dir}")
|
29
26
|
|
30
27
|
# Search through all .gpy files in the contracts directory
|
31
|
-
for file_path in contracts_dir.
|
28
|
+
for file_path in contracts_dir.rglob("*.gpy"):
|
32
29
|
try:
|
33
30
|
# Read the file content
|
34
31
|
with open(file_path, "r") as f:
|
@@ -3,7 +3,7 @@ from gltest.artifacts import find_contract_definition
|
|
3
3
|
from gltest.assertions import tx_execution_failed
|
4
4
|
from gltest.exceptions import DeploymentError
|
5
5
|
from .client import get_gl_client
|
6
|
-
from
|
6
|
+
from gltest.types import CalldataEncodable, GenLayerTransaction, TransactionStatus
|
7
7
|
from eth_account.signers.local import LocalAccount
|
8
8
|
from typing import List, Any, Type, Optional, Dict, Callable
|
9
9
|
import types
|
@@ -18,36 +18,47 @@ class Contract:
|
|
18
18
|
|
19
19
|
address: str
|
20
20
|
account: Optional[LocalAccount] = None
|
21
|
+
_schema: Optional[Dict[str, Any]] = None
|
21
22
|
|
22
23
|
@classmethod
|
23
|
-
def
|
24
|
-
cls,
|
24
|
+
def new(
|
25
|
+
cls,
|
26
|
+
address: str,
|
27
|
+
schema: Dict[str, Any],
|
28
|
+
account: Optional[LocalAccount] = None,
|
25
29
|
) -> "Contract":
|
26
30
|
"""
|
27
31
|
Build the methods from the schema.
|
28
32
|
"""
|
29
33
|
if not isinstance(schema, dict) or "methods" not in schema:
|
30
34
|
raise ValueError("Invalid schema: must contain 'methods' field")
|
35
|
+
instance = cls(address=address, _schema=schema, account=account)
|
36
|
+
instance._build_methods_from_schema()
|
37
|
+
return instance
|
31
38
|
|
32
|
-
|
33
|
-
|
39
|
+
def _build_methods_from_schema(self):
|
40
|
+
if self._schema is None:
|
41
|
+
raise ValueError("No schema provided")
|
42
|
+
for method_name, method_info in self._schema["methods"].items():
|
34
43
|
if not isinstance(method_info, dict) or "readonly" not in method_info:
|
35
44
|
raise ValueError(
|
36
|
-
f"Invalid method info for {method_name}: must contain 'readonly' field"
|
45
|
+
f"Invalid method info for '{method_name}': must contain 'readonly' field"
|
37
46
|
)
|
38
|
-
|
39
|
-
|
40
|
-
method_name,
|
41
|
-
types.MethodType(
|
42
|
-
cls.contract_method_factory(method_name, method_info["readonly"]),
|
43
|
-
instance,
|
44
|
-
),
|
47
|
+
method_func = self.contract_method_factory(
|
48
|
+
method_name, method_info["readonly"]
|
45
49
|
)
|
46
|
-
|
50
|
+
bound_method = types.MethodType(method_func, self)
|
51
|
+
setattr(self, method_name, bound_method)
|
47
52
|
|
48
53
|
def connect(self, account: LocalAccount) -> "Contract":
|
49
|
-
|
50
|
-
|
54
|
+
"""
|
55
|
+
Create a new instance of the contract with the same methods and a different account.
|
56
|
+
"""
|
57
|
+
new_contract = self.__class__(
|
58
|
+
address=self.address, account=account, _schema=self._schema
|
59
|
+
)
|
60
|
+
new_contract._build_methods_from_schema()
|
61
|
+
return new_contract
|
51
62
|
|
52
63
|
@staticmethod
|
53
64
|
def contract_method_factory(method_name: str, read_only: bool) -> Callable:
|
@@ -78,6 +89,9 @@ class Contract:
|
|
78
89
|
leader_only: bool = False,
|
79
90
|
wait_interval: Optional[int] = None,
|
80
91
|
wait_retries: Optional[int] = None,
|
92
|
+
wait_transaction_status: TransactionStatus = TransactionStatus.FINALIZED,
|
93
|
+
wait_triggered_transactions: bool = True,
|
94
|
+
wait_triggered_transactions_status: TransactionStatus = TransactionStatus.ACCEPTED,
|
81
95
|
) -> GenLayerTransaction:
|
82
96
|
"""
|
83
97
|
Wrapper to the contract write method.
|
@@ -98,8 +112,18 @@ class Contract:
|
|
98
112
|
if wait_retries is not None:
|
99
113
|
extra_args["retries"] = wait_retries
|
100
114
|
receipt = client.wait_for_transaction_receipt(
|
101
|
-
transaction_hash=tx_hash,
|
115
|
+
transaction_hash=tx_hash,
|
116
|
+
status=wait_transaction_status,
|
117
|
+
**extra_args,
|
102
118
|
)
|
119
|
+
if wait_triggered_transactions:
|
120
|
+
triggered_transactions = receipt["triggered_transactions"]
|
121
|
+
for triggered_transaction in triggered_transactions:
|
122
|
+
client.wait_for_transaction_receipt(
|
123
|
+
transaction_hash=triggered_transaction,
|
124
|
+
status=wait_triggered_transactions_status,
|
125
|
+
**extra_args,
|
126
|
+
)
|
103
127
|
return receipt
|
104
128
|
|
105
129
|
return read_contract_wrapper if read_only else write_contract_wrapper
|
@@ -138,6 +162,7 @@ class ContractFactory:
|
|
138
162
|
leader_only: bool = False,
|
139
163
|
wait_interval: Optional[int] = None,
|
140
164
|
wait_retries: Optional[int] = None,
|
165
|
+
wait_transaction_status: TransactionStatus = TransactionStatus.FINALIZED,
|
141
166
|
) -> Contract:
|
142
167
|
"""
|
143
168
|
Deploy the contract
|
@@ -157,9 +182,8 @@ class ContractFactory:
|
|
157
182
|
if wait_retries is not None:
|
158
183
|
extra_args["retries"] = wait_retries
|
159
184
|
tx_receipt = client.wait_for_transaction_receipt(
|
160
|
-
transaction_hash=tx_hash, status=
|
185
|
+
transaction_hash=tx_hash, status=wait_transaction_status, **extra_args
|
161
186
|
)
|
162
|
-
|
163
187
|
if (
|
164
188
|
not tx_receipt
|
165
189
|
or "data" not in tx_receipt
|
@@ -176,8 +200,8 @@ class ContractFactory:
|
|
176
200
|
|
177
201
|
contract_address = tx_receipt["data"]["contract_address"]
|
178
202
|
schema = client.get_contract_schema(address=contract_address)
|
179
|
-
return Contract.
|
180
|
-
address=contract_address, schema=schema
|
203
|
+
return Contract.new(
|
204
|
+
address=contract_address, schema=schema, account=account
|
181
205
|
)
|
182
206
|
except Exception as e:
|
183
207
|
raise DeploymentError(
|
@@ -0,0 +1,16 @@
|
|
1
|
+
from gltest.plugin_config import set_contracts_dir
|
2
|
+
from pathlib import Path
|
3
|
+
|
4
|
+
|
5
|
+
def pytest_addoption(parser):
|
6
|
+
parser.addoption(
|
7
|
+
"--contracts-dir",
|
8
|
+
action="store",
|
9
|
+
default="contracts",
|
10
|
+
help="Directory containing contract files",
|
11
|
+
)
|
12
|
+
|
13
|
+
|
14
|
+
def pytest_configure(config):
|
15
|
+
contracts_dir = config.getoption("--contracts-dir")
|
16
|
+
set_contracts_dir(Path(contracts_dir))
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
4
4
|
|
5
5
|
[project]
|
6
6
|
name = "genlayer-test"
|
7
|
-
version = "0.1.
|
7
|
+
version = "0.1.0b2"
|
8
8
|
description = "GenLayer Testing Suite"
|
9
9
|
authors = [
|
10
10
|
{ name = "GenLayer" }
|
@@ -30,5 +30,8 @@ classifiers = [
|
|
30
30
|
[tool.setuptools.packages.find]
|
31
31
|
where = ["."]
|
32
32
|
|
33
|
+
[project.entry-points.pytest11]
|
34
|
+
gltest = "gltest.plugin_hooks"
|
35
|
+
|
33
36
|
[project.scripts]
|
34
|
-
gltest = "
|
37
|
+
gltest = "gltest_cli.main:main"
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|