Skip to content

Commit 01b19a7

Browse files
committed
feat: Additional validation for Path model in cases involving mpt_issuance_id
1 parent e7e8609 commit 01b19a7

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

tests/unit/models/test_path.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
from unittest import TestCase
2+
3+
from xrpl.models.exceptions import XRPLModelException
4+
from xrpl.models.path import PathStep
5+
6+
_ACCOUNT = "r9LqNeG6qHxjeUocjvVki2XR35weJ9mZgQ"
7+
_ISSUER = "rpGtkFRXhgVaBzC5XCR7gyE2AZN5SN3SEW"
8+
_MPT_ID = "00000001A407AF5856CECE4281FED12B7B179B49A4AEF506"
9+
10+
11+
class TestPathStepMPT(TestCase):
12+
# --- valid cases ---
13+
14+
def test_valid_mpt_issuance_id_only(self):
15+
step = PathStep(mpt_issuance_id=_MPT_ID)
16+
self.assertTrue(step.is_valid())
17+
18+
def test_valid_account_only(self):
19+
step = PathStep(account=_ACCOUNT)
20+
self.assertTrue(step.is_valid())
21+
22+
# --- account + mpt_issuance_id ---
23+
24+
def test_account_with_mpt_issuance_id(self):
25+
with self.assertRaises(XRPLModelException) as ctx:
26+
PathStep(account=_ACCOUNT, mpt_issuance_id=_MPT_ID)
27+
self.assertIn(
28+
"Cannot set account if mpt_issuance_id is specified",
29+
ctx.exception.args[0],
30+
)
31+
32+
# --- currency + mpt_issuance_id ---
33+
34+
def test_currency_with_mpt_issuance_id(self):
35+
with self.assertRaises(XRPLModelException) as ctx:
36+
PathStep(currency="USD", mpt_issuance_id=_MPT_ID)
37+
self.assertIn(
38+
"Cannot set both currency and mpt_issuance_id",
39+
ctx.exception.args[0],
40+
)
41+
42+
# --- mpt_issuance_id + currency (from mpt validator) ---
43+
44+
def test_mpt_issuance_id_with_currency(self):
45+
"""Same combo as above, but verifies the mpt_issuance_id validator's message."""
46+
with self.assertRaises(XRPLModelException) as ctx:
47+
PathStep(mpt_issuance_id=_MPT_ID, currency="USD")
48+
self.assertIn(
49+
"Cannot set both mpt_issuance_id and currency",
50+
ctx.exception.args[0],
51+
)
52+
53+
# --- mpt_issuance_id + account (from mpt validator) ---
54+
55+
def test_mpt_issuance_id_with_account(self):
56+
with self.assertRaises(XRPLModelException) as ctx:
57+
PathStep(mpt_issuance_id=_MPT_ID, account=_ACCOUNT)
58+
self.assertIn(
59+
"Cannot set both mpt_issuance_id and account",
60+
ctx.exception.args[0],
61+
)

xrpl/models/path.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ def _get_account_error(self: Self) -> Optional[str]:
4444
return None
4545
if self.currency is not None or self.issuer is not None:
4646
return "Cannot set account if currency or issuer are set"
47+
if self.mpt_issuance_id is not None:
48+
return "Cannot set account if mpt_issuance_id is specified"
4749
return None
4850

4951
def _get_currency_error(self: Self) -> Optional[str]:
@@ -71,6 +73,8 @@ def _get_mpt_issuance_id_error(self: Self) -> Optional[str]:
7173
return None
7274
if self.currency is not None:
7375
return "Cannot set both mpt_issuance_id and currency"
76+
if self.account is not None:
77+
return "Cannot set both mpt_issuance_id and account"
7478
return None
7579

7680

0 commit comments

Comments
 (0)