Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: assorted fixes #570

Merged
merged 17 commits into from
May 25, 2023
Merged
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"asyncio",
"binarycodec",
"keypair",
"keypairs",
"nftoken",
"rippletest",
"ripplex",
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added `submit_and_wait` to sign (if needed), autofill, submit a transaction and wait for its final outcome
- `submit` and `send_reliable_submission` now accept an optional boolean param `fail_hard` (if `True` halt the submission if it's not immediately validated)

### Changed:
- Allowed keypairs.sign to take a hex string in addition to bytes

### Fixed:
- Refactored `does_account_exist` and `get_balance` to avoid deprecated methods and use `ledger_index` parameter
- Fixed crashes in the SignerListSet validation

### Removed:
- RPCs and utils related to the old sidechain design
Expand Down
26 changes: 18 additions & 8 deletions tests/integration/it_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,11 @@ async def fund_wallet(
await client.request(LEDGER_ACCEPT_REQUEST)


# just submits a transaction to the ledger, synchronously
def submit_transaction(
transaction: Transaction,
wallet: Wallet,
client: SyncClient = JSON_RPC_CLIENT,
client: SyncClient,
check_fee: bool = True,
) -> Response:
"""Signs and submits a transaction to the XRPL."""
Expand All @@ -131,29 +132,38 @@ def submit_transaction(
)


# just submits a transaction to the ledger, asynchronously
async def submit_transaction_async(
transaction: Transaction,
wallet: Wallet,
client: Client = ASYNC_JSON_RPC_CLIENT,
client: AsyncClient,
check_fee: bool = True,
) -> Response:
return await sign_and_submit_async(transaction, wallet, client, check_fee=check_fee)


# submits a transaction to the ledger and closes a ledger, synchronously
def sign_and_reliable_submission(
transaction: Transaction, wallet: Wallet, use_json_client: bool = True
transaction: Transaction,
wallet: Wallet,
client: SyncClient = JSON_RPC_CLIENT,
check_fee: bool = True,
) -> Response:
client = _choose_client(use_json_client)
response = submit_transaction(transaction, wallet, client)
response = submit_transaction(transaction, wallet, client, check_fee=check_fee)
client.request(LEDGER_ACCEPT_REQUEST)
return response


# submits a transaction to the ledger and closes a ledger, asynchronously
async def sign_and_reliable_submission_async(
transaction: Transaction, wallet: Wallet, use_json_client: bool = True
transaction: Transaction,
wallet: Wallet,
client: AsyncClient = ASYNC_JSON_RPC_CLIENT,
check_fee: bool = True,
) -> Response:
client = _choose_client_async(use_json_client)
response = await submit_transaction_async(transaction, wallet, client)
response = await submit_transaction_async(
transaction, wallet, client, check_fee=check_fee
)
await client.request(LEDGER_ACCEPT_REQUEST)
return response

Expand Down
12 changes: 10 additions & 2 deletions tests/integration/reqs/test_subscribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ async def test_transactions_subscription(self, client):

count = 0
async for message in client:
await sign_and_reliable_submission_async(payment_transaction, WALLET)
# TODO: refactor so this can use the same client
await sign_and_reliable_submission_async(
payment_transaction,
WALLET,
)
if count != 0:
self.assertEqual(message["type"], "transaction")
if count == _MESSAGE_LIMIT:
Expand All @@ -108,7 +112,11 @@ async def test_transactions_proposed_subscription(self, client):

count = 0
async for message in client:
await sign_and_reliable_submission_async(payment_transaction, WALLET)
# TODO: refactor so this can use the same client
await sign_and_reliable_submission_async(
payment_transaction,
WALLET,
)
if count != 0:
self.assertEqual(message["type"], "transaction")
if count == _MESSAGE_LIMIT:
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/sugar/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async def test_get_latest_transaction(self, client):
destination=DESTINATION.classic_address,
amount=amount,
)
await sign_and_reliable_submission_async(payment, WALLET)
await sign_and_reliable_submission_async(payment, WALLET, client)

response = await get_latest_transaction(WALLET.classic_address, client)
self.assertEqual(len(response.result["transactions"]), 1)
Expand Down
12 changes: 7 additions & 5 deletions tests/integration/sugar/test_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from tests.integration.it_utils import (
accept_ledger_async,
sign_and_reliable_submission_async,
submit_transaction_async,
test_async_and_sync,
)
from tests.integration.reusable_values import DESTINATION as DESTINATION_WALLET
Expand Down Expand Up @@ -60,7 +59,9 @@ async def test_none_as_destination_tag(self, client):
)

