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

CHIA-1730: port chia plotnft to @chia_commands framework #18833

Merged
merged 62 commits into from
Dec 3, 2024
Merged
Changes from 1 commit
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
27bb718
chia plotnft CLI improvements
emlowe Nov 7, 2024
2abc8ea
use CliRpcConnectionError
emlowe Nov 7, 2024
76141c1
add check to show
emlowe Nov 7, 2024
3012f25
fix typo
emlowe Nov 7, 2024
2d14e7c
Update plotnft CLI to newer framework
emlowe Nov 7, 2024
4600233
Fix help cut-paste error
emlowe Nov 7, 2024
fd610bb
add test using new framework
emlowe Nov 7, 2024
4255d8d
some minor fixes
emlowe Nov 7, 2024
55a6bd2
use click.Choice for pool/local option
emlowe Nov 7, 2024
709fbde
some click options
emlowe Nov 8, 2024
432a142
Some more plotnft cli tests
emlowe Nov 8, 2024
9237cb0
drop test_pool_cmdline from mypy-exclusions
emlowe Nov 8, 2024
7c1bd9d
mypy fixes
emlowe Nov 8, 2024
2d4a702
several fixes
emlowe Nov 8, 2024
f602d85
Add leave test
emlowe Nov 8, 2024
69e9186
join tests
emlowe Nov 8, 2024
933f5ed
more join tests
emlowe Nov 8, 2024
a3a8d9c
missing await
emlowe Nov 8, 2024
37e10c0
Try setting config
emlowe Nov 8, 2024
6ebf3b8
use root_path from NeedsWalletRPC
emlowe Nov 8, 2024
a784788
linting
emlowe Nov 8, 2024
e8c1d46
Some cleanup
emlowe Nov 8, 2024
963d94e
Add claim tests
emlowe Nov 8, 2024
847f451
Merge remote-tracking branch 'origin/main' into EL.plotnft-cli-id
emlowe Nov 12, 2024
18493b8
Improved tests
emlowe Nov 12, 2024
18e8d5b
refactor some test code
emlowe Nov 12, 2024
a47c2a4
Add inspect tests
emlowe Nov 13, 2024
4d86993
Skip bad test for now
emlowe Nov 13, 2024
0fefffe
Add in change payout tests
emlowe Nov 13, 2024
edbea38
quoting error
emlowe Nov 13, 2024
9595fed
Add test for get_login_link
emlowe Nov 13, 2024
d74bc3a
Add in a few negative tests for join
emlowe Nov 13, 2024
9c3389b
Few more tests
emlowe Nov 14, 2024
ac482e5
Experment with clirunner env overrides
emlowe Nov 14, 2024
ad0b89a
put back chia_root into context dict
emlowe Nov 14, 2024
34edcc0
Some cleanup and one more test
emlowe Nov 14, 2024
5030c51
maybe final test
emlowe Nov 14, 2024
e1ab54a
some updates
emlowe Nov 15, 2024
ebd553a
Merge remote-tracking branch 'origin/main' into EL.plotnft-cli-id
emlowe Nov 15, 2024
e2ab86b
some dedup and reorg of test code
emlowe Nov 15, 2024
093043d
run trusted and untrusted paramertization
emlowe Nov 15, 2024
b9f2822
make reuse puzhash stuff work
emlowe Nov 15, 2024
3c67791
Add in required mock object for test_update_pool_config_new_config
emlowe Nov 15, 2024
2f4dea1
rearrange code per review comment - limit use of NeedsWalletRPC to ch…
emlowe Nov 18, 2024
0210745
Add in plotnft click parsing tests
emlowe Nov 18, 2024
5999957
added ability to pass in obj to runner invoke
emlowe Nov 19, 2024
f3063c5
Add in some more test cases
emlowe Nov 19, 2024
ef68d75
fix up create issues with config
emlowe Nov 19, 2024
25f7cad
Add in couple more test cases for error conditions
emlowe Nov 19, 2024
21c1ee6
Minor code cleanup
emlowe Nov 19, 2024
64db81e
Use long options for readability, minor code cleanup
emlowe Nov 20, 2024
47acd59
Use config file for farmer rpc port
emlowe Nov 20, 2024
063a0e5
simplify code
emlowe Nov 20, 2024
6278a59
Add testing for prompt cases
emlowe Nov 20, 2024
c242f90
Add mocking for default_root_path
emlowe Nov 20, 2024
bc59679
context cleanup
emlowe Nov 21, 2024
d08d970
temp debugging output
emlowe Nov 21, 2024
d95c028
patch the proper object
emlowe Nov 21, 2024
3fb781f
merge to origin/main
emlowe Nov 22, 2024
2bee14e
move some wallet fixtures into top level conftest and remove conftest…
emlowe Nov 26, 2024
6074bf8
Merge remote-tracking branch 'origin/main' into EL.plotnft-cli-id
emlowe Nov 26, 2024
46d9df5
merge to origin/main
emlowe Nov 26, 2024
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
Prev Previous commit
Next Next commit
Some more plotnft cli tests
emlowe committed Nov 8, 2024
commit 432a142ea81c6a56f8652c97b2b25b3d19a50987
152 changes: 144 additions & 8 deletions chia/_tests/pools/test_pool_cmdline.py
Original file line number Diff line number Diff line change
@@ -9,13 +9,14 @@
from click.testing import CliRunner

