Skip to content

[DO NOT MERGE] Smart Escrows #818

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

Draft
wants to merge 30 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
79b5bc8
basics
mvadari Mar 10, 2025
db9234b
add tests, fix issues, refactor escrow tests
mvadari Mar 11, 2025
09f98af
add EscrowCancel
mvadari Mar 11, 2025
c7b3b48
cleanup
mvadari Mar 11, 2025
d661438
remove repeat test
mvadari Mar 11, 2025
6a64843
Merge branch 'main' into smart-escrows
mvadari Mar 18, 2025
1399929
bump version for beta
mvadari Mar 26, 2025
dc465b4
add faucet info
mvadari Mar 28, 2025
e4050e5
Merge branch 'main' into smart-escrows
mvadari Mar 28, 2025
3a009c2
easier running wallet tests
mvadari Mar 28, 2025
468b29b
Update rippled.cfg
mvadari Mar 28, 2025
cbeee6b
if it ain't broke don't fix it
mvadari Mar 28, 2025
445b233
add more buffer
mvadari Mar 28, 2025
67a7775
add 1s wait between snippet runs
mvadari Mar 28, 2025
4443d69
more fixes
mvadari Mar 28, 2025
2a68fde
bump version
mvadari Mar 28, 2025
34e6d80
increase faucet timeout
mvadari Mar 28, 2025
87e39ed
Merge branch 'main' into smart-escrows
mvadari Apr 15, 2025
cfa95f5
update to Devnet 2
mvadari Apr 29, 2025
fc3f5f6
update beta version
mvadari May 2, 2025
1f25b90
update definitions
mvadari May 4, 2025
65f875f
Merge branch 'main' into smart-escrows
mvadari May 8, 2025
8d06f4c
Merge branch 'main' into smart-escrows
mvadari May 29, 2025
7238d6f
fix integration tests
mvadari May 29, 2025
fa6955e
bump version
mvadari May 29, 2025
3fec605
add workflow_dispatch to publish flow
mvadari May 29, 2025
1a46cb4
fix tests (hopefully)
mvadari May 29, 2025
64c4adc
Merge branch 'main' into smart-escrows
mvadari Jun 5, 2025
217e815
fix definitions
mvadari Jun 5, 2025
087f280
Merge branch 'main' into smart-escrows
mvadari Jun 8, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .ci-config/rippled.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ pool.ntp.org
[ips]
r.ripple.com 51235

[validators_file]
validators.txt

[rpc_startup]
{ "command": "log_level", "severity": "info" }

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/publish_to_pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
push:
tags:
- '*'
workflow_dispatch:

