Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error messages for DryRunInspector.from_single_response() #12

Merged
merged 2 commits into from
May 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<!-- markdownlint-disable MD024 -->
# Changelog

## `v0.1.2`

### Fixed

* Misleading error message in the case of an erroring dry run response

## `v0.1.1`

### Added
Expand Down
3 changes: 3 additions & 0 deletions graviton/blackbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,9 @@ def get_txn_mode(cls, txn: dict) -> ExecutionMode:

@classmethod
def from_single_response(cls, dryrun_resp: dict) -> "DryRunInspector":
error = dryrun_resp.get("error")
assert not error, f"dryrun response included the following error: [{error}]"

txns = dryrun_resp.get("txns") or []
assert (
len(txns) == 1
Expand Down
70 changes: 70 additions & 0 deletions tests/unit/inspector_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import pytest

from graviton.blackbox import DryRunInspector


def test_from_single_response_errors():
error_resp = {
"error": "dryrun Source[0]: 1 error",
"protocol-version": "future",
"txns": None,
}

with pytest.raises(AssertionError) as ae:
DryRunInspector.from_single_response(error_resp)

assert (
ae.value.args[0]
== "dryrun response included the following error: [dryrun Source[0]: 1 error]"
)

no_txns_resp1 = {
"error": None,
"protocol-version": "future",
"txns": None,
}

with pytest.raises(AssertionError) as ae:
DryRunInspector.from_single_response(no_txns_resp1)

assert (
ae.value.args[0]
== "require exactly 1 dry run transaction to create a singleton but had 0 instead"
)

no_txns_resp2 = {
"protocol-version": "future",
"txns": None,
}

with pytest.raises(AssertionError) as ae:
DryRunInspector.from_single_response(no_txns_resp2)

assert (
ae.value.args[0]
== "require exactly 1 dry run transaction to create a singleton but had 0 instead"
)

too_many_txns_resp = {"protocol-version": "future", "txns": [1, 2, 3]}

with pytest.raises(AssertionError) as ae:
DryRunInspector.from_single_response(too_many_txns_resp)

assert (
ae.value.args[0]
== "require exactly 1 dry run transaction to create a singleton but had 3 instead"
)

too_many_txns_resp_w_err = {
"error": "this is REALLLY REALLY BAD!!!",
"protocol-version": "future",
"txns": [1, 2, 3],
}

with pytest.raises(AssertionError) as ae:
DryRunInspector.from_single_response(too_many_txns_resp_w_err)

assert (
ae.value.args[0]
== "dryrun response included the following error: [this is REALLLY REALLY BAD!!!]"
)
2 changes: 0 additions & 2 deletions tests/unit/sanity_test.py

This file was deleted.