from chia._tests.environments.wallet import WalletStateTransition, WalletTestFramework
from chia._tests.util.misc import Marks, datacases
from chia._tests.util.misc import Marks, boolean_datacases, datacases
from chia._tests.util.time_out_assert import time_out_assert
from chia.cmds.cmd_classes import NeedsWalletRPC, WalletClientInfo
from chia.cmds.plotnft import CreatePlotNFTCMD
from chia.cmds.plotnft import CreatePlotNFTCMD, ShowPlotNFTCMD
from chia.pools.pool_wallet_info import PoolSingletonState, PoolWalletInfo
from chia.rpc.wallet_rpc_client import WalletRpcClient
from chia.util.errors import CliRpcConnectionError
from chia.util.ints import uint32, uint64
from chia.wallet.util.wallet_types import WalletType
from chia.wallet.wallet_state_manager import WalletStateManager

@@ -29,6 +30,64 @@ class StateUrlCase:
marks: Marks = ()


async def verify_pool_state(wallet_rpc: WalletRpcClient, w_id: int, expected_state: PoolSingletonState) -> bool:
pw_status: PoolWalletInfo = (await wallet_rpc.pw_status(w_id))[0]
return pw_status.current.state == expected_state.value


async def create_new_plotnft(wallet_test_framework: WalletTestFramework) -> int:
wallet_state_manager: WalletStateManager = wallet_test_framework.environments[0].wallet_state_manager
wallet_rpc: WalletRpcClient = wallet_test_framework.environments[0].rpc_client

our_ph = await wallet_state_manager.main_wallet.get_new_puzzlehash()

await wallet_rpc.create_new_pool_wallet(
target_puzzlehash=our_ph,
pool_url="http://pool.example.com",
relative_lock_height=uint32(10),
backup_host="",
mode="new",
state="FARMING_TO_POOL",
fee=uint64(0),
)

await wallet_test_framework.process_pending_states(
[
WalletStateTransition(
pre_block_balance_updates={
1: {
"confirmed_wallet_balance": 0,
"unconfirmed_wallet_balance": -1,
"spendable_balance": -250000000000,
"max_send_amount": -250000000000,
"pending_change": 249999999999,
"pending_coin_removal_count": 1,
},
},
post_block_balance_updates={
1: {
"confirmed_wallet_balance": -1,
"unconfirmed_wallet_balance": 0,
"spendable_balance": 249999999999,
"max_send_amount": 249999999999,
"unspent_coin_count": 0,
"pending_change": -249999999999,
"pending_coin_removal_count": -1,
},
2: {"init": True, "unspent_coin_count": 1},
},
)
]
)

summaries_response = await wallet_rpc.get_wallets(WalletType.POOLING_WALLET)
assert len(summaries_response) == 1
wallet_id: int = summaries_response[0]["id"]

await time_out_assert(45, verify_pool_state, True, wallet_rpc, wallet_id, PoolSingletonState.FARMING_TO_POOL)
return wallet_id