# WHEN we sign locally, autofill, and submit the transaction
response = await sign_and_reliable_submission_async(payment_transaction, WALLET)
response = await sign_and_reliable_submission_async(
payment_transaction, WALLET, client
)
payment_hash = response.result["tx_json"]["hash"]
payment_ledger_index = response.result["validated_ledger_index"]

Expand Down Expand Up @@ -91,7 +92,7 @@ async def test_high_fee_account_delete_unauthorized(self, client):
)
# We expect an XRPLException to be raised
with self.assertRaises(XRPLException):
await submit_transaction_async(account_delete, WALLET)
await sign_and_reliable_submission_async(account_delete, WALLET, client)

@test_async_and_sync(globals())
async def test_high_fee_account_set_unauthorized(self, client):
Expand All @@ -109,12 +110,12 @@ async def test_high_fee_account_set_unauthorized(self, client):
)
# We expect an XRPLException to be raised
with self.assertRaises(XRPLException):
await submit_transaction_async(account_set, WALLET)
await sign_and_reliable_submission_async(account_set, WALLET, client)

@test_async_and_sync(globals())
async def test_payment_high_fee_authorized(self, client):
# GIVEN a new Payment transaction
response = await submit_transaction_async(
response = await sign_and_reliable_submission_async(
Payment(
account=WALLET.classic_address,
amount="1",
Expand All @@ -123,6 +124,7 @@ async def test_payment_high_fee_authorized(self, client):
destination=DESTINATION,
),
WALLET,
client,
# WITHOUT checking the fee value
check_fee=False,
)
Expand Down
1 change: 1 addition & 0 deletions tests/integration/sugar/test_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class TestWallet(IntegrationTestCase):
async def test_generate_faucet_wallet_rel_sub(self, client):
destination = await generate_faucet_wallet(client)
wallet = await generate_faucet_wallet(client)
# TODO: refactor so this actually waits for validation
response = await submit_transaction_async(
Payment(
account=wallet.classic_address,
Expand Down
9 changes: 6 additions & 3 deletions tests/integration/transactions/test_account_delete.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from tests.integration.integration_test_case import IntegrationTestCase
from tests.integration.it_utils import submit_transaction_async, test_async_and_sync
from tests.integration.it_utils import (
sign_and_reliable_submission_async,
test_async_and_sync,
)
from tests.integration.reusable_values import DESTINATION, WALLET
from xrpl.models.response import ResponseStatus
from xrpl.models.transactions import AccountDelete
Expand All @@ -24,8 +27,8 @@ async def test_all_fields(self, client):
destination=DESTINATION.classic_address,
destination_tag=DESTINATION_TAG,
)
response = await submit_transaction_async(
account_delete, WALLET, check_fee=False
response = await sign_and_reliable_submission_async(
account_delete, WALLET, client, check_fee=False
)
self.assertEqual(response.status, ResponseStatus.SUCCESS)

Expand Down
9 changes: 6 additions & 3 deletions tests/integration/transactions/test_account_set.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from tests.integration.integration_test_case import IntegrationTestCase
from tests.integration.it_utils import submit_transaction_async, test_async_and_sync
from tests.integration.it_utils import (
sign_and_reliable_submission_async,
test_async_and_sync,
)
from tests.integration.reusable_values import WALLET
from xrpl.models.response import ResponseStatus
from xrpl.models.transactions import AccountSet
Expand All @@ -22,7 +25,7 @@ async def test_required_fields_and_set_flag(self, client):
account=ACCOUNT,
set_flag=SET_FLAG,
)
response = await submit_transaction_async(account_set, WALLET)
response = await sign_and_reliable_submission_async(account_set, WALLET, client)
self.assertEqual(response.status, ResponseStatus.SUCCESS)
self.assertEqual(response.result["engine_result"], "tesSUCCESS")

Expand All @@ -37,6 +40,6 @@ async def test_all_fields_minus_set_flag(self, client):
transfer_rate=TRANSFER_RATE,
tick_size=TICK_SIZE,
)
response = await submit_transaction_async(account_set, WALLET)
response = await sign_and_reliable_submission_async(account_set, WALLET, client)
self.assertEqual(response.status, ResponseStatus.SUCCESS)
self.assertEqual(response.result["engine_result"], "tesSUCCESS")
9 changes: 7 additions & 2 deletions tests/integration/transactions/test_check_cancel.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from tests.integration.integration_test_case import IntegrationTestCase
from tests.integration.it_utils import submit_transaction_async, test_async_and_sync
from tests.integration.it_utils import (
sign_and_reliable_submission_async,
test_async_and_sync,
)
from tests.integration.reusable_values import WALLET
from xrpl.models.response import ResponseStatus
from xrpl.models.transactions import CheckCancel
Expand All @@ -16,7 +19,9 @@ async def test_all_fields(self, client):
account=ACCOUNT,
check_id=CHECK_ID,
)
response = await submit_transaction_async(check_cancel, WALLET)
response = await sign_and_reliable_submission_async(
check_cancel, WALLET, client
)
self.assertEqual(response.status, ResponseStatus.SUCCESS)
# This transaction shouldn't actually succeed, because this isn't a real check:
# Docs for tecNO_ENTRY read:
Expand Down
9 changes: 6 additions & 3 deletions tests/integration/transactions/test_check_cash.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from tests.integration.integration_test_case import IntegrationTestCase
from tests.integration.it_utils import submit_transaction_async, test_async_and_sync
from tests.integration.it_utils import (
sign_and_reliable_submission_async,
test_async_and_sync,
)
from tests.integration.reusable_values import WALLET
from xrpl.models.response import ResponseStatus
from xrpl.models.transactions import CheckCash
Expand All @@ -18,7 +21,7 @@ async def test_required_fields_with_amount(self, client):
check_id=CHECK_ID,
amount=AMOUNT,
)
response = await submit_transaction_async(check_cash, WALLET)
response = await sign_and_reliable_submission_async(check_cash, WALLET, client)
self.assertEqual(response.status, ResponseStatus.SUCCESS)
# Getting `tecNO_ENTRY` codes because using a non-existent check ID
self.assertEqual(response.result["engine_result"], "tecNO_ENTRY")
Expand All @@ -30,6 +33,6 @@ async def test_required_fields_with_deliver_min(self, client):
check_id=CHECK_ID,
deliver_min=DELIVER_MIN,
)
response = await submit_transaction_async(check_cash, WALLET)
response = await sign_and_reliable_submission_async(check_cash, WALLET, client)
self.assertEqual(response.status, ResponseStatus.SUCCESS)
self.assertEqual(response.result["engine_result"], "tecNO_ENTRY")
9 changes: 7 additions & 2 deletions tests/integration/transactions/test_check_create.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from tests.integration.integration_test_case import IntegrationTestCase
from tests.integration.it_utils import submit_transaction_async, test_async_and_sync
from tests.integration.it_utils import (
sign_and_reliable_submission_async,
test_async_and_sync,
)
from tests.integration.reusable_values import DESTINATION, WALLET
from xrpl.models.response import ResponseStatus
from xrpl.models.transactions import CheckCreate
Expand All @@ -22,6 +25,8 @@ async def test_all_fields(self, client):
expiration=EXPIRATION,
invoice_id=INVOICE_ID,
)
response = await submit_transaction_async(check_create, WALLET)
response = await sign_and_reliable_submission_async(
check_create, WALLET, client
)
self.assertEqual(response.status, ResponseStatus.SUCCESS)
self.assertEqual(response.result["engine_result"], "tesSUCCESS")
13 changes: 10 additions & 3 deletions tests/integration/transactions/test_deposit_preauth.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from tests.integration.integration_test_case import IntegrationTestCase
from tests.integration.it_utils import submit_transaction_async, test_async_and_sync
from tests.integration.it_utils import (
sign_and_reliable_submission_async,
test_async_and_sync,
)
from tests.integration.reusable_values import WALLET
from xrpl.models.response import ResponseStatus
from xrpl.models.transactions import DepositPreauth
Expand All @@ -15,7 +18,9 @@ async def test_authorize(self, client):
account=ACCOUNT,
authorize=ADDRESS,
)
response = await submit_transaction_async(deposit_preauth, WALLET)
response = await sign_and_reliable_submission_async(
deposit_preauth, WALLET, client
)
self.assertEqual(response.status, ResponseStatus.SUCCESS)

