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

feat: Multi-Purpose Tokens (MPT) #732

Merged
merged 66 commits into from
Dec 12, 2024
Merged
Changes from 1 commit
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
3bde9eb
update definitions
khancode Jul 15, 2024
5051728
add MPTokenIssuanceCreate
khancode Jul 19, 2024
0510c09
update CHANGELOG
khancode Jul 19, 2024
b048781
remove redundant account
khancode Jul 19, 2024
6993c1b
add int to hex util and MPTokenIssuanceCreate integ test (commented)
khancode Jul 23, 2024
2a5bcb8
fix lint error
khancode Jul 23, 2024
c793141
fix return types of int_conversions
khancode Jul 23, 2024
9fdee49
add MPTAmount support in Payment tx and binary-codec
khancode Aug 14, 2024
0566f25
fix Self import in MPTAmount
khancode Aug 14, 2024
bc6ea59
Revert "fix Self import in MPTAmount"
khancode Aug 14, 2024
6a55a1d
Revert "add MPTAmount support in Payment tx and binary-codec"
khancode Aug 14, 2024
1d75779
use Python ^3.11 and poetry update dependencies
khancode Aug 14, 2024
54471cd
Revert "use Python ^3.11 and poetry update dependencies"
khancode Aug 14, 2024
84421b6
use Python ^3.10 and poetry update dependencies
khancode Aug 14, 2024
88c6f32
Revert "use Python ^3.10 and poetry update dependencies"
khancode Aug 14, 2024
76de09f
remove Python 3.7 support to fix dependency installation and use 3.8 …
khancode Aug 14, 2024
af6ee29
remove python 3.7 from unit test; part of #737
khancode Aug 14, 2024
a995cf1
Revert "Revert "add MPTAmount support in Payment tx and binary-codec""
khancode Aug 14, 2024
dbeb5e7
Revert "Revert "fix Self import in MPTAmount""
khancode Aug 14, 2024
71de9df
resolve lint errors
khancode Aug 14, 2024
8cbf809
resolve mypy errors
khancode Aug 15, 2024
5c14d23
Merge branch 'main' into mpt
khancode Aug 15, 2024
c1a9b4d
add MPTokenAuthorize tx
khancode Aug 18, 2024
75ada8b
fix lint error
khancode Aug 18, 2024
5c1bd40
fix lint on REQUIRED
khancode Aug 18, 2024
e5ebdcd
add mpt_issuance and mptoken to ledger entries
khancode Aug 18, 2024
2f4991d
add ledger entry tests
khancode Aug 18, 2024
715fb36
add MPT support to Clawback tx
khancode Aug 18, 2024
77e6951
add MPTokenIssuanceSet tx and fix imports
khancode Aug 18, 2024
0ae0bb5
add MPTokenIssuanceDestroy tx
khancode Aug 18, 2024
eda3fb7
update version to 4.0.0b0
khancode Aug 21, 2024
2a11523
update definitions
khancode Sep 19, 2024
aa8710b
bump version
khancode Sep 19, 2024
21c7c92
update definitions.json
khancode Oct 16, 2024
1d5a660
use base 10 serialization for all amount fields in MPT
khancode Oct 16, 2024
ed7e993
resolve lint errors
khancode Oct 16, 2024
a595e67
resolve more lint errors
khancode Oct 16, 2024
e256253
Merge branch 'main' into mpt
khancode Oct 16, 2024
02efe76
bump version
khancode Oct 16, 2024
68bc036
Merge branch 'main' into mpt
khancode Nov 11, 2024
200ccf7
update poetry.lock
khancode Nov 11, 2024
ac03053
update definitions, rename MPTokenHolder to Holder, remove LockedAmount
khancode Nov 11, 2024
0716f79
bump version to 4.0.0b3
khancode Nov 11, 2024
761e42d
Merge branch 'main' into mpt
khancode Nov 13, 2024
6e8b76f
fix definitions
khancode Nov 13, 2024
b39c1d0
Merge branch 'main' into mpt
khancode Dec 9, 2024
81e272e
set version to regular 4.0.0
khancode Dec 9, 2024
a8a25e3
update Docker image
khancode Dec 9, 2024
9ed5f8e
update docker run command
khancode Dec 9, 2024
4831a88
fix docker run command
khancode Dec 9, 2024
ec3fcf3
uncomment MPT integ tests
khancode Dec 9, 2024
ed88c61
Revert "uncomment MPT integ tests"
khancode Dec 10, 2024
20f6e56
uncomment issuance create integ test
khancode Dec 10, 2024
6e3ad2d
debug MaximumAmount base10 regex match
khancode Dec 10, 2024
0d7f384
fix field.name not passed in uint64
khancode Dec 10, 2024
bf85918
uncomment issuance destroy integ test
khancode Dec 10, 2024
f467d2d
uncomment authorize and issuance set integ tests
khancode Dec 10, 2024
b70414a
uncomment mpt payment integ test
khancode Dec 10, 2024
bf36ce0
uncomment mpt clawback integ test
khancode Dec 10, 2024
fdb43e3
fix test_clawback integ test
khancode Dec 10, 2024
babb8f9
fix mpt clawback integ test
khancode Dec 10, 2024
f05bca8
fix docstrings
khancode Dec 11, 2024
b7786c3
remove typo
khancode Dec 12, 2024
6eba955
add test to verify uint64 parsing
khancode Dec 12, 2024
a19326c
make error message more specific
khancode Dec 12, 2024
7e91c4c
add TODO comment for MPT balance
khancode Dec 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add MPTAmount support in Payment tx and binary-codec
khancode committed Aug 14, 2024

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
commit 9fdee49911f2391a08782836f37ace4df76fb514
52 changes: 52 additions & 0 deletions tests/integration/transactions/test_payment.py
Original file line number Diff line number Diff line change
@@ -4,9 +4,16 @@
test_async_and_sync,
)
from tests.integration.reusable_values import DESTINATION, WALLET

