Skip to content

Commit e7e8609

Browse files
committed
feat: Additional validation for AMMClawback transaction with mpt asset
1 parent 3cb8d1e commit e7e8609

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

tests/unit/models/transactions/test_amm_clawback.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,45 @@ def test_valid_mpt_clawback_without_amount(self):
9898
)
9999
self.assertTrue(txn.is_valid())
100100

101+
def test_mpt_clawback_amount_type_mismatch(self):
102+
"""asset is MPTCurrency but amount is IssuedCurrencyAmount."""
103+
with self.assertRaises(XRPLModelException) as error:
104+
AMMClawback(
105+
account=_ISSUER_ACCOUNT,
106+
holder=_HOLDER_ACCOUNT,
107+
asset=MPTCurrency(mpt_issuance_id=_MPT_ISSUANCE_ID_1),
108+
asset2=MPTCurrency(mpt_issuance_id=_MPT_ISSUANCE_ID_2),
109+
amount=IssuedCurrencyAmount(
110+
currency="ETH",
111+
issuer=_ISSUER_ACCOUNT,
112+
value="100",
113+
),
114+
)
115+
self.assertEqual(
116+
error.exception.args[0],
117+
"{'AMMClawback': 'Mismatch between Asset and Amount Currency types. "
118+
+ "Asset is MPTCurrency whereas Amount is not.'}",
119+
)
120+
121+
def test_mpt_clawback_mismatched_issuance_id(self):
122+
"""asset and amount are both MPT but have different mpt_issuance_id."""
123+
with self.assertRaises(XRPLModelException) as error:
124+
AMMClawback(
125+
account=_ISSUER_ACCOUNT,
126+
holder=_HOLDER_ACCOUNT,
127+
asset=MPTCurrency(mpt_issuance_id=_MPT_ISSUANCE_ID_1),
128+
asset2=MPTCurrency(mpt_issuance_id=_MPT_ISSUANCE_ID_2),
129+
amount=MPTAmount(
130+
mpt_issuance_id=_MPT_ISSUANCE_ID_2,
131+
value="10",
132+
),
133+
)
134+
self.assertEqual(
135+
error.exception.args[0],
136+
"{'AMMClawback': 'Mismatch in the Asset.mpt_issuance_id and "
137+
+ "Amount.mpt_issuance_id fields'}",
138+
)
139+
101140
def test_mpt_clawback_non_hex_characters(self):
102141
bad_id = "Z" * MPT_ISSUANCE_ID_LENGTH
103142
with self.assertRaises(XRPLModelException) as error:

xrpl/models/transactions/amm_clawback.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from typing_extensions import Self
1010

11-
from xrpl.models.amounts import Amount, IssuedCurrencyAmount
11+
from xrpl.models.amounts import Amount, IssuedCurrencyAmount, MPTAmount
1212
from xrpl.models.currencies import Currency, IssuedCurrency, MPTCurrency
1313
from xrpl.models.required import REQUIRED
1414
from xrpl.models.transactions.transaction import Transaction, TransactionFlagInterface
@@ -113,4 +113,17 @@ def _validate_wallet_and_amount_fields(self: Self) -> Optional[str]:
113113
+ "fields."
114114
)
115115

116+
if isinstance(self.asset, MPTCurrency):
117+
if self.amount is not None:
118+
if not isinstance(self.amount, MPTAmount):
119+
errors += (
120+
"Mismatch between Asset and Amount Currency types. Asset "
121+
+ "is MPTCurrency whereas Amount is not."
122+
)
123+
elif self.amount.mpt_issuance_id != self.asset.mpt_issuance_id:
124+
errors += (
125+
"Mismatch in the Asset.mpt_issuance_id and "
126+
+ "Amount.mpt_issuance_id fields"
127+
)
128+
116129
return errors if errors else None

0 commit comments

Comments
 (0)