jobs:
build:
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = "xrpl-py"
version = "4.1.0"
description = "A complete Python library for interacting with the XRP ledger"
version = "4.2.0b3"
description = "A complete Python library for interacting with the XRP ledger (Smart Escrow beta)"
license = "ISC"
readme = "README.md"
authors = [
Expand Down
21 changes: 12 additions & 9 deletions tests/faucet/test_faucet_wallet.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import asyncio
import time
from threading import Thread
from unittest import TestCase

try:
from unittest import IsolatedAsyncioTestCase
except ImportError:
from aiounittest import AsyncTestCase as IsolatedAsyncioTestCase # type: ignore

import httpx

from tests.integration.it_utils import submit_transaction_async
from xrpl.asyncio.clients import AsyncJsonRpcClient, AsyncWebsocketClient
from xrpl.asyncio.wallet import generate_faucet_wallet
from xrpl.clients import JsonRpcClient, WebsocketClient
from xrpl.core.addresscodec.main import classic_address_to_xaddress
from xrpl.models.requests import AccountInfo
from xrpl.models.transactions import Payment
from xrpl.wallet import generate_faucet_wallet as sync_generate_faucet_wallet
from xrpl.wallet.main import Wallet

# Add retry logic for wallet funding to handle newly introduced faucet rate limiting.
MAX_RETRY_DURATION = 600 # 10 minutes
Expand Down Expand Up @@ -107,8 +109,8 @@ async def generate_faucet_wallet_and_fund_again(
self.assertTrue(new_balance > balance)


class TestWallet(TestCase):
def test_run_faucet_tests(self):
class TestWallet(IsolatedAsyncioTestCase):
async def test_run_faucet_tests(self):
# run all the tests that start with `_test_` in parallel
def run_test(test_name):
with self.subTest(method=test_name):
Expand Down Expand Up @@ -199,7 +201,8 @@ async def _parallel_test_generate_faucet_wallet_devnet_async_websockets(self):
) as client:
await generate_faucet_wallet_and_fund_again(self, client)

def test_wallet_get_xaddress(self):
wallet = Wallet.create()
expected = classic_address_to_xaddress(wallet.address, None, False)
self.assertEqual(wallet.get_xaddress(), expected)
async def _parallel_test_generate_faucet_wallet_wasm_devnet_async_websockets(self):
async with AsyncWebsocketClient(
"wss://wasm.devnet.rippletest.net:51233"
) as client:
await generate_faucet_wallet_and_fund_again(self, client)
12 changes: 8 additions & 4 deletions tests/integration/it_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ async def sign_and_reliable_submission_async(


def accept_ledger(
use_json_client: bool = True, delay: float = LEDGER_ACCEPT_TIME
use_json_client: bool = True, delay: float = LEDGER_ACCEPT_TIME, wait: bool = False
) -> None:
"""
Allows integration tests for sync clients to send a `ledger_accept` request
Expand All @@ -232,11 +232,13 @@ def accept_ledger(
delay: float for how many seconds to wait before accepting ledger.
"""
client = _choose_client(use_json_client)
SyncTestTimer(client, delay)
timer = SyncTestTimer(client, delay)
if wait:
timer._timer.join() # Wait for the timer to finish


async def accept_ledger_async(
use_json_client: bool = True, delay: float = LEDGER_ACCEPT_TIME
use_json_client: bool = True, delay: float = LEDGER_ACCEPT_TIME, wait: bool = False
) -> None:
"""
Allows integration tests for async clients to send a `ledger_accept` request
Expand All @@ -247,7 +249,9 @@ async def accept_ledger_async(
delay: float for how many seconds to wait before accepting ledger.
"""
client = _choose_client_async(use_json_client)
AsyncTestTimer(client, delay)
timer = AsyncTestTimer(client, delay)
if wait:
await timer._job()


def _choose_client(use_json_client: bool) -> SyncClient:
Expand Down
133 changes: 133 additions & 0 deletions tests/integration/transactions/test_escrow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
from tests.integration.integration_test_case import IntegrationTestCase
from tests.integration.it_utils import (
accept_ledger_async,
sign_and_reliable_submission_async,
test_async_and_sync,
)
from tests.integration.reusable_values import DESTINATION, WALLET
from xrpl.models import EscrowCancel, EscrowCreate, EscrowFinish, Ledger
from xrpl.models.response import ResponseStatus

ACCOUNT = WALLET.address

AMOUNT = "10000"
CONDITION = (
"A0258020E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855810100"
)
DESTINATION_TAG = 23480
SOURCE_TAG = 11747

FINISH_FUNCTION = (
"0061736d010000000105016000017f02190108686f73745f6c69620c6765"
"744c656467657253716e00000302010005030100100611027f00418080c0"
"000b7f00418080c0000b072e04066d656d6f727902000666696e69736800"
"010a5f5f646174615f656e6403000b5f5f686561705f6261736503010a09"
"010700100041044a0b004d0970726f64756365727302086c616e67756167"
"65010452757374000c70726f6365737365642d6279010572757374631d31"
"2e38352e31202834656231363132353020323032352d30332d3135290049"
"0f7461726765745f6665617475726573042b0f6d757461626c652d676c6f"
"62616c732b087369676e2d6578742b0f7265666572656e63652d74797065"
"732b0a6d756c746976616c7565"
)


class TestEscrow(IntegrationTestCase):
@test_async_and_sync(globals())
async def test_all_fields_cancel(self, client):
ledger = await client.request(Ledger(ledger_index="validated"))
close_time = ledger.result["ledger"]["close_time"]
escrow_create = EscrowCreate(
account=ACCOUNT,
amount=AMOUNT,
destination=DESTINATION.classic_address,
destination_tag=DESTINATION_TAG,
cancel_after=close_time + 3,
finish_after=close_time + 2,
source_tag=SOURCE_TAG,
)
response = await sign_and_reliable_submission_async(
escrow_create, WALLET, client
)
self.assertEqual(response.status, ResponseStatus.SUCCESS)
self.assertEqual(response.result["engine_result"], "tesSUCCESS")
sequence = response.result["tx_json"]["Sequence"]
# TODO: check account_objects

for _ in range(3):
await accept_ledger_async(wait=True)

escrow_cancel = EscrowCancel(
account=ACCOUNT,
owner=ACCOUNT,
offer_sequence=sequence,
)
response = await sign_and_reliable_submission_async(
escrow_cancel, WALLET, client
)
self.assertEqual(response.status, ResponseStatus.SUCCESS)
self.assertEqual(response.result["engine_result"], "tesSUCCESS")

@test_async_and_sync(globals())
async def test_all_fields_finish(self, client):
ledger = await client.request(Ledger(ledger_index="validated"))
close_time = ledger.result["ledger"]["close_time"]
escrow_create = EscrowCreate(
account=ACCOUNT,
amount=AMOUNT,
destination=DESTINATION.classic_address,
destination_tag=DESTINATION_TAG,
finish_after=close_time + 2,
source_tag=SOURCE_TAG,
)
response = await sign_and_reliable_submission_async(
escrow_create, WALLET, client
)
self.assertEqual(response.status, ResponseStatus.SUCCESS)
self.assertEqual(response.result["engine_result"], "tesSUCCESS")
sequence = response.result["tx_json"]["Sequence"]
# TODO: check account_objects

for _ in range(2):
await accept_ledger_async(wait=True)

escrow_finish = EscrowFinish(
account=ACCOUNT,
owner=ACCOUNT,
offer_sequence=sequence,
)
response = await sign_and_reliable_submission_async(
escrow_finish, WALLET, client
)
self.assertEqual(response.status, ResponseStatus.SUCCESS)
self.assertEqual(response.result["engine_result"], "tesSUCCESS")

@test_async_and_sync(globals())
async def test_finish_function(self, client):
ledger = await client.request(Ledger(ledger_index="validated"))
close_time = ledger.result["ledger"]["close_time"]
escrow_create = EscrowCreate(
account=ACCOUNT,
amount=AMOUNT,
destination=DESTINATION.classic_address,
finish_function=FINISH_FUNCTION,
cancel_after=close_time + 200,
)
response = await sign_and_reliable_submission_async(
escrow_create, WALLET, client
)
self.assertEqual(response.status, ResponseStatus.SUCCESS)
self.assertEqual(response.result["engine_result"], "tesSUCCESS")
sequence = response.result["tx_json"]["Sequence"]
# TODO: check account_objects

escrow_finish = EscrowFinish(
account=ACCOUNT,
owner=ACCOUNT,
offer_sequence=sequence,
computation_allowance=5,
)
response = await sign_and_reliable_submission_async(
escrow_finish, WALLET, client
)
self.assertEqual(response.status, ResponseStatus.SUCCESS)
self.assertEqual(response.result["engine_result"], "tesSUCCESS")
27 changes: 0 additions & 27 deletions tests/integration/transactions/test_escrow_cancel.py

This file was deleted.

38 changes: 0 additions & 38 deletions tests/integration/transactions/test_escrow_create.py

This file was deleted.

38 changes: 0 additions & 38 deletions tests/integration/transactions/test_escrow_finish.py

This file was deleted.

10 changes: 6 additions & 4 deletions tests/unit/asyn/wallet/test_wallet.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from unittest import TestCase

from xrpl.asyncio.wallet.wallet_generation import (
_DEV_FAUCET_URL,
_TEST_FAUCET_URL,
_DEVNET_FAUCET_URL,
_TESTNET_FAUCET_URL,
_WASM_DEVNET_FAUCET_URL,
XRPLFaucetException,
get_faucet_url,
process_faucet_host_url,
Expand All @@ -18,8 +19,9 @@ def test_wallet_get_xaddress(self):
self.assertEqual(wallet.get_xaddress(), expected)

def test_get_faucet_wallet_valid(self):
self.assertEqual(get_faucet_url(1), _TEST_FAUCET_URL)
self.assertEqual(get_faucet_url(2), _DEV_FAUCET_URL)
self.assertEqual(get_faucet_url(1), _TESTNET_FAUCET_URL)
self.assertEqual(get_faucet_url(2), _DEVNET_FAUCET_URL)
self.assertEqual(get_faucet_url(2002), _WASM_DEVNET_FAUCET_URL)

def test_get_faucet_wallet_invalid(self):
with self.assertRaises(XRPLFaucetException):
Expand Down
Loading
Loading