# from xrpl.models.amounts.mpt_amount import MPTAmount
from xrpl.models.exceptions import XRPLModelException

# from xrpl.models.requests.account_objects import AccountObjects, AccountObjectType
from xrpl.models.transactions import Payment

# from xrpl.models.transactions.mptoken_issuance_create import MPTokenIssuanceCreate
# from xrpl.utils import int_to_hex


class TestPayment(IntegrationTestCase):
@test_async_and_sync(globals())
@@ -134,3 +141,48 @@ async def test_deliver_max_alias_field(self, client):
client,
)
self.assertFalse(response.is_successful())

# TODO: uncomment test module when rippled Docker image supports MPT feature
# @test_async_and_sync(globals())
# async def test_mpt_payment(self, client):
# tx = MPTokenIssuanceCreate(
# account=WALLET.classic_address,
# maximum_amount=int_to_hex(9223372036854775807), # "7fffffffffffffff"
# asset_scale=2,
# )

# response = await sign_and_reliable_submission_async(
# tx,
# WALLET,
# client,
# )

# self.assertTrue(response.is_successful())
# self.assertEqual(response.result["engine_result"], "tesSUCCESS")

# # confirm MPTokenIssuance ledger object was created
# account_objects_response = await client.request(
# AccountObjects(
# account=WALLET.address, type=AccountObjectType.MPT_ISSUANCE
# )
# )

# # subsequent integration tests (sync/async + json/websocket) add one
# # MPTokenIssuance object to the account
# account_objects = account_objects_response.result["account_objects"]
# self.assertTrue(len(account_objects) > 0)

# mpt_issuance_id = account_objects[0]["mpt_issuance_id"]

# payment = Payment(
# account=WALLET.address,
# amount=MPTAmount(mpt_issuance_id=mpt_issuance_id, value="10"),
# destination=DESTINATION.address,
# )

