-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for PriceOracle Amendment (XLS 47d) --------- Co-authored-by: Omar Khan <[email protected]> Co-authored-by: Mayukha Vadari <[email protected]> Co-authored-by: pdp2121 <[email protected]>
- Loading branch information
1 parent
260d7dc
commit 13e4012
Showing
21 changed files
with
1,020 additions
and
21 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import time | ||
|
||
from tests.integration.integration_test_case import IntegrationTestCase | ||
from tests.integration.it_utils import ( | ||
sign_and_reliable_submission_async, | ||
test_async_and_sync, | ||
) | ||
from tests.integration.reusable_values import WALLET | ||
from xrpl.models import AccountObjects, AccountObjectType, OracleDelete, OracleSet | ||
from xrpl.models.response import ResponseStatus | ||
from xrpl.models.transactions.oracle_set import PriceData | ||
from xrpl.utils import str_to_hex | ||
|
||
_PROVIDER = str_to_hex("chainlink") | ||
_ASSET_CLASS = str_to_hex("currency") | ||
|
||
|
||
class TestDeleteOracle(IntegrationTestCase): | ||
@test_async_and_sync(globals()) | ||
async def test_basic(self, client): | ||
oracle_id = self.value | ||
|
||
# Create PriceOracle, to be deleted later | ||
tx = OracleSet( | ||
account=WALLET.address, | ||
# unlike the integration tests for OracleSet transaction, we do not have to | ||
# dynamically change the oracle_document_id for these integration tests. | ||
# This is because the Oracle LedgerObject is deleted by the end of the test. | ||
oracle_document_id=oracle_id, | ||
provider=_PROVIDER, | ||
asset_class=_ASSET_CLASS, | ||
last_update_time=int(time.time()), | ||
price_data_series=[ | ||
PriceData( | ||
base_asset="XRP", quote_asset="USD", asset_price=740, scale=1 | ||
), | ||
PriceData( | ||
base_asset="BTC", quote_asset="EUR", asset_price=100, scale=2 | ||
), | ||
], | ||
) | ||
response = await sign_and_reliable_submission_async(tx, WALLET, client) | ||
self.assertEqual(response.status, ResponseStatus.SUCCESS) | ||
self.assertEqual(response.result["engine_result"], "tesSUCCESS") | ||
|
||
# Create PriceOracle to delete | ||
tx = OracleDelete( | ||
account=WALLET.address, | ||
oracle_document_id=oracle_id, | ||
) | ||
response = await sign_and_reliable_submission_async(tx, WALLET, client) | ||
self.assertEqual(response.status, ResponseStatus.SUCCESS) | ||
self.assertEqual(response.result["engine_result"], "tesSUCCESS") | ||
|
||
# confirm that the PriceOracle was actually deleted | ||
account_objects_response = await client.request( | ||
AccountObjects(account=WALLET.address, type=AccountObjectType.ORACLE) | ||
) | ||
self.assertEqual(len(account_objects_response.result["account_objects"]), 0) |
This file contains 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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import time | ||
|
||
from tests.integration.integration_test_case import IntegrationTestCase | ||
from tests.integration.it_utils import ( | ||
sign_and_reliable_submission_async, | ||
test_async_and_sync, | ||
) | ||
from tests.integration.reusable_values import WALLET | ||
from xrpl.models import AccountObjects, AccountObjectType, OracleSet | ||
from xrpl.models.response import ResponseStatus | ||
from xrpl.models.transactions.oracle_set import PriceData | ||
from xrpl.utils import str_to_hex | ||
|
||
_PROVIDER = str_to_hex("provider") | ||
_ASSET_CLASS = str_to_hex("currency") | ||
|
||
|
||
class TestSetOracle(IntegrationTestCase): | ||
@test_async_and_sync(globals()) | ||
async def test_all_fields(self, client): | ||
tx = OracleSet( | ||
account=WALLET.address, | ||
# if oracle_document_id is not modified, the (sync, async) + | ||
# (json, websocket) combination of integration tests will update the same | ||
# oracle object using identical "LastUpdateTime". Updates to an oracle must | ||
# be more recent than its previous LastUpdateTime | ||
# a unique value is obtained for each combination of test run within the | ||
# implementation of the test_async_and_sync decorator. | ||
oracle_document_id=self.value, | ||
provider=_PROVIDER, | ||
asset_class=_ASSET_CLASS, | ||
last_update_time=int(time.time()), | ||
price_data_series=[ | ||
PriceData( | ||
base_asset="XRP", quote_asset="USD", asset_price=740, scale=1 | ||
), | ||
PriceData( | ||
base_asset="BTC", quote_asset="EUR", asset_price=100, scale=2 | ||
), | ||
], | ||
) | ||
response = await sign_and_reliable_submission_async(tx, WALLET, client) | ||
self.assertEqual(response.status, ResponseStatus.SUCCESS) | ||
self.assertEqual(response.result["engine_result"], "tesSUCCESS") | ||
|
||
# confirm that the PriceOracle was actually created | ||
account_objects_response = await client.request( | ||
AccountObjects(account=WALLET.address, type=AccountObjectType.ORACLE) | ||
) | ||
|
||
# subsequent integration tests (sync/async + json/websocket) add one | ||
# oracle object to the account | ||
self.assertTrue(len(account_objects_response.result["account_objects"]) > 0) |
This file contains 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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
from unittest import TestCase | ||
|
||
from xrpl.models import XRPLModelException | ||
from xrpl.models.requests import GetAggregatePrice | ||
from xrpl.models.requests.get_aggregate_price import Oracle | ||
|
||
_ACCT_STR_1 = "rBwHKFS534tfG3mATXSycCnX8PAd3XJswj" | ||
_ORACLE_DOC_ID_1 = 1 | ||
|
||
_ACCT_STR_2 = "rDMKwhm13oJBxBgiWS2SheZhKT5nZP8kez" | ||
_ORACLE_DOC_ID_2 = 2 | ||
|
||
|
||
class TestGetAggregatePrice(TestCase): | ||
def test_invalid_requests(self): | ||
"""Unit test to validate invalid requests""" | ||
with self.assertRaises(XRPLModelException): | ||
# oracles array must contain at least one element | ||
GetAggregatePrice( | ||
base_asset="USD", | ||
quote_asset="XRP", | ||
oracles=[], | ||
) | ||
|
||
with self.assertRaises(XRPLModelException): | ||
# base_asset is missing in the request | ||
GetAggregatePrice( | ||
quote_asset="XRP", | ||
oracles=[ | ||
Oracle(account=_ACCT_STR_1, oracle_document_id=_ORACLE_DOC_ID_1), | ||
Oracle(account=_ACCT_STR_2, oracle_document_id=_ORACLE_DOC_ID_2), | ||
], | ||
) | ||
|
||
with self.assertRaises(XRPLModelException): | ||
# quote_asset is missing in the request | ||
GetAggregatePrice( | ||
base_asset="USD", | ||
oracles=[ | ||
Oracle(account=_ACCT_STR_1, oracle_document_id=_ORACLE_DOC_ID_1), | ||
Oracle(account=_ACCT_STR_2, oracle_document_id=_ORACLE_DOC_ID_2), | ||
], | ||
) | ||
|
||
def test_valid_request(self): | ||
"""Unit test for validating archetypical requests""" | ||
request = GetAggregatePrice( | ||
base_asset="USD", | ||
quote_asset="XRP", | ||
oracles=[ | ||
Oracle(account=_ACCT_STR_1, oracle_document_id=_ORACLE_DOC_ID_1), | ||
Oracle(account=_ACCT_STR_2, oracle_document_id=_ORACLE_DOC_ID_2), | ||
], | ||
) | ||
self.assertTrue(request.is_valid()) | ||
|
||
# specifying trim and time_threshold value | ||
request = GetAggregatePrice( | ||
base_asset="USD", | ||
quote_asset="XRP", | ||
oracles=[ | ||
Oracle(account=_ACCT_STR_1, oracle_document_id=_ORACLE_DOC_ID_1), | ||
Oracle(account=_ACCT_STR_2, oracle_document_id=_ORACLE_DOC_ID_2), | ||
], | ||
trim=20, | ||
time_threshold=10, | ||
) | ||
self.assertTrue(request.is_valid()) |
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from unittest import TestCase | ||
|
||
from xrpl.models.transactions import OracleDelete | ||
|
||
_ACCOUNT = "rsA2LpzuawewSBQXkiju3YQTMzW13pAAdW" | ||
|
||
|
||
class TestDeleteOracle(TestCase): | ||
def test_valid(self): | ||
tx = OracleDelete( | ||
account=_ACCOUNT, | ||
oracle_document_id=1, | ||
) | ||
self.assertTrue(tx.is_valid()) |
Oops, something went wrong.