genlayer-test 0.1.1__py3-none-any.whl → 0.1.3__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,22 +1,20 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: genlayer-test
3
- Version: 0.1.1
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
19
- Requires-Dist: genlayer-py==0.1.0
17
+ Requires-Dist: genlayer-py==0.3.0
20
18
  Dynamic: license-file
21
19
 
22
20
  # GenLayer Testing Suite
@@ -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,12 +1,12 @@
1
- genlayer_test-0.1.1.dist-info/licenses/LICENSE,sha256=che_H4vE0QUx3HvWrAa1_jDEVInift0U6VO15-QqEls,1064
1
+ genlayer_test-0.1.3.dist-info/licenses/LICENSE,sha256=che_H4vE0QUx3HvWrAa1_jDEVInift0U6VO15-QqEls,1064
2
2
  gltest/__init__.py,sha256=AK_YfRvwlhrOheOelUG8qIRG17on0-nFCF747dopg2w,332
3
- gltest/assertions.py,sha256=O9pHt9aOxMVYk_C2fF2-qzT_xYMaK0YigR3HXeejmaU,590
3
+ gltest/assertions.py,sha256=0dEk0VxcHK4I7GZPHxJmz-2jaA60V499gOSR74rZbfM,1748
4
4
  gltest/exceptions.py,sha256=deJPmrTe5gF33qkkKF2IVJY7lc_knI7Ql3N7jZ8aLZs,510
5
5
  gltest/plugin_config.py,sha256=8Z97RtEJ89OcRbki_oRuBBVct_q56BFmKvthan1y9Y4,840
6
6
  gltest/plugin_hooks.py,sha256=py1rzIR9QSsFOt8SEePPL96e-8DeiPFxvcPZurRlExM,1436
7
7
  gltest/types.py,sha256=BODmwTr2gAUEiO9FjiuTiWwuKvXgo4xZWstQWNUfnlw,156
8
8
  gltest/artifacts/__init__.py,sha256=qiJN5F1cVh_3fmxZeDFznoABxAdLhLqBfUUKwqXqvgo,87
9
- gltest/artifacts/contract.py,sha256=CBRfUTltKv2tPy--LcmVbP_4hbXYt9VrunvJlMzNd5s,3566
9
+ gltest/artifacts/contract.py,sha256=0Sp8YTKBw7hwuhIQ7Q-PnchxNfusF0HNAcWaWPWT9Cg,3570
10
10
  gltest/glchain/__init__.py,sha256=X-mEbREoAOe9K4n74C55gCiXH4wItzY5HTJcg3_F3mI,412
11
11
  gltest/glchain/account.py,sha256=ZxYsfbtBXKVC5vV4pko3yyL6lhPljqIb68NgIgvInSc,403
12
12
  gltest/glchain/client.py,sha256=q04LIQy5SCIrYZflZiTapfeQ-AaSTa0w369ehnVbJLM,532
@@ -17,6 +17,7 @@ gltest/helpers/take_snapshot.py,sha256=eXqEKXM2hcox3pLGIcNddobU8zXPQvD-Iwf87eHqW
17
17
  gltest_cli/main.py,sha256=Ti2-0Ev1x5_cM0D1UKqdgaDt80CDHEQGtdRne2qLm4M,53
18
18
  tests/artifact/test_contract_definition.py,sha256=8X829MsNfEObtIMmotk6nRVLDEp5KfJE6zrAK4IPfCc,3323
19
19
  tests/artifact/contracts/not_ic_contract.py,sha256=hQyGnYiiVceYdLI2WrvcFgPqzy1S4-YMb9FPhiHEGSA,510
20
+ tests/assertions/test_assertions.py,sha256=qzVrOdOM4xYtIy1sFHVAD_-naDHOequ23tEN0MELh0k,10781
20
21
  tests/examples/contracts/football_prediction_market.py,sha256=kdouFijjeCdIJyaVJlgXcqbBAXecA9_YdhklSsIW-QM,3219