# response = await sign_and_reliable_submission_async(
# payment,
# WALLET,
# client,
# )
# self.assertTrue(response.is_successful())
172 changes: 172 additions & 0 deletions tests/unit/core/binarycodec/fixtures/data/data-driven-tests.json
Original file line number Diff line number Diff line change
@@ -2762,6 +2762,14 @@
"expected_hex": "4000000000000001",
"is_negative": false
},
{
"test_json": "-1",
"type_id": 6,
"is_native": true,
"type": "Amount",
"error": "Value is negative",
"is_negative": true
},
{
"test_json": {
"currency": "USD",
@@ -3947,6 +3955,170 @@
"type_specialisation_field": "TransactionResult",
"type": "UInt8",
"expected_hex": "8D"
},
{
"test_json": {
"mpt_issuance_id": "00002403C84A0A28E0190E208E982C352BBD5006600555CF",
"value": "9223372036854775808"
},
"type": "Amount",
"error": "Value is too large"
},
{
"test_json": {
"mpt_issuance_id": "00002403C84A0A28E0190E208E982C352BBD5006600555CF",
"value": "18446744073709551615"
},
"type": "Amount",
"error": "Value is too large"
},
{
"test_json": {
"mpt_issuance_id": "00002403C84A0A28E0190E208E982C352BBD5006600555CF",
"value": "-1"
},
"type": "Amount",
"error": "Value is negative"
},
{
"test_json": {
"mpt_issuance_id": "00002403C84A0A28E0190E208E982C352BBD5006600555CF",
"value": "10.1"
},
"type": "Amount",
"error": "Value has decimal point"
},
{
"test_json": {
"mpt_issuance_id": "10",
"value": "10"
},
"type": "Amount",
"error": "mpt_issuance_id has invalid hash length"
},
{
"test_json": {
"mpt_issuance_id": "00002403C84A0A28E0190E208E982C352BBD5006600555CF",
"value": "10",
"issuer": "rrrrrrrrrrrrrrrrrrrrBZbvji"
},
"type": "Amount",
"error": "Issuer not valid for MPT"
},
{
"test_json": {
"mpt_issuance_id": "00002403C84A0A28E0190E208E982C352BBD5006600555CF",
"value": "10",
"currency": "USD"
},
"type": "Amount",
"error": "Currency not valid for MPT"
},
{
"test_json": {
"mpt_issuance_id": "00002403C84A0A28E0190E208E982C352BBD5006600555CF",
"value": "a"
},
"type": "Amount",
"error": "Value has incorrect hex format"
},
{
"test_json": {
"mpt_issuance_id": "00002403C84A0A28E0190E208E982C352BBD5006600555CF",
"value": "0xy"
},
"type": "Amount",
"error": "Value has bad hex character"
},
{
"test_json": {
"mpt_issuance_id": "00002403C84A0A28E0190E208E982C352BBD5006600555CF",
"value": "/"
},
"type": "Amount",
"error": "Value has bad character"
},
{
"test_json": {
"mpt_issuance_id": "00002403C84A0A28E0190E208E982C352BBD5006600555CF",
"value": "0x8000000000000000"
},
"type": "Amount",
"error": "Hex value out of range"
},
{
"test_json": {
"mpt_issuance_id": "00002403C84A0A28E0190E208E982C352BBD5006600555CF",
"value": "0xFFFFFFFFFFFFFFFF"
},
"type": "Amount",
"error": "Hex value out of range"
},
{
"test_json": {
"mpt_issuance_id":"00002403C84A0A28E0190E208E982C352BBD5006600555CF",
"value": "9223372036854775807"
},
"type_id": 6,
"is_native": false,
"type": "Amount",
"expected_hex": "607FFFFFFFFFFFFFFF00002403C84A0A28E0190E208E982C352BBD5006600555CF",
"is_negative": false
},
{
"test_json": {
"mpt_issuance_id":"00002403C84A0A28E0190E208E982C352BBD5006600555CF",
"value": "0"
},
"type_id": 6,
"is_native": false,
"type": "Amount",
"expected_hex": "60000000000000000000002403C84A0A28E0190E208E982C352BBD5006600555CF",
"is_negative": false
},
{
"test_json": {
"mpt_issuance_id":"00002403C84A0A28E0190E208E982C352BBD5006600555CF",
"value": "-0"
},
"type_id": 6,
"is_native": false,
"type": "Amount",
"expected_hex": "60000000000000000000002403C84A0A28E0190E208E982C352BBD5006600555CF",
"is_negative": false
},
{
"test_json": {
"mpt_issuance_id":"00002403C84A0A28E0190E208E982C352BBD5006600555CF",
"value": "100"
},
"type_id": 6,
"is_native": false,
"type": "Amount",
"expected_hex": "60000000000000006400002403C84A0A28E0190E208E982C352BBD5006600555CF",
"is_negative": false
},
{
"test_json": {
"mpt_issuance_id":"00002403C84A0A28E0190E208E982C352BBD5006600555CF",
"value": "0xa"
},
"type_id": 6,
"is_native": false,
"type": "Amount",
"expected_hex": "60000000000000000A00002403C84A0A28E0190E208E982C352BBD5006600555CF",
"is_negative": false
},
{
"test_json": {
"mpt_issuance_id":"00002403C84A0A28E0190E208E982C352BBD5006600555CF",
"value": "0x7FFFFFFFFFFFFFFF"
},
"type_id": 6,
"is_native": false,
"type": "Amount",
"expected_hex": "607FFFFFFFFFFFFFFF00002403C84A0A28E0190E208E982C352BBD5006600555CF",
"is_negative": false
}
]
}
29 changes: 29 additions & 0 deletions tests/unit/core/binarycodec/types/test_amount.py
Original file line number Diff line number Diff line change
@@ -81,6 +81,24 @@
["100000000000000000", "416345785D8A0000"],
]

# [MPT dict, expected serialized hex]
MPT_CASES = [
[
{
"mpt_issuance_id": "0000012FFD9EE5DA93AC614B4DB94D7E0FCE415CA51BED47",
"value": "1",
},
"6000000000000000010000012FFD9EE5DA93AC614B4DB94D7E0FCE415CA51BED47",
],
[
{
"value": "9223372036854775807",
"mpt_issuance_id": "0000012FFD9EE5DA93AC614B4DB94D7E0FCE415CA51BED47",
},
"607FFFFFFFFFFFFFFF0000012FFD9EE5DA93AC614B4DB94D7E0FCE415CA51BED47",
],
]