@test_async_and_sync(globals())
Expand All @@ -24,5 +29,7 @@ async def test_unauthorize(self, client):
account=ACCOUNT,
unauthorize=ADDRESS,
)
response = await submit_transaction_async(deposit_preauth, WALLET)
response = await sign_and_reliable_submission_async(
deposit_preauth, WALLET, client
)
self.assertEqual(response.status, ResponseStatus.SUCCESS)
9 changes: 7 additions & 2 deletions tests/integration/transactions/test_escrow_cancel.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from tests.integration.integration_test_case import IntegrationTestCase
from tests.integration.it_utils import submit_transaction_async, test_async_and_sync
from tests.integration.it_utils import (
sign_and_reliable_submission_async,
test_async_and_sync,
)
from tests.integration.reusable_values import WALLET
from xrpl.models.response import ResponseStatus
from xrpl.models.transactions import EscrowCancel
Expand All @@ -17,6 +20,8 @@ async def test_all_fields(self, client):
owner=OWNER,
offer_sequence=OFFER_SEQUENCE,
)
response = await submit_transaction_async(escrow_cancel, WALLET)
response = await sign_and_reliable_submission_async(
escrow_cancel, WALLET, client
)
# Actual engine_result is `tecNO_TARGET since OWNER account doesn't exist
self.assertEqual(response.status, ResponseStatus.SUCCESS)
9 changes: 7 additions & 2 deletions tests/integration/transactions/test_escrow_create.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from tests.integration.integration_test_case import IntegrationTestCase
from tests.integration.it_utils import submit_transaction_async, test_async_and_sync
from tests.integration.it_utils import (
sign_and_reliable_submission_async,
test_async_and_sync,
)
from tests.integration.reusable_values import WALLET
from xrpl.models.response import ResponseStatus
from xrpl.models.transactions import EscrowCreate
Expand Down Expand Up @@ -29,7 +32,9 @@ async def test_all_fields(self, client):
finish_after=FINISH_AFTER,
source_tag=SOURCE_TAG,
)
response = await submit_transaction_async(escrow_create, WALLET)
response = await sign_and_reliable_submission_async(
escrow_create, WALLET, client
)
# Actual engine_result will be `tecNO_PERMISSION`...
# maybe due to CONDITION or something
self.assertEqual(response.status, ResponseStatus.SUCCESS)
9 changes: 7 additions & 2 deletions tests/integration/transactions/test_escrow_finish.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from tests.integration.integration_test_case import IntegrationTestCase
from tests.integration.it_utils import submit_transaction_async, test_async_and_sync
from tests.integration.it_utils import (
sign_and_reliable_submission_async,
test_async_and_sync,
)
from tests.integration.reusable_values import WALLET
from xrpl.models.response import ResponseStatus
from xrpl.models.transactions import EscrowFinish
Expand Down Expand Up @@ -27,7 +30,9 @@ async def test_all_fields(self, client):
condition=CONDITION,
fulfillment=FULFILLMENT,
)
response = await submit_transaction_async(escrow_finish, WALLET)
response = await sign_and_reliable_submission_async(
escrow_finish, WALLET, client
)
# Actual engine_result will be 'tecNO_TARGET' since using non-extant
# account for OWNER
self.assertEqual(response.status, ResponseStatus.SUCCESS)
Loading