-
Notifications
You must be signed in to change notification settings - Fork 106
Single Asset Vault XLS-65d #814
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
Open
ckeshava
wants to merge
23
commits into
XRPLF:main
Choose a base branch
from
ckeshava:sav
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
f0a0f58
models for SAV transactions and requests
ckeshava e4e9ec5
initial framework of integration tests; definitions file
ckeshava 5d015a3
provide MPT support for SAV transaction fields
ckeshava 6ea3965
Test extreme values in the serialzation of STAmount
ckeshava f06f909
Problems in STAmount: Unable to (de)serialize extreme values
ckeshava 2858df2
[WIP] use struct library to pack Number data
ckeshava 3e86842
Merge remote-tracking branch 'upstream/main' into sav
ckeshava ea1ef24
[WIP] VaultClawback integ tests need to be completed; Errors regardin…
ckeshava 6966ae7
add integ test for VaultClawback transaction
ckeshava 24b4df0
Enforce proper serialization of Number types
ckeshava 3646909
docs explanation of transaction models
ckeshava 307c515
handle 0 case in Number type
ckeshava e97a4b7
simplify the extractNumberParts logic; Avoid using magic numbers;
ckeshava 1617cad
introduce model for MPTIssue
ckeshava 671690a
Update VaultCreate model to include Withdrawal Policy
ckeshava b09b37a
remove irrelevant tests for amount binary codec
ckeshava 537cc2f
reorder the REQUIRED fields to be at the top of the transactions mode…
ckeshava 6c4f801
pretty print of Number values
ckeshava 2765937
update the data member name of the MPTIssue class
ckeshava 18bfd1c
pacify linter errors
ckeshava f967f23
Update tests/unit/core/binarycodec/types/test_number.py
ckeshava eb78553
Accept mypy suggestions
ckeshava 4cb1d02
use custom method of Number class for debugging unit tests
ckeshava 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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 | |||||
|
||||||
### Added | ||||||
- Improved validation for models to also check param types | ||||||
- Support for Single Asset Vault (XLS-65d) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
## [4.1.0] - 2025-2-13 | ||||||
|
||||||
|
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 |
---|---|---|
@@ -0,0 +1,135 @@ | ||
from tests.integration.integration_test_case import IntegrationTestCase | ||
from tests.integration.it_utils import ( | ||
fund_wallet_async, | ||
sign_and_reliable_submission_async, | ||
test_async_and_sync, | ||
) | ||
from tests.integration.reusable_values import WALLET | ||
from xrpl.models import ( | ||
Payment, | ||
TrustSet, | ||
VaultClawback, | ||
VaultCreate, | ||
VaultDelete, | ||
VaultDeposit, | ||
VaultSet, | ||
VaultWithdraw, | ||
) | ||
from xrpl.models.amounts.issued_currency_amount import IssuedCurrencyAmount | ||
from xrpl.models.currencies import IssuedCurrency | ||
from xrpl.models.requests import AccountObjects | ||
from xrpl.models.requests.account_objects import AccountObjectType | ||
from xrpl.models.response import ResponseStatus | ||
from xrpl.utils import str_to_hex | ||
from xrpl.wallet import Wallet | ||
|
||
|
||
class TestSingleAssetVault(IntegrationTestCase): | ||
@test_async_and_sync(globals()) | ||
async def test_sav_lifecycle(self, client): | ||
|
||
vault_owner = Wallet.create() | ||
await fund_wallet_async(vault_owner) | ||
|
||
issuer_wallet = Wallet.create() | ||
await fund_wallet_async(issuer_wallet) | ||
|
||
# Step-0.a: Prerequisites: Set up the IOU trust line | ||
tx = TrustSet( | ||
account=WALLET.address, | ||
limit_amount=IssuedCurrencyAmount( | ||
currency="USD", issuer=issuer_wallet.address, value="1000" | ||
), | ||
) | ||
response = await sign_and_reliable_submission_async(tx, WALLET, client) | ||
self.assertEqual(response.status, ResponseStatus.SUCCESS) | ||
self.assertEqual(response.result["engine_result"], "tesSUCCESS") | ||
|
||
# Step-0.b: Send the payment of IOUs from issuer_wallet to WALLET | ||
tx = Payment( | ||
account=issuer_wallet.address, | ||
amount=IssuedCurrencyAmount( | ||
currency="USD", issuer=issuer_wallet.address, value="1000" | ||
), | ||
destination=WALLET.address, | ||
) | ||
response = await sign_and_reliable_submission_async(tx, issuer_wallet, client) | ||
self.assertEqual(response.status, ResponseStatus.SUCCESS) | ||
self.assertEqual(response.result["engine_result"], "tesSUCCESS") | ||
|
||
# Step-1: Create a vault | ||
tx = VaultCreate( | ||
account=vault_owner.address, | ||
asset=IssuedCurrency(currency="USD", issuer=issuer_wallet.address), | ||
asset_maximum="1000", | ||
withdrawal_policy=1, | ||
) | ||
response = await sign_and_reliable_submission_async(tx, vault_owner, client) | ||
self.assertEqual(response.status, ResponseStatus.SUCCESS) | ||
self.assertEqual(response.result["engine_result"], "tesSUCCESS") | ||
|
||
# Verify the existence of the vault with account_objects RPC call | ||
account_objects_response = await client.request( | ||
AccountObjects(account=vault_owner.address, type=AccountObjectType.VAULT) | ||
) | ||
self.assertEqual(len(account_objects_response.result["account_objects"]), 1) | ||
|
||
VAULT_ID = account_objects_response.result["account_objects"][0]["index"] | ||
ckeshava marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# Step-2: Update the characteristics of the vault with VaultSet transaction | ||
tx = VaultSet( | ||
account=vault_owner.address, | ||
vault_id=VAULT_ID, | ||
data=str_to_hex("auxilliary data pertaining to the vault"), | ||
) | ||
response = await sign_and_reliable_submission_async(tx, vault_owner, client) | ||
self.assertEqual(response.status, ResponseStatus.SUCCESS) | ||
self.assertEqual(response.result["engine_result"], "tesSUCCESS") | ||
|
||
# Step-3: Execute a VaultDeposit transaction | ||
tx = VaultDeposit( | ||
account=WALLET.address, | ||
vault_id=VAULT_ID, | ||
amount=IssuedCurrencyAmount( | ||
currency="USD", issuer=issuer_wallet.address, value="10" | ||
), | ||
) | ||
response = await sign_and_reliable_submission_async(tx, WALLET, client) | ||
self.assertEqual(response.status, ResponseStatus.SUCCESS) | ||
self.assertEqual(response.result["engine_result"], "tesSUCCESS") | ||
|
||
# Step-4: Execute a VaultWithdraw transaction | ||
tx = VaultWithdraw( | ||
account=WALLET.address, | ||
vault_id=VAULT_ID, | ||
amount=IssuedCurrencyAmount( | ||
currency="USD", issuer=issuer_wallet.address, value="9" | ||
), | ||
) | ||
response = await sign_and_reliable_submission_async(tx, WALLET, client) | ||
self.assertEqual(response.status, ResponseStatus.SUCCESS) | ||
self.assertEqual(response.result["engine_result"], "tesSUCCESS") | ||
|
||
# Step-5: Execute a VaultClawback transaction from issuer_wallet | ||
tx = VaultClawback( | ||
holder=WALLET.address, | ||
account=issuer_wallet.address, | ||
vault_id=VAULT_ID, | ||
# Note: Although the amount is specified as 9, 1 unit of the IOU will be | ||
# clawed back, because that is the remaining balance in the vault | ||
amount=IssuedCurrencyAmount( | ||
currency="USD", issuer=issuer_wallet.address, value="9" | ||
), | ||
) | ||
response = await sign_and_reliable_submission_async(tx, issuer_wallet, client) | ||
self.assertEqual(response.status, ResponseStatus.SUCCESS) | ||
self.assertEqual(response.result["engine_result"], "tesSUCCESS") | ||
|
||
# Step-6: Delete the Vault with VaultDelete transaction | ||
tx = VaultDelete( | ||
account=vault_owner.address, | ||
vault_id=VAULT_ID, | ||
) | ||
response = await sign_and_reliable_submission_async(tx, vault_owner, client) | ||
self.assertEqual(response.status, ResponseStatus.SUCCESS) | ||
self.assertEqual(response.result["engine_result"], "tesSUCCESS") |
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import unittest | ||
|
||
from xrpl.core.binarycodec.types.number import Number | ||
|
||
|
||
class TestNumber(unittest.TestCase): | ||
def test_serialization_and_deserialization(self): | ||
serialized_number = Number.from_value("124") | ||
self.assertEqual(serialized_number.to_json(), "124") | ||
|
||
serialized_number = Number.from_value("1000") | ||
self.assertEqual(serialized_number.to_json(), "1000") | ||
|
||
serialized_number = Number.from_value("0") | ||
self.assertEqual(serialized_number.to_json(), "0") | ||
|
||
serialized_number = Number.from_value("-1") | ||
self.assertEqual(serialized_number.to_json(), "-1") | ||
|
||
serialized_number = Number.from_value("-10") | ||
self.assertEqual(serialized_number.to_json(), "-10") | ||
|
||
serialized_number = Number.from_value("123.456") | ||
self.assertEqual(serialized_number.to_json(), "123.456") | ||
|
||
serialized_number = Number.from_value("1.456e-45") | ||
self.assertEqual(serialized_number.to_json(), "1456000000000000e-60") | ||
|
||
serialized_number = Number.from_value("0.456e34") | ||
self.assertEqual(serialized_number.to_json(), "4560000000000000e18") | ||
|
||
serialized_number = Number.from_value("4e34") | ||
self.assertEqual(serialized_number.to_json(), "4000000000000000e19") | ||
|
||
ckeshava marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def test_extreme_limits(self): | ||
lowest_mantissa = "-9223372036854776" | ||
serialized_number = Number.from_value(lowest_mantissa + "e3") | ||
self.assertEqual( | ||
serialized_number.display_serialized_hex(), "FFDF3B645A1CAC0800000003" | ||
) | ||
|
||
highest_mantissa = "9223372036854776" | ||
serialized_number = Number.from_value(highest_mantissa + "e3") | ||
self.assertEqual( | ||
serialized_number.display_serialized_hex(), "0020C49BA5E353F800000003" | ||
) |
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this all still a part of 2.3.0 (no new releases)?