Skip to content

Commit df6982b

Browse files
committed
feat: integ tests for CheckCash, CheckCreate transactions
1 parent c8e11ec commit df6982b

File tree

3 files changed

+150
-7
lines changed

3 files changed

+150
-7
lines changed

tests/integration/it_utils.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from xrpl.asyncio.transaction import sign_and_submit as sign_and_submit_async
1414
from xrpl.clients import Client, JsonRpcClient, WebsocketClient
1515
from xrpl.clients.sync_client import SyncClient
16-
from xrpl.constants import CryptoAlgorithm
16+
from xrpl.constants import CryptoAlgorithm, XRPLException
1717
from xrpl.models import GenericRequest, Payment, Request, Response, Transaction
1818
from xrpl.models.amounts import MPTAmount
1919
from xrpl.models.amounts.issued_currency_amount import IssuedCurrencyAmount
@@ -658,6 +658,11 @@ async def create_mpt_token_and_authorize_source_async(
658658
tx_resp = await sign_and_reliable_submission_async(
659659
mp_token_issuance, issuer, client=client
660660
)
661+
if tx_resp.result["engine_result"] != "tesSUCCESS":
662+
raise XRPLException(
663+
f"Unable to execute MPTokenIssuanceCreate Transaction: {tx_resp}"
664+
)
665+
661666
seq = tx_resp.result["tx_json"]["Sequence"]
662667

663668
response = await client.request(
@@ -680,7 +685,13 @@ async def create_mpt_token_and_authorize_source_async(
680685
account=source.classic_address,
681686
mptoken_issuance_id=mpt_issuance_id,
682687
)
683-
await sign_and_reliable_submission_async(authorize_tx, source, client=client)
688+
response = await sign_and_reliable_submission_async(
689+
authorize_tx, source, client=client
690+
)
691+
if response.result["engine_result"] != "tesSUCCESS":
692+
raise XRPLException(
693+
f"Unable to execute MPTokenAuthorize Transaction: {response}"
694+
)
684695

685696
# Send some MPToken to the source wallet that can be used further.
686697
payment_tx = Payment(
@@ -691,7 +702,11 @@ async def create_mpt_token_and_authorize_source_async(
691702
value="100000",
692703
),
693704
)
694-
await sign_and_reliable_submission_async(payment_tx, issuer, client=client)
705+
response = await sign_and_reliable_submission_async(
706+
payment_tx, issuer, client=client
707+
)
708+
if response.result["engine_result"] != "tesSUCCESS":
709+
raise XRPLException(f"Unable to execute Payment Transaction: {response}")
695710

696711
return mpt_issuance_id
697712

tests/integration/transactions/test_check_cash.py

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
from tests.integration.integration_test_case import IntegrationTestCase
22
from tests.integration.it_utils import (
3+
create_mpt_token_and_authorize_source_async,
4+
fund_wallet_async,
35
sign_and_reliable_submission_async,
46
test_async_and_sync,
57
)
68
from tests.integration.reusable_values import WALLET
9+
from xrpl.models.amounts import MPTAmount
10+
from xrpl.models.requests.account_objects import AccountObjects, AccountObjectType
711
from xrpl.models.response import ResponseStatus
8-
from xrpl.models.transactions import CheckCash
12+
from xrpl.models.transactions import CheckCash, CheckCreate, MPTokenIssuanceCreateFlag
13+
from xrpl.wallet import Wallet
914

1015
ACCOUNT = WALLET.address
1116
CHECK_ID = "838766BA2B995C00744175F69A1B11E32C3DBC40E64801A4056FCBD657F57334"
1217
AMOUNT = "100000000"
1318
DELIVER_MIN = "100000000"
1419

1520

16-
class TestCheckCreate(IntegrationTestCase):
21+
class TestCheckCash(IntegrationTestCase):
1722
@test_async_and_sync(globals())
1823
async def test_required_fields_with_amount(self, client):
1924
check_cash = CheckCash(
@@ -36,3 +41,65 @@ async def test_required_fields_with_deliver_min(self, client):
3641
response = await sign_and_reliable_submission_async(check_cash, WALLET, client)
3742
self.assertEqual(response.status, ResponseStatus.SUCCESS)
3843
self.assertEqual(response.result["engine_result"], "tecNO_ENTRY")
44+
45+
@test_async_and_sync(globals())
46+
async def test_check_cash_with_mpt(self, client):
47+
issuer = Wallet.create()
48+
await fund_wallet_async(issuer)
49+
destination_check_wallet = Wallet.create()
50+
await fund_wallet_async(destination_check_wallet)
51+
52+
mpt_issuance_id = await create_mpt_token_and_authorize_source_async(
53+
issuer=issuer,
54+
source=destination_check_wallet,
55+
client=client,
56+
flags=[
57+
MPTokenIssuanceCreateFlag.TF_MPT_CAN_TRANSFER,
58+
MPTokenIssuanceCreateFlag.TF_MPT_CAN_TRADE,
59+
],
60+
)
61+
62+
# Issuer creates a check to destination for 50 MPT
63+
mpt_amount = MPTAmount(mpt_issuance_id=mpt_issuance_id, value="50")
64+
create_response = await sign_and_reliable_submission_async(
65+
CheckCreate(
66+
account=issuer.classic_address,
67+
destination=destination_check_wallet.classic_address,
68+
send_max=mpt_amount,
69+
),
70+
issuer,
71+
client,
72+
)
73+
self.assertEqual(create_response.result["engine_result"], "tesSUCCESS")
74+
75+
# Find the check ID
76+
account_objects_response = await client.request(
77+
AccountObjects(
78+
account=destination_check_wallet.classic_address,
79+
type=AccountObjectType.CHECK,
80+
)
81+
)
82+
checks = account_objects_response.result["account_objects"]
83+
self.assertEqual(len(checks), 1)
84+
mpt_check_id = checks[0]["index"]
85+
86+
# Destination cashes the check
87+
cash_response = await sign_and_reliable_submission_async(
88+
CheckCash(
89+
account=destination_check_wallet.classic_address,
90+
check_id=mpt_check_id,
91+
amount=mpt_amount,
92+
),
93+
destination_check_wallet,
94+
client,
95+
)
96+
self.assertEqual(cash_response.result["engine_result"], "tesSUCCESS")
97+
98+
# Verify the check was consumed
99+
account_objects_response = await client.request(
100+
AccountObjects(
101+
account=destination_check_wallet.classic_address,
102+
type=AccountObjectType.CHECK,
103+
)
104+
)
105+
self.assertEqual(len(account_objects_response.result["account_objects"]), 0)

tests/integration/transactions/test_check_create.py

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
from tests.integration.integration_test_case import IntegrationTestCase
22
from tests.integration.it_utils import (
3+
create_mpt_token_and_authorize_source_async,
4+
fund_wallet_async,
35
sign_and_reliable_submission_async,
46
test_async_and_sync,
57
)
68
from tests.integration.reusable_values import DESTINATION, WALLET
9+
from xrpl.models.amounts import MPTAmount
10+
from xrpl.models.requests.account_objects import AccountObjects, AccountObjectType
11+
from xrpl.models.requests.ledger_entry import LedgerEntry
712
from xrpl.models.response import ResponseStatus
8-
from xrpl.models.transactions import CheckCreate
13+
from xrpl.models.transactions import (
14+
CheckCreate,
15+
MPTokenAuthorize,
16+
MPTokenIssuanceCreate,
17+
MPTokenIssuanceCreateFlag,
18+
)
19+
from xrpl.wallet import Wallet
920

1021
ACCOUNT = WALLET.address
1122
DESTINATION_TAG = 1
@@ -33,4 +44,54 @@ async def test_all_fields(self, client):
3344

3445
@test_async_and_sync(globals())
3546
async def test_use_MPT_with_Check(self, client):
36-
pass
47+
issuer = Wallet.create()
48+
await fund_wallet_async(issuer)
49+
check_destination_wallet = Wallet.create()
50+
await fund_wallet_async(check_destination_wallet)
51+
52+
mpt_issuance_id = await create_mpt_token_and_authorize_source_async(
53+
issuer=issuer,
54+
source=check_destination_wallet,
55+
client=client,
56+
flags=[
57+
MPTokenIssuanceCreateFlag.TF_MPT_CAN_TRANSFER,
58+
MPTokenIssuanceCreateFlag.TF_MPT_CAN_TRADE,
59+
],
60+
)
61+
62+
send_max = MPTAmount(mpt_issuance_id=mpt_issuance_id, value="50")
63+
response = await sign_and_reliable_submission_async(
64+
CheckCreate(
65+
account=issuer.classic_address,
66+
destination=check_destination_wallet.classic_address,
67+
send_max=send_max,
68+
),
69+
issuer,
70+
client,
71+
)
72+
self.assertEqual(response.status, ResponseStatus.SUCCESS)
73+
self.assertEqual(response.result["engine_result"], "tesSUCCESS")
74+
75+
# Find the check object ID via account_objects
76+
account_objects_response = await client.request(
77+
AccountObjects(
78+
account=check_destination_wallet.classic_address,
79+
type=AccountObjectType.CHECK,
80+
)
81+
)
82+
checks = account_objects_response.result["account_objects"]
83+
self.assertEqual(len(checks), 1)
84+
check_index = checks[0]["index"]
85+
86+
# Validate the check using ledger_entry
87+
ledger_entry_response = await client.request(LedgerEntry(check=check_index))
88+
check_node = ledger_entry_response.result["node"]
89+
self.assertEqual(check_node["LedgerEntryType"], "Check")
90+
self.assertEqual(check_node["Account"], issuer.classic_address)
91+
self.assertEqual(
92+
check_node["Destination"], check_destination_wallet.classic_address
93+
)
94+
self.assertEqual(
95+
check_node["SendMax"],
96+
{"mpt_issuance_id": mpt_issuance_id, "value": "50"},
97+
)

0 commit comments

Comments
 (0)