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

fix bug in GenericRequest.to_dict() #391

Merged
merged 5 commits into from
May 24, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Resolve `txnNotFound` error with `send_reliable_submission` when waiting for a submitted malformed transaction
- Small typing mistake in GenericRequest
- Fix GenericRequest initialization bug

## [1.5.0] - 2022-04-25
### Added
Expand Down
7 changes: 6 additions & 1 deletion tests/unit/models/requests/test_requests.py
@@ -1,10 +1,15 @@
from unittest import TestCase

from xrpl.models.requests import Fee
from xrpl.models.requests import Fee, GenericRequest


class TestRequest(TestCase):
def test_to_dict_includes_method_as_string(self):
tx = Fee()
value = tx.to_dict()["method"]
self.assertEqual(type(value), str)

def test_generic_request_to_dict_sets_command_as_method(self):
khancode marked this conversation as resolved.
Show resolved Hide resolved
command = "validator_list_sites"
tx = GenericRequest(command=command).to_dict()
self.assertDictEqual(tx, {"method": command})
8 changes: 7 additions & 1 deletion xrpl/models/requests/generic_request.py
Expand Up @@ -79,8 +79,14 @@ def to_dict(self: GenericRequest) -> Dict[str, Any]:
"""
# uses self.__dict__ instead of self.__dataclass_fields__.keys(), which is what
# the other models do, because this model doesn't have any dataclass fields
return {
dict = {
key: self._to_dict_elem(getattr(self, key))
for key in self.__dict__
if getattr(self, key) is not None
}

if "command" in dict:
dict["method"] = dict["command"]
del dict["command"]

return dict