class TestAmount(TestSerializedType):
def test_assert_xrp_is_valid_passes(self):
@@ -148,6 +166,11 @@ def test_from_value_xrp(self):
amount_object = amount.Amount.from_value(json)
self.assertEqual(amount_object.to_hex(), serialized)

def test_from_value_mpt(self):
for json, serialized in MPT_CASES:
amount_object = amount.Amount.from_value(json)
self.assertEqual(amount_object.to_hex(), serialized)

def test_to_json_issued_currency(self):
for json, serialized in IOU_CASES:
parser = BinaryParser(serialized)
@@ -160,6 +183,12 @@ def test_to_json_xrp(self):
amount_object = amount.Amount.from_parser(parser)
self.assertEqual(amount_object.to_json(), json)

def test_to_json_mpt(self):
for json, serialized in MPT_CASES:
parser = BinaryParser(serialized)
amount_object = amount.Amount.from_parser(parser)
self.assertEqual(amount_object.to_json(), json)

def test_fixtures(self):
for fixture in data_driven_fixtures_for_type("Amount"):
self.fixture_test(fixture)
29 changes: 29 additions & 0 deletions tests/unit/core/binarycodec/types/test_hash_types.py
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
from xrpl.core.binarycodec.exceptions import XRPLBinaryCodecException
from xrpl.core.binarycodec.types.hash128 import Hash128
from xrpl.core.binarycodec.types.hash160 import Hash160
from xrpl.core.binarycodec.types.hash192 import Hash192
from xrpl.core.binarycodec.types.hash256 import Hash256


@@ -67,6 +68,34 @@ def test_raises_invalid_value_type(self):
self.assertRaises(XRPLBinaryCodecException, Hash160.from_value, invalid_value)


class TestHash192(TestCase):
def setUp(self):
# 24 bytes, 48 nibbles
self.hex_192_bits = "100000000020000000003000000000400000000050000000"
self.parser = BinaryParser(self.hex_192_bits)
self.expected_width = 24

def test_constructors(self):
from_constructor = Hash192(bytes.fromhex(self.hex_192_bits))
from_value = Hash192.from_value(self.hex_192_bits)
from_parser = Hash192.from_parser(self.parser)

self.assertEqual(from_constructor.to_hex(), self.hex_192_bits)
self.assertEqual(from_value.to_hex(), self.hex_192_bits)
self.assertEqual(from_parser.to_hex(), self.hex_192_bits)

def test_constructor_raises_invalid_length(self):
# 25 bytes, 50 nibbles
too_many_bytes_hex = "10000000002000000000300000000040000000005000000012"
self.assertRaises(
XRPLBinaryCodecException, Hash192.from_value, too_many_bytes_hex
)

def test_raises_invalid_value_type(self):
invalid_value = 1
self.assertRaises(XRPLBinaryCodecException, Hash192.from_value, invalid_value)


class TestHash256(TestCase):
def setUp(self):
# 32 bytes, 64 nibbles
14 changes: 14 additions & 0 deletions tests/unit/models/transactions/test_payment.py
Original file line number Diff line number Diff line change
@@ -133,3 +133,17 @@ def test_destination_wallet(self):
}
with self.assertRaises(XRPLModelException):
Payment(**transaction_dict)

def test_mpt_payment(self):
transaction_dict = {
"account": _ACCOUNT,
"fee": _FEE,
"sequence": _SEQUENCE,
"amount": {
"mpt_issuance_id": "000004C463C52827307480341125DA0577DEFC38405B0E3E",
"value": "10",
},
"destination": _DESTINATION,
}
tx = Payment(**transaction_dict)
self.assertTrue(tx.is_valid())
khancode marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 2 additions & 0 deletions xrpl/core/binarycodec/types/__init__.py
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
from xrpl.core.binarycodec.types.hash import Hash
from xrpl.core.binarycodec.types.hash128 import Hash128
from xrpl.core.binarycodec.types.hash160 import Hash160
from xrpl.core.binarycodec.types.hash192 import Hash192
from xrpl.core.binarycodec.types.hash256 import Hash256
from xrpl.core.binarycodec.types.issue import Issue
from xrpl.core.binarycodec.types.path_set import PathSet
@@ -27,6 +28,7 @@
"Hash",
"Hash128",
"Hash160",
"Hash192",
"Hash256",
"Issue",
"PathSet",
Loading