Ejemplo n.º 1
0
    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
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
0
    async def test_get_transaction_from_hash(self, client):
        # GIVEN a new transaction (payment)
        payment_transaction = Payment(
            account=WALLET.classic_address,
            amount="100",
            destination=DESTINATION,
            sequence=WALLET.sequence,
        )

        # WHEN we sign locally and autofill the transaction
        signed_payment_transaction = await safe_sign_and_autofill_transaction(
            payment_transaction, WALLET, client)

        # AND submit the transaction
        response = await send_reliable_submission(signed_payment_transaction,
                                                  client)

        # THEN we expect to retrieve this transaction from its hash
        payment = await get_transaction_from_hash(response.result["hash"],
                                                  client)

        # 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
Ejemplo n.º 4
0
 async def test_basic_functionality(self, client):
     response = await submit_transaction_async(
         Payment(
             account=WALLET.classic_address,
             sequence=WALLET.sequence,
             amount="1",
             destination=DESTINATION.classic_address,
         ),
         WALLET,
     )
     self.assertTrue(response.is_successful())
     WALLET.sequence += 1
Ejemplo n.º 5
0
 def test_basic_functionality(self):
     response = submit_transaction(
         Payment(
             account=WALLET.classic_address,
             sequence=WALLET.next_sequence_num,
             amount="1",
             destination=DESTINATION.classic_address,
         ),
         WALLET,
     )
     self.assertTrue(response.is_successful())
     WALLET.next_sequence_num += 1
Ejemplo n.º 6
0
 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
Ejemplo n.º 7
0
 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)
Ejemplo n.º 8
0
    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)
Ejemplo n.º 9
0
 async def test_reliable_submission_bad_transaction(self, client):
     WALLET.sequence = await get_next_valid_seq_number(ACCOUNT, client)
     payment_dict = {
         "account": ACCOUNT,
         "last_ledger_sequence": WALLET.sequence + 20,
         "fee": "10",
         "amount": "100",
         "destination": DESTINATION,
     }
     payment_transaction = Payment.from_dict(payment_dict)
     signed_payment_transaction = await safe_sign_transaction(
         payment_transaction, WALLET)
     with self.assertRaises(XRPLRequestFailureException):
         await send_reliable_submission(signed_payment_transaction, client)
Ejemplo n.º 10
0
 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
Ejemplo n.º 11
0
 def test_generate_faucet_wallet_rel_sub(self):
     destination = generate_faucet_wallet(DEV_JSON_RPC_CLIENT)
     wallet = generate_faucet_wallet(DEV_JSON_RPC_CLIENT)
     response = submit_transaction(
         Payment(
             account=wallet.classic_address,
             sequence=wallet.next_sequence_num,
             fee="10",
             amount="1",
             destination=destination.classic_address,
         ),
         wallet,
         client=DEV_JSON_RPC_CLIENT,
     )
     self.assertTrue(response.is_successful())
Ejemplo n.º 12
0
 async def test_generate_faucet_wallet_rel_sub(self, client):
     destination = await generate_faucet_wallet(client)
     wallet = await generate_faucet_wallet(client)
     response = await submit_transaction_async(
         Payment(
             account=wallet.classic_address,
             sequence=wallet.sequence,
             fee="10",
             amount="1",
             destination=destination.classic_address,
         ),
         wallet,
         client=client,
     )
     self.assertTrue(response.is_successful())
Ejemplo n.º 13
0
    async def test_calculate_payment_fee(self, client):
        # GIVEN a new Payment transaction
        payment = Payment(
            account=WALLET.classic_address,
            amount="100",
            destination=DESTINATION,
            sequence=WALLET.sequence,
        )

        # AFTER autofilling the transaction fee
        payment_signed = await safe_sign_and_autofill_transaction(
            payment, WALLET, client)

        # THEN We expect the fee to be the default network fee (usually 10 drops)
        expected_fee = await get_fee(client)
        self.assertEqual(payment_signed.fee, expected_fee)
Ejemplo n.º 14
0
 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
Ejemplo n.º 15
0
    async def test_get_latest_transaction(self, client):
        # NOTE: this test may take a long time to run
        amount = "21000000"
        payment = Payment(
            account=WALLET.classic_address,
            destination=DESTINATION.classic_address,
            amount=amount,
        )
        await sign_and_reliable_submission_async(payment, WALLET)
        WALLET.sequence += 1

        response = await get_latest_transaction(WALLET.classic_address, client)
        self.assertEqual(len(response.result["transactions"]), 1)
        transaction = response.result["transactions"][0]["tx"]
        self.assertEqual(transaction["TransactionType"], "Payment")
        self.assertEqual(transaction["Amount"], amount)
        self.assertEqual(transaction["Account"], WALLET.classic_address)
Ejemplo n.º 16
0
 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())
Ejemplo n.º 17
0
 def test_payment_high_fee_authorized(self):
     # GIVEN a new Payment transaction
     response = submit_transaction(
         Payment(
             account=WALLET.classic_address,
             sequence=WALLET.sequence,
             amount="1",
             # WITH the fee higher than 2 XRP
             fee=FEE,
             destination=DESTINATION,
         ),
         WALLET,
         # WITHOUT checking the fee value
         check_fee=False,
     )
     # THEN we expect the transaction to be successful
     self.assertTrue(response.is_successful())
     WALLET.sequence += 1
Ejemplo n.º 18
0
    def test_get_latest_transaction(self):
        # NOTE: this test may take a long time to run
        amount = "21000000"
        payment = Payment(
            account=WALLET.classic_address,
            destination=DESTINATION.classic_address,
            amount=amount,
            last_ledger_sequence=WALLET.sequence + 20,
        )
        sign_and_reliable_submission(payment, WALLET)
        WALLET.sequence += 1

        response = get_latest_transaction(WALLET.classic_address,
                                          JSON_RPC_CLIENT)
        self.assertEqual(len(response.result["transactions"]), 1)
        transaction = response.result["transactions"][0]["tx"]
        self.assertEqual(transaction["TransactionType"], "Payment")
        self.assertEqual(transaction["Amount"], amount)
        self.assertEqual(transaction["Account"], WALLET.classic_address)
Ejemplo n.º 19
0
 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
Ejemplo n.º 20
0
# Derive an x-address from the classic address:
# https://xrpaddress.info/
from xrpl.core import addresscodec
test_xaddress = addresscodec.classic_address_to_xaddress(test_account,
                                                         tag=12345,
                                                         is_test_network=True)
print("\nClassic address:\n\n", test_account)
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)
Ejemplo n.º 21
0
    def test_to_xrpl_paths(self):
        paths_json = [
            [
                {
                    "account": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",
                    "type": 1
                },
                {
                    "currency": "USD",
                    "issuer": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q",
                    "type": 48,
                },
                {
                    "account": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q",
                    "type": 1
                },
                {
                    "account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
                    "type": 1
                },
            ],
        ]

        p = Payment(
            account="rweYz56rfmQ98cAdRaeTxQS9wVMGnrdsFp",
            amount=IssuedCurrencyAmount(
                currency="USD",
                issuer="rweYz56rfmQ98cAdRaeTxQS9wVMGnrdsFp",
                value="0.0001",
            ),
            destination="rweYz56rfmQ98cAdRaeTxQS9wVMGnrdsFp",
            send_max=IssuedCurrencyAmount(
                currency="BTC",
                issuer="rweYz56rfmQ98cAdRaeTxQS9wVMGnrdsFp",
                value="0.0000002831214446",
            ),
            paths=paths_json,
            sequence=290,
        )
        tx_json = p.to_xrpl()

        expected = {
            "Account":
            "rweYz56rfmQ98cAdRaeTxQS9wVMGnrdsFp",
            "TransactionType":
            "Payment",
            "Sequence":
            290,
            "Flags":
            0,
            "SigningPubKey":
            "",
            "Amount": {
                "currency": "USD",
                "issuer": "rweYz56rfmQ98cAdRaeTxQS9wVMGnrdsFp",
                "value": "0.0001",
            },
            "Destination":
            "rweYz56rfmQ98cAdRaeTxQS9wVMGnrdsFp",
            "Paths": [[
                {
                    "account": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",
                    "type": 1
                },
                {
                    "currency": "USD",
                    "issuer": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q",
                    "type": 48,
                },
                {
                    "account": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q",
                    "type": 1
                },
                {
                    "account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn",
                    "type": 1
                },
            ]],
            "SendMax": {
                "currency": "BTC",
                "issuer": "rweYz56rfmQ98cAdRaeTxQS9wVMGnrdsFp",
                "value": "0.0000002831214446",
            },
        }
        self.assertEqual(tx_json, expected)
Ejemplo n.º 22
0
# Define signer address
import os  
my_secret = os.getenv("MYSECRET")
from xrpl.wallet import Wallet
wallet = Wallet(seed="MYSECRET", sequence=16237283)
print(wallet.classic_address) # "raaFKKmgf6CRZttTVABeTcsqzRQ51bNR6Q"

from xrpl.models.transactions import Payment
from xrpl.utils import xrp_to_drops
my_payment = Payment(
    account=wallet.classic_address,
    amount=xrp_to_drops(22),
    fee="10",
    destination="rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe",
    sequence=16126889,
)
print("Payment object:", my_payment)

# Sign transaction -------------------------------------------------------------
import xrpl.transaction 
signed = xrpl.transaction.safe_sign_transaction(my_payment, wallet)
print("Signed transaction blob:", signed)
Ejemplo n.º 23
0
# Define signer address
import os
my_secret = os.getenv("MYSECRET")
from xrpl.wallet import Wallet
wallet = Wallet(seed=my_secret, sequence=16237283)
print(wallet.classic_address)  # "raaFKKmgf6CRZttTVABeTcsqzRQ51bNR6Q"

from xrpl.models.transactions import Payment
from xrpl.utils import xrp_to_drops
my_payment = Payment(
    account=wallet.classic_address,
    amount=xrp_to_drops(22),
    fee="10",
    destination="rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe",
    sequence=wallet.
    sequence,  # this needs to be incremented upon every successful transaction
)
print("Payment object:", my_payment)

# Sign transaction -------------------------------------------------------------
import xrpl.transaction
signed = xrpl.transaction.safe_sign_transaction(my_payment, wallet)
print("Signed transaction blob:", signed)