Skip to content

Commit

Permalink
fix bug in GenericRequest.to_dict() (#391)
Browse files Browse the repository at this point in the history
  • Loading branch information
khancode committed May 24, 2022
1 parent f404ee9 commit 5a784b0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
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 bug in GenericRequest.to_dict()

## [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):
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

0 comments on commit 5a784b0

Please sign in to comment.