@pytest.mark.parametrize(
"wallet_environments",
[
@@ -106,14 +165,9 @@ async def test_plotnft_cli_create(

summaries_response = await wallet_rpc.get_wallets(WalletType.POOLING_WALLET)
assert len(summaries_response) == 1
summaries_response = await wallet_rpc.get_wallets(WalletType.POOLING_WALLET)
wallet_id: int = summaries_response[0]["id"]

async def verify_pool_state(w_id: int, expected_state: PoolSingletonState) -> bool:
pw_status: PoolWalletInfo = (await wallet_rpc.pw_status(w_id))[0]
return pw_status.current.state == expected_state.value

await time_out_assert(45, verify_pool_state, True, wallet_id, PoolSingletonState.SELF_POOLING)
await time_out_assert(45, verify_pool_state, True, wallet_rpc, wallet_id, PoolSingletonState.SELF_POOLING)


@datacases(
@@ -148,3 +202,85 @@ async def test_plotnft_cli_create_errors(
dont_prompt=True,
pool_url=case.pool_url,
).run()


@pytest.mark.parametrize(
"wallet_environments",
[
{
"num_environments": 1,
"blocks_needed": [1],
"trusted": True,
"reuse_puzhash": False,
}
],
indirect=True,
)
# @boolean_datacases(name="with_wallet_id", false="no_wallet_id", true="with_wallet_id")
@pytest.mark.anyio
async def test_plotnft_cli_show(
wallet_environments: WalletTestFramework,
capsys: pytest.CaptureFixture[str],
# with_wallet_id: bool,
) -> 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,
)

runner = CliRunner()
with runner.isolated_filesystem():
with pytest.raises(CliRpcConnectionError, match="No pool wallet found"):
await ShowPlotNFTCMD(
rpc_info=NeedsWalletRPC(
client_info=client_info,
wallet_rpc_port=wallet_rpc.port,
fingerprint=wallet_state_manager.root_pubkey.get_fingerprint(),
),
id=None,
).run()
capsys.readouterr()

with pytest.raises(CliRpcConnectionError, match="is not a pool wallet"):
await ShowPlotNFTCMD(
rpc_info=NeedsWalletRPC(
client_info=client_info,
wallet_rpc_port=wallet_rpc.port,
fingerprint=wallet_state_manager.root_pubkey.get_fingerprint(),
),
id=15,
).run()
capsys.readouterr()

wallet_id = await create_new_plotnft(wallet_environments)

# need to capute the output and verify
await ShowPlotNFTCMD(
rpc_info=NeedsWalletRPC(
client_info=client_info,
wallet_rpc_port=wallet_rpc.port,
fingerprint=wallet_state_manager.root_pubkey.get_fingerprint(),
),
id=wallet_id,
).run()
out, _err = capsys.readouterr()
assert "Current state: FARMING_TO_POOL" in out

# wallet_id = await create_new_plotnft(wallet_environments)

await ShowPlotNFTCMD(
rpc_info=NeedsWalletRPC(
client_info=client_info,
wallet_rpc_port=wallet_rpc.port,
fingerprint=wallet_state_manager.root_pubkey.get_fingerprint(),
),
id=None,
).run()
out, _err = capsys.readouterr()
assert "Current state: FARMING_TO_POOL" in out

# Need to run the farmer to make further tests

2 changes: 1 addition & 1 deletion chia/cmds/plotnft.py
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ class ShowPlotNFTCMD:
async def run(self) -> None:
from .plotnft_funcs import show

await show(self.rpc_info.wallet_rpc_port, self.rpc_info.fingerprint, self.id)
await show(self.rpc_info, self.id)


@chia_command(
26 changes: 14 additions & 12 deletions chia/cmds/plotnft_funcs.py
Original file line number Diff line number Diff line change
@@ -204,13 +204,15 @@ async def pprint_all_pool_wallet_state(
print("")


async def show(wallet_rpc_port: Optional[int], fp: Optional[int], wallet_id_passed_in: Optional[int]) -> None:
async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, _, _):
await wallet_id_lookup_and_check(wallet_client, wallet_id_passed_in)
async def show(rpc_info: NeedsWalletRPC, wallet_id_passed_in: Optional[int]) -> None:
async with rpc_info.wallet_rpc() as wallet_info:
await wallet_id_lookup_and_check(wallet_info.client, wallet_id_passed_in)
summaries_response = await wallet_info.client.get_wallets()
config = wallet_info.config
address_prefix = config["network_overrides"]["config"][config["selected_network"]]["address_prefix"]
pool_state_dict = dict()
try:
async with get_any_service_client(FarmerRpcClient) as (farmer_client, config):
address_prefix = config["network_overrides"]["config"][config["selected_network"]]["address_prefix"]
summaries_response = await wallet_client.get_wallets()
async with get_any_service_client(FarmerRpcClient) as (farmer_client, _):
pool_state_list = (await farmer_client.get_pool_state())["pool_state"]
pool_state_dict: dict[bytes32, dict[str, Any]] = {
bytes32.from_hexstr(pool_state_item["pool_config"]["launcher_id"]): pool_state_item
@@ -221,24 +223,24 @@ async def show(wallet_rpc_port: Optional[int], fp: Optional[int], wallet_id_pass
typ = WalletType(int(summary["type"]))
if summary["id"] == wallet_id_passed_in and typ != WalletType.POOLING_WALLET:
print(
f"Wallet with id: {wallet_id_passed_in} is not a pooling wallet."
f"Wallet with id: {wallet_id_passed_in} is not a pool wallet."
" Please provide a different id."
)
return
pool_wallet_info, _ = await wallet_client.pw_status(wallet_id_passed_in)
pool_wallet_info, _ = await wallet_info.client.pw_status(wallet_id_passed_in)
await pprint_pool_wallet_state(
wallet_client,
wallet_info.client,
wallet_id_passed_in,
pool_wallet_info,
address_prefix,
pool_state_dict.get(pool_wallet_info.launcher_id),
)
else:
await pprint_all_pool_wallet_state(
wallet_client, summaries_response, address_prefix, pool_state_dict
wallet_info.client, summaries_response, address_prefix, pool_state_dict
)
except CliRpcConnectionError: # we want to output this if we can't connect to the farmer
await pprint_all_pool_wallet_state(wallet_client, summaries_response, address_prefix, pool_state_dict)
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:
@@ -293,7 +295,7 @@ async def wallet_id_lookup_and_check(wallet_client: WalletRpcClient, wallet_id:
selected_wallet_id = wallet_id

if not any(wallet["id"] == selected_wallet_id for wallet in pool_wallets):
raise CliRpcConnectionError(f"Wallet with id: {selected_wallet_id} is not a pooling wallet.")
raise CliRpcConnectionError(f"Wallet with id: {selected_wallet_id} is not a pool wallet.")

return selected_wallet_id
except ValueError as e: