genlayer-test 0.1.2__tar.gz → 0.1.3__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 (60) hide show
  1. {genlayer_test-0.1.2/genlayer_test.egg-info → genlayer_test-0.1.3}/PKG-INFO +48 -11
  2. genlayer_test-0.1.2/PKG-INFO → genlayer_test-0.1.3/README.md +44 -26
  3. genlayer_test-0.1.2/README.md → genlayer_test-0.1.3/genlayer_test.egg-info/PKG-INFO +63 -5
  4. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/gltest/artifacts/contract.py +1 -1
  5. genlayer_test-0.1.3/gltest/assertions.py +59 -0
  6. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/pyproject.toml +4 -6
  7. genlayer_test-0.1.3/tests/assertions/test_assertions.py +344 -0
  8. genlayer_test-0.1.2/gltest/assertions.py +0 -18
  9. genlayer_test-0.1.2/tests/assertions/test_assertions.py +0 -31
  10. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/LICENSE +0 -0
  11. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/genlayer_test.egg-info/SOURCES.txt +0 -0
  12. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/genlayer_test.egg-info/dependency_links.txt +0 -0
  13. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/genlayer_test.egg-info/entry_points.txt +0 -0
  14. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/genlayer_test.egg-info/requires.txt +0 -0
  15. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/genlayer_test.egg-info/top_level.txt +0 -0
  16. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/gltest/__init__.py +0 -0
  17. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/gltest/artifacts/__init__.py +0 -0
  18. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/gltest/exceptions.py +0 -0
  19. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/gltest/glchain/__init__.py +0 -0
  20. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/gltest/glchain/account.py +0 -0
  21. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/gltest/glchain/client.py +0 -0
  22. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/gltest/glchain/contract.py +0 -0
  23. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/gltest/helpers/__init__.py +0 -0
  24. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/gltest/helpers/fixture_snapshot.py +0 -0
  25. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/gltest/helpers/take_snapshot.py +0 -0
  26. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/gltest/plugin_config.py +0 -0
  27. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/gltest/plugin_hooks.py +0 -0
  28. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/gltest/types.py +0 -0
  29. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/gltest_cli/main.py +0 -0
  30. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/setup.cfg +0 -0
  31. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/tests/artifact/contracts/not_ic_contract.py +0 -0
  32. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/tests/artifact/test_contract_definition.py +0 -0
  33. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/tests/examples/contracts/football_prediction_market.py +0 -0
  34. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/tests/examples/contracts/intelligent_oracle.py +0 -0
  35. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/tests/examples/contracts/intelligent_oracle_factory.py +0 -0
  36. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/tests/examples/contracts/llm_erc20.py +0 -0
  37. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/tests/examples/contracts/log_indexer.py +0 -0
  38. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/tests/examples/contracts/multi_file_contract/__init__.py +0 -0
  39. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/tests/examples/contracts/multi_file_contract/other.py +0 -0
  40. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/tests/examples/contracts/multi_read_erc20.py +0 -0
  41. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/tests/examples/contracts/multi_tenant_storage.py +0 -0
  42. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/tests/examples/contracts/read_erc20.py +0 -0
  43. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/tests/examples/contracts/storage.py +0 -0
  44. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/tests/examples/contracts/user_storage.py +0 -0
  45. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/tests/examples/contracts/wizard_of_coin.py +0 -0
  46. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/tests/examples/tests/test_football_prediction_market.py +0 -0
  47. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/tests/examples/tests/test_intelligent_oracle_factory.py +0 -0
  48. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/tests/examples/tests/test_llm_erc20.py +0 -0
  49. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/tests/examples/tests/test_log_indexer.py +0 -0
  50. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/tests/examples/tests/test_multi_file_contract.py +0 -0
  51. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/tests/examples/tests/test_multi_file_contract_legacy.py +0 -0
  52. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/tests/examples/tests/test_multi_read_erc20.py +0 -0
  53. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/tests/examples/tests/test_multi_tenant_storage.py +0 -0
  54. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/tests/examples/tests/test_read_erc20.py +0 -0
  55. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/tests/examples/tests/test_storage.py +0 -0
  56. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/tests/examples/tests/test_storage_legacy.py +0 -0
  57. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/tests/examples/tests/test_user_storage.py +0 -0
  58. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/tests/examples/tests/test_wizard_of_coin.py +0 -0
  59. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/tests/plugin/conftest.py +0 -0
  60. {genlayer_test-0.1.2 → genlayer_test-0.1.3}/tests/plugin/test_plugin_hooks.py +0 -0
@@ -1,18 +1,16 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: genlayer-test
3
- Version: 0.1.2
3
+ Version: 0.1.3
4
4
  Summary: GenLayer Testing Suite
5
5
  Author: GenLayer
6
6
  License-Expression: MIT
7
7
  Classifier: Development Status :: 4 - Beta
8
8
  Classifier: Intended Audience :: Developers
9
9
  Classifier: Programming Language :: Python :: 3
10
- Classifier: Programming Language :: Python :: 3.8
11
- Classifier: Programming Language :: Python :: 3.9
12
- Classifier: Programming Language :: Python :: 3.10
13
- Classifier: Programming Language :: Python :: 3.11
10
+ Classifier: Programming Language :: Python :: 3.12
11
+ Classifier: Programming Language :: Python :: 3.13
14
12
  Classifier: Topic :: Software Development :: Testing
15
- Requires-Python: >=3.8
13
+ Requires-Python: >=3.12
16
14
  Description-Content-Type: text/markdown
17
15
  License-File: LICENSE
18
16
  Requires-Dist: pytest
@@ -162,7 +160,7 @@ Before diving into the examples, let's understand the basic project structure:
162
160
  ```
163
161
  genlayer-example/
164
162
  ├── contracts/ # Contract definitions
165
- │ └── storage.gpy # Example storage contract
163
+ │ └── storage.py # Example storage contract
166
164
  └── test/ # Test files
167
165
  └── test_contract.py # Contract test cases
168
166
  ```
@@ -279,6 +277,44 @@ def test_write_methods():
279
277
  assert contract.get_storage() == "new_value"
280
278
  ```
281
279
 
280
+ ### Assertions
281
+
282
+ The GenLayer Testing Suite provides powerful assertion functions to validate transaction results and their output:
283
+
284
+ #### Basic Transaction Assertions
285
+
286
+ ```python
287
+ from gltest.assertions import tx_execution_succeeded, tx_execution_failed
288
+
289
+ # Basic success/failure checks
290
+ assert tx_execution_succeeded(tx_receipt)
291
+ assert tx_execution_failed(tx_receipt) # Opposite of tx_execution_succeeded
292
+ ```
293
+
294
+ #### Advanced Output Matching
295
+
296
+ You can match specific patterns in the transaction's stdout and stderr output using regex patterns, similar to pytest's `match` parameter:
297
+
298
+ ```python
299
+ # Simple string matching
300
+ assert tx_execution_succeeded(tx_receipt, match_std_out="Process completed")
301
+ assert tx_execution_failed(tx_receipt, match_std_err="Warning: deprecated")
302
+
303
+ # Regex pattern matching
304
+ assert tx_execution_succeeded(tx_receipt, match_std_out=r".*code \d+")
305
+ assert tx_execution_failed(tx_receipt, match_std_err=r"Method.*failed")
306
+ ```
307
+
308
+ #### Assertion Function Parameters
309
+
310
+ Both `tx_execution_succeeded` and `tx_execution_failed` accept the following parameters:
311
+
312
+ - `result`: The transaction result object from contract method calls
313
+ - `match_std_out` (optional): String or regex pattern to match in stdout
314
+ - `match_std_err` (optional): String or regex pattern to match in stderr
315
+
316
+ **Network Compatibility**: The stdout/stderr matching feature (`match_std_out` and `match_std_err` parameters) is only available when running on **studionet** and **localnet**. These features are not supported on testnet.
317
+
282
318
  For more example contracts, check out the [contracts directory](tests/examples/contracts) which contains various sample contracts demonstrating different features and use cases.
283
319
 
284
320
  ## 📝 Best Practices
@@ -354,7 +390,7 @@ For more example contracts, check out the [contracts directory](tests/examples/c
354
390
  # Default structure
355
391
  your_project/
356
392
  ├── contracts/ # Default contracts directory
357
- │ └── my_contract.gpy # Your contract file
393
+ │ └── my_contract.py # Your contract file
358
394
  └── tests/
359
395
  └── test_contract.py # Your test file
360
396
 
@@ -366,7 +402,8 @@ For more example contracts, check out the [contracts directory](tests/examples/c
366
402
  - **Problem**: Contracts aren't being recognized or loaded properly.
367
403
  - **Solution**: Follow the correct naming and structure conventions:
368
404
  ```python
369
- # Correct file: contracts/my_contract.gpy
405
+ # Correct file: contracts/my_contract.py
406
+
370
407
  # Correct structure:
371
408
  from genlayer import *
372
409
 
@@ -374,7 +411,7 @@ For more example contracts, check out the [contracts directory](tests/examples/c
374
411
  # Contract code here
375
412
  pass
376
413
 
377
- # Incorrect file: contracts/my_contract.py # Wrong extension
414
+
378
415
  # Incorrect structure:
379
416
  class MyContract: # Missing gl.Contract inheritance
380
417
  pass
@@ -385,7 +422,7 @@ For more example contracts, check out the [contracts directory](tests/examples/c
385
422
  - **Solution**: Verify your environment:
386
423
  ```bash
387
424
  # Check Python version
388
- python --version # Should be >= 3.8
425
+ python --version # Should be >= 3.12
389
426
 
390
427
  # Check GenLayer Studio status
391
428
  docker ps # Should show GenLayer Studio running
@@ -1,24 +1,3 @@
1
- Metadata-Version: 2.4
2
- Name: genlayer-test
3
- Version: 0.1.2
4
- Summary: GenLayer Testing Suite
5
- Author: GenLayer
6
- License-Expression: MIT
7
- Classifier: Development Status :: 4 - Beta
8
- Classifier: Intended Audience :: Developers
9
- Classifier: Programming Language :: Python :: 3
10
- Classifier: Programming Language :: Python :: 3.8
11
- Classifier: Programming Language :: Python :: 3.9
12
- Classifier: Programming Language :: Python :: 3.10
13
- Classifier: Programming Language :: Python :: 3.11
14
- Classifier: Topic :: Software Development :: Testing
15
- Requires-Python: >=3.8
16
- Description-Content-Type: text/markdown
17
- License-File: LICENSE
18
- Requires-Dist: pytest
19
- Requires-Dist: genlayer-py==0.3.0
20
- Dynamic: license-file
21
-
22
1
  # GenLayer Testing Suite
23
2
 
24
3
  [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/license/mit/)
@@ -162,7 +141,7 @@ Before diving into the examples, let's understand the basic project structure:
162
141
  ```
163
142
  genlayer-example/
164
143
  ├── contracts/ # Contract definitions
165
- │ └── storage.gpy # Example storage contract
144
+ │ └── storage.py # Example storage contract
166
145
  └── test/ # Test files
167
146
  └── test_contract.py # Contract test cases
168
147
  ```
@@ -279,6 +258,44 @@ def test_write_methods():
279
258
  assert contract.get_storage() == "new_value"
280
259
  ```
281
260
 
261
+ ### Assertions
262
+
263
+ The GenLayer Testing Suite provides powerful assertion functions to validate transaction results and their output:
264
+
265
+ #### Basic Transaction Assertions
266
+
267
+ ```python
268
+ from gltest.assertions import tx_execution_succeeded, tx_execution_failed
269
+
270
+ # Basic success/failure checks
271
+ assert tx_execution_succeeded(tx_receipt)
272
+ assert tx_execution_failed(tx_receipt) # Opposite of tx_execution_succeeded
273
+ ```
274
+
275
+ #### Advanced Output Matching
276
+
277
+ You can match specific patterns in the transaction's stdout and stderr output using regex patterns, similar to pytest's `match` parameter:
278
+
279
+ ```python
280
+ # Simple string matching
281
+ assert tx_execution_succeeded(tx_receipt, match_std_out="Process completed")
282
+ assert tx_execution_failed(tx_receipt, match_std_err="Warning: deprecated")
283
+
284
+ # Regex pattern matching
285
+ assert tx_execution_succeeded(tx_receipt, match_std_out=r".*code \d+")
286
+ assert tx_execution_failed(tx_receipt, match_std_err=r"Method.*failed")
287
+ ```
288
+
289
+ #### Assertion Function Parameters
290
+
291
+ Both `tx_execution_succeeded` and `tx_execution_failed` accept the following parameters:
292
+
293
+ - `result`: The transaction result object from contract method calls
294
+ - `match_std_out` (optional): String or regex pattern to match in stdout
295
+ - `match_std_err` (optional): String or regex pattern to match in stderr
296
+
297
+ **Network Compatibility**: The stdout/stderr matching feature (`match_std_out` and `match_std_err` parameters) is only available when running on **studionet** and **localnet**. These features are not supported on testnet.
298
+
282
299
  For more example contracts, check out the [contracts directory](tests/examples/contracts) which contains various sample contracts demonstrating different features and use cases.
283
300
 
284
301
  ## 📝 Best Practices
@@ -354,7 +371,7 @@ For more example contracts, check out the [contracts directory](tests/examples/c
354
371
  # Default structure
355
372
  your_project/
356
373
  ├── contracts/ # Default contracts directory
357
- │ └── my_contract.gpy # Your contract file
374
+ │ └── my_contract.py # Your contract file
358
375
  └── tests/
359
376
  └── test_contract.py # Your test file
360
377
 
@@ -366,7 +383,8 @@ For more example contracts, check out the [contracts directory](tests/examples/c
366
383
  - **Problem**: Contracts aren't being recognized or loaded properly.
367
384
  - **Solution**: Follow the correct naming and structure conventions:
368
385
  ```python
369
- # Correct file: contracts/my_contract.gpy
386
+ # Correct file: contracts/my_contract.py
387
+
370
388
  # Correct structure:
371
389
  from genlayer import *
372
390
 
@@ -374,7 +392,7 @@ For more example contracts, check out the [contracts directory](tests/examples/c
374
392
  # Contract code here
375
393
  pass
376
394
 
377
- # Incorrect file: contracts/my_contract.py # Wrong extension
395
+
378
396
  # Incorrect structure:
379
397
  class MyContract: # Missing gl.Contract inheritance
380
398
  pass
@@ -385,7 +403,7 @@ For more example contracts, check out the [contracts directory](tests/examples/c
385
403
  - **Solution**: Verify your environment:
386
404
  ```bash
387
405
  # Check Python version
388
- python --version # Should be >= 3.8
406
+ python --version # Should be >= 3.12
389
407
 
390
408
  # Check GenLayer Studio status
391
409
  docker ps # Should show GenLayer Studio running
@@ -1,3 +1,22 @@
1
+ Metadata-Version: 2.4
2
+ Name: genlayer-test
3
+ Version: 0.1.3
4
+ Summary: GenLayer Testing Suite
5
+ Author: GenLayer
6
+ License-Expression: MIT
7
+ Classifier: Development Status :: 4 - Beta
8
+ Classifier: Intended Audience :: Developers
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.12
11
+ Classifier: Programming Language :: Python :: 3.13
12
+ Classifier: Topic :: Software Development :: Testing
13
+ Requires-Python: >=3.12
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Requires-Dist: pytest
17
+ Requires-Dist: genlayer-py==0.3.0
18
+ Dynamic: license-file
19
+
1
20
  # GenLayer Testing Suite
2
21
 
3
22
  [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/license/mit/)
@@ -141,7 +160,7 @@ Before diving into the examples, let's understand the basic project structure:
141
160
  ```
142
161
  genlayer-example/
143
162
  ├── contracts/ # Contract definitions
144
- │ └── storage.gpy # Example storage contract
163
+ │ └── storage.py # Example storage contract
145
164
  └── test/ # Test files
146
165
  └── test_contract.py # Contract test cases
147
166
  ```
@@ -258,6 +277,44 @@ def test_write_methods():
258
277
  assert contract.get_storage() == "new_value"
259
278
  ```
260
279
 
280
+ ### Assertions
281
+
282
+ The GenLayer Testing Suite provides powerful assertion functions to validate transaction results and their output:
283
+
284
+ #### Basic Transaction Assertions
285
+
286
+ ```python
287
+ from gltest.assertions import tx_execution_succeeded, tx_execution_failed
288
+
289
+ # Basic success/failure checks
290
+ assert tx_execution_succeeded(tx_receipt)
291
+ assert tx_execution_failed(tx_receipt) # Opposite of tx_execution_succeeded
292
+ ```
293
+
294
+ #### Advanced Output Matching
295
+
296
+ You can match specific patterns in the transaction's stdout and stderr output using regex patterns, similar to pytest's `match` parameter:
297
+
298
+ ```python
299
+ # Simple string matching
300
+ assert tx_execution_succeeded(tx_receipt, match_std_out="Process completed")
301
+ assert tx_execution_failed(tx_receipt, match_std_err="Warning: deprecated")
302
+
303
+ # Regex pattern matching
304
+ assert tx_execution_succeeded(tx_receipt, match_std_out=r".*code \d+")
305
+ assert tx_execution_failed(tx_receipt, match_std_err=r"Method.*failed")
306
+ ```
307
+
308
+ #### Assertion Function Parameters
309
+
310
+ Both `tx_execution_succeeded` and `tx_execution_failed` accept the following parameters:
311
+
312
+ - `result`: The transaction result object from contract method calls
313
+ - `match_std_out` (optional): String or regex pattern to match in stdout
314
+ - `match_std_err` (optional): String or regex pattern to match in stderr
315
+
316
+ **Network Compatibility**: The stdout/stderr matching feature (`match_std_out` and `match_std_err` parameters) is only available when running on **studionet** and **localnet**. These features are not supported on testnet.
317
+
261
318
  For more example contracts, check out the [contracts directory](tests/examples/contracts) which contains various sample contracts demonstrating different features and use cases.
262
319
 
263
320
  ## 📝 Best Practices
@@ -333,7 +390,7 @@ For more example contracts, check out the [contracts directory](tests/examples/c
333
390
  # Default structure
334
391
  your_project/
335
392
  ├── contracts/ # Default contracts directory
336
- │ └── my_contract.gpy # Your contract file
393
+ │ └── my_contract.py # Your contract file
337
394
  └── tests/
338
395
  └── test_contract.py # Your test file
339
396
 
@@ -345,7 +402,8 @@ For more example contracts, check out the [contracts directory](tests/examples/c
345
402
  - **Problem**: Contracts aren't being recognized or loaded properly.
346
403
  - **Solution**: Follow the correct naming and structure conventions:
347
404
  ```python
348
- # Correct file: contracts/my_contract.gpy
405
+ # Correct file: contracts/my_contract.py
406
+
349
407
  # Correct structure:
350
408
  from genlayer import *
351
409
 
@@ -353,7 +411,7 @@ For more example contracts, check out the [contracts directory](tests/examples/c
353
411
  # Contract code here
354
412
  pass
355
413
 
356
- # Incorrect file: contracts/my_contract.py # Wrong extension
414
+
357
415
  # Incorrect structure:
358
416
  class MyContract: # Missing gl.Contract inheritance
359
417
  pass
@@ -364,7 +422,7 @@ For more example contracts, check out the [contracts directory](tests/examples/c
364
422
  - **Solution**: Verify your environment:
365
423
  ```bash
366
424
  # Check Python version
367
- python --version # Should be >= 3.8
425
+ python --version # Should be >= 3.12
368
426
 
369
427
  # Check GenLayer Studio status
370
428
  docker ps # Should show GenLayer Studio running
@@ -10,7 +10,7 @@ from typing import Union
10
10
 
11
11
  @dataclass
12
12
  class ContractDefinition:
13
- """Class that represents a contract definition from a .gpy file."""
13
+ """Class that represents a contract definition from a contract file."""
14
14
 
15
15
  contract_name: str
16
16
  contract_code: Union[str, bytes]
@@ -0,0 +1,59 @@
1
+ import re
2
+ from typing import Optional
3
+ from genlayer_py.types import GenLayerTransaction
4
+
5
+
6
+ def tx_execution_succeeded(
7
+ result: GenLayerTransaction,
8
+ match_std_out: Optional[str] = None,
9
+ match_std_err: Optional[str] = None,
10
+ ) -> bool:
11
+ if "consensus_data" not in result:
12
+ return False
13
+ if "leader_receipt" not in result["consensus_data"]:
14
+ return False
15
+ if len(result["consensus_data"]["leader_receipt"]) == 0:
16
+ return False
17
+
18
+ leader_receipt = result["consensus_data"]["leader_receipt"][0]
19
+
20
+ if "execution_result" not in leader_receipt:
21
+ return False
22
+
23
+ execution_result = leader_receipt["execution_result"]
24
+
25
+ if execution_result != "SUCCESS":
26
+ return False
27
+
28
+ if match_std_out is not None or match_std_err is not None:
29
+ if "genvm_result" not in leader_receipt:
30
+ return False
31
+
32
+ genvm_result = leader_receipt["genvm_result"]
33
+
34
+ if match_std_out is not None:
35
+ if "stdout" not in genvm_result:
36
+ return False
37
+ try:
38
+ if not re.search(match_std_out, genvm_result["stdout"]):
39
+ return False
40
+ except re.error:
41
+ return False
42
+
43
+ if match_std_err is not None:
44
+ if "stderr" not in genvm_result:
45
+ return False
46
+ try:
47
+ if not re.search(match_std_err, genvm_result["stderr"]):
48
+ return False
49
+ except re.error:
50
+ return False
51
+ return True
52
+
53
+
54
+ def tx_execution_failed(
55
+ result: GenLayerTransaction,
56
+ match_std_out: Optional[str] = None,
57
+ match_std_err: Optional[str] = None,
58
+ ) -> bool:
59
+ return not tx_execution_succeeded(result, match_std_out, match_std_err)
@@ -4,14 +4,14 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "genlayer-test"
7
- version = "0.1.2"
7
+ version = "0.1.3"
8
8
  description = "GenLayer Testing Suite"
9
9
  authors = [
10
10
  { name = "GenLayer" }
11
11
  ]
12
12
  license = "MIT"
13
13
  readme = "README.md"
14
- requires-python = ">=3.8"
14
+ requires-python = ">=3.12"
15
15
  dependencies = [
16
16
  "pytest",
17
17
  "genlayer-py==0.3.0",
@@ -20,10 +20,8 @@ classifiers = [
20
20
  "Development Status :: 4 - Beta",
21
21
  "Intended Audience :: Developers",
22
22
  "Programming Language :: Python :: 3",
23
- "Programming Language :: Python :: 3.8",
24
- "Programming Language :: Python :: 3.9",
25
- "Programming Language :: Python :: 3.10",
26
- "Programming Language :: Python :: 3.11",
23
+ "Programming Language :: Python :: 3.12",
24
+ "Programming Language :: Python :: 3.13",
27
25
  "Topic :: Software Development :: Testing",
28
26
  ]
29
27
 
@@ -0,0 +1,344 @@
1
+ from gltest.assertions import tx_execution_succeeded, tx_execution_failed
2
+
3
+ GENLAYER_SUCCESS_TRANSACTION = {
4
+ "consensus_data": {"leader_receipt": [{"execution_result": "SUCCESS"}]}
5
+ }
6
+
7
+ GENLAYER_FAILED_TRANSACTION = {
8
+ "consensus_data": {"leader_receipt": [{"execution_result": "ERROR"}]}
9
+ }
10
+
11
+ GENLAYER_EMPTY_LEADER_RECEIPT = {"consensus_data": {"leader_receipt": []}}
12
+
13
+ GENLAYER_GENVM_TRANSACTION = {
14
+ "consensus_data": {
15
+ "leader_receipt": [
16
+ {
17
+ "execution_result": "SUCCESS",
18
+ "genvm_result": {
19
+ "stdout": "Process completed successfully with code 123 items",
20
+ "stderr": "Warning: deprecated function used",
21
+ },
22
+ }
23
+ ]
24
+ }
25
+ }
26
+
27
+ GENLAYER_GENVM_EMPTY_STDERR = {
28
+ "consensus_data": {
29
+ "leader_receipt": [
30
+ {
31
+ "execution_result": "SUCCESS",
32
+ "genvm_result": {
33
+ "stdout": "Task finished without errors",
34
+ "stderr": "",
35
+ },
36
+ }
37
+ ]
38
+ }
39
+ }
40
+
41
+ GENLAYER_GENVM_NO_STDOUT = {
42
+ "consensus_data": {
43
+ "leader_receipt": [
44
+ {
45
+ "execution_result": "SUCCESS",
46
+ "genvm_result": {"stderr": "Error occurred"},
47
+ }
48
+ ]
49
+ }
50
+ }
51
+
52
+ GENLAYER_GENVM_FAILED = {
53
+ "consensus_data": {
54
+ "leader_receipt": [
55
+ {
56
+ "execution_result": "ERROR",
57
+ "genvm_result": {
58
+ "stdout": "Process failed",
59
+ "stderr": "Critical error occurred",
60
+ },
61
+ }
62
+ ]
63
+ }
64
+ }
65
+
66
+
67
+ def test_with_successful_transaction():
68
+ """Test assertion functions with a basic successful transaction.
69
+
70
+ Validates that:
71
+ - tx_execution_succeeded returns True for successful transactions
72
+ - tx_execution_failed returns False for successful transactions
73
+ """
74
+ assert tx_execution_succeeded(GENLAYER_SUCCESS_TRANSACTION) is True
75
+ assert tx_execution_failed(GENLAYER_SUCCESS_TRANSACTION) is False
76
+
77
+
78
+ def test_with_failed_transaction():
79
+ """Test assertion functions with a basic failed transaction.
80
+
81
+ Validates that:
82
+ - tx_execution_succeeded returns False for failed transactions
83
+ - tx_execution_failed returns True for failed transactions
84
+ """
85
+ assert tx_execution_succeeded(GENLAYER_FAILED_TRANSACTION) is False
86
+ assert tx_execution_failed(GENLAYER_FAILED_TRANSACTION) is True
87
+
88
+
89
+ def test_with_empty_leader_receipt():
90
+ """Test assertion functions with empty leader_receipt array.
91
+
92
+ Validates that:
93
+ - Both functions handle empty leader_receipt gracefully
94
+ - Empty leader_receipt is treated as a failed transaction
95
+ """
96
+ assert tx_execution_succeeded(GENLAYER_EMPTY_LEADER_RECEIPT) is False
97
+ assert tx_execution_failed(GENLAYER_EMPTY_LEADER_RECEIPT) is True
98
+
99
+
100
+ def test_with_invalid_transaction():
101
+ """Test assertion functions with completely invalid transaction structure.
102
+
103
+ Validates that:
104
+ - Both functions handle malformed transactions gracefully
105
+ - Invalid transactions are treated as failed
106
+ """
107
+ assert tx_execution_succeeded({}) is False
108
+ assert tx_execution_failed({}) is True
109
+
110
+
111
+ def test_genvm_result_without_match():
112
+ """Test assertion functions with genvm_result but no match parameters.
113
+
114
+ Validates that:
115
+ - Transactions with genvm_result succeed when execution_result is SUCCESS
116
+ - No match parameters means only basic execution status is checked
117
+ """
118
+ assert tx_execution_succeeded(GENLAYER_GENVM_TRANSACTION) is True
119
+ assert tx_execution_failed(GENLAYER_GENVM_TRANSACTION) is False
120
+
121
+
122
+ def test_match_std_out_simple_string():
123
+ """Test stdout matching with simple string patterns.
124
+
125
+ Validates that:
126
+ - Simple string matching works correctly in stdout
127
+ - Non-matching strings cause the assertion to fail
128
+ - tx_execution_failed behaves oppositely to tx_execution_succeeded
129
+ """
130
+ assert (
131
+ tx_execution_succeeded(
132
+ GENLAYER_GENVM_TRANSACTION, match_std_out="Process completed"
133
+ )
134
+ is True
135
+ )
136
+ assert (
137
+ tx_execution_succeeded(GENLAYER_GENVM_TRANSACTION, match_std_out="nonexistent")
138
+ is False
139
+ )
140
+ assert (
141
+ tx_execution_failed(GENLAYER_GENVM_TRANSACTION, match_std_out="nonexistent")
142
+ is True
143
+ )
144
+
145
+
146
+ def test_match_std_err_simple_string():
147
+ """Test stderr matching with simple string patterns.
148
+
149
+ Validates that:
150
+ - Simple string matching works correctly in stderr
151
+ - Non-matching strings cause the assertion to fail
152
+ - tx_execution_failed behaves oppositely to tx_execution_succeeded
153
+ """
154
+ assert (
155
+ tx_execution_succeeded(GENLAYER_GENVM_TRANSACTION, match_std_err="Warning")
156
+ is True
157
+ )
158
+ assert (
159
+ tx_execution_succeeded(GENLAYER_GENVM_TRANSACTION, match_std_err="nonexistent")
160
+ is False
161
+ )
162
+ assert (
163
+ tx_execution_failed(GENLAYER_GENVM_TRANSACTION, match_std_err="nonexistent")
164
+ is True
165
+ )
166
+
167
+
168
+ def test_match_std_out_regex():
169
+ """Test stdout matching with regex patterns.
170
+
171
+ Validates that:
172
+ - Complex regex patterns work correctly in stdout
173
+ - Different regex patterns match appropriately
174
+ - Non-matching regex patterns cause assertions to fail
175
+ - Tests various regex features like \\d+, .*, word boundaries
176
+ """
177
+ assert (
178
+ tx_execution_succeeded(GENLAYER_GENVM_TRANSACTION, match_std_out=r".*code \d+")
179
+ is True
180
+ )
181
+ assert (
182
+ tx_execution_succeeded(GENLAYER_GENVM_TRANSACTION, match_std_out=r".* 123 .*")
183
+ is True
184
+ )
185
+ assert (
186
+ tx_execution_succeeded(
187
+ GENLAYER_GENVM_TRANSACTION, match_std_out=r"Process.*successfully"
188
+ )
189
+ is True
190
+ )
191
+ assert (
192
+ tx_execution_succeeded(GENLAYER_GENVM_TRANSACTION, match_std_out=r"code \d{4}")
193
+ is False
194
+ )
195
+
196
+
197
+ def test_match_std_err_regex():
198
+ """Test stderr matching with regex patterns.
199
+
200
+ Validates that:
201
+ - Complex regex patterns work correctly in stderr
202
+ - Different regex patterns match appropriately
203
+ - Non-matching regex patterns cause assertions to fail
204
+ - Tests various regex features like .*, word boundaries
205
+ """
206
+ assert (
207
+ tx_execution_succeeded(GENLAYER_GENVM_TRANSACTION, match_std_err=r"Warning:.*")
208
+ is True
209
+ )
210
+ assert (
211
+ tx_execution_succeeded(
212
+ GENLAYER_GENVM_TRANSACTION, match_std_err=r".*deprecated.*"
213
+ )
214
+ is True
215
+ )
216
+ assert (
217
+ tx_execution_succeeded(GENLAYER_GENVM_TRANSACTION, match_std_err=r"Error:.*")
218
+ is False
219
+ )
220
+
221
+
222
+ def test_match_both_stdout_and_stderr():
223
+ """Test matching both stdout and stderr simultaneously.
224
+
225
+ Validates that:
226
+ - Both stdout and stderr patterns must match for success
227
+ - If either pattern fails to match, the assertion fails
228
+ - Combined matching works with both simple strings and regex
229
+ """
230
+ assert (
231
+ tx_execution_succeeded(
232
+ GENLAYER_GENVM_TRANSACTION,
233
+ match_std_out="Process completed",
234
+ match_std_err="Warning",
235
+ )
236
+ is True
237
+ )
238
+
239
+ assert (
240
+ tx_execution_succeeded(
241
+ GENLAYER_GENVM_TRANSACTION,
242
+ match_std_out="Process completed",
243
+ match_std_err="nonexistent",
244
+ )
245
+ is False
246
+ )
247
+
248
+
249
+ def test_match_empty_stderr():
250
+ """Test matching empty stderr with different approaches.
251
+
252
+ Validates that:
253
+ - Empty stderr can be matched with regex pattern ^$
254
+ - Empty stderr can be matched with empty string
255
+ - Non-empty patterns fail when stderr is empty
256
+ """
257
+ assert (
258
+ tx_execution_succeeded(GENLAYER_GENVM_EMPTY_STDERR, match_std_err=r"^$") is True
259
+ )
260
+ assert tx_execution_succeeded(GENLAYER_GENVM_EMPTY_STDERR, match_std_err="") is True
261
+ assert (
262
+ tx_execution_succeeded(GENLAYER_GENVM_EMPTY_STDERR, match_std_err="Warning")
263
+ is False
264
+ )
265
+
266
+
267
+ def test_missing_stdout_field():
268
+ """Test behavior when stdout field is missing from genvm_result.
269
+
270
+ Validates that:
271
+ - Missing stdout field causes match_std_out to fail
272
+ - The assertion handles missing fields gracefully
273
+ - tx_execution_failed returns True when stdout matching is requested but field is missing
274
+ """
275
+ assert (
276
+ tx_execution_succeeded(GENLAYER_GENVM_NO_STDOUT, match_std_out="anything")
277
+ is False
278
+ )
279
+ assert (
280
+ tx_execution_failed(GENLAYER_GENVM_NO_STDOUT, match_std_out="anything") is True
281
+ )
282
+
283
+
284
+ def test_missing_stderr_field():
285
+ """Test behavior when stderr field is missing from genvm_result.
286
+
287
+ Validates that:
288
+ - Missing stderr field causes match_std_err to fail
289
+ - The assertion handles missing fields gracefully
290
+ - tx_execution_failed returns True when stderr matching is requested but field is missing
291
+ """
292
+ genvm_no_stderr = {
293
+ "consensus_data": {
294
+ "leader_receipt": [
295
+ {"execution_result": "SUCCESS", "genvm_result": {"stdout": "Success"}}
296
+ ]
297
+ }
298
+ }
299
+ assert tx_execution_succeeded(genvm_no_stderr, match_std_err="anything") is False
300
+ assert tx_execution_failed(genvm_no_stderr, match_std_err="anything") is True
301
+
302
+
303
+ def test_failed_execution_with_genvm_result():
304
+ """Test assertion behavior with failed execution but present genvm_result.
305
+
306
+ Validates that:
307
+ - execution_result takes precedence over output matching
308
+ - Even with matching stdout/stderr, failed executions return False
309
+ - The basic execution status is checked before output matching
310
+ """
311
+ assert tx_execution_succeeded(GENLAYER_GENVM_FAILED) is False
312
+ assert tx_execution_failed(GENLAYER_GENVM_FAILED) is True
313
+
314
+ # Even with matching stdout/stderr, should still fail if execution_result is not SUCCESS
315
+ assert (
316
+ tx_execution_succeeded(GENLAYER_GENVM_FAILED, match_std_out="Process failed")
317
+ is False
318
+ )
319
+ assert (
320
+ tx_execution_succeeded(GENLAYER_GENVM_FAILED, match_std_err="Critical error")
321
+ is False
322
+ )
323
+
324
+
325
+ def test_missing_genvm_result_with_match():
326
+ """Test behavior when genvm_result is missing but match parameters are provided.
327
+
328
+ Validates that:
329
+ - Missing genvm_result causes output matching to fail
330
+ - Both stdout and stderr matching fail when genvm_result is absent
331
+ - tx_execution_failed returns True when match parameters are used without genvm_result
332
+ """
333
+ assert (
334
+ tx_execution_succeeded(GENLAYER_SUCCESS_TRANSACTION, match_std_out="anything")
335
+ is False
336
+ )
337
+ assert (
338
+ tx_execution_succeeded(GENLAYER_SUCCESS_TRANSACTION, match_std_err="anything")
339
+ is False
340
+ )
341
+ assert (
342
+ tx_execution_failed(GENLAYER_SUCCESS_TRANSACTION, match_std_out="anything")
343
+ is True
344
+ )
@@ -1,18 +0,0 @@
1
- from genlayer_py.types import GenLayerTransaction
2
-
3
-
4
- def tx_execution_succeeded(result: GenLayerTransaction) -> bool:
5
- if "consensus_data" not in result:
6
- return False
7
- if "leader_receipt" not in result["consensus_data"]:
8
- return False
9
- if len(result["consensus_data"]["leader_receipt"]) == 0:
10
- return False
11
- if "execution_result" not in result["consensus_data"]["leader_receipt"][0]:
12
- return False
13
- execution_result = result["consensus_data"]["leader_receipt"][0]["execution_result"]
14
- return execution_result == "SUCCESS"
15
-
16
-
17
- def tx_execution_failed(result: GenLayerTransaction) -> bool:
18
- return not tx_execution_succeeded(result)
@@ -1,31 +0,0 @@
1
- from gltest.assertions import tx_execution_succeeded, tx_execution_failed
2
-
3
- GENLAYER_SUCCESS_TRANSACTION = {
4
- "consensus_data": {"leader_receipt": [{"execution_result": "SUCCESS"}]}
5
- }
6
-
7
- GENLAYER_FAILED_TRANSACTION = {
8
- "consensus_data": {"leader_receipt": [{"execution_result": "ERROR"}]}
9
- }
10
-
11
- GENLAYER_EMPTY_LEADER_RECEIPT = {"consensus_data": {"leader_receipt": []}}
12
-
13
-
14
- def test_with_successful_transaction():
15
- assert tx_execution_succeeded(GENLAYER_SUCCESS_TRANSACTION) is True
16
- assert tx_execution_failed(GENLAYER_SUCCESS_TRANSACTION) is False
17
-
18
-
19
- def test_with_failed_transaction():
20
- assert tx_execution_succeeded(GENLAYER_FAILED_TRANSACTION) is False
21
- assert tx_execution_failed(GENLAYER_FAILED_TRANSACTION) is True
22
-
23
-
24
- def test_with_empty_leader_receipt():
25
- assert tx_execution_succeeded(GENLAYER_EMPTY_LEADER_RECEIPT) is False
26
- assert tx_execution_failed(GENLAYER_EMPTY_LEADER_RECEIPT) is True
27
-
28
-
29
- def test_with_invalid_transaction():
30
- assert tx_execution_succeeded({}) is False
31
- assert tx_execution_failed({}) is True
File without changes
File without changes