fixup test_did.test_get_info() and .test_update_metadata() (#14061) (#14075)

This commit is contained in:
Kyle Altendorf 2022-12-07 19:05:42 -05:00 committed by GitHub
parent 15e657723a
commit b8f6396078
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -23,8 +23,7 @@ from chia.wallet.did_wallet.did_wallet import DIDWallet
from chia.wallet.did_wallet.did_wallet_puzzles import create_fullpuz
from chia.wallet.util.address_type import AddressType
from chia.wallet.util.wallet_types import WalletType
# pytestmark = pytest.mark.skip("TODO: Fix tests")
from tests.util.wallet_is_synced import wallet_is_synced
async def get_wallet_num(wallet_manager):
@ -881,7 +880,6 @@ class TestDIDWallet:
)
@pytest.mark.asyncio
async def test_get_info(self, two_wallet_nodes, trusted):
num_blocks = 3
fee = uint64(1000)
full_nodes, wallets, _ = two_wallet_nodes
full_node_api = full_nodes[0]
@ -890,7 +888,6 @@ class TestDIDWallet:
wallet_node_2, server_3 = wallets[1]
wallet = wallet_node.wallet_state_manager.main_wallet
wallet1 = wallet_node_2.wallet_state_manager.main_wallet
ph = await wallet.get_new_puzzlehash()
ph1 = await wallet1.get_new_puzzlehash()
api_0 = WalletRpcApi(wallet_node)
if trusted:
@ -906,31 +903,20 @@ class TestDIDWallet:
await server_2.start_client(PeerInfo("localhost", uint16(server_1._port)), None)
await server_3.start_client(PeerInfo("localhost", uint16(server_1._port)), None)
for i in range(1, num_blocks):
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(ph))
funds = sum(
[
calculate_pool_reward(uint32(i)) + calculate_base_farmer_reward(uint32(i))
for i in range(1, num_blocks - 1)
]
)
await time_out_assert(15, wallet.get_confirmed_balance, funds)
await full_node_api.farm_blocks(count=2, wallet=wallet)
did_amount = uint64(101)
async with wallet_node.wallet_state_manager.lock:
did_wallet_1: DIDWallet = await DIDWallet.create_new_did_wallet(
wallet_node.wallet_state_manager, wallet, uint64(101), [], metadata={"twitter": "twitter"}, fee=fee
wallet_node.wallet_state_manager, wallet, did_amount, [], metadata={"twitter": "twitter"}, fee=fee
)
spend_bundle_list = await wallet_node.wallet_state_manager.tx_store.get_unconfirmed_for_wallet(
transaction_records = await wallet_node.wallet_state_manager.tx_store.get_unconfirmed_for_wallet(
did_wallet_1.id()
)
spend_bundle = spend_bundle_list[0].spend_bundle
await time_out_assert_not_none(5, full_node_api.full_node.mempool_manager.get_spendbundle, spend_bundle.name())
for i in range(1, num_blocks):
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(ph))
await time_out_assert(15, did_wallet_1.get_confirmed_balance, 101)
await time_out_assert(15, did_wallet_1.get_unconfirmed_balance, 101)
await full_node_api.process_transaction_records(records=transaction_records)
await time_out_assert(15, wallet_is_synced, True, wallet_node, full_node_api)
assert await did_wallet_1.get_confirmed_balance() == did_amount
assert await did_wallet_1.get_unconfirmed_balance() == did_amount
response = await api_0.did_get_info({"coin_id": did_wallet_1.did_info.origin_coin.name().hex()})
assert response["launcher_id"] == did_wallet_1.did_info.origin_coin.name().hex()
@ -950,18 +936,19 @@ class TestDIDWallet:
assert not response["success"]
# Test multiple odd coins
coin_1 = (await wallet.select_coins(uint64(1), exclude=[coin])).pop()
odd_amount = uint64(1)
coin_1 = (await wallet.select_coins(odd_amount, exclude=[coin])).pop()
assert coin_1.amount % 2 == 0
tx = await wallet.generate_signed_transaction(
1,
odd_amount,
ph1,
fee,
exclude_coins=set([coin]),
)
await wallet.push_transaction(tx)
for i in range(1, num_blocks):
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(ph1))
await time_out_assert(15, wallet1.get_confirmed_balance, 2000000000001)
await full_node_api.process_transaction_records(records=[tx])
await time_out_assert(15, wallet_is_synced, True, wallet_node_2, full_node_api)
assert await wallet1.get_confirmed_balance() == odd_amount
try:
await api_0.did_get_info({"coin_id": coin_1.name().hex()})
# We expect a ValueError here
@ -1047,7 +1034,6 @@ class TestDIDWallet:
)
@pytest.mark.asyncio
async def test_update_metadata(self, two_wallet_nodes, trusted):
num_blocks = 3
fee = uint64(1000)
full_nodes, wallets, _ = two_wallet_nodes
full_node_api = full_nodes[0]
@ -1055,9 +1041,6 @@ class TestDIDWallet:
wallet_node, server_2 = wallets[0]
wallet_node_2, server_3 = wallets[1]
wallet = wallet_node.wallet_state_manager.main_wallet
wallet1 = wallet_node_2.wallet_state_manager.main_wallet
ph = await wallet.get_new_puzzlehash()
ph1 = await wallet1.get_new_puzzlehash()
if trusted:
wallet_node.config["trusted_peers"] = {
full_node_api.full_node.server.node_id.hex(): full_node_api.full_node.server.node_id.hex()
@ -1071,34 +1054,23 @@ class TestDIDWallet:
await server_2.start_client(PeerInfo("localhost", uint16(server_1._port)), None)
await server_3.start_client(PeerInfo("localhost", uint16(server_1._port)), None)
for i in range(1, num_blocks):
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(ph))
funds = sum(
[
calculate_pool_reward(uint32(i)) + calculate_base_farmer_reward(uint32(i))
for i in range(1, num_blocks - 1)
]
)
await time_out_assert(15, wallet.get_confirmed_balance, funds)
expected_confirmed_balance = await full_node_api.farm_blocks(count=2, wallet=wallet)
did_amount = uint64(101)
async with wallet_node.wallet_state_manager.lock:
did_wallet_1: DIDWallet = await DIDWallet.create_new_did_wallet(
wallet_node.wallet_state_manager, wallet, uint64(101), [], fee=fee
wallet_node.wallet_state_manager, wallet, did_amount, [], fee=fee
)
spend_bundle_list = await wallet_node.wallet_state_manager.tx_store.get_unconfirmed_for_wallet(
transaction_records = await wallet_node.wallet_state_manager.tx_store.get_unconfirmed_for_wallet(
did_wallet_1.id()
)
spend_bundle = spend_bundle_list[0].spend_bundle
await time_out_assert_not_none(5, full_node_api.full_node.mempool_manager.get_spendbundle, spend_bundle.name())
for i in range(1, num_blocks):
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(ph1))
await time_out_assert(15, did_wallet_1.get_confirmed_balance, 101)
await time_out_assert(15, did_wallet_1.get_unconfirmed_balance, 101)
await time_out_assert(15, wallet.get_confirmed_balance, 3999999998899)
await time_out_assert(15, wallet.get_unconfirmed_balance, 3999999998899)
await full_node_api.process_transaction_records(records=transaction_records)
await time_out_assert(15, wallet_is_synced, True, wallet_node, full_node_api)
expected_confirmed_balance -= did_amount + fee
assert await did_wallet_1.get_confirmed_balance() == did_amount
assert await did_wallet_1.get_unconfirmed_balance() == did_amount
assert await wallet.get_confirmed_balance() == expected_confirmed_balance
assert await wallet.get_unconfirmed_balance() == expected_confirmed_balance
puzhash = did_wallet_1.did_info.current_inner.get_tree_hash()
parent_num = get_parent_num(did_wallet_1)
@ -1106,16 +1078,21 @@ class TestDIDWallet:
metadata["Twitter"] = "http://www.twitter.com"
await did_wallet_1.update_metadata(metadata)
await did_wallet_1.create_update_spend(fee)
transaction_records = await wallet_node.wallet_state_manager.tx_store.get_unconfirmed_for_wallet(
did_wallet_1.id()
)
await full_node_api.process_transaction_records(records=transaction_records)
for i in range(1, num_blocks):
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(ph1))
await time_out_assert(15, did_wallet_1.get_confirmed_balance, 101)
await time_out_assert(15, did_wallet_1.get_unconfirmed_balance, 101)
expected_confirmed_balance -= fee
await time_out_assert(15, get_parent_num, parent_num + 2, did_wallet_1)
await time_out_assert(15, wallet_is_synced, True, wallet_node, full_node_api)
assert await did_wallet_1.get_confirmed_balance() == did_amount
assert await did_wallet_1.get_unconfirmed_balance() == did_amount
assert get_parent_num(did_wallet_1) == parent_num + 2
assert puzhash != did_wallet_1.did_info.current_inner.get_tree_hash()
await time_out_assert(15, wallet.get_confirmed_balance, 3999999997899)
await time_out_assert(15, wallet.get_unconfirmed_balance, 3999999997899)
assert await wallet.get_confirmed_balance() == expected_confirmed_balance
assert await wallet.get_unconfirmed_balance() == expected_confirmed_balance
assert did_wallet_1.did_info.metadata.find("Twitter") > 0