Repository navigation
feat: add match argument in tx execution succeeded and failed - #24
cristiam86 merged 6 commits into
Conversation
DXP-301 Add match argument in tx_execution_succeeded and tx_execution_failed functions
Allow to test with std_err and std_out match operator Note: only available for localnet |
## Walkthrough
The changes update the transaction assertion functions to support optional matching of stdout and stderr outputs using strings or regex patterns. Documentation in the README is expanded to explain these new features, and comprehensive tests are added to validate the extended assertion logic. The project version is incremented.
## Changes
| File(s) | Change Summary |
|----------------------------------------------|-----------------------------------------------------------------------------------------------------|
| README.md | Added documentation for new assertion features, including usage examples and parameter descriptions.|
| gltest/assertions.py | Extended `tx_execution_succeeded` and `tx_execution_failed` to support optional stdout/stderr matching.|
| tests/assertions/test_assertions.py | Added extensive tests covering new output matching scenarios and edge cases. |
| pyproject.toml | Updated project version from 0.1.2 to 0.1.3 and raised minimum Python version to 3.12. |
| gltest/artifacts/contract.py | Generalized docstring for `ContractDefinition` to refer to any contract file instead of `.gpy`. |
## Sequence Diagram(s)
```mermaid
sequenceDiagram
participant Test as Test Suite
participant Assertions as assertions.py
participant Tx as GenLayerTransaction
Test->>Assertions: tx_execution_succeeded(Tx, match_std_out, match_std_err)
Assertions->>Tx: Check execution result status
alt match_std_out or match_std_err provided
Assertions->>Tx: Check for genvm_result
alt genvm_result present
Assertions->>Tx: Match stdout/stderr with pattern(s)
alt All matches succeed
Assertions-->>Test: Return True
else Any match fails
Assertions-->>Test: Return False
end
else genvm_result missing
Assertions-->>Test: Return False
end
else
Assertions-->>Test: Return status check result
endPossibly related PRs
Suggested reviewers
Poem
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
gltest/assertions.py (1)
6-46: Consider refactoring to reduce complexity.The static analysis correctly identifies high cyclomatic complexity. Consider extracting the output matching logic into a separate helper function to improve readability and maintainability.
def _validate_output_match(genvm_result: dict, match_std_out: Optional[str], match_std_err: Optional[str]) -> bool: """Helper function to validate output matching.""" if match_std_out is not None: if "stdout" not in genvm_result: return False try: if not re.search(match_std_out, genvm_result["stdout"]): return False except re.error: return False if match_std_err is not None: if "stderr" not in genvm_result: return False try: if not re.search(match_std_err, genvm_result["stderr"]): return False except re.error: return False return True def tx_execution_succeeded( result: GenLayerTransaction, match_std_out: Optional[str] = None, match_std_err: Optional[str] = None, ) -> bool: # Basic validation logic... if execution_result != "SUCCESS": return False if match_std_out is not None or match_std_err is not None: if "genvm_result" not in leader_receipt: return False return _validate_output_match(leader_receipt["genvm_result"], match_std_out, match_std_err) return True🧰 Tools
🪛 Pylint (3.3.7)
[refactor] 6-6: Too many return statements (11/6)
(R0911)
[refactor] 6-6: Too many branches (13/12)
(R0912)
README.md (1)
293-293: Minor formatting improvement for parameter list.Consider adjusting the punctuation formatting for the parameter list to improve readability.
-Both `tx_execution_succeeded` and `tx_execution_failed` accept the following parameters: -- `result`: The transaction result object from contract method calls +Both `tx_execution_succeeded` and `tx_execution_failed` accept the following parameters: +- `result`: The transaction result object from contract method calls🧰 Tools
🪛 LanguageTool
[uncategorized] ~293-~293: Loose punctuation mark.
Context: ...pt the following parameters: -result: The transaction result object from cont...(UNLIKELY_OPENING_PUNCTUATION)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
README.md(1 hunks)gltest/assertions.py(1 hunks)pyproject.toml(1 hunks)tests/assertions/test_assertions.py(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
tests/assertions/test_assertions.py (1)
gltest/assertions.py (2)
tx_execution_succeeded(6-46)tx_execution_failed(49-54)
🪛 LanguageTool
README.md
[uncategorized] ~293-~293: Loose punctuation mark.
Context: ...pt the following parameters: - result: The transaction result object from cont...
(UNLIKELY_OPENING_PUNCTUATION)
🪛 Pylint (3.3.7)
gltest/assertions.py
[refactor] 6-6: Too many return statements (11/6)
(R0911)
[refactor] 6-6: Too many branches (13/12)
(R0912)
🔇 Additional comments (7)
pyproject.toml (1)
7-7: LGTM: Appropriate version bump for feature addition.The version increment from 0.1.2 to 0.1.3 correctly reflects the addition of new assertion functionality.
gltest/assertions.py (3)
1-2: LGTM: Appropriate imports for new functionality.The
reimport for regex matching andOptionalfor type hints are correctly added to support the new output matching features.
6-10: LGTM: Well-designed function signature extension.The optional parameters with default
Nonevalues maintain backward compatibility while enabling the new output matching functionality.🧰 Tools
🪛 Pylint (3.3.7)
[refactor] 6-6: Too many return statements (11/6)
(R0911)
[refactor] 6-6: Too many branches (13/12)
(R0912)
49-54: LGTM: Elegant implementation using negation.The
tx_execution_failedfunction correctly delegates totx_execution_succeededand negates the result, ensuring consistent behavior between the two functions.README.md (1)
261-298: LGTM: Comprehensive documentation for new assertion features.The new "Assertions" section provides excellent documentation with clear examples for both basic usage and advanced output matching. The environment compatibility note is particularly valuable for users.
🧰 Tools
🪛 LanguageTool
[uncategorized] ~293-~293: Loose punctuation mark.
Context: ...pt the following parameters: -result: The transaction result object from cont...(UNLIKELY_OPENING_PUNCTUATION)
tests/assertions/test_assertions.py (2)
13-64: LGTM: Well-designed test fixtures covering diverse scenarios.The test fixtures comprehensively cover various transaction structures including successful/failed executions, different genvm_result configurations, empty fields, and missing fields. This provides excellent foundation for thorough testing.
111-344: LGTM: Comprehensive test coverage for new assertion functionality.The test suite excellently validates all aspects of the new output matching features:
- Basic success/failure scenarios without output matching
- Simple string and regex pattern matching for both stdout and stderr
- Combined stdout/stderr matching
- Edge cases like empty fields and missing genvm_result
- Proper precedence of execution_result over output matching
- Error handling for missing fields
The test organization with clear docstrings and descriptive test names makes the test suite very maintainable.
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Fixes DXP-301
Fixes DXP-319
What
match_std_outandmatch_std_errarguments to bothtx_execution_succeededandtx_execution_failedSummary by CodeRabbit
Summary by CodeRabbit
New Features
Documentation
Tests
Chores