def test_last_ledger_expiration(self): WALLET.next_sequence_num = get_next_valid_seq_number(ACCOUNT, JSON_RPC_CLIENT) payment_dict = { "account": ACCOUNT, "sequence": WALLET.next_sequence_num, "last_ledger_sequence": WALLET.next_sequence_num + 1, "fee": "10000", "amount": "100", "destination": DESTINATION, } payment_transaction = Payment.from_dict(payment_dict) with self.assertRaises(LastLedgerSequenceExpiredException): send_reliable_submission(payment_transaction, WALLET, JSON_RPC_CLIENT)
def test_reliable_submission_bad_transaction(self): WALLET.next_sequence_num = get_next_valid_seq_number(ACCOUNT, JSON_RPC_CLIENT) payment_dict = { "account": ACCOUNT, "last_ledger_sequence": WALLET.next_sequence_num + 20, "fee": "10", "amount": "100", "destination": DESTINATION, } payment_transaction = Payment.from_dict(payment_dict) signed_payment_transaction = safe_sign_transaction(payment_transaction, WALLET) with self.assertRaises(XRPLRequestFailureException): send_reliable_submission(signed_payment_transaction, JSON_RPC_CLIENT) WALLET.next_sequence_num -= 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_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_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 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_simple(self): WALLET.next_sequence_num = get_next_valid_seq_number(ACCOUNT, JSON_RPC_CLIENT) account_set = AccountSet( account=ACCOUNT, fee=FEE, sequence=WALLET.next_sequence_num, set_flag=SET_FLAG, last_ledger_sequence=WALLET.next_sequence_num + 10, ) response = send_reliable_submission(account_set, WALLET, JSON_RPC_CLIENT) self.assertTrue(response.result["validated"]) self.assertEqual(response.result["meta"]["TransactionResult"], "tesSUCCESS") self.assertTrue(response.is_successful())
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_payment(self): WALLET.next_sequence_num = get_next_valid_seq_number(ACCOUNT, JSON_RPC_CLIENT) payment_dict = { "account": ACCOUNT, "sequence": WALLET.next_sequence_num, "last_ledger_sequence": WALLET.next_sequence_num + 10, "fee": "10000", "amount": "10", "destination": DESTINATION, } payment_transaction = Payment.from_dict(payment_dict) response = send_reliable_submission( payment_transaction, WALLET, JSON_RPC_CLIENT ) self.assertTrue(response.result["validated"]) self.assertEqual(response.result["meta"]["TransactionResult"], "tesSUCCESS") self.assertTrue(response.is_successful())
def test_reliable_submission_payment(self): WALLET.sequence = get_next_valid_seq_number(ACCOUNT, JSON_RPC_CLIENT) payment_dict = { "account": ACCOUNT, "sequence": WALLET.sequence, "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()) self.assertEqual(response.result["Fee"], get_fee(JSON_RPC_CLIENT)) WALLET.sequence += 1
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 xrpl.models.amounts import IssuedCurrencyAmount from xrpl.models.transactions import OfferCreate, PaymentChannelCreate from xrpl.transaction import send_reliable_submission from xrpl.wallet import generate_faucet_wallet WALLET = generate_faucet_wallet(JSON_RPC_CLIENT) DESTINATION = generate_faucet_wallet(JSON_RPC_CLIENT) FEE = get_fee(JSON_RPC_CLIENT) OFFER = send_reliable_submission( OfferCreate( account=WALLET.classic_address, fee=FEE, sequence=WALLET.next_sequence_num, last_ledger_sequence=WALLET.next_sequence_num + 10, taker_gets="13100000", taker_pays=IssuedCurrencyAmount( currency="USD", issuer=WALLET.classic_address, value="10", ), ), WALLET, JSON_RPC_CLIENT, ) PAYMENT_CHANNEL = send_reliable_submission( PaymentChannelCreate( account=WALLET.classic_address, fee=FEE, sequence=WALLET.next_sequence_num, last_ledger_sequence=WALLET.next_sequence_num + 10, amount="1", destination=DESTINATION.classic_address,
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)