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 22 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
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.0b2"
description = "A complete Python library for interacting with the XRP ledger (Smart Escrow beta)"
license = "ISC"
readme = "README.md"
authors = [
Expand Down
19 changes: 11 additions & 8 deletions tests/integration/sugar/test_wallet.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import asyncio
from threading import Thread

from tests.integration.integration_test_case import IntegrationTestCase
try:
from unittest import IsolatedAsyncioTestCase
except ImportError:
from aiounittest import AsyncTestCase as IsolatedAsyncioTestCase # type: ignore

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


def sync_generate_faucet_wallet_and_fund_again(
Expand Down Expand Up @@ -65,7 +67,7 @@ async def generate_faucet_wallet_and_fund_again(
self.assertTrue(new_balance > balance)


class TestWallet(IntegrationTestCase):
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):
Expand Down Expand Up @@ -157,7 +159,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)
135 changes: 135 additions & 0 deletions tests/integration/transactions/test_escrow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
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 = (
"0061736d010000000105016000017f021b0108686f73745f6c69620e6765745f6c"
"65646765725f73716e0000030201000405017001010105030100100619037f0141"
"8080c0000b7f00418080c0000b7f00418080c0000b072d04066d656d6f72790200"
"05726561647900010a5f5f646174615f656e6403010b5f5f686561705f62617365"
"03020a0d010b0010808080800041044a0b006e046e616d65000e0d7761736d5f6c"
"69622e7761736d01430200395f5a4e387761736d5f6c696238686f73745f6c6962"
"31346765745f6c65646765725f73716e3137686663383539386237646539633036"
"64624501057265616479071201000f5f5f737461636b5f706f696e746572005509"
"70726f64756365727302086c616e6775616765010452757374000c70726f636573"
"7365642d62790105727573746325312e38332e302d6e696768746c792028633266"
"37346333663920323032342d30392d30392900490f7461726765745f6665617475"
"726573042b0a6d756c746976616c75652b0f6d757461626c652d676c6f62616c73"
"2b0f7265666572656e63652d74797065732b087369676e2d657874"
)


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(4):
await accept_ledger_async(delay=0.5)

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(6):
await accept_ledger_async(delay=0.5)

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,
)
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
42 changes: 38 additions & 4 deletions tests/unit/models/transactions/test_escrow_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,56 @@


class TestEscrowCreate(TestCase):
def test_all_fields_valid(self):
account = "r9LqNeG6qHxjeUocjvVki2XR35weJ9mZgQ"
amount = "amount"
cancel_after = 3
destination = "destination"
destination_tag = 1
finish_after = 2
finish_function = "abcdef"
condition = "abcdef"

escrow_create = EscrowCreate(
account=account,
amount=amount,
destination=destination,
destination_tag=destination_tag,
cancel_after=cancel_after,
finish_after=finish_after,
finish_function=finish_function,
condition=condition,
)
self.assertTrue(escrow_create.is_valid())

def test_final_after_less_than_cancel_after(self):
account = "r9LqNeG6qHxjeUocjvVki2XR35weJ9mZgQ"
amount = "amount"
cancel_after = 1
finish_after = 2
destination = "destination"
fee = "0.00001"
sequence = 19048

with self.assertRaises(XRPLModelException):
EscrowCreate(
account=account,
amount=amount,
cancel_after=cancel_after,
destination=destination,
fee=fee,
finish_after=finish_after,
sequence=sequence,
)

def test_no_finish(self):
account = "r9LqNeG6qHxjeUocjvVki2XR35weJ9mZgQ"
amount = "amount"
cancel_after = 1
destination = "destination"
destination_tag = 1

with self.assertRaises(XRPLModelException):
EscrowCreate(
account=account,
amount=amount,
destination=destination,
destination_tag=destination_tag,
cancel_after=cancel_after,
)
Loading
Loading