genlayer-test 0.2.0__py3-none-any.whl → 0.3.0__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.
Files changed (43) hide show
  1. {genlayer_test-0.2.0.dist-info → genlayer_test-0.3.0.dist-info}/METADATA +77 -10
  2. genlayer_test-0.3.0.dist-info/RECORD +65 -0
  3. {genlayer_test-0.2.0.dist-info → genlayer_test-0.3.0.dist-info}/entry_points.txt +1 -1
  4. gltest/__init__.py +4 -4
  5. gltest/artifacts/contract.py +9 -4
  6. gltest/glchain/__init__.py +3 -3
  7. gltest/glchain/account.py +15 -11
  8. gltest/glchain/client.py +39 -3
  9. gltest/glchain/contract.py +57 -26
  10. gltest/helpers/fixture_snapshot.py +3 -2
  11. gltest_cli/config/__init__.py +0 -0
  12. gltest_cli/config/constants.py +10 -0
  13. gltest_cli/config/general.py +10 -0
  14. gltest_cli/config/plugin.py +102 -0
  15. gltest_cli/config/types.py +137 -0
  16. gltest_cli/config/user.py +222 -0
  17. gltest_cli/logging.py +51 -0
  18. tests/__init__.py +0 -0
  19. tests/examples/tests/test_llm_erc20.py +2 -2
  20. tests/examples/tests/test_multi_read_erc20.py +13 -3
  21. tests/examples/tests/test_multi_tenant_storage.py +12 -3
  22. tests/examples/tests/test_read_erc20.py +2 -2
  23. tests/examples/tests/test_storage.py +4 -2
  24. tests/examples/tests/test_user_storage.py +17 -3
  25. tests/gltest/__init__.py +0 -0
  26. tests/gltest/artifact/__init__.py +0 -0
  27. tests/gltest/artifact/test_contract_definition.py +91 -0
  28. tests/gltest_cli/__init__.py +0 -0
  29. tests/gltest_cli/config/test_plugin.py +127 -0
  30. tests/gltest_cli/config/test_user.py +351 -0
  31. genlayer_test-0.2.0.dist-info/RECORD +0 -55
  32. gltest/plugin_config.py +0 -42
  33. gltest/plugin_hooks.py +0 -51
  34. tests/artifact/test_contract_definition.py +0 -347
  35. tests/plugin/test_plugin_hooks.py +0 -78
  36. {genlayer_test-0.2.0.dist-info → genlayer_test-0.3.0.dist-info}/WHEEL +0 -0
  37. {genlayer_test-0.2.0.dist-info → genlayer_test-0.3.0.dist-info}/licenses/LICENSE +0 -0
  38. {genlayer_test-0.2.0.dist-info → genlayer_test-0.3.0.dist-info}/top_level.txt +0 -0
  39. /tests/{plugin/conftest.py → conftest.py} +0 -0
  40. /tests/{artifact → gltest/artifact}/contracts/duplicate_ic_contract_1.py +0 -0
  41. /tests/{artifact → gltest/artifact}/contracts/duplicate_ic_contract_2.py +0 -0
  42. /tests/{artifact → gltest/artifact}/contracts/not_ic_contract.py +0 -0
  43. /tests/{assertions → gltest/assertions}/test_assertions.py +0 -0
