From ef5a3c4c338c88e6e8ff6666f85d1053c8c881ac Mon Sep 17 00:00:00 2001 From: mr-t Date: Tue, 13 Aug 2024 16:55:11 +0200 Subject: [PATCH] assert escrowed collection data on chain B is properly set --- ts-relayer-tests/src/cw721-utils.ts | 53 +++++++++++++++++++++++++++++ ts-relayer-tests/src/ics721.spec.ts | 47 +++++++++++++++++++++++-- 2 files changed, 97 insertions(+), 3 deletions(-) diff --git a/ts-relayer-tests/src/cw721-utils.ts b/ts-relayer-tests/src/cw721-utils.ts index ce447f00..c4ca272d 100644 --- a/ts-relayer-tests/src/cw721-utils.ts +++ b/ts-relayer-tests/src/cw721-utils.ts @@ -128,6 +128,59 @@ export function ownerOf( return client.sign.queryContractSmart(cw721Contract, msg); } +export function getCollectionInfoAndExtension( + client: CosmWasmSigner, + cw721Contract: string +): Promise<{ + name: string; + symbol: string; + extension: { + description: string; + image: string; + external_link: string | null; + explicit_content: string | null; + start_trading_time: string | null; + royalty_info: { + payment_address: string; + share: string; + } | null; + } | null; + updated_at: "1723541397075433676"; +}> { + const msg = { + get_collection_info_and_extension: {}, + }; + return client.sign.queryContractSmart(cw721Contract, msg); +} + +export function getMinterOwnership( + client: CosmWasmSigner, + cw721Contract: string +): Promise<{ + owner: string; + pending_owner: string | null; + pending_expiry: string | null; +}> { + const msg = { + get_minter_ownership: {}, + }; + return client.sign.queryContractSmart(cw721Contract, msg); +} + +export function getCreatorOwnership( + client: CosmWasmSigner, + cw721Contract: string +): Promise<{ + owner: string; + pending_owner: string | null; + pending_expiry: string | null; +}> { + const msg = { + get_creator_ownership: {}, + }; + return client.sign.queryContractSmart(cw721Contract, msg); +} + export function numTokens( client: CosmWasmSigner, cw721Contract: string diff --git a/ts-relayer-tests/src/ics721.spec.ts b/ts-relayer-tests/src/ics721.spec.ts index 23ab7696..8aa52440 100644 --- a/ts-relayer-tests/src/ics721.spec.ts +++ b/ts-relayer-tests/src/ics721.spec.ts @@ -4,7 +4,16 @@ import anyTest, { ExecutionContext, TestFn } from "ava"; import { Order } from "cosmjs-types/ibc/core/channel/v1/channel"; import { instantiateContract } from "./controller"; -import { allTokens, approve, mint, ownerOf, sendNft } from "./cw721-utils"; +import { + allTokens, + approve, + getCollectionInfoAndExtension, + getCreatorOwnership, + getMinterOwnership, + mint, + ownerOf, + sendNft, +} from "./cw721-utils"; import { adminCleanAndBurnNft, adminCleanAndUnescrowNft, @@ -169,7 +178,10 @@ const standardSetup = async (t: ExecutionContext) => { const { contractAddress: wasmIcs721 } = await instantiateContract( wasmClient, wasmIcs721Id, - { cw721_base_code_id: wasmCw721Id }, + { + cw721_base_code_id: wasmCw721Id, + cw721_admin: wasmClient.senderAddress, // set cw721 admin, this will be also used as creator and payment address for escrowed cw721 by ics721 + }, "label ics721" ); t.log(`- wasm ICS721 contract address: ${wasmIcs721}`); @@ -179,7 +191,10 @@ const standardSetup = async (t: ExecutionContext) => { const { contractAddress: osmoIcs721 } = await instantiateContract( osmoClient, osmoIcs721Id, - { cw721_base_code_id: osmoCw721Id }, + { + cw721_base_code_id: osmoCw721Id, + cw721_admin: osmoClient.senderAddress, // set cw721 admin, this will be also used as creator and payment address for escrowed cw721 by ics721 + }, "label ics721" ); t.log(`- osmo ICS721 contract address: ${osmoIcs721}`); @@ -401,6 +416,32 @@ test.serial("transfer NFT: wasmd -> osmo", async (t) => { // assert NFT on chain B is owned by osmoAddr tokenOwner = await ownerOf(osmoClient, osmoCw721, tokenId); t.is(osmoAddr, tokenOwner.owner); + // assert escrowed collection data on chain B is properly set + const wasmCollectionData = await getCollectionInfoAndExtension( + wasmClient, + wasmCw721 + ); + const osmoCollectionData = await getCollectionInfoAndExtension( + osmoClient, + osmoCw721 + ); + osmoCollectionData.updated_at = wasmCollectionData.updated_at; // ignore updated_at + if (wasmCollectionData.extension?.royalty_info?.payment_address) { + wasmCollectionData.extension.royalty_info.payment_address = osmoAddr; // osmo cw721 admin address is used as payment address + } + t.deepEqual( + wasmCollectionData, + osmoCollectionData, + `collection data must match: ${JSON.stringify( + wasmCollectionData + )} vs ${JSON.stringify(osmoCollectionData)}` + ); + // assert creator is set to osmoAddr + const creatorOwnerShip = await getCreatorOwnership(osmoClient, osmoCw721); + t.is(osmoAddr, creatorOwnerShip.owner); + // assert minter is set to ics721 + const minterOwnerShip = await getMinterOwnership(osmoClient, osmoCw721); + t.is(osmoIcs721, minterOwnerShip.owner); // test back transfer NFT to wasm chain t.log(`transfering back to wasm chain via ${channel.channel.dest.channelId}`);