-
Notifications
You must be signed in to change notification settings - Fork 110
refactor: improve Request.from_dict
to have fewer exceptions to the rule
#726
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
Merged
Merged
Changes from 21 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
5a3ba97
improve Request.from_dict
mvadari b16e842
update changelog
mvadari c160a6e
better erroring for amm_info
mvadari de91678
improve generalization
mvadari 0673861
complete codecov
mvadari 0eb6241
add TODO
mvadari 3160497
remove commented out code
mvadari 2228ee1
clean up
mvadari 14e76f6
improve comment
mvadari a3d68d4
fix(?) flakiness in snippet
mvadari c8dc831
improve comment
mvadari 3982553
fix nft_history
mvadari 45f1366
Merge branch 'main' into request-from-dict
mvadari e309bbb
fix error message
mvadari 1946b65
alphabetize
mvadari 1d67dd5
Merge branch 'main' into request-from-dict
mvadari a8d3c9d
Merge branch 'main' into request-from-dict
mvadari 6d4fdbc
Merge branch 'main' into request-from-dict
mvadari aad0a68
Merge branch 'main' into request-from-dict
mvadari 2b2319a
Merge branch 'main' into request-from-dict
mvadari 8d155b8
Merge branch 'main' into request-from-dict
mvadari 6b1074d
Merge branch 'main' into request-from-dict
mvadari 9d994d7
Merge branch 'main' into request-from-dict
mvadari 3fd5a38
Merge branch 'main' into request-from-dict
mvadari 6b2dd0e
Merge branch 'main' into request-from-dict
mvadari 6adc111
Merge branch 'main' into request-from-dict
mvadari b54c7c7
Merge branch 'main' into request-from-dict
mvadari e118125
Merge branch 'main' into request-from-dict
mvadari d66ef4a
Merge branch 'main' into request-from-dict
mvadari 343d6ae
Merge branch 'main' into request-from-dict
mvadari 01ea00b
Merge branch 'main' into request-from-dict
mvadari 0538032
Merge branch 'main' into request-from-dict
mvadari 0aa8488
Merge branch 'main' into request-from-dict
mvadari 3c9d7b6
improve changelog
mvadari 31da90a
Merge branch 'main' into request-from-dict
mvadari e7d148b
Merge branch 'main' into request-from-dict
mvadari File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,101 @@ | ||
from unittest import TestCase | ||
|
||
from xrpl.models.requests import Fee, GenericRequest | ||
from xrpl.models.exceptions import XRPLModelException | ||
from xrpl.models.requests import Fee, GenericRequest, Request | ||
from xrpl.models.requests.request import _DEFAULT_API_VERSION | ||
|
||
|
||
class TestRequest(TestCase): | ||
def test_to_dict_includes_method_as_string(self): | ||
tx = Fee() | ||
value = tx.to_dict()["method"] | ||
req = Fee() | ||
value = req.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, "api_version": _DEFAULT_API_VERSION} | ||
) | ||
req = GenericRequest(command=command).to_dict() | ||
expected = {**req, "api_version": _DEFAULT_API_VERSION} | ||
self.assertDictEqual(req, expected) | ||
mvadari marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def test_from_dict(self): | ||
req = {"method": "account_tx", "account": "rN6zcSynkRnf8zcgTVrRL8K7r4ovE7J4Zj"} | ||
obj = Request.from_dict(req) | ||
self.assertEqual(obj.__class__.__name__, "AccountTx") | ||
expected = { | ||
**req, | ||
"binary": False, | ||
"forward": False, | ||
"api_version": _DEFAULT_API_VERSION, | ||
} | ||
self.assertDictEqual(obj.to_dict(), expected) | ||
|
||
def test_from_dict_no_method(self): | ||
req = {"account": "rN6zcSynkRnf8zcgTVrRL8K7r4ovE7J4Zj"} | ||
with self.assertRaises(XRPLModelException): | ||
Request.from_dict(req) | ||
|
||
def test_from_dict_wrong_method(self): | ||
req = {"method": "account_tx"} | ||
with self.assertRaises(XRPLModelException): | ||
Fee.from_dict(req) | ||
|
||
def test_from_dict_noripple_check(self): | ||
req = { | ||
"method": "noripple_check", | ||
"account": "rN6zcSynkRnf8zcgTVrRL8K7r4ovE7J4Zj", | ||
"role": "user", | ||
} | ||
obj = Request.from_dict(req) | ||
self.assertEqual(obj.__class__.__name__, "NoRippleCheck") | ||
expected = { | ||
**req, | ||
"transactions": False, | ||
"limit": 300, | ||
"api_version": _DEFAULT_API_VERSION, | ||
} | ||
self.assertDictEqual(obj.to_dict(), expected) | ||
|
||
def test_from_dict_account_nfts(self): | ||
req = { | ||
"method": "account_nfts", | ||
"account": "rN6zcSynkRnf8zcgTVrRL8K7r4ovE7J4Zj", | ||
} | ||
obj = Request.from_dict(req) | ||
expected = {**req, "api_version": _DEFAULT_API_VERSION} | ||
self.assertEqual(obj.__class__.__name__, "AccountNFTs") | ||
self.assertDictEqual(obj.to_dict(), expected) | ||
|
||
def test_from_dict_amm_info(self): | ||
req = { | ||
"method": "amm_info", | ||
"amm_account": "rN6zcSynkRnf8zcgTVrRL8K7r4ovE7J4Zj", | ||
} | ||
obj = Request.from_dict(req) | ||
expected = {**req, "api_version": _DEFAULT_API_VERSION} | ||
self.assertEqual(obj.__class__.__name__, "AMMInfo") | ||
self.assertDictEqual(obj.to_dict(), expected) | ||
|
||
mvadari marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def test_from_dict_nft_history(self): | ||
req = { | ||
"method": "nft_history", | ||
"nft_id": "00000000", | ||
} | ||
obj = Request.from_dict(req) | ||
expected = { | ||
**req, | ||
"binary": False, | ||
"forward": False, | ||
"api_version": _DEFAULT_API_VERSION, | ||
} | ||
self.assertEqual(obj.__class__.__name__, "NFTHistory") | ||
self.assertDictEqual(obj.to_dict(), expected) | ||
|
||
mvadari marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def test_from_dict_generic_request(self): | ||
req = { | ||
"method": "tx_history", | ||
"start": 0, | ||
} | ||
obj = Request.from_dict(req) | ||
expected = {**req, "api_version": _DEFAULT_API_VERSION} | ||
self.assertEqual(obj.__class__.__name__, "GenericRequest") | ||
self.assertDictEqual(obj.to_dict(), expected) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.