def test_get_transaction_from_hash_with_binary(self): # GIVEN a new transaction (payment) payment_transaction = Payment(account=WALLET.classic_address, amount="100", destination=DESTINATION) # WHEN we sign locally and autofill the transaction signed_payment_transaction = safe_sign_and_autofill_transaction( payment_transaction, WALLET, JSON_RPC_CLIENT) # AND submit the transaction response = send_reliable_submission(signed_payment_transaction, JSON_RPC_CLIENT) payment_hash = response.result["hash"] # THEN we expect to retrieve this transaction from its hash with the # binary parameter set to true payment = get_transaction_from_hash(payment_hash, JSON_RPC_CLIENT, True) # AND we expect the result hash to be the same as the original payment hash self.assertEqual(payment.result["hash"], payment_hash) # AND we expect the response to be successful (200) self.assertTrue(payment.is_successful()) WALLET.sequence += 1
def test_get_transaction_from_hash_with_min_max_ledgers(self): # GIVEN a new transaction (payment) payment_transaction = Payment(account=WALLET.classic_address, amount="100", destination=DESTINATION) # WHEN we sign locally and autofill the transaction signed_payment_transaction = safe_sign_and_autofill_transaction( payment_transaction, WALLET, JSON_RPC_CLIENT) # AND submit the transaction response = send_reliable_submission(signed_payment_transaction, JSON_RPC_CLIENT) payment_hash = response.result["hash"] payment_ledger_index = response.result["ledger_index"] # THEN we expect to retrieve this transaction from its hash with # min_ledger and max_ledger parameters payment = get_transaction_from_hash( payment_hash, JSON_RPC_CLIENT, False, payment_ledger_index - 500, payment_ledger_index + 500, ) # AND we expect the result Account to be the same as the original payment Acct self.assertEqual(payment.result["Account"], ACCOUNT) # AND we expect the response to be successful (200) self.assertTrue(payment.is_successful()) WALLET.sequence += 1
def test_calculate_payment_fee(self): # GIVEN a new Payment transaction payment = Payment(account=WALLET.classic_address, amount="100", destination=DESTINATION) # AFTER autofilling the transaction fee payment_signed = safe_sign_and_autofill_transaction( payment, WALLET, JSON_RPC_CLIENT) # THEN We expect the fee to be the default network fee (usually 10 drops) expected_fee = get_fee(JSON_RPC_CLIENT) self.assertEqual(payment_signed.fee, expected_fee)
def payment(self, destination, sender, amount, sequence, seed) -> bool: my_tx_payment = Payment( account=sender, amount=xrp_to_drops(amount), destination=destination, sequence=sequence, ) sign_wallet = Wallet(seed, sequence) my_tx_payment_signed = safe_sign_and_autofill_transaction( my_tx_payment, sign_wallet, self.client) tx_response = send_reliable_submission(my_tx_payment_signed, self.client) return True
def test_reliable_submission_simple(self): WALLET.next_sequence_num = get_next_valid_seq_number(ACCOUNT, JSON_RPC_CLIENT) account_set = AccountSet( account=ACCOUNT, sequence=WALLET.next_sequence_num, set_flag=SET_FLAG, ) signed_account_set = safe_sign_and_autofill_transaction( account_set, WALLET, JSON_RPC_CLIENT ) response = send_reliable_submission(signed_account_set, JSON_RPC_CLIENT) self.assertTrue(response.result["validated"]) self.assertEqual(response.result["meta"]["TransactionResult"], "tesSUCCESS") self.assertTrue(response.is_successful()) WALLET.next_sequence_num += 1
def test_calculate_account_delete_fee(self): # GIVEN a new AccountDelete transaction account_delete = AccountDelete( account=ACCOUNT, sequence=WALLET.sequence, destination=DESTINATION, destination_tag=DESTINATION_TAG, ) # AFTER autofilling the transaction fee account_delete_signed = safe_sign_and_autofill_transaction( account_delete, WALLET, JSON_RPC_CLIENT) # THEN we expect the calculated fee to be 5000000 drops (5 XRP) expected_fee = "5000000" self.assertEqual(account_delete_signed.fee, expected_fee)
def test_reliable_submission_last_ledger_expiration(self): WALLET.sequence = get_next_valid_seq_number(ACCOUNT, JSON_RPC_CLIENT) payment_dict = { "account": ACCOUNT, "sequence": WALLET.sequence, "last_ledger_sequence": WALLET.sequence + 1, "fee": "10000", "amount": "100", "destination": DESTINATION, } payment_transaction = Payment.from_dict(payment_dict) signed_payment_transaction = safe_sign_and_autofill_transaction( payment_transaction, WALLET, JSON_RPC_CLIENT) with self.assertRaises(XRPLReliableSubmissionException): send_reliable_submission(signed_payment_transaction, JSON_RPC_CLIENT) WALLET.sequence -= 1
def test_reliable_submission_payment(self): WALLET.next_sequence_num = get_next_valid_seq_number(ACCOUNT, JSON_RPC_CLIENT) payment_dict = { "account": ACCOUNT, "sequence": WALLET.next_sequence_num, "fee": "10000", "amount": "10", "destination": DESTINATION, } payment_transaction = Payment.from_dict(payment_dict) signed_payment_transaction = safe_sign_and_autofill_transaction( payment_transaction, WALLET, JSON_RPC_CLIENT ) response = send_reliable_submission(signed_payment_transaction, JSON_RPC_CLIENT) self.assertTrue(response.result["validated"]) self.assertEqual(response.result["meta"]["TransactionResult"], "tesSUCCESS") self.assertTrue(response.is_successful()) WALLET.next_sequence_num += 1
def test_calculate_escrow_finish_fee(self): # GIVEN a new EscrowFinish transaction escrow_finish = EscrowFinish( account=ACCOUNT, sequence=WALLET.sequence, owner=OWNER, offer_sequence=OFFER_SEQUENCE, condition=CONDITION, fulfillment=FULFILLMENT, ) # AFTER autofilling the transaction fee escrow_finish_signed = safe_sign_and_autofill_transaction( escrow_finish, WALLET, JSON_RPC_CLIENT) # AND calculating the expected fee with the formula # 10 drops × (33 + (Fulfillment size in bytes ÷ 16)) net_fee = int(get_fee(JSON_RPC_CLIENT)) fulfillment_in_bytes = FULFILLMENT.encode("ascii") expected_fee = net_fee * (33 + len(fulfillment_in_bytes) / 16) # THEN we expect the fee to be the calculation result above self.assertEqual(float(escrow_finish_signed.fee), float(expected_fee))
print("X-address:\n\n", test_xaddress) # Prepare payment from xrpl.models.transactions import Payment from xrpl.utils import xrp_to_drops my_tx_payment = Payment( account=test_account, amount=xrp_to_drops(22), destination="rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe", ) # print prepared payment print(my_tx_payment) # Sign the transaction from xrpl.transaction import safe_sign_and_autofill_transaction my_tx_payment_signed = safe_sign_and_autofill_transaction( my_tx_payment, test_wallet, client) # Print signed tx print("Signed tx:", my_tx_payment_signed) # Submit and send the transaction from xrpl.transaction import send_reliable_submission tx_response = send_reliable_submission(my_tx_payment_signed, client) # Print tx response print("Tx response:", tx_response)
from tests.integration.reusable_values import WALLET from xrpl.core.binarycodec import encode from xrpl.models.amounts import IssuedCurrencyAmount from xrpl.models.requests import SubmitOnly from xrpl.models.transactions import OfferCreate from xrpl.transaction import ( safe_sign_and_autofill_transaction, transaction_json_to_binary_codec_form, ) TX = OfferCreate( account=WALLET.classic_address, sequence=WALLET.sequence, last_ledger_sequence=WALLET.sequence + 10, taker_gets="13100000", taker_pays=IssuedCurrencyAmount( currency="USD", issuer=WALLET.classic_address, value="10", ), ) TRANSACTION = safe_sign_and_autofill_transaction(TX, WALLET, JSON_RPC_CLIENT) TX_JSON = transaction_json_to_binary_codec_form(TRANSACTION.to_dict()) TX_BLOB = encode(TX_JSON) class TestSubmitOnly(TestCase): def test_basic_functionality(self): response = JSON_RPC_CLIENT.request(SubmitOnly(tx_blob=TX_BLOB, )) self.assertTrue(response.is_successful())
def sign_and_reliable_submission( transaction: Transaction, wallet: Wallet, client=JSON_RPC_CLIENT ) -> Response: signed_tx = safe_sign_and_autofill_transaction(transaction, wallet, client) return send_reliable_submission(signed_tx, client)
def sign_and_reliable_submission(transaction: Transaction, wallet: Wallet, use_json_client: bool = True) -> Response: client = _choose_client(use_json_client) signed_tx = safe_sign_and_autofill_transaction(transaction, wallet, client) return send_reliable_submission(signed_tx, client)