Merge pull request #11774 from trepca/nft1_test_fix

fixed royalty address position in RPC call, more tests
This commit is contained in:
William Allen
2022-06-03 14:04:58 -05:00
committed by GitHub
5 changed files with 148 additions and 17 deletions
+1 -1
View File
@@ -1370,8 +1370,8 @@ class WalletRpcApi:
did_id = bytes.fromhex(did_id)
spend_bundle = await nft_wallet.generate_new_nft(
metadata,
royalty_puzhash,
target_puzhash,
royalty_puzhash,
uint16(request.get("royalty_percentage", 0)),
did_id,
fee,
+3 -1
View File
@@ -29,9 +29,11 @@ class NFTInfo(Streamable):
owner_pubkey: Optional[bytes]
"""Pubkey of the NFT owner"""
royalty: Optional[uint16]
royalty_percentage: Optional[uint16]
"""Percentage of the transaction fee paid to the author, e.g. 1000 = 1%"""
royalty_puzzle_hash: Optional[bytes32]
"""Puzzle hash where royalty will be sent to"""
data_uris: List[str]
""" A list of content URIs"""
+1
View File
@@ -109,6 +109,7 @@ def get_nft_info_from_puzzle(nft_coin_info: NFTCoinInfo) -> NFTInfo:
uncurried_nft.owner_did,
uncurried_nft.owner_pubkey,
uncurried_nft.trade_price_percentage,
uncurried_nft.royalty_address,
data_uris,
uncurried_nft.data_hash.as_python(),
meta_uris,
+2 -1
View File
@@ -156,8 +156,9 @@ class UncurriedNFT:
_, p2_args = p2_puzzle.uncurry()
(pubkey_sexp,) = p2_args.as_iter()
transfer_program_mod, transfer_program_args = transfer_program.uncurry()
_, _, royalty_address, royalty_percentage, _, _ = transfer_program_args.as_iter()
_, _, royalty_address_p, royalty_percentage, _, _ = transfer_program_args.as_iter()
royalty_percentage = uint16(royalty_percentage.as_int())
royalty_address = royalty_address_p.atom
current_did = current_did.atom
if current_did == b"":
# For unassigned NFT, set owner DID to None
+141 -14
View File
@@ -341,13 +341,14 @@ async def test_nft_wallet_rpc_creation_and_list(two_wallet_nodes: Any, trusted:
assert len(coins) == 2
uris = []
for coin in coins:
assert not coin.supports_did
uris.append(coin.data_uris[0])
assert coin.mint_height > 0
assert len(uris) == 2
assert "https://chialisp.com/img/logo.svg" in uris
assert bytes32.fromhex(coins[1].to_json_dict()["nft_coin_id"][2:]) in [x.name() for x in sb.additions()]
except AssertionError:
if time_left < 0:
if time_left < 1:
raise
await asyncio.sleep(0.5)
time_left -= 0.5
@@ -480,7 +481,7 @@ async def test_nft_wallet_rpc_update_metadata(two_wallet_nodes: Any, trusted: An
assert "http://metadata" == coin["metadata_uris"][0]
assert len(coin["license_uris"]) == 0
except AssertionError:
if time_left < 0:
if time_left < 1:
raise
await asyncio.sleep(0.5)
time_left -= 0.5
@@ -518,7 +519,7 @@ async def test_nft_wallet_rpc_update_metadata(two_wallet_nodes: Any, trusted: An
assert len(coin["metadata_uris"]) == 1
assert "http://data" == coin["data_uris"][0]
except AssertionError:
if time_left < 0:
if time_left < 1:
raise
await asyncio.sleep(0.5)
time_left -= 0.5
@@ -530,7 +531,7 @@ async def test_nft_wallet_rpc_update_metadata(two_wallet_nodes: Any, trusted: An
)
@pytest.mark.asyncio
async def test_nft_with_did_wallet_creation(two_wallet_nodes: Any, trusted: Any) -> None:
num_blocks = 2
num_blocks = 3
full_nodes, wallets = two_wallet_nodes
full_node_api: FullNodeSimulator = full_nodes[0]
full_node_server = full_node_api.server
@@ -563,12 +564,6 @@ async def test_nft_with_did_wallet_creation(two_wallet_nodes: Any, trusted: Any)
await time_out_assert(10, wallet_0.get_unconfirmed_balance, funds)
await time_out_assert(10, wallet_0.get_confirmed_balance, funds)
for _ in range(1, num_blocks):
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(ph))
for _ in range(1, num_blocks):
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(ph))
await asyncio.sleep(5)
did_wallet: DIDWallet = await DIDWallet.create_new_did_wallet(
wallet_node_0.wallet_state_manager, wallet_0, uint64(1)
)
@@ -587,6 +582,17 @@ async def test_nft_with_did_wallet_creation(two_wallet_nodes: Any, trusted: Any)
assert res.get("success")
nft_wallet_0_id = res["wallet_id"]
# this shouldn't work
res = await api_0.create_new_wallet(dict(wallet_type="nft_wallet", name="NFT WALLET 1", did_id=hex_did_id))
assert isinstance(res, dict)
assert res.get("success")
assert res["wallet_id"] == nft_wallet_0_id
# now create NFT wallet with P2 standard puzzle for inner puzzle
res = await api_0.create_new_wallet(dict(wallet_type="nft_wallet", name="NFT WALLET 0"))
assert isinstance(res, dict)
assert res.get("success")
nft_wallet_p2_puzzle = res["wallet_id"]
assert nft_wallet_p2_puzzle != nft_wallet_0_id
await time_out_assert(10, wallet_0.get_unconfirmed_balance, 5999999999999)
await time_out_assert(10, wallet_0.get_confirmed_balance, 5999999999999)
# Create a NFT with DID
@@ -627,8 +633,8 @@ async def test_nft_with_did_wallet_creation(two_wallet_nodes: Any, trusted: Any)
for i in range(1, num_blocks):
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(ph))
await time_out_assert(10, wallet_0.get_unconfirmed_balance, 9999999999998 - 1)
await time_out_assert(10, wallet_0.get_confirmed_balance, 9999999999998 - 1)
await time_out_assert(10, wallet_0.get_unconfirmed_balance, 13999999999998 - 1)
await time_out_assert(10, wallet_0.get_confirmed_balance, 13999999999998 - 1)
# Check DID NFT
time_left = 5.0
coins_response = {}
@@ -650,10 +656,9 @@ async def test_nft_with_did_wallet_creation(two_wallet_nodes: Any, trusted: Any)
assert did_nft["owner_did"][2:] == hex_did_id
assert did_nft["owner_pubkey"] is not None
# Check unassigned NFT
await asyncio.sleep(5)
nft_wallets = await wallet_node_0.wallet_state_manager.get_all_wallet_info_entries(WalletType.NFT)
assert len(nft_wallets) == 2
coins_response = await api_0.nft_get_nfts(dict(wallet_id=nft_wallets[1].id))
coins_response = await api_0.nft_get_nfts(dict(wallet_id=nft_wallet_p2_puzzle))
assert coins_response["nft_list"], isinstance(coins_response, dict)
assert coins_response.get("success")
coins = coins_response["nft_list"]
@@ -665,3 +670,125 @@ async def test_nft_with_did_wallet_creation(two_wallet_nodes: Any, trusted: Any)
assert non_did_nft["data_hash"] == "0xD4584AD463139FA8C0D9F68F4B59F181".lower()
assert non_did_nft["owner_did"] is None
assert non_did_nft["owner_pubkey"] is not None
@pytest.mark.parametrize(
"trusted",
[True, False],
)
@pytest.mark.asyncio
async def test_nft_rpc_mint(two_wallet_nodes: Any, trusted: Any) -> None:
num_blocks = 3
full_nodes, wallets = two_wallet_nodes
full_node_api: FullNodeSimulator = full_nodes[0]
full_node_server = full_node_api.server
wallet_node_0, server_0 = wallets[0]
wallet_node_1, server_1 = wallets[1]
wallet_0 = wallet_node_0.wallet_state_manager.main_wallet
wallet_1 = wallet_node_1.wallet_state_manager.main_wallet
api_0 = WalletRpcApi(wallet_node_0)
ph = await wallet_0.get_new_puzzlehash()
ph1 = await wallet_1.get_new_puzzlehash()
if trusted:
wallet_node_0.config["trusted_peers"] = {
full_node_api.full_node.server.node_id.hex(): full_node_api.full_node.server.node_id.hex()
}
wallet_node_1.config["trusted_peers"] = {
full_node_api.full_node.server.node_id.hex(): full_node_api.full_node.server.node_id.hex()
}
else:
wallet_node_0.config["trusted_peers"] = {}
wallet_node_1.config["trusted_peers"] = {}
await server_0.start_client(PeerInfo("localhost", uint16(full_node_server._port)), None)
await server_1.start_client(PeerInfo("localhost", uint16(full_node_server._port)), None)
for _ 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(10, wallet_0.get_unconfirmed_balance, funds)
await time_out_assert(10, wallet_0.get_confirmed_balance, funds)
did_wallet: DIDWallet = await DIDWallet.create_new_did_wallet(
wallet_node_0.wallet_state_manager, wallet_0, uint64(1)
)
spend_bundle_list = await wallet_node_0.wallet_state_manager.tx_store.get_unconfirmed_for_wallet(wallet_0.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 _ in range(1, num_blocks):
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(ph))
await time_out_assert(15, wallet_0.get_pending_change_balance, 0)
hex_did_id = did_wallet.get_my_DID()
res = await api_0.create_new_wallet(dict(wallet_type="nft_wallet", name="NFT WALLET 1", did_id=hex_did_id))
assert isinstance(res, dict)
assert res.get("success")
nft_wallet_0_id = res["wallet_id"]
await time_out_assert(10, wallet_0.get_unconfirmed_balance, 5999999999999)
await time_out_assert(10, wallet_0.get_confirmed_balance, 5999999999999)
# Create a NFT with DID
royalty_address = ph1
data_hash_param = "0xD4584AD463139FA8C0D9F68F4B59F185"
license_uris = ["http://mylicenseuri"]
license_hash = "0xcafef00d"
meta_uris = ["http://metauri"]
meta_hash = "0xdeadbeef"
royalty_percentage = 200
sn = 10
st = 100
resp = await api_0.nft_mint_nft(
{
"wallet_id": nft_wallet_0_id,
"hash": data_hash_param,
"uris": ["https://www.chia.net/img/branding/chia-logo.svg"],
"license_uris": license_uris,
"license_hash": license_hash,
"meta_hash": meta_hash,
"series_number": sn,
"series_total": st,
"meta_uris": meta_uris,
"royalty_address": royalty_address,
"target_address": ph,
"royalty_percentage": royalty_percentage,
}
)
assert resp.get("success")
sb = resp["spend_bundle"]
# ensure hints are generated
assert compute_memos(sb)
await time_out_assert_not_none(5, full_node_api.full_node.mempool_manager.get_spendbundle, sb.name())
for i in range(1, num_blocks):
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(ph))
await time_out_assert(10, wallet_0.get_unconfirmed_balance, 9999999999998)
await time_out_assert(10, wallet_0.get_confirmed_balance, 9999999999998)
time_left = 5.0
coins_response = {}
while time_left > 0:
coins_response = await api_0.nft_get_nfts(dict(wallet_id=nft_wallet_0_id))
if coins_response.get("nft_list"):
break
await asyncio.sleep(0.5)
time_left -= 0.5
assert coins_response["nft_list"], isinstance(coins_response, dict)
assert coins_response.get("success")
coins = coins_response["nft_list"]
assert len(coins) == 1
did_nft = coins[0]
assert did_nft.royalty_puzzle_hash == royalty_address
assert did_nft.data_hash == bytes.fromhex(data_hash_param[2:])
assert did_nft.metadata_hash == bytes.fromhex(meta_hash[2:])
assert did_nft.metadata_uris == meta_uris
assert did_nft.license_uris == license_uris
assert did_nft.license_hash == bytes.fromhex(license_hash[2:])
assert did_nft.series_total == st
assert did_nft.series_number == sn
assert did_nft.royalty_percentage == royalty_percentage