Skip to content

Commit 6f2db6b

Browse files
committed
Add test for CreateNewWallet.__post_init__()
1 parent 5f8d1c5 commit 6f2db6b

File tree

1 file changed

+225
-0
lines changed

1 file changed

+225
-0
lines changed

chia/_tests/wallet/rpc/test_wallet_rpc.py

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
from chia.cmds.coins import CombineCMD, SplitCMD
4848
from chia.cmds.param_types import CliAmount
4949
from chia.full_node.full_node_rpc_client import FullNodeRpcClient
50+
from chia.pools.pool_wallet_info import NewPoolWalletInitialTargetState
5051
from chia.rpc.rpc_client import ResponseFailureError
5152
from chia.simulator.full_node_simulator import FullNodeSimulator
5253
from chia.types.blockchain_format.coin import Coin, coin_as_list
@@ -4236,3 +4237,227 @@ def test_send_transaction_multi_post_init() -> None:
42364237
SendTransactionMulti( # type: ignore[type-var]
42374238
wallet_id=uint32(1),
42384239
).convert_to_proxy(VCSpend)
4240+
4241+
4242+
def test_create_new_wallet_post_init() -> None:
4243+
with pytest.raises(
4244+
ValueError,
4245+
match=re.escape("Invalid pool wallet initial state: FOO"),
4246+
):
4247+
NewPoolWalletInitialTargetState(state="FOO")
4248+
4249+
with pytest.raises(
4250+
ValueError,
4251+
match=re.escape("target_puzzle_hash must be set when state is FARMING_TO_POOL"),
4252+
):
4253+
NewPoolWalletInitialTargetState(state="FARMING_TO_POOL")
4254+
4255+
with pytest.raises(
4256+
ValueError,
4257+
match=re.escape("pool_url must be set when state is FARMING_TO_POOL"),
4258+
):
4259+
NewPoolWalletInitialTargetState(state="FARMING_TO_POOL", target_puzzle_hash=bytes32.zeros)
4260+
4261+
with pytest.raises(
4262+
ValueError,
4263+
match=re.escape("relative_lock_height must be set when state is FARMING_TO_POOL"),
4264+
):
4265+
NewPoolWalletInitialTargetState(state="FARMING_TO_POOL", target_puzzle_hash=bytes32.zeros, pool_url="")
4266+
4267+
with pytest.raises(
4268+
ValueError,
4269+
match=re.escape("target_puzzle_hash is only valid for FARMING_TO_POOL"),
4270+
):
4271+
NewPoolWalletInitialTargetState(state="SELF_POOLING", target_puzzle_hash=bytes32.zeros)
4272+
4273+
with pytest.raises(
4274+
ValueError,
4275+
match=re.escape("pool_url is only valid for FARMING_TO_POOL"),
4276+
):
4277+
NewPoolWalletInitialTargetState(state="SELF_POOLING", pool_url="")
4278+
4279+
with pytest.raises(
4280+
ValueError,
4281+
match=re.escape("relative_lock_height is only valid for FARMING_TO_POOL"),
4282+
):
4283+
NewPoolWalletInitialTargetState(state="SELF_POOLING", relative_lock_height=uint32(0))
4284+
4285+
with pytest.raises(
4286+
ValueError,
4287+
match=re.escape('Must specify a "mode" when creating a new CAT wallet'),
4288+
):
4289+
CreateNewWallet(wallet_type=CreateNewWalletType.CAT_WALLET)
4290+
4291+
with pytest.raises(
4292+
ValueError,
4293+
match=re.escape("Support for this RPC mode has been dropped."),
4294+
):
4295+
CreateNewWallet(wallet_type=CreateNewWalletType.CAT_WALLET, mode=WalletCreationMode.NEW)
4296+
4297+
with pytest.raises(
4298+
ValueError,
4299+
match=re.escape('Must specify an "amount" of CATs to generate'),
4300+
):
4301+
CreateNewWallet(wallet_type=CreateNewWalletType.CAT_WALLET, mode=WalletCreationMode.NEW, test=True)
4302+
4303+
with pytest.raises(
4304+
ValueError,
4305+
match=re.escape('"asset_id" is not an argument for new CAT wallets. Maybe you meant existing?'),
4306+
):
4307+
CreateNewWallet(
4308+
wallet_type=CreateNewWalletType.CAT_WALLET,
4309+
mode=WalletCreationMode.NEW,
4310+
test=True,
4311+
amount=uint64(0),
4312+
asset_id=bytes32.zeros,
4313+
)
4314+
4315+
with pytest.raises(
4316+
ValueError,
4317+
match=re.escape('Must specify an "asset_id" when creating an existing CAT wallet'),
4318+
):
4319+
CreateNewWallet(wallet_type=CreateNewWalletType.CAT_WALLET, mode=WalletCreationMode.EXISTING)
4320+
4321+
with pytest.raises(
4322+
ValueError,
4323+
match=re.escape('"amount" is not an argument for existing CAT wallets'),
4324+
):
4325+
CreateNewWallet(
4326+
wallet_type=CreateNewWalletType.CAT_WALLET,
4327+
mode=WalletCreationMode.EXISTING,
4328+
asset_id=bytes32.zeros,
4329+
amount=uint64(0),
4330+
)
4331+
4332+
with pytest.raises(
4333+
ValueError,
4334+
match=re.escape('"test" mode is not supported except for new CAT wallets'),
4335+
):
4336+
CreateNewWallet(wallet_type=CreateNewWalletType.DID_WALLET, test=True)
4337+
4338+
with pytest.raises(
4339+
ValueError,
4340+
match=re.escape('"asset_id" is not a valid argument. Maybe you meant to create an existing CAT wallet?'),
4341+
):
4342+
CreateNewWallet(wallet_type=CreateNewWalletType.DID_WALLET, asset_id=bytes32.zeros)
4343+
4344+
with pytest.raises(
4345+
ValueError,
4346+
match=re.escape('"mode": "existing" is only valid for CAT wallets'),
4347+
):
4348+
CreateNewWallet(wallet_type=CreateNewWalletType.DID_WALLET, mode=WalletCreationMode.EXISTING)
4349+
4350+
with pytest.raises(
4351+
ValueError,
4352+
match=re.escape('Must specify "did_type": "new/recovery"'),
4353+
):
4354+
CreateNewWallet(wallet_type=CreateNewWalletType.DID_WALLET)
4355+
4356+
with pytest.raises(
4357+
ValueError,
4358+
match=re.escape('Must specify an "amount" when creating a new DID'),
4359+
):
4360+
CreateNewWallet(wallet_type=CreateNewWalletType.DID_WALLET, did_type=DIDType.NEW)
4361+
4362+
with pytest.raises(
4363+
ValueError,
4364+
match=re.escape('Recovery options are no longer supported. "backup_dids" cannot be set.'),
4365+
):
4366+
CreateNewWallet(
4367+
wallet_type=CreateNewWalletType.DID_WALLET, did_type=DIDType.NEW, amount=uint64(0), backup_dids=["foo"]
4368+
)
4369+
4370+
with pytest.raises(
4371+
ValueError,
4372+
match=re.escape('"backup_data" is only an option in "did_type": "recovery"'),
4373+
):
4374+
CreateNewWallet(
4375+
wallet_type=CreateNewWalletType.DID_WALLET, did_type=DIDType.NEW, amount=uint64(0), backup_data="foo"
4376+
)
4377+
4378+
with pytest.raises(
4379+
ValueError,
4380+
match=re.escape('Cannot specify an "amount" when recovering a DID'),
4381+
):
4382+
CreateNewWallet(wallet_type=CreateNewWalletType.DID_WALLET, did_type=DIDType.RECOVERY, amount=uint64(0))
4383+
4384+
with pytest.raises(
4385+
ValueError,
4386+
match=re.escape('Cannot specify "backup_dids" when recovering a DID'),
4387+
):
4388+
CreateNewWallet(wallet_type=CreateNewWalletType.DID_WALLET, did_type=DIDType.RECOVERY, backup_dids=["foo"])
4389+
4390+
with pytest.raises(
4391+
ValueError,
4392+
match=re.escape('Cannot specify "metadata" when recovering a DID'),
4393+
):
4394+
CreateNewWallet(wallet_type=CreateNewWalletType.DID_WALLET, did_type=DIDType.RECOVERY, metadata={"foo": "bar"})
4395+
4396+
with pytest.raises(
4397+
ValueError,
4398+
match=re.escape('Must specify "backup_data" when recovering a DID'),
4399+
):
4400+
CreateNewWallet(wallet_type=CreateNewWalletType.DID_WALLET, did_type=DIDType.RECOVERY)
4401+
4402+
with pytest.raises(
4403+
ValueError,
4404+
match=re.escape('"did_type" is only a valid argument for DID wallets'),
4405+
):
4406+
CreateNewWallet(wallet_type=CreateNewWalletType.NFT_WALLET, did_type=DIDType.NEW)
4407+
4408+
with pytest.raises(
4409+
ValueError,
4410+
match=re.escape('"backup_dids" is only a valid argument for DID wallets'),
4411+
):
4412+
CreateNewWallet(wallet_type=CreateNewWalletType.NFT_WALLET, backup_dids=["foo"])
4413+
4414+
with pytest.raises(
4415+
ValueError,
4416+
match=re.escape('"metadata" is only a valid argument for DID wallets'),
4417+
):
4418+
CreateNewWallet(wallet_type=CreateNewWalletType.NFT_WALLET, metadata={"foo": "bar"})
4419+
4420+
with pytest.raises(
4421+
ValueError,
4422+
match=re.escape('"wallet_name" is only a valid argument for DID wallets'),
4423+
):
4424+
CreateNewWallet(wallet_type=CreateNewWalletType.NFT_WALLET, wallet_name="foo")
4425+
4426+
with pytest.raises(
4427+
ValueError,
4428+
match=re.escape('"backup_data" is only a valid argument for DID wallets'),
4429+
):
4430+
CreateNewWallet(wallet_type=CreateNewWalletType.NFT_WALLET, backup_data="foo")
4431+
4432+
with pytest.raises(
4433+
ValueError,
4434+
match=re.escape('"did_id" is only a valid argument for NFT wallets'),
4435+
):
4436+
CreateNewWallet(wallet_type=CreateNewWalletType.POOL_WALLET, did_id="foo")
4437+
4438+
with pytest.raises(
4439+
ValueError,
4440+
match=re.escape('"initial_target_state" is required for new pool wallets'),
4441+
):
4442+
CreateNewWallet(wallet_type=CreateNewWalletType.POOL_WALLET)
4443+
4444+
with pytest.raises(
4445+
ValueError,
4446+
match=re.escape('"initial_target_state" is only a valid argument for pool wallets'),
4447+
):
4448+
CreateNewWallet(
4449+
wallet_type=CreateNewWalletType.NFT_WALLET,
4450+
initial_target_state=NewPoolWalletInitialTargetState("SELF_POOLING"),
4451+
)
4452+
4453+
with pytest.raises(
4454+
ValueError,
4455+
match=re.escape('"p2_singleton_delayed_ph" is only a valid argument for pool wallets'),
4456+
):
4457+
CreateNewWallet(wallet_type=CreateNewWalletType.NFT_WALLET, p2_singleton_delayed_ph=bytes32.zeros)
4458+
4459+
with pytest.raises(
4460+
ValueError,
4461+
match=re.escape('"p2_singleton_delay_time" is only a valid argument for pool wallets'),
4462+
):
4463+
CreateNewWallet(wallet_type=CreateNewWalletType.NFT_WALLET, p2_singleton_delay_time=uint64(0))

0 commit comments

Comments
 (0)