Skip to content

Commit

Permalink
fix: fix network ID tests + refactor network ID logic (#655)
Browse files Browse the repository at this point in the history
fix network ID tests, remove hooks testnet exception
  • Loading branch information
mvadari authored Oct 5, 2023
1 parent 73622f8 commit 7ba9fa7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 46 deletions.
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

0 comments on commit 7ba9fa7

Please sign in to comment.