Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
257 changes: 199 additions & 58 deletions chia/_tests/pools/test_pool_rpc.py

Large diffs are not rendered by default.

22 changes: 16 additions & 6 deletions chia/_tests/wallet/did_wallet/test_did.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,14 @@
from chia.wallet.wallet import Wallet
from chia.wallet.wallet_action_scope import WalletActionScope
from chia.wallet.wallet_node import WalletNode
from chia.wallet.wallet_request_types import DIDFindLostDID, DIDGetCurrentCoinInfo, DIDGetInfo
from chia.wallet.wallet_request_types import (
CreateNewWallet,
CreateNewWalletType,
DIDFindLostDID,
DIDGetCurrentCoinInfo,
DIDGetInfo,
DIDType,
)
from chia.wallet.wallet_rpc_api import WalletRpcApi


Expand Down Expand Up @@ -284,11 +291,14 @@ async def test_creation_from_backup_file(wallet_environments: WalletTestFramewor
backup_data = did_wallet_1.create_backup()

# Wallet2 recovers DIDWallet2 to a new set of keys
await env_2.rpc_client.create_new_did_wallet(
uint64(1),
DEFAULT_TX_CONFIG,
type="recovery",
backup_data=backup_data,
await env_2.rpc_client.create_new_wallet(
CreateNewWallet(
wallet_type=CreateNewWalletType.DID_WALLET,
did_type=DIDType.RECOVERY,
backup_data=backup_data,
push=True,
),
wallet_environments.tx_config,
)
did_wallet_2 = env_2.wallet_state_manager.get_wallet(id=uint32(2), required_type=DIDWallet)
current_coin_info_response = await env_0.rpc_client.did_get_current_coin_info(
Expand Down
22 changes: 18 additions & 4 deletions chia/_tests/wallet/nft_wallet/test_nft_bulk_mint.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@
from chia.wallet.nft_wallet.uncurry_nft import UncurriedNFT
from chia.wallet.transaction_record import TransactionRecord
from chia.wallet.util.address_type import AddressType
from chia.wallet.wallet_request_types import NFTGetNFTs, NFTMintBulk, NFTMintMetadata, PushTransactions, SelectCoins
from chia.wallet.wallet_request_types import (
CreateNewWallet,
CreateNewWalletType,
NFTGetNFTs,
NFTMintBulk,
NFTMintMetadata,
PushTransactions,
SelectCoins,
)


async def nft_count(wallet: NFTWallet) -> int:
Expand Down Expand Up @@ -263,9 +271,15 @@ async def test_nft_mint_rpc(wallet_environments: WalletTestFramework, zero_royal
hex_did_id = did_wallet_maker.get_my_DID()
hmr_did_id = encode_puzzle_hash(bytes32.from_hexstr(hex_did_id), AddressType.DID.hrp(env_0.node.config))

nft_wallet_maker = await env_0.rpc_client.create_new_nft_wallet(name="NFT WALLET 1", did_id=hmr_did_id)
create_wallet_res = await env_0.rpc_client.create_new_wallet(
CreateNewWallet(wallet_type=CreateNewWalletType.NFT_WALLET, name="NFT WALLET 1", did_id=hmr_did_id, push=True),
wallet_environments.tx_config,
)

await env_1.rpc_client.create_new_nft_wallet(name="NFT WALLET 2", did_id=None)
await env_1.rpc_client.create_new_wallet(
CreateNewWallet(wallet_type=CreateNewWalletType.NFT_WALLET, name="NFT WALLET 2", did_id=None, push=True),
wallet_environments.tx_config,
)

await env_0.change_balances({"nft": {"init": True}})
await env_1.change_balances({"nft": {"init": True}})
Expand Down Expand Up @@ -316,7 +330,7 @@ async def test_nft_mint_rpc(wallet_environments: WalletTestFramework, zero_royal
for i in range(0, n, chunk):
resp = await env_0.rpc_client.nft_mint_bulk(
NFTMintBulk(
wallet_id=nft_wallet_maker["wallet_id"],
wallet_id=create_wallet_res.wallet_id,
metadata_list=[NFTMintMetadata.from_json_dict(metadata) for metadata in metadata_list[i : i + chunk]],
target_list=target_list[i : i + chunk],
royalty_percentage=uint16.construct_optional(royalty_percentage),
Expand Down
116 changes: 92 additions & 24 deletions chia/_tests/wallet/rpc/test_wallet_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@
CheckOfferValidity,
ClawbackPuzzleDecoratorOverride,
CombineCoins,
CreateNewWallet,
CreateNewWalletType,
CreateOfferForIDs,
CreateSignedTransaction,
DefaultCAT,
Expand All @@ -132,6 +134,7 @@
DIDMessageSpend,
DIDSetWalletName,
DIDTransferDID,
DIDType,
DIDUpdateMetadata,
FungibleAsset,
GetAllOffers,
Expand Down Expand Up @@ -169,6 +172,7 @@
TakeOffer,
VerifySignature,
VerifySignatureResponse,
WalletCreationMode,
)
from chia.wallet.wallet_rpc_api import WalletRpcApi
from chia.wallet.wallet_rpc_client import WalletRpcClient
Expand Down Expand Up @@ -642,9 +646,17 @@ async def test_create_signed_transaction(
if is_cat:
generated_funds = 10**9

res = await wallet_1_rpc.create_new_cat_and_wallet(uint64(generated_funds), test=True)
assert res["success"]
wallet_id = res["wallet_id"]
create_cat_res = await wallet_1_rpc.create_new_wallet(
CreateNewWallet(
wallet_type=CreateNewWalletType.CAT_WALLET,
mode=WalletCreationMode.NEW,
amount=uint64(generated_funds),
test=True,
push=True,
),
tx_config=DEFAULT_TX_CONFIG,
)
wallet_id = create_cat_res.wallet_id

await time_out_assert(5, check_mempool_spend_count, True, full_node_api, 1)
for _ in range(5):
Expand Down Expand Up @@ -1248,10 +1260,17 @@ async def test_cat_endpoints(wallet_environments: WalletTestFramework, wallet_ty
assert asset_to_name_response.name == next(iter(DEFAULT_CATS.items()))[1]["name"]

# Creates a second wallet with the same CAT
res = await env_1.rpc_client.create_wallet_for_existing_cat(asset_id)
assert res["success"]
cat_1_id = res["wallet_id"]
cat_1_asset_id = bytes.fromhex(res["asset_id"])
create_wallet_res = await env_1.rpc_client.create_new_wallet(
CreateNewWallet(
wallet_type=CreateNewWalletType.CAT_WALLET,
mode=WalletCreationMode.EXISTING,
asset_id=asset_id,
push=True,
),
tx_config=wallet_environments.tx_config,
)
cat_1_id = create_wallet_res.wallet_id
cat_1_asset_id = create_wallet_res.asset_id
assert cat_1_asset_id == asset_id

await wallet_environments.process_pending_states(
Expand Down Expand Up @@ -1505,7 +1524,15 @@ async def test_offer_endpoints(wallet_environments: WalletTestFramework, wallet_
cat_asset_id = cat_wallet.cat_info.limitations_program_hash

# Creates a wallet for the same CAT on wallet_2 and send 4 CAT from wallet_1 to it
await env_2.rpc_client.create_wallet_for_existing_cat(cat_asset_id)
await env_2.rpc_client.create_new_wallet(
CreateNewWallet(
wallet_type=CreateNewWalletType.CAT_WALLET,
mode=WalletCreationMode.EXISTING,
asset_id=cat_asset_id,
push=True,
),
tx_config=wallet_environments.tx_config,
)
wallet_2_address = (await env_2.rpc_client.get_next_address(GetNextAddress(cat_wallet_id, False))).address
adds = [Addition(puzzle_hash=decode_puzzle_hash(wallet_2_address), amount=uint64(4), memos=["the cat memo"])]
tx_res = (
Expand Down Expand Up @@ -2036,15 +2063,23 @@ async def test_did_endpoints(wallet_rpc_environment: WalletRpcTestEnvironment) -
await generate_funds(env.full_node.api, env.wallet_1, 5)

# Create a DID wallet
res = await wallet_1_rpc.create_new_did_wallet(amount=1, tx_config=DEFAULT_TX_CONFIG, name="Profile 1")
assert res["success"]
did_wallet_id_0 = res["wallet_id"]
did_id_0 = res["my_did"]
create_new_res = await wallet_1_rpc.create_new_wallet(
CreateNewWallet(
wallet_type=CreateNewWalletType.DID_WALLET,
did_type=DIDType.NEW,
amount=uint64(1),
wallet_name="Profile 1",
push=True,
),
tx_config=DEFAULT_TX_CONFIG,
)
did_wallet_id_0 = create_new_res.wallet_id
did_id_0 = create_new_res.my_did

# Get wallet name
get_name_res = await wallet_1_rpc.did_get_wallet_name(DIDGetWalletName(did_wallet_id_0))
assert get_name_res.name == "Profile 1"
nft_wallet = wallet_1_node.wallet_state_manager.wallets[did_wallet_id_0 + 1]
nft_wallet = wallet_1_node.wallet_state_manager.wallets[uint32(did_wallet_id_0 + 1)]
assert isinstance(nft_wallet, NFTWallet)
assert nft_wallet.get_name() == "Profile 1 NFT Wallet"

Expand Down Expand Up @@ -2153,8 +2188,11 @@ async def test_nft_endpoints(wallet_rpc_environment: WalletRpcTestEnvironment) -

await generate_funds(env.full_node.api, env.wallet_1, 5)

res = await wallet_1_rpc.create_new_nft_wallet(None)
nft_wallet_id = res["wallet_id"]
create_wallet_res = await wallet_1_rpc.create_new_wallet(
CreateNewWallet(wallet_type=CreateNewWalletType.NFT_WALLET, did_id=None, push=True),
DEFAULT_TX_CONFIG,
)
nft_wallet_id = create_wallet_res.wallet_id
mint_res = await wallet_1_rpc.mint_nft(
request=NFTMintNFTRequest(
wallet_id=nft_wallet_id,
Expand Down Expand Up @@ -3012,13 +3050,19 @@ async def test_set_wallet_resync_on_startup(wallet_rpc_environment: WalletRpcTes
client: WalletRpcClient = env.wallet_1.rpc_client
await generate_funds(full_node_api, env.wallet_1)
wc = env.wallet_1.rpc_client
await wc.create_new_did_wallet(1, DEFAULT_TX_CONFIG, 0)
await wc.create_new_wallet(
CreateNewWallet(wallet_type=CreateNewWalletType.DID_WALLET, did_type=DIDType.NEW, amount=uint64(1), push=True),
DEFAULT_TX_CONFIG,
)
await time_out_assert(5, check_mempool_spend_count, True, full_node_api, 1)
await farm_transaction_block(full_node_api, env.wallet_1.node)
await time_out_assert(20, check_client_synced, True, wc)

nft_wallet = await wc.create_new_nft_wallet(None)
nft_wallet_id = nft_wallet["wallet_id"]
create_wallet_res = await wc.create_new_wallet(
CreateNewWallet(wallet_type=CreateNewWalletType.NFT_WALLET, did_id=None, push=True),
DEFAULT_TX_CONFIG,
)
nft_wallet_id = create_wallet_res.wallet_id
address = (await wc.get_next_address(GetNextAddress(env.wallet_1.wallet.id(), True))).address
await wc.mint_nft(
request=NFTMintNFTRequest(
Expand Down Expand Up @@ -3227,9 +3271,16 @@ async def test_cat_spend_run_tail(wallet_rpc_environment: WalletRpcTestEnvironme
await farm_transaction(full_node_api, wallet_node, eve_spend)

# Make sure we have the CAT
res = await client.create_wallet_for_existing_cat(Program.to(None).get_tree_hash())
assert res["success"]
cat_wallet_id = res["wallet_id"]
create_wallet_res = await client.create_new_wallet(
CreateNewWallet(
wallet_type=CreateNewWalletType.CAT_WALLET,
mode=WalletCreationMode.EXISTING,
asset_id=Program.to(None).get_tree_hash(),
push=True,
),
tx_config=DEFAULT_TX_CONFIG,
)
cat_wallet_id = create_wallet_res.wallet_id
await time_out_assert(20, get_confirmed_balance, tx_amount, client, cat_wallet_id)

# Attempt to melt it fully
Expand Down Expand Up @@ -3270,11 +3321,28 @@ async def test_get_balances(wallet_rpc_environment: WalletRpcTestEnvironment) ->

await time_out_assert(20, check_client_synced, True, client)
# Creates a CAT wallet with 100 mojos and a CAT with 20 mojos
await client.create_new_cat_and_wallet(uint64(100), test=True)
await client.create_new_wallet(
CreateNewWallet(
wallet_type=CreateNewWalletType.CAT_WALLET,
mode=WalletCreationMode.NEW,
amount=uint64(100),
test=True,
push=True,
),
tx_config=DEFAULT_TX_CONFIG,
)

await time_out_assert(20, check_client_synced, True, client)
res = await client.create_new_cat_and_wallet(uint64(20), test=True)
assert res["success"]
await client.create_new_wallet(
CreateNewWallet(
wallet_type=CreateNewWalletType.CAT_WALLET,
mode=WalletCreationMode.NEW,
amount=uint64(20),
test=True,
push=True,
),
tx_config=DEFAULT_TX_CONFIG,
)
await time_out_assert(5, check_mempool_spend_count, True, full_node_api, 2)
await farm_transaction_block(full_node_api, wallet_node)
await time_out_assert(20, check_client_synced, True, client)
Expand Down
37 changes: 24 additions & 13 deletions chia/cmds/plotnft_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,20 @@
load_pool_config,
update_pool_config,
)
from chia.pools.pool_wallet_info import PoolSingletonState, PoolWalletInfo
from chia.pools.pool_wallet_info import NewPoolWalletInitialTargetState, PoolSingletonState, PoolWalletInfo
from chia.protocols.pool_protocol import POOL_PROTOCOL_VERSION
from chia.rpc.rpc_client import ResponseFailureError
from chia.server.server import ssl_context_for_root
from chia.ssl.create_ssl import get_mozilla_ca_crt
from chia.util.bech32m import encode_puzzle_hash
from chia.util.default_root import DEFAULT_ROOT_PATH
from chia.util.errors import CliRpcConnectionError
from chia.wallet.transaction_record import TransactionRecord
from chia.wallet.util.address_type import AddressType
from chia.wallet.util.tx_config import DEFAULT_TX_CONFIG
from chia.wallet.util.wallet_types import WalletType
from chia.wallet.wallet_request_types import (
CreateNewWallet,
CreateNewWalletType,
GetTransaction,
GetWalletBalance,
GetWallets,
Expand All @@ -51,6 +52,7 @@
PWSelfPool,
PWStatus,
TransactionEndpointResponse,
WalletCreationMode,
WalletInfoResponse,
)
from chia.wallet.wallet_rpc_client import WalletRpcClient
Expand Down Expand Up @@ -91,7 +93,7 @@ async def create(
# Could use initial_pool_state_from_dict to simplify
if state == "SELF_POOLING":
pool_url = None
relative_lock_height = uint32(0)
relative_lock_height = None
target_puzzle_hash = None # wallet will fill this in
elif state == "FARMING_TO_POOL":
enforce_https = wallet_info.config["selected_network"] == "mainnet"
Expand All @@ -110,22 +112,31 @@ async def create(
cli_confirm("Confirm (y/n): ", "Aborting.")

try:
tx_record: TransactionRecord = await wallet_info.client.create_new_pool_wallet(
target_puzzle_hash,
pool_url,
relative_lock_height,
"localhost:5000",
"new",
state,
fee,
create_response = await wallet_info.client.create_new_wallet(
CreateNewWallet(
wallet_type=CreateNewWalletType.POOL_WALLET,
initial_target_state=NewPoolWalletInitialTargetState(
target_puzzle_hash=target_puzzle_hash,
state=state,
pool_url=pool_url,
relative_lock_height=relative_lock_height,
),
mode=WalletCreationMode.NEW,
fee=fee,
push=True,
),
DEFAULT_TX_CONFIG,
)
assert create_response.transaction is not None # mypy doesn't know about __post_init__
start = time.time()
while time.time() - start < 10:
await asyncio.sleep(0.1)
tx = (await wallet_info.client.get_transaction(GetTransaction(tx_record.name))).transaction
tx = (
await wallet_info.client.get_transaction(GetTransaction(create_response.transaction.name))
).transaction
if len(tx.sent_to) > 0:
print(transaction_submitted_msg(tx))
print(transaction_status_msg(wallet_info.fingerprint, tx_record.name))
print(transaction_status_msg(wallet_info.fingerprint, create_response.transaction.name))
return None
except Exception as e:
raise CliRpcConnectionError(
Expand Down
Loading
Loading