gltest/plugin_hooks.py DELETED
@@ -1,51 +0,0 @@
1
- from gltest.plugin_config import (
2
- set_contracts_dir,
3
- set_default_wait_interval,
4
- set_default_wait_retries,
5
- set_rpc_url,
6
- )
7
- from pathlib import Path
8
- from genlayer_py.chains.localnet import SIMULATOR_JSON_RPC_URL
9
-
10
-
11
- def pytest_addoption(parser):
12
- group = parser.getgroup("gltest")
13
- group.addoption(
14
- "--contracts-dir",
15
- action="store",
16
- default="contracts",
17
- help="Directory containing contract files",
18
- )
19
-
20
- group.addoption(
21
- "--default-wait-interval",
22
- action="store",
23
- default=10000,
24
- help="Default wait interval for waiting transaction receipts",
25
- )
26
-
27
- group.addoption(
28
- "--default-wait-retries",
29
- action="store",
30
- default=15,
31
- help="Default wait retries for waiting transaction receipts",
32
- )
33
-
34
- group.addoption(
35
- "--rpc-url",
36
- action="store",
37
- default=SIMULATOR_JSON_RPC_URL,
38
- help="RPC URL for the genlayer network",
39
- )
40
-
41
-
42
- def pytest_configure(config):
43
- contracts_dir = config.getoption("--contracts-dir")
44
- default_wait_interval = config.getoption("--default-wait-interval")
45
- default_wait_retries = config.getoption("--default-wait-retries")
46
- rpc_url = config.getoption("--rpc-url")
47
-
48
- set_contracts_dir(Path(contracts_dir))
49
- set_default_wait_interval(int(default_wait_interval))
50
- set_default_wait_retries(int(default_wait_retries))
51
- set_rpc_url(str(rpc_url))
@@ -1,347 +0,0 @@
1
- import pytest
2
- from gltest.artifacts.contract import (
3
- find_contract_definition_from_name,
4
- find_contract_definition_from_path,
5
- compute_contract_code,
6
- )
7
- from gltest.plugin_config import set_contracts_dir
8
- from pathlib import Path
9
-
10
-
11
- def test_single_file():
12
- """
13
- Test finding a contract definition by name for a single-file contract.
14
-
15
- Verifies that the function correctly identifies and loads a contract
16
- from a single Python file, extracting the contract name and computing
17
- the contract code without any additional runner files.
18
- """
19
- set_contracts_dir(".")
20
- contract_definition = find_contract_definition_from_name("PredictionMarket")
21
-
22
- assert contract_definition.contract_name == "PredictionMarket"
23
-
24
- # Assert complete contract definition
25
- expected_main_file_path = Path("examples/contracts/football_prediction_market.py")
26
- expected_runner_file_path = None
27
- contract_code = compute_contract_code(
28
- expected_main_file_path, expected_runner_file_path
29
- )
30
- assert contract_definition.contract_code == contract_code
31
- assert (
32
- str(contract_definition.main_file_path)
33
- == "examples/contracts/football_prediction_market.py"
34
- )
35
- assert contract_definition.runner_file_path is None
36
-
37
-
38
- def test_multiple_files():
39
- """
40
- Test finding a contract definition by name for a multi-file contract.
41
-
42
- Verifies that the function correctly identifies and loads a contract
43
- from a multi-file structure with __init__.py and runner.json,
44
- properly packaging all files into a ZIP archive for deployment.
45
- """
46
- set_contracts_dir(".")
47
- contract_definition = find_contract_definition_from_name("MultiFileContract")
48
-
49
- assert contract_definition.contract_name == "MultiFileContract"
50
-
51
- # Assert complete contract definition
52
- expected_main_file_path = Path("examples/contracts/multi_file_contract/__init__.py")
53
- expected_runner_file_path = Path(
54
- "examples/contracts/multi_file_contract/runner.json"
55
- )
56
- assert contract_definition.main_file_path == expected_main_file_path
57
- assert contract_definition.runner_file_path == expected_runner_file_path
58
- contract_code = compute_contract_code(
59
- expected_main_file_path, expected_runner_file_path
60
- )
61
- assert contract_definition.contract_code == contract_code
62
-
63
-
64
- def test_single_file_legacy():
65
- """
66
- Test finding a contract definition by name for a legacy single-file contract.
67
-
68
- Verifies that the function correctly handles legacy .gpy files,
69
- maintaining backward compatibility with older contract formats
70
- while extracting contract name and computing contract code.
71
- """
72
- set_contracts_dir(".")
73
- contract_definition = find_contract_definition_from_name("StorageLegacy")
74
-
75
- # Assert complete contract definition
76
- assert contract_definition.contract_name == "StorageLegacy"
77
- expected_main_file_path = Path("examples/contracts/storage_legacy.gpy")
78
- expected_runner_file_path = None
79
- contract_code = compute_contract_code(
80
- expected_main_file_path, expected_runner_file_path
81
- )
82
- assert contract_definition.contract_code == contract_code
83
- assert (
84
- str(contract_definition.main_file_path)
85
- == "examples/contracts/storage_legacy.gpy"
86
- )
87
- assert contract_definition.runner_file_path is None
88
-
89
-
90
- def test_multiple_files_legacy():
91
- """
92
- Test finding a contract definition by name for a legacy multi-file contract.
93
-
94
- Verifies that the function correctly handles legacy multi-file contracts
95
- with .gpy extension and runner.json, ensuring proper packaging and
96
- backward compatibility with older contract structures.
97
- """
98
- set_contracts_dir(".")
99
- contract_definition = find_contract_definition_from_name("MultiFileContractLegacy")
100
-
101
- # Assert complete contract definition
102
- assert contract_definition.contract_name == "MultiFileContractLegacy"
103
- expected_main_file_path = Path(
104
- "examples/contracts/multi_file_contract_legacy/__init__.gpy"
105
- )
106
- expected_runner_file_path = Path(
107
- "examples/contracts/multi_file_contract_legacy/runner.json"
108
- )
109
- assert contract_definition.main_file_path == expected_main_file_path
110
- assert contract_definition.runner_file_path == expected_runner_file_path
111
- contract_code = compute_contract_code(
112
- expected_main_file_path, expected_runner_file_path
113
- )
114
- assert contract_definition.contract_code == contract_code
115
-
116
-
117
- def test_class_is_not_intelligent_contract():
118
- """
119
- Test error handling when searching for a non-existent contract by name.
120
-
121
- Verifies that the function raises FileNotFoundError when attempting
122
- to find a contract that doesn't exist in the contracts directory,
123
- ensuring proper error handling for invalid contract names.
124
- """
125
- set_contracts_dir(".")
126
-
127
- with pytest.raises(FileNotFoundError):
128
- _ = find_contract_definition_from_name("NotICContract")
129
-
130
-
131
- def test_find_from_path_single_file():
132
- """
133
- Test finding a contract definition by file path for a single-file contract.
134
-
135
- Verifies that the function correctly loads a contract when given a relative
136
- path to a single Python file, extracting the contract name via AST parsing
137
- and computing the contract code without additional runner files.
138
- """
139
- set_contracts_dir(".")
140
- contract_definition = find_contract_definition_from_path(
141
- "examples/contracts/football_prediction_market.py"
142
- )
143
-
144
- assert contract_definition.contract_name == "PredictionMarket"
145
-
146
- # Assert complete contract definition
147
- expected_main_file_path = Path("examples/contracts/football_prediction_market.py")
148
- expected_runner_file_path = None
149
- contract_code = compute_contract_code(
150
- expected_main_file_path, expected_runner_file_path
151
- )
152
- assert contract_definition.contract_code == contract_code
153
- assert (
154
- str(contract_definition.main_file_path)
155
- == "examples/contracts/football_prediction_market.py"
156
- )
157
- assert contract_definition.runner_file_path is None
158
-
159
-
160
- def test_find_from_path_multiple_files():
161
- """
162
- Test finding a contract definition by file path for a multi-file contract.
163
-
164
- Verifies that the function correctly loads a contract when given a relative
165
- path to __init__.py in a multi-file structure, automatically detecting
166
- the associated runner.json and packaging all files appropriately.
167
- """
168
- set_contracts_dir(".")
169
- contract_definition = find_contract_definition_from_path(
170
- "examples/contracts/multi_file_contract/__init__.py"
171
- )
172
-
173
- assert contract_definition.contract_name == "MultiFileContract"
174
-
175
- # Assert complete contract definition
176
- expected_main_file_path = Path("examples/contracts/multi_file_contract/__init__.py")
177
- expected_runner_file_path = Path(
178
- "examples/contracts/multi_file_contract/runner.json"
179
- )
180
- assert contract_definition.main_file_path == expected_main_file_path
181
- assert contract_definition.runner_file_path == expected_runner_file_path
182
- contract_code = compute_contract_code(
183
- expected_main_file_path, expected_runner_file_path
184
- )
185
- assert contract_definition.contract_code == contract_code
186
-
187
-
188
- def test_find_from_path_single_file_legacy():
189
- """
190
- Test finding a contract definition by file path for a legacy single-file contract.
191
-
192
- Verifies that the function correctly handles legacy .gpy files when accessed
193
- by file path, maintaining backward compatibility while extracting contract
194
- name via AST parsing and computing appropriate contract code.
195
- """
196
- set_contracts_dir(".")
197
- contract_definition = find_contract_definition_from_path(
198
- "examples/contracts/storage_legacy.gpy"
199
- )
200
-
201
- # Assert complete contract definition
202
- assert contract_definition.contract_name == "StorageLegacy"
203
- expected_main_file_path = Path("examples/contracts/storage_legacy.gpy")
204
- expected_runner_file_path = None
205
- contract_code = compute_contract_code(
206
- expected_main_file_path, expected_runner_file_path
207
- )
208
- assert contract_definition.contract_code == contract_code
209
- assert (
210
- str(contract_definition.main_file_path)
211
- == "examples/contracts/storage_legacy.gpy"
212
- )
213
- assert contract_definition.runner_file_path is None
214
-
215
-
216
- def test_find_from_path_multiple_files_legacy():
217
- """
218
- Test finding a contract definition by file path for a legacy multi-file contract.
219
-
220
- Verifies that the function correctly handles legacy multi-file contracts
221
- with .gpy extension when accessed by file path, properly detecting
222
- runner.json and maintaining backward compatibility with older structures.
223
- """
224
- set_contracts_dir(".")
225
- contract_definition = find_contract_definition_from_path(
226
- "examples/contracts/multi_file_contract_legacy/__init__.gpy"
227
- )
228
-
229
- # Assert complete contract definition
230
- assert contract_definition.contract_name == "MultiFileContractLegacy"
231
- expected_main_file_path = Path(
232
- "examples/contracts/multi_file_contract_legacy/__init__.gpy"
233
- )
234
- expected_runner_file_path = Path(
235
- "examples/contracts/multi_file_contract_legacy/runner.json"
236
- )
237
- assert contract_definition.main_file_path == expected_main_file_path
238
- assert contract_definition.runner_file_path == expected_runner_file_path
239
- contract_code = compute_contract_code(
240
- expected_main_file_path, expected_runner_file_path
241
- )
242
- assert contract_definition.contract_code == contract_code
243
-
244
-
245
- def test_find_from_path_file_not_found():
246
- """
247
- Test error handling when the specified contract file doesn't exist.
248
-
249
- Verifies that the function raises FileNotFoundError with appropriate
250
- error message when attempting to load a contract from a non-existent
251
- file path relative to the contracts directory.
252
- """
253
- set_contracts_dir(".")
254
-
255
- with pytest.raises(FileNotFoundError, match="Contract file not found at:"):
256
- _ = find_contract_definition_from_path("nonexistent/contract.py")
257
-
258
-
259
- def test_find_from_path_contracts_dir_not_found():
260
- """
261
- Test error handling when the contracts directory doesn't exist.
262
-
263
- Verifies that the function raises FileNotFoundError with appropriate
264
- error message when the configured contracts directory is invalid,
265
- ensuring proper validation before attempting file operations.
266
- """
267
- set_contracts_dir("nonexistent_directory")
268
-
269
- with pytest.raises(FileNotFoundError, match="Contracts directory not found at:"):
270
- _ = find_contract_definition_from_path("some/contract.py")
271
-
272
-
273
- def test_find_from_path_no_valid_contract_class():
274
- """
275
- Test error handling when a file exists but contains no valid contract class.
276
-
277
- Verifies that the function raises ValueError with appropriate error message
278
- when attempting to load a file that exists but doesn't contain a class
279
- that inherits from gl.Contract, ensuring proper AST parsing validation.
280
- """
281
- set_contracts_dir(".")
282
-
283
- with pytest.raises(ValueError, match="No valid contract class found in"):
284
- _ = find_contract_definition_from_path("artifact/contracts/not_ic_contract.py")
285
-
286
-
287
- def test_multiple_contracts_same_name():
288
- """
289
- Test error handling when multiple contracts with the same name exist.
290
-
291
- Verifies that the function raises ValueError with appropriate error message
292
- when multiple files contain contracts with the same name, listing all
293
- duplicate file locations and providing guidance for resolution.
294
- """
295
- set_contracts_dir(".")
296
-
297
- with pytest.raises(
298
- ValueError,
299
- match=r"Multiple contracts named 'DuplicateContract' found in contracts directory\. Found in files: .+\. Please ensure contract names are unique\.",
300
- ):
301
- _ = find_contract_definition_from_name("DuplicateContract")
302
-
303
-
304
- def test_duplicate_contract_error_message_format():
305
- """
306
- Test that the duplicate contract error message contains all expected elements.
307
-
308
- Verifies that when multiple contracts with the same name are found, the error
309
- message includes the contract name, mentions "contracts directory", lists
310
- file paths, and provides clear guidance about ensuring uniqueness.
311
- """
312
- set_contracts_dir(".")
313
-
314
- try:
315
- _ = find_contract_definition_from_name("DuplicateContract")
316
- pytest.fail("Expected ValueError for duplicate contracts")
317
- except ValueError as e:
318
- error_message = str(e)
319
- # Verify error message contains key components
320
- assert "Multiple contracts named 'DuplicateContract' found" in error_message
321
- assert "contracts directory" in error_message
322
- assert "Found in files:" in error_message
323
- assert "Please ensure contract names are unique" in error_message
324
- # Verify that multiple file paths are mentioned (comma-separated)
325
- assert (
326
- "," in error_message
327
- or len(error_message.split("Found in files: ")[1].split(".")[0]) > 0
328
- )
329
- except Exception as e:
330
- pytest.fail(f"Expected ValueError but got {type(e).__name__}: {e}")
331
-
332
-
333
- def test_single_contract_still_works_with_duplicate_detection():
334
- """
335
- Test that normal single contract loading still works after duplicate detection changes.
336
-
337
- Verifies that the enhanced search_path_by_class_name function doesn't break
338
- the normal case where only one contract with a given name exists, ensuring
339
- backward compatibility with existing functionality.
340
- """
341
- set_contracts_dir(".")
342
-
343
- # This should work normally - no duplicates expected for PredictionMarket
344
- contract_definition = find_contract_definition_from_name("PredictionMarket")
345
- assert contract_definition.contract_name == "PredictionMarket"
346
- assert contract_definition.main_file_path is not None
347
- assert "football_prediction_market.py" in str(contract_definition.main_file_path)
@@ -1,78 +0,0 @@
1
- def test_help_message(pytester):
2
- result = pytester.runpytest(
3
- "--help",
4
- )
5
- # fnmatch_lines does an assertion internally
6
- result.stdout.fnmatch_lines(
7
- [
8
- "gltest:",
9
- "*--contracts-dir=CONTRACTS_DIR",
10
- "*Directory containing contract files",
11
- "*--default-wait-interval=DEFAULT_WAIT_INTERVAL",
12
- "*Default wait interval for waiting transaction receipts",
13
- "*--default-wait-retries=DEFAULT_WAIT_RETRIES",
14
- "*Default wait retries for waiting transaction receipts",
15
- "*--rpc-url=RPC_URL*RPC URL for the genlayer network",
16
- ]
17
- )
18
-
19
-
20
- def test_default_wait_interval(pytester):
21
-
22
- pytester.makepyfile(
23
- """
24
- from gltest.plugin_config import get_default_wait_interval
25
-
26
- def test_default_wait_interval():
27
- assert get_default_wait_interval() == 5000
28
- """
29
- )
30
-
31
- result = pytester.runpytest("--default-wait-interval=5000", "-v")
32
-
33
- result.stdout.fnmatch_lines(
34
- [
35
- "*::test_default_wait_interval PASSED*",
36
- ]
37
- )
38
- assert result.ret == 0
39
-
40
-
41
- def test_default_wait_retries(pytester):
42
- pytester.makepyfile(
43
- """
44
- from gltest.plugin_config import get_default_wait_retries
45
-
46
- def test_default_wait_retries():
47
- assert get_default_wait_retries() == 4000
48
- """
49
- )
50
-
51
- result = pytester.runpytest("--default-wait-retries=4000", "-v")
52
-
53
- result.stdout.fnmatch_lines(
54
- [
55
- "*::test_default_wait_retries PASSED*",
56
- ]
57
- )
58
- assert result.ret == 0
59
-
60
-
61
- def test_rpc_url(pytester):
62
- pytester.makepyfile(
63
- """
64
- from gltest.plugin_config import get_rpc_url
65
-
66
- def test_rpc_url():
67
- assert get_rpc_url() == 'http://custom-rpc-url:8545'
68
- """
69
- )
70
-
71
- result = pytester.runpytest("--rpc-url=http://custom-rpc-url:8545", "-v")
72
-
73
- result.stdout.fnmatch_lines(
74
- [
75
- "*::test_rpc_url PASSED*",
76
- ]
77
- )
78
- assert result.ret == 0
File without changes