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: fix network ID tests + refactor network ID logic #655

Merged
merged 2 commits into from
Oct 5, 2023
Merged
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
49 changes: 10 additions & 39 deletions tests/integration/sugar/test_network_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,16 @@ class TestNetworkID(TestCase):
# Autofill should override tx networkID for network with ID > 1024
# and build_version from 1.11.0 or later.
def test_networkid_override(self):
client = JsonRpcClient("https://sidechain-net1.devnet.rippletest.net:51234")
wallet = generate_faucet_wallet(client, debug=True)
# Override client build_version since 1.11.0 is not released yet.
client.build_version = "1.11.0"
tx = AccountSet(
account=wallet.classic_address,
fee=_FEE,
domain="www.example.com",
)
tx_autofilled = autofill(tx, client)
self.assertGreaterEqual(client.network_id, _RESTRICTED_NETWORKS)
self.assertEqual(tx_autofilled.network_id, client.network_id)
with WebsocketClient("wss://hooks-testnet-v3.xrpl-labs.com") as client:
wallet = generate_faucet_wallet(client, debug=True)
tx = AccountSet(
account=wallet.classic_address,
fee=_FEE,
domain="www.example.com",
)
tx_autofilled = autofill(tx, client)
self.assertGreaterEqual(client.network_id, _RESTRICTED_NETWORKS)
self.assertEqual(tx_autofilled.network_id, client.network_id)

# Autofill should ignore tx network_id for build version earlier than 1.11.0.
def test_networkid_ignore_early_version(self):
Expand All @@ -40,30 +38,3 @@ def test_networkid_ignore_early_version(self):
)
tx_autofilled = autofill(tx, client)
self.assertEqual(tx_autofilled.network_id, None)

# Autofill should ignore tx network_id for networks with ID <= 1024.
def test_networkid_ignore_restricted_networks(self):
client = JsonRpcClient("https://s.altnet.rippletest.net:51234")
wallet = generate_faucet_wallet(client, debug=True)
# Override client build_version since 1.11.0 is not released yet.
client.build_version = "1.11.0"
tx = AccountSet(
account=wallet.classic_address,
fee=_FEE,
domain="www.example.com",
)
tx_autofilled = autofill(tx, client)
self.assertLessEqual(client.network_id, _RESTRICTED_NETWORKS)
self.assertEqual(tx_autofilled.network_id, None)

# Autofill should override tx networkID for hooks-testnet.
def test_networkid_override_hooks_testnet(self):
with WebsocketClient("wss://hooks-testnet-v3.xrpl-labs.com") as client:
wallet = generate_faucet_wallet(client, debug=True)
tx = AccountSet(
account=wallet.classic_address,
fee=_FEE,
domain="www.example.com",
)
tx_autofilled = autofill(tx, client)
self.assertEqual(tx_autofilled.network_id, client.network_id)
10 changes: 3 additions & 7 deletions xrpl/asyncio/transaction/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
# More context: https://github.com/XRPLF/rippled/pull/4370
_RESTRICTED_NETWORKS = 1024
_REQUIRED_NETWORKID_VERSION = "1.11.0"
_HOOKS_TESTNET_ID = 21338
# TODO: make this dynamic based on the current ledger fee
_OWNER_RESERVE_FEE: Final[int] = int(xrp_to_drops(2))

Expand Down Expand Up @@ -283,12 +282,9 @@ def _tx_needs_networkID(client: Client) -> bool:
bool: whether the transactions required network ID to be valid
"""
if client.network_id and client.network_id > _RESTRICTED_NETWORKS:
if (
client.build_version
and _is_not_later_rippled_version(
_REQUIRED_NETWORKID_VERSION, client.build_version
)
) or client.network_id == _HOOKS_TESTNET_ID:
if client.build_version and _is_not_later_rippled_version(
_REQUIRED_NETWORKID_VERSION, client.build_version
):
return True
return False

Expand Down