Skip to content

Commit

Permalink
make more progress
Browse files Browse the repository at this point in the history
  • Loading branch information
mvadari committed Nov 13, 2023
2 parents d07f711 + 132a94a commit fa3aff0
Show file tree
Hide file tree
Showing 15 changed files with 1,112 additions and 6 deletions.
1 change: 1 addition & 0 deletions .ci-config/rippled.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ XRPFees
# 1.11.0 Amendments
ExpandedSignerList
# 1.12.0 Amendments
AMM
Clawback
fixReducedOffersV1
fixNFTokenRemint
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/integration_test.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
name: Integration test

env:
POETRY_VERSION: 1.4.2
RIPPLED_DOCKER_IMAGE: rippleci/rippled:2.0.0-b4

on:
push:
branches: [ master ]
pull_request:
workflow_dispatch:

env:
POETRY_VERSION: 1.4.2

jobs:
integration-test:
name: Integration test
Expand All @@ -31,7 +32,7 @@ jobs:

- name: Run docker in background
run: |
docker run --detach --rm --name rippled-service -p 5005:5005 -p 6006:6006 --volume "${{ github.workspace }}/.ci-config/":"/opt/ripple/etc/" --health-cmd="wget localhost:6006 || exit 1" --health-interval=5s --health-retries=10 --health-timeout=2s --env GITHUB_ACTIONS=true --env CI=true rippleci/rippled:2.0.0-b3 /opt/ripple/bin/rippled -a --conf /opt/ripple/etc/rippled.cfg
docker run --detach --rm --name rippled-service -p 5005:5005 -p 6006:6006 --volume "${{ github.workspace }}/.ci-config/":"/opt/ripple/etc/" --health-cmd="wget localhost:6006 || exit 1" --health-interval=5s --health-retries=10 --health-timeout=2s --env GITHUB_ACTIONS=true --env CI=true ${{ env.RIPPLED_DOCKER_IMAGE }} /opt/ripple/bin/rippled -a --conf /opt/ripple/etc/rippled.cfg
- name: Install poetry
if: steps.cache-poetry.outputs.cache-hit != 'true'
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Breaking down the command:
* `--interactive` allows you to interact with the container.
* `-t` starts a terminal in the container for you to send commands to.
* `--volume $PWD/.ci-config:/config/` identifies the `rippled.cfg` and `validators.txt` to import. It must be an absolute path, so we use `$PWD` instead of `./`.
* `xrpllabsofficial/xrpld:1.12.0-b1` is an image that is regularly updated with the latest `rippled` releases and can be found here: https:/WietseWind/docker-rippled
* `xrpllabsofficial/xrpld:1.12.0` is an image that is regularly updated with the latest `rippled` releases and can be found here: https:/WietseWind/docker-rippled
* `-a` starts `rippled` in standalone mode
* `--start` signals to start `rippled` with the specified amendments in `rippled.cfg` enabled immediately instead of voting for 2 weeks on them.

Expand Down
162 changes: 161 additions & 1 deletion tests/integration/it_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import inspect
from threading import Timer as ThreadingTimer
from time import sleep
from typing import cast
from typing import Any, Dict, cast

import xrpl # noqa: F401 - needed for sync tests
from xrpl.asyncio.clients import AsyncJsonRpcClient, AsyncWebsocketClient
Expand All @@ -14,6 +14,12 @@
from xrpl.clients.sync_client import SyncClient
from xrpl.constants import CryptoAlgorithm
from xrpl.models import GenericRequest, Payment, Request, Response, Transaction
from xrpl.models.amounts.issued_currency_amount import IssuedCurrencyAmount
from xrpl.models.currencies.issued_currency import IssuedCurrency
from xrpl.models.currencies.xrp import XRP
from xrpl.models.transactions.account_set import AccountSet, AccountSetAsfFlag
from xrpl.models.transactions.amm_create import AMMCreate
from xrpl.models.transactions.trust_set import TrustSet, TrustSetFlag
from xrpl.transaction import sign_and_submit # noqa: F401 - needed for sync tests
from xrpl.transaction import ( # noqa: F401 - needed for sync tests
submit as submit_transaction_alias,
Expand Down Expand Up @@ -302,3 +308,157 @@ def _get_non_decorator_code(function):
if "def " in code_lines[line]:
return code_lines[line:]
line += 1


def create_amm_pool(
client: SyncClient = JSON_RPC_CLIENT,
) -> Dict[str, Any]:
issuer_wallet = Wallet.create()
fund_wallet(issuer_wallet)
lp_wallet = Wallet.create()
fund_wallet(lp_wallet)
currency_code = "USD"

# test prerequisites - create trustline and send funds
sign_and_reliable_submission(
AccountSet(
account=issuer_wallet.classic_address,
set_flag=AccountSetAsfFlag.ASF_DEFAULT_RIPPLE,
),
issuer_wallet,
)

sign_and_reliable_submission(
TrustSet(
account=lp_wallet.classic_address,
flags=TrustSetFlag.TF_CLEAR_NO_RIPPLE,
limit_amount=IssuedCurrencyAmount(
issuer=issuer_wallet.classic_address,
currency=currency_code,
value="1000",
),
),
lp_wallet,
)

sign_and_reliable_submission(
Payment(
account=issuer_wallet.classic_address,
destination=lp_wallet.classic_address,
amount=IssuedCurrencyAmount(
currency=currency_code,
issuer=issuer_wallet.classic_address,
value="500",
),
),
issuer_wallet,
)

sign_and_reliable_submission(
AMMCreate(
account=lp_wallet.classic_address,
amount="250",
amount2=IssuedCurrencyAmount(
issuer=issuer_wallet.classic_address,
currency=currency_code,
value="250",
),
trading_fee=12,
),
lp_wallet,
client,
)

asset = XRP()
asset2 = IssuedCurrency(
currency=currency_code,
issuer=issuer_wallet.classic_address,
)

return {
"asset": asset,
"asset2": asset2,
"issuer_wallet": issuer_wallet,
}


async def create_amm_pool_async(
client: AsyncClient = ASYNC_JSON_RPC_CLIENT,
) -> Dict[str, Any]:
issuer_wallet = Wallet.create()
await fund_wallet_async(issuer_wallet)
lp_wallet = Wallet.create()
await fund_wallet_async(lp_wallet)
currency_code = "USD"

# test prerequisites - create trustline and send funds
await sign_and_reliable_submission_async(
AccountSet(
account=issuer_wallet.classic_address,
set_flag=AccountSetAsfFlag.ASF_DEFAULT_RIPPLE,
),
issuer_wallet,
)

await sign_and_reliable_submission_async(
TrustSet(
account=lp_wallet.classic_address,
flags=TrustSetFlag.TF_CLEAR_NO_RIPPLE,
limit_amount=IssuedCurrencyAmount(
issuer=issuer_wallet.classic_address,
currency=currency_code,
value="1000",
),
),
lp_wallet,
)

await sign_and_reliable_submission_async(
Payment(
account=issuer_wallet.classic_address,
destination=lp_wallet.classic_address,
amount=IssuedCurrencyAmount(
currency=currency_code,
issuer=issuer_wallet.classic_address,
value="500",
),
),
issuer_wallet,
)

await sign_and_reliable_submission_async(
AMMCreate(
account=lp_wallet.classic_address,
amount="250",
amount2=IssuedCurrencyAmount(
issuer=issuer_wallet.classic_address,
currency=currency_code,
value="250",
),
trading_fee=12,
),
lp_wallet,
client,
)

asset = XRP()
asset2 = IssuedCurrency(
currency=currency_code,
issuer=issuer_wallet.classic_address,
)

return {
"asset": asset,
"asset2": asset2,
"issuer_wallet": issuer_wallet,
}


def compare_amm_values(val, val2, round_buffer):
diff = abs(float(val) - float(val2))
if diff > round_buffer:
raise ValueError(
f"Values [{val}, {val2}] with difference {diff} are too far apart "
f"with round_buffer {round_buffer}"
)
return True
28 changes: 28 additions & 0 deletions tests/integration/reqs/test_amm_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from tests.integration.integration_test_case import IntegrationTestCase
from tests.integration.it_utils import test_async_and_sync
from tests.integration.reusable_values import AMM_ASSET, AMM_ASSET2
from xrpl.models.requests.amm_info import AMMInfo

asset = AMM_ASSET
asset2 = AMM_ASSET2


class TestAMMInfo(IntegrationTestCase):
@test_async_and_sync(globals())
async def test_basic_functionality(self, client):
amm_info = await client.request(
AMMInfo(
asset=asset,
asset2=asset2,
)
)

self.assertEqual(float(amm_info.result["amm"]["amount"]), 1250)
self.assertEqual(
amm_info.result["amm"]["amount2"],
{
"currency": asset2.currency,
"issuer": asset2.issuer,
"value": "250",
},
)
10 changes: 10 additions & 0 deletions tests/integration/reqs/test_server_definitions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from tests.integration.integration_test_case import IntegrationTestCase
from tests.integration.it_utils import test_async_and_sync
from xrpl.models.requests import ServerDefinitions


class TestServerDefinitions(IntegrationTestCase):
@test_async_and_sync(globals())
async def test_basic_functionality(self, client):
response = await client.request(ServerDefinitions())
self.assertTrue(response.is_successful())
46 changes: 46 additions & 0 deletions tests/integration/reusable_values.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import asyncio
from typing import Any, Dict

from tests.integration.it_utils import (
ASYNC_JSON_RPC_CLIENT,
MASTER_ACCOUNT,
create_amm_pool_async,
fund_wallet_async,
sign_and_reliable_submission_async,
)
from xrpl.asyncio.clients.async_client import AsyncClient
from xrpl.models import (
XRP,
AMMDeposit,
AMMDepositFlag,
IssuedCurrencyAmount,
OfferCreate,
PaymentChannelCreate,
Expand Down Expand Up @@ -84,23 +90,63 @@ async def _set_up_reusable_values():
door_wallet,
)

setup_amm_pool_res = await setup_amm_pool(wallet=wallet)
amm_asset = setup_amm_pool_res["asset"]
amm_asset2 = setup_amm_pool_res["asset2"]
amm_issuer_wallet = setup_amm_pool_res["issuer_wallet"]

return (
wallet,
destination,
door_wallet,
witness_wallet,
offer,
payment_channel,
amm_asset,
amm_asset2,
amm_issuer_wallet,
bridge,
)


async def setup_amm_pool(
wallet: Wallet,
client: AsyncClient = ASYNC_JSON_RPC_CLIENT,
) -> Dict[str, Any]:
amm_pool = await create_amm_pool_async(client=client)
asset = amm_pool["asset"]
asset2 = amm_pool["asset2"]
issuer_wallet = amm_pool["issuer_wallet"]

# Need to deposit (be an LP) to make bid/vote/withdraw eligible in tests for WALLET
await sign_and_reliable_submission_async(
AMMDeposit(
account=wallet.classic_address,
asset=asset,
asset2=asset2,
amount="1000",
flags=AMMDepositFlag.TF_SINGLE_ASSET,
),
wallet,
client,
)

return {
"asset": asset,
"asset2": asset2,
"issuer_wallet": issuer_wallet,
}


(
WALLET,
DESTINATION,
DOOR_WALLET,
WITNESS_WALLET,
OFFER,
PAYMENT_CHANNEL,
AMM_ASSET,
AMM_ASSET2,
AMM_ISSUER_WALLET,
BRIDGE,
) = asyncio.run(_set_up_reusable_values())
Loading

0 comments on commit fa3aff0

Please sign in to comment.