|
| 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 | + ) |
0 commit comments