21
22
  tests/examples/contracts/intelligent_oracle.py,sha256=WrNZWWoi1sz22Azt2EXgdWHDg5Ihca2pWUHrM9pVfQE,12319
22
23
  tests/examples/contracts/intelligent_oracle_factory.py,sha256=ax496IZuDCA728rRcbjwTaM4Q4E-Y1jGkHsEcyf1cig,1490
@@ -45,8 +46,8 @@ tests/examples/tests/test_user_storage.py,sha256=QEgt2p22LAyzBnBb0YW4BWa_Jasrt15
45
46
  tests/examples/tests/test_wizard_of_coin.py,sha256=aUDeV5w0XONMMS71Vzw80lHfcSM0z8RKPJSXAuDwRto,392
46
47
  tests/plugin/conftest.py,sha256=RKdoE5_zcMimeojAoA_GSFI9du4pMzMi1vZ1njtfoAs,28
47
48
  tests/plugin/test_plugin_hooks.py,sha256=FQOrkhoXLinq0sjvoYjr63Oqg-ZVPcNFeUrK4bqrn4E,2020
48
- genlayer_test-0.1.1.dist-info/METADATA,sha256=SLlBr5OZZWmgBKAfkz889L-k7mMYX92PFyiCjK67oVQ,13471
49
- genlayer_test-0.1.1.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
50
- genlayer_test-0.1.1.dist-info/entry_points.txt,sha256=rXhrPVq2IhVsd4uWzxzwCTx7jA1KcQIVNxDCUuxq4f8,89
51
- genlayer_test-0.1.1.dist-info/top_level.txt,sha256=-qiGZxTRBytujzgVcKpxjvQ-WNeUDjXa59ceGMwMpko,24
52
- genlayer_test-0.1.1.dist-info/RECORD,,
49
+ genlayer_test-0.1.3.dist-info/METADATA,sha256=10N09rjm2S2uoCmyyVu6A9hPuU6w2-_rP8jU4HYsNc0,14814
50
+ genlayer_test-0.1.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
51
+ genlayer_test-0.1.3.dist-info/entry_points.txt,sha256=rXhrPVq2IhVsd4uWzxzwCTx7jA1KcQIVNxDCUuxq4f8,89
52
+ genlayer_test-0.1.3.dist-info/top_level.txt,sha256=-qiGZxTRBytujzgVcKpxjvQ-WNeUDjXa59ceGMwMpko,24
53
+ genlayer_test-0.1.3.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.8.0)
2
+ Generator: setuptools (80.9.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -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]
gltest/assertions.py CHANGED
@@ -1,16 +1,59 @@
1
+ import re
2
+ from typing import Optional
1
3
  from genlayer_py.types import GenLayerTransaction
2
4
 
3
5
 
4
- def tx_execution_succeeded(result: GenLayerTransaction) -> bool:
6
+ def tx_execution_succeeded(
7
+ result: GenLayerTransaction,
8
+ match_std_out: Optional[str] = None,
9
+ match_std_err: Optional[str] = None,
10
+ ) -> bool:
5
11
  if "consensus_data" not in result:
6
12
  return False
7
13
  if "leader_receipt" not in result["consensus_data"]:
8
14
  return False
9
- if "execution_result" not in result["consensus_data"]["leader_receipt"]:
15
+ if len(result["consensus_data"]["leader_receipt"]) == 0:
10
16
  return False
11
- execution_result = result["consensus_data"]["leader_receipt"]["execution_result"]
12
- return execution_result == "SUCCESS"
13
17
 
18
+ leader_receipt = result["consensus_data"]["leader_receipt"][0]
14
19
 
15
- def tx_execution_failed(result: GenLayerTransaction) -> bool:
16
- return not tx_execution_succeeded(result)
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)
@@ -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
+ )