mirror of
https://github.com/Chia-Network/chia-blockchain.git
synced 2026-08-24 10:05:29 -05:00
Add RPC client and tests for cancel_offers endpoint (#15758)
This commit is contained in:
@@ -1846,7 +1846,7 @@ class WalletRpcApi:
|
||||
continue
|
||||
if trade.offer and trade.offer != b"":
|
||||
offer = Offer.from_bytes(trade.offer)
|
||||
if key in offer.driver_dict:
|
||||
if key in offer.arbitrage():
|
||||
records.append(trade)
|
||||
continue
|
||||
|
||||
|
||||
@@ -874,6 +874,26 @@ class WalletRpcClient(RpcClient):
|
||||
async def cancel_offer(self, trade_id: bytes32, fee=uint64(0), secure: bool = True):
|
||||
await self.fetch("cancel_offer", {"trade_id": trade_id.hex(), "secure": secure, "fee": fee})
|
||||
|
||||
async def cancel_offers(
|
||||
self,
|
||||
fee=uint64(0),
|
||||
secure: bool = True,
|
||||
batch_size: int = 5,
|
||||
cancel_all: bool = False,
|
||||
asset_id: Optional[bytes32] = None,
|
||||
) -> None:
|
||||
await self.fetch(
|
||||
"cancel_offers",
|
||||
{
|
||||
"secure": secure,
|
||||
"batch_fee": fee,
|
||||
"secure": secure,
|
||||
"batch_size": batch_size,
|
||||
"cancel_all": cancel_all,
|
||||
"asset_id": None if asset_id is None else asset_id.hex(),
|
||||
},
|
||||
)
|
||||
|
||||
# NFT wallet
|
||||
async def create_new_nft_wallet(self, did_id, name=None) -> dict[str, Any]:
|
||||
request: Dict[str, Any] = {
|
||||
|
||||
@@ -1160,6 +1160,38 @@ async def test_offer_endpoints(wallet_rpc_environment: WalletRpcTestEnvironment)
|
||||
)
|
||||
###
|
||||
|
||||
await wallet_1_rpc.create_offer_for_ids(
|
||||
{uint32(1): -5, cat_asset_id.hex(): 1},
|
||||
driver_dict=driver_dict,
|
||||
)
|
||||
assert len([o for o in await wallet_1_rpc.get_all_offers() if o.status == TradeStatus.PENDING_ACCEPT.value]) == 2
|
||||
await wallet_1_rpc.cancel_offers(batch_size=1)
|
||||
assert len([o for o in await wallet_1_rpc.get_all_offers() if o.status == TradeStatus.PENDING_ACCEPT.value]) == 0
|
||||
|
||||
await farm_transaction_block(full_node_api, wallet_node)
|
||||
|
||||
await wallet_1_rpc.create_offer_for_ids(
|
||||
{uint32(1): -5, cat_asset_id.hex(): 1},
|
||||
driver_dict=driver_dict,
|
||||
)
|
||||
await wallet_1_rpc.create_offer_for_ids(
|
||||
{uint32(1): 5, cat_asset_id.hex(): -1},
|
||||
driver_dict=driver_dict,
|
||||
)
|
||||
assert len([o for o in await wallet_1_rpc.get_all_offers() if o.status == TradeStatus.PENDING_ACCEPT.value]) == 2
|
||||
await wallet_1_rpc.cancel_offers(cancel_all=True)
|
||||
assert len([o for o in await wallet_1_rpc.get_all_offers() if o.status == TradeStatus.PENDING_ACCEPT.value]) == 0
|
||||
|
||||
await wallet_1_rpc.create_offer_for_ids(
|
||||
{uint32(1): 5, cat_asset_id.hex(): -1},
|
||||
driver_dict=driver_dict,
|
||||
)
|
||||
assert len([o for o in await wallet_1_rpc.get_all_offers() if o.status == TradeStatus.PENDING_ACCEPT.value]) == 1
|
||||
await wallet_1_rpc.cancel_offers(asset_id=bytes32([0] * 32))
|
||||
assert len([o for o in await wallet_1_rpc.get_all_offers() if o.status == TradeStatus.PENDING_ACCEPT.value]) == 1
|
||||
await wallet_1_rpc.cancel_offers(asset_id=cat_asset_id)
|
||||
assert len([o for o in await wallet_1_rpc.get_all_offers() if o.status == TradeStatus.PENDING_ACCEPT.value]) == 0
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_coin_records_by_names(wallet_rpc_environment: WalletRpcTestEnvironment) -> None:
|
||||
|
||||
Reference in New Issue
Block a user