Skip to content

Commit

Permalink
Add test for get_login_link
Browse files Browse the repository at this point in the history
  • Loading branch information
emlowe committed Nov 13, 2024
1 parent edbea38 commit 9595fed
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 4 deletions.
52 changes: 52 additions & 0 deletions chia/_tests/pools/test_pool_cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
ChangePayoutInstructionsPlotNFTCMD,
ClaimPlotNFTCMD,
CreatePlotNFTCMD,
GetLoginLinkCMD,
InspectPlotNFTCMD,
JoinPlotNFTCMD,
LeavePlotNFTCMD,
Expand All @@ -28,6 +29,7 @@
from chia.pools.pool_config import PoolWalletConfig, load_pool_config, update_pool_config
from chia.pools.pool_wallet_info import PoolSingletonState, PoolWalletInfo
from chia.rpc.wallet_rpc_client import WalletRpcClient
from chia.simulator.setup_services import setup_farmer
from chia.types.blockchain_format.sized_bytes import bytes32
from chia.util.bech32m import encode_puzzle_hash
from chia.util.errors import CliRpcConnectionError
Expand Down Expand Up @@ -909,3 +911,53 @@ async def test_plotnft_cli_change_payout(
wanted_config = next((x for x in config if x.launcher_id == pw_info.launcher_id), None)
assert wanted_config is not None
assert wanted_config.payout_instructions == burn_ph.hex()


@pytest.mark.limit_consensus_modes(reason="unneeded")
@pytest.mark.parametrize(
"wallet_environments",
[
{
"num_environments": 1,
"blocks_needed": [10],
"trusted": True,
"reuse_puzhash": False,
}
],
indirect=True,
)
@pytest.mark.anyio
async def test_plotnft_cli_get_login_link(
capsys: pytest.CaptureFixture[str],
wallet_environments: WalletTestFramework,
self_hostname: str,
) -> None:
wallet_state_manager: WalletStateManager = wallet_environments.environments[0].wallet_state_manager
wallet_rpc: WalletRpcClient = wallet_environments.environments[0].rpc_client
_client_info: WalletClientInfo = WalletClientInfo(
wallet_rpc,
wallet_state_manager.root_pubkey.get_fingerprint(),
wallet_state_manager.config,
)
bt = wallet_environments.full_node.bt

async with setup_farmer(
b_tools=bt,
root_path=wallet_environments.environments[0].node.root_path,
self_hostname=self_hostname,
consensus_constants=bt.constants,
) as farmer:
root_path = wallet_environments.environments[0].node.root_path

assert farmer.rpc_server and farmer.rpc_server.webserver
context = {
"root_path": root_path,
"rpc_port": farmer.rpc_server.webserver.listen_port,
}
runner = CliRunner()
with runner.isolated_filesystem():
with pytest.raises(CliRpcConnectionError, match="Was not able to get login link"):
await GetLoginLinkCMD(
context=context,
launcher_id=bytes32(32 * b"0"),
).run()
4 changes: 3 additions & 1 deletion chia/cmds/plotnft.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ class GetLoginLinkCMD:
async def run(self) -> None:
from .plotnft_funcs import get_login_link

await get_login_link(self.launcher_id)
await get_login_link(
self.launcher_id, rpc_port=self.context.get("rpc_port"), root_path=self.context.get("root_path")
)


# Functions with this mark in this file are not being ported to @tx_out_cmd due to lack of observer key support
Expand Down
6 changes: 3 additions & 3 deletions chia/cmds/plotnft_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,11 @@ async def show(rpc_info: NeedsWalletRPC, wallet_id_passed_in: Optional[int]) ->
await pprint_all_pool_wallet_state(wallet_info.client, summaries_response, address_prefix, pool_state_dict)


async def get_login_link(launcher_id: bytes32) -> None:
async with get_any_service_client(FarmerRpcClient) as (farmer_client, _):
async def get_login_link(launcher_id: bytes32, rpc_port: Optional[int], root_path: Optional[Path]) -> None:
async with get_any_service_client(FarmerRpcClient, rpc_port=rpc_port, root_path=root_path) as (farmer_client, _):
login_link: Optional[str] = await farmer_client.get_pool_login_link(launcher_id)
if login_link is None:
print("Was not able to get login link.")
raise CliRpcConnectionError("Was not able to get login link.")
else:
print(login_link)

Expand Down

0 comments on commit 9595fed

Please sign in to comment.