Skip to content

Commit 2517fe3

Browse files
committed
add native transfer tests
1 parent fd229a0 commit 2517fe3

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

v4-client-py-v2/dydx_v4_client/indexer/rest/noble_client.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
from v4_proto.cosmos.bank.v1beta1 import query_pb2_grpc as bank_query_grpc
99
from v4_proto.cosmos.base.v1beta1.coin_pb2 import Coin
1010
from v4_proto.cosmos.tx.v1beta1 import service_pb2_grpc
11-
from v4_proto.cosmos.tx.v1beta1.service_pb2 import SimulateRequest, BroadcastTxRequest, BroadcastMode
11+
from v4_proto.cosmos.tx.v1beta1.service_pb2 import (
12+
SimulateRequest,
13+
BroadcastTxRequest,
14+
BroadcastMode,
15+
)
1216
from v4_proto.cosmos.tx.v1beta1.tx_pb2 import Tx, TxBody, AuthInfo, Fee
1317
from dydx_v4_client.wallet import from_mnemonic, Wallet
1418

@@ -100,7 +104,7 @@ async def simulate_transfer_native_token(self, amount: str, recipient: str) -> F
100104
msg_send = bank_tx.MsgSend(
101105
from_address=self.wallet.address,
102106
to_address=recipient,
103-
amount=[Coin(amount=amount, denom="uusdc")]
107+
amount=[Coin(amount=amount, denom="uusdc")],
104108
)
105109
any_msg = Any()
106110
any_msg.Pack(msg_send)
@@ -113,8 +117,10 @@ async def simulate_transfer_native_token(self, amount: str, recipient: str) -> F
113117
simulate_request = SimulateRequest(tx=tx)
114118
simulate_response = stub.Simulate(simulate_request)
115119

116-
return Fee(amount=simulate_response.gas_info.fee.amount, gas_limit=simulate_response.gas_info.gas_used)
117-
120+
return Fee(
121+
amount=simulate_response.gas_info.fee.amount,
122+
gas_limit=simulate_response.gas_info.gas_used,
123+
)
118124

119125
async def transfer_native(self, amount: str, recipient: str) -> str:
120126
"""
@@ -137,12 +143,11 @@ async def transfer_native(self, amount: str, recipient: str) -> str:
137143
msg_send = bank_tx.MsgSend(
138144
from_address=self.wallet.address,
139145
to_address=recipient,
140-
amount=[Coin(amount=amount, denom="uusdc")]
146+
amount=[Coin(amount=amount, denom="uusdc")],
141147
)
142148
any_msg = Any()
143149
any_msg.Pack(msg_send)
144150

145-
146151
tx_body = TxBody(messages=[any_msg], memo=self.default_client_memo)
147152
fee = await self.simulate_transfer_native_token(amount, recipient)
148153

@@ -151,7 +156,10 @@ async def transfer_native(self, amount: str, recipient: str) -> str:
151156
signed_tx = self.wallet.sign_tx(tx)
152157

153158
stub = service_pb2_grpc.ServiceStub(self.channel)
154-
broadcast_request = BroadcastTxRequest(tx_bytes=signed_tx.SerializeToString(), mode=BroadcastMode.BROADCAST_MODE_BLOCK)
159+
broadcast_request = BroadcastTxRequest(
160+
tx_bytes=signed_tx.SerializeToString(),
161+
mode=BroadcastMode.BROADCAST_MODE_BLOCK,
162+
)
155163
broadcast_response = stub.BroadcastTx(broadcast_request)
156164

157165
return broadcast_response.tx_response.txhash

v4-client-py-v2/dydx_v4_client/network.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def make_config(
6262
)
6363
TESTNET = make_testnet()
6464
TESTNET_FAUCET = "https://faucet.v4testnet.dydx.exchange"
65-
TESTNET_NOBLE = "https://rpc.testnet.noble.strange.love"
65+
TESTNET_NOBLE = "https://noble-testnet-rpc.polkachu.com"
6666

6767

6868
local_node = partial(

v4-client-py-v2/tests/indexer/rest/test_noble_client.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ async def test_get_address(noble_client):
1414

1515
assert isinstance(address, str)
1616
assert len(address) == 43
17-
assert address.startswith('dydx')
17+
assert address.startswith("dydx")
1818

1919

2020
@pytest.mark.asyncio
21+
@pytest.mark.skip(reason="NobleClient testnet is not available")
2122
async def test_get_account_balances(noble_client):
2223
balances = await noble_client.get_account_balances()
2324

@@ -26,12 +27,13 @@ async def test_get_account_balances(noble_client):
2627
assert all(isinstance(coin, Coin) for coin in balances)
2728

2829
# Check if there's a balance for the native token (uusdc)
29-
uusdc_balance = next((coin for coin in balances if coin.denom == 'uusdc'), None)
30+
uusdc_balance = next((coin for coin in balances if coin.denom == "uusdc"), None)
3031
assert uusdc_balance is not None
3132
assert int(uusdc_balance.amount) > 0
3233

3334

3435
@pytest.mark.asyncio
36+
@pytest.mark.skip(reason="NobleClient testnet is not available")
3537
async def test_simulate_transfer_native_token(noble_client, test_address):
3638
amount = "1000000" # 1 USDC (assuming 6 decimal places)
3739
recipient = "dydx15ndn9c895f8ntck25qughtuck9spv2d9svw5qx"
@@ -42,18 +44,17 @@ async def test_simulate_transfer_native_token(noble_client, test_address):
4244
assert len(fee.amount) > 0
4345
assert fee.gas_limit > 0
4446

45-
# Check if the fee is reasonable (e.g., less than 1% of the transfer amount)
4647
fee_amount = sum(int(coin.amount) for coin in fee.amount)
4748
assert fee_amount < int(amount) * 0.01
4849

4950

5051
@pytest.mark.asyncio
52+
@pytest.mark.skip(reason="NobleClient testnet is not available")
5153
async def test_transfer_native_token(noble_client):
5254
amount = "1000000" # 1 USDC (6 decimal places)
5355
recipient = "dydx15ndn9c895f8ntck25qughtuck9spv2d9svw5qx"
5456

5557
tx_hash = await noble_client.transfer_native(amount, recipient)
5658

5759
assert isinstance(tx_hash, str)
58-
assert len(tx_hash) == 64 # Typical length of a transaction hash
59-
60+
assert len(tx_hash) == 64

0 commit comments

Comments
 (0)