diff --git a/ts-relayer-tests/src/ics721.spec.ts b/ts-relayer-tests/src/ics721.spec.ts index cfbf65a..ac49a86 100644 --- a/ts-relayer-tests/src/ics721.spec.ts +++ b/ts-relayer-tests/src/ics721.spec.ts @@ -1,19 +1,11 @@ -import { CosmWasmSigner } from "@confio/relayer"; -import { fromUtf8 } from "@cosmjs/encoding"; -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 { - adminCleanAndBurnNft, - adminCleanAndUnescrowNft, - incomingChannels, - migrate, - migrateIncomingProxy, - nftContracts, - outgoingChannels, -} from "./ics721-utils"; +import { CosmWasmSigner } from '@confio/relayer'; +import { fromUtf8 } from '@cosmjs/encoding'; +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 { adminCleanAndBurnNft, adminCleanAndUnescrowNft, incomingChannels, migrate, migrateIncomingProxy, nftContracts, outgoingChannels } from './ics721-utils'; import { assertAckErrors, assertAckSuccess, @@ -26,7 +18,7 @@ import { setupWasmClient, uploadAndInstantiate, uploadAndInstantiateAll, -} from "./utils"; +} from './utils'; interface TestContext { wasmClient: CosmWasmSigner; @@ -53,12 +45,11 @@ interface TestContext { const test = anyTest as TestFn; -const WASM_FILE_CW721 = "./internal/cw721_metadata_onchain_v0.19.0.wasm"; -const WASM_FILE_CW721_INCOMING_PROXY = "./internal/cw721_incoming_proxy.wasm"; -const WASM_FILE_CW721_OUTGOING_PROXY = - "./internal/cw721_outgoing_proxy_rate_limit.wasm"; -const WASM_FILE_CW_ICS721_ICS721 = "./internal/ics721_base.wasm"; -const MALICIOUS_CW721 = "./internal/cw721_tester.wasm"; +const WASM_FILE_CW721 = './internal/cw721_metadata_onchain_v0.19.0.wasm'; +const WASM_FILE_CW721_INCOMING_PROXY = './internal/cw721_incoming_proxy.wasm'; +const WASM_FILE_CW721_OUTGOING_PROXY = './internal/cw721_outgoing_proxy_rate_limit.wasm'; +const WASM_FILE_CW_ICS721_ICS721 = './internal/ics721_base.wasm'; +const MALICIOUS_CW721 = './internal/cw721_tester.wasm'; const standardSetup = async (t: ExecutionContext) => { t.context.wasmClient = await setupWasmClient(MNEMONIC); @@ -73,9 +64,21 @@ const standardSetup = async (t: ExecutionContext) => { cw721: { path: WASM_FILE_CW721, instantiateMsg: { - name: "ark", - symbol: "ark", + name: 'ark', + symbol: 'ark', + collection_info_extension: { + description: 'description', + image: 'https://ark.pass/image.png', + external_link: 'https://interchain.arkprotocol.io', + explicit_content: false, + royalty_info: { + payment_address: t.context.wasmClient.senderAddress, + share: 0.1, + }, + }, + creator: wasmClient.senderAddress, minter: wasmClient.senderAddress, + withdraw_address: wasmClient.senderAddress, }, }, cw721IncomingProxy: { @@ -95,10 +98,21 @@ const standardSetup = async (t: ExecutionContext) => { cw721: { path: WASM_FILE_CW721, instantiateMsg: { - name: "ark", - symbol: "ark", + name: 'ark', + symbol: 'ark', + collection_info_extension: { + description: 'description', + image: 'https://ark.pass/image.png', + external_link: 'https://interchain.arkprotocol.io', + explicit_content: false, + royalty_info: { + payment_address: t.context.osmoClient.senderAddress, + share: 0.1, + }, + }, creator: osmoClient.senderAddress, minter: osmoClient.senderAddress, + withdraw_address: osmoClient.senderAddress, }, }, cw721IncomingProxy: { @@ -115,76 +129,40 @@ const standardSetup = async (t: ExecutionContext) => { }, }; - const info = await uploadAndInstantiateAll( - wasmClient, - osmoClient, - wasmContracts, - osmoContracts - ); + const info = await uploadAndInstantiateAll(wasmClient, osmoClient, wasmContracts, osmoContracts); const wasmCw721Id = info.wasmContractInfos.cw721.codeId; const osmoCw721Id = info.osmoContractInfos.cw721.codeId; - const wasmCw721IncomingProxyId = - info.wasmContractInfos.cw721IncomingProxy.codeId; + const wasmCw721IncomingProxyId = info.wasmContractInfos.cw721IncomingProxy.codeId; t.context.wasmCw721IncomingProxyId = wasmCw721IncomingProxyId; - const osmoCw721IncomingProxyId = - info.osmoContractInfos.cw721IncomingProxy.codeId; + const osmoCw721IncomingProxyId = info.osmoContractInfos.cw721IncomingProxy.codeId; const wasmIcs721Id = info.wasmContractInfos.ics721.codeId; const osmoIcs721Id = info.osmoContractInfos.ics721.codeId; - const wasmCw721OutgoingProxyId = - info.wasmContractInfos.cw721OutgoingProxy.codeId; - const osmoCw721OutgoingProxyId = - info.osmoContractInfos.cw721OutgoingProxy.codeId; + const wasmCw721OutgoingProxyId = info.wasmContractInfos.cw721OutgoingProxy.codeId; + const osmoCw721OutgoingProxyId = info.osmoContractInfos.cw721OutgoingProxy.codeId; t.context.wasmCw721 = info.wasmContractInfos.cw721.address as string; t.context.osmoCw721 = info.osmoContractInfos.cw721.address as string; t.log(`instantiating wasm ICS721 contract (${wasmIcs721Id})`); - const { contractAddress: wasmIcs721 } = await instantiateContract( - wasmClient, - wasmIcs721Id, - { cw721_base_code_id: wasmCw721Id }, - "label ics721" - ); + const { contractAddress: wasmIcs721 } = await instantiateContract(wasmClient, wasmIcs721Id, { cw721_base_code_id: wasmCw721Id }, 'label ics721'); t.log(`- wasm ICS721 contract address: ${wasmIcs721}`); t.context.wasmIcs721 = wasmIcs721; t.log(`instantiating osmo ICS721 contract (${osmoIcs721Id})`); - const { contractAddress: osmoIcs721 } = await instantiateContract( - osmoClient, - osmoIcs721Id, - { cw721_base_code_id: osmoCw721Id }, - "label ics721" - ); + const { contractAddress: osmoIcs721 } = await instantiateContract(osmoClient, osmoIcs721Id, { cw721_base_code_id: osmoCw721Id }, 'label ics721'); t.log(`- osmo ICS721 contract address: ${osmoIcs721}`); t.context.osmoIcs721 = osmoIcs721; - t.log( - `creating IBC connection and channel between ${wasmIcs721} <-> ${osmoIcs721}` - ); - const channelInfo = await createIbcConnectionAndChannel( - wasmClient, - osmoClient, - wasmIcs721, - osmoIcs721, - Order.ORDER_UNORDERED, - "ics721-1" - ); - t.log( - `- channel for incoming proxy on both chains: ${JSON.stringify( - channelInfo.channel, - bigIntReplacer, - 2 - )}` - ); + t.log(`creating IBC connection and channel between ${wasmIcs721} <-> ${osmoIcs721}`); + const channelInfo = await createIbcConnectionAndChannel(wasmClient, osmoClient, wasmIcs721, osmoIcs721, Order.ORDER_UNORDERED, 'ics721-1'); + t.log(`- channel for incoming proxy on both chains: ${JSON.stringify(channelInfo.channel, bigIntReplacer, 2)}`); t.context.channel = channelInfo; - t.log( - `instantiating wasm cw721-incoming-proxy (${wasmCw721IncomingProxyId}) with channel ${channelInfo.channel.src.channelId}` - ); + t.log(`instantiating wasm cw721-incoming-proxy (${wasmCw721IncomingProxyId}) with channel ${channelInfo.channel.src.channelId}`); const { contractAddress: wasmCw721IncomingProxy } = await instantiateContract( wasmClient, wasmCw721IncomingProxyId, @@ -192,55 +170,33 @@ const standardSetup = async (t: ExecutionContext) => { origin: wasmIcs721, channels: [channelInfo.channel.src.channelId], }, - "label incoming proxy" + 'label incoming proxy' ); t.log(`- wasm cw721-incoming-proxy address: ${wasmCw721IncomingProxy}`); t.context.wasmCw721IncomingProxy = wasmCw721IncomingProxy; - t.log( - `migrate ${wasmIcs721} contract with incoming proxy ${wasmCw721IncomingProxy}` - ); + t.log(`migrate ${wasmIcs721} contract with incoming proxy ${wasmCw721IncomingProxy}`); await migrate(wasmClient, wasmIcs721, wasmIcs721Id, wasmCw721IncomingProxy); - const onlyOsmoIncomingChannelInfo = await createIbcConnectionAndChannel( - wasmClient, - osmoClient, - wasmIcs721, - osmoIcs721, - Order.ORDER_UNORDERED, - "ics721-1" - ); - t.log( - `- channel for incoming proxy only on wasm chain: ${JSON.stringify( - onlyOsmoIncomingChannelInfo.channel, - bigIntReplacer, - 2 - )}` - ); + const onlyOsmoIncomingChannelInfo = await createIbcConnectionAndChannel(wasmClient, osmoClient, wasmIcs721, osmoIcs721, Order.ORDER_UNORDERED, 'ics721-1'); + t.log(`- channel for incoming proxy only on wasm chain: ${JSON.stringify(onlyOsmoIncomingChannelInfo.channel, bigIntReplacer, 2)}`); t.context.onlyOsmoIncomingChannel = onlyOsmoIncomingChannelInfo; - t.log( - `instantiating osmo cw721-incoming-proxy (${osmoCw721IncomingProxyId}) with channel ${channelInfo.channel.dest.channelId}and ${onlyOsmoIncomingChannelInfo.channel.dest.channelId}` - ); + t.log(`instantiating osmo cw721-incoming-proxy (${osmoCw721IncomingProxyId}) with channel ${channelInfo.channel.dest.channelId}and ${onlyOsmoIncomingChannelInfo.channel.dest.channelId}`); const { contractAddress: osmoCw721IncomingProxy } = await instantiateContract( osmoClient, osmoCw721IncomingProxyId, { origin: osmoIcs721, - channels: [ - channelInfo.channel.dest.channelId, - onlyOsmoIncomingChannelInfo.channel.dest.channelId, - ], + channels: [channelInfo.channel.dest.channelId, onlyOsmoIncomingChannelInfo.channel.dest.channelId], }, - "label incoming proxy" + 'label incoming proxy' ); t.log(`- osmo cw721-incoming-proxy address: ${osmoCw721IncomingProxy}`); t.context.osmoCw721IncomingProxy = osmoCw721IncomingProxy; const per_block = 10; // use high rate limit to avoid test failures - t.log( - `instantiating wasm cw721-outgoing-proxy (${wasmCw721OutgoingProxyId}) with ${per_block} per blocks rate limit` - ); + t.log(`instantiating wasm cw721-outgoing-proxy (${wasmCw721OutgoingProxyId}) with ${per_block} per blocks rate limit`); const { contractAddress: wasmCw721OutgoingProxy } = await instantiateContract( wasmClient, wasmCw721OutgoingProxyId, @@ -248,14 +204,12 @@ const standardSetup = async (t: ExecutionContext) => { origin: wasmIcs721, rate_limit: { per_block }, }, - "label outgoing proxy" + 'label outgoing proxy' ); t.log(`- wasm cw721-outgoing-proxy address: ${wasmCw721OutgoingProxy}`); t.context.wasmCw721OutgoingProxy = wasmCw721OutgoingProxy; - t.log( - `instantiating osmo cw721-outgoing-proxy (${osmoCw721OutgoingProxyId}) with ${per_block} per blocks rate limit` - ); + t.log(`instantiating osmo cw721-outgoing-proxy (${osmoCw721OutgoingProxyId}) with ${per_block} per blocks rate limit`); const { contractAddress: osmoCw721OutgoingProxy } = await instantiateContract( osmoClient, osmoCw721OutgoingProxyId, @@ -263,57 +217,26 @@ const standardSetup = async (t: ExecutionContext) => { origin: osmoIcs721, rate_limit: { per_block }, }, - "label outgoing proxy" + 'label outgoing proxy' ); t.log(`- osmo cw721-outgoing-proxy address: ${osmoCw721OutgoingProxy}`); t.context.osmoCw721OutgoingProxy = osmoCw721OutgoingProxy; - t.log( - `migrate ${wasmIcs721} contract with incoming (${wasmCw721IncomingProxy}) and outgoing proxy (${wasmCw721OutgoingProxy})` - ); - await migrate( - wasmClient, - wasmIcs721, - wasmIcs721Id, - wasmCw721IncomingProxy, - wasmCw721OutgoingProxy - ); + t.log(`migrate ${wasmIcs721} contract with incoming (${wasmCw721IncomingProxy}) and outgoing proxy (${wasmCw721OutgoingProxy})`); + await migrate(wasmClient, wasmIcs721, wasmIcs721Id, wasmCw721IncomingProxy, wasmCw721OutgoingProxy); - t.log( - `migrate ${osmoIcs721} contract with incoming (${osmoCw721IncomingProxy}) and outgoing proxy (${osmoCw721OutgoingProxy})` - ); - await migrate( - osmoClient, - osmoIcs721, - osmoIcs721Id, - osmoCw721IncomingProxy, - osmoCw721OutgoingProxy - ); + t.log(`migrate ${osmoIcs721} contract with incoming (${osmoCw721IncomingProxy}) and outgoing proxy (${osmoCw721OutgoingProxy})`); + await migrate(osmoClient, osmoIcs721, osmoIcs721Id, osmoCw721IncomingProxy, osmoCw721OutgoingProxy); - t.log( - `creating another IBC connection and channel between wasm and osmo (${wasmIcs721} <-> ${osmoIcs721})` - ); - const otherChannelInfo = await createIbcConnectionAndChannel( - wasmClient, - osmoClient, - wasmIcs721, - osmoIcs721, - Order.ORDER_UNORDERED, - "ics721-1" - ); - t.log( - `- other channel not WLed for incoming proxy: ${JSON.stringify( - otherChannelInfo.channel, - bigIntReplacer, - 2 - )}` - ); + t.log(`creating another IBC connection and channel between wasm and osmo (${wasmIcs721} <-> ${osmoIcs721})`); + const otherChannelInfo = await createIbcConnectionAndChannel(wasmClient, osmoClient, wasmIcs721, osmoIcs721, Order.ORDER_UNORDERED, 'ics721-1'); + t.log(`- other channel not WLed for incoming proxy: ${JSON.stringify(otherChannelInfo.channel, bigIntReplacer, 2)}`); t.context.otherChannel = otherChannelInfo; t.pass(); }; -test.serial("transfer NFT: wasmd -> osmo", async (t) => { +test.serial('transfer NFT: wasmd -> osmo', async (t) => { await standardSetup(t); const { @@ -332,7 +255,7 @@ test.serial("transfer NFT: wasmd -> osmo", async (t) => { onlyOsmoIncomingChannel, } = t.context; - let tokenId = "1"; + let tokenId = '1'; await mint(wasmClient, wasmCw721, tokenId, wasmAddr, undefined); // assert token is minted let tokenOwner = await ownerOf(wasmClient, wasmCw721, tokenId); @@ -351,17 +274,11 @@ test.serial("transfer NFT: wasmd -> osmo", async (t) => { }, }, }; - let transferResponse = await sendNft( - wasmClient, - wasmCw721, - wasmCw721OutgoingProxy, - ibcMsg, - tokenId - ); + let transferResponse = await sendNft(wasmClient, wasmCw721, wasmCw721OutgoingProxy, ibcMsg, tokenId); t.truthy(transferResponse); // Relay and verify we got a success - t.log("relaying packets"); + t.log('relaying packets'); let info = await channel.link.relayAll(); assertAckSuccess(info.acksFromA); @@ -398,7 +315,7 @@ test.serial("transfer NFT: wasmd -> osmo", async (t) => { tokenId ); t.truthy(transferResponse); - t.log("relaying packets"); + t.log('relaying packets'); // Verify we got a success info = await channel.link.relayAll(); @@ -413,39 +330,19 @@ test.serial("transfer NFT: wasmd -> osmo", async (t) => { // ==== test transfer NFT to osmo chain via unknown, not WLed channel by incoming proxy ==== // test rejected NFT transfer due to unknown channel by incoming proxy - tokenId = "2"; + tokenId = '2'; await mint(wasmClient, wasmCw721, tokenId, wasmAddr, undefined); // assert token is minted tokenOwner = await ownerOf(wasmClient, wasmCw721, tokenId); t.is(wasmAddr, tokenOwner.owner); - t.log( - `transfering to osmo chain via unknown ${otherChannel.channel.src.channelId}` - ); - const beforeWasmOutgoingClassTokenToChannelList = await outgoingChannels( - wasmClient, - wasmIcs721 - ); - const beforeWasmIncomingClassTokenToChannelList = await incomingChannels( - wasmClient, - wasmIcs721 - ); - const beforeWasmNftContractsToClassIdList = await nftContracts( - wasmClient, - wasmIcs721 - ); - const beforeOsmoOutgoingClassTokenToChannelList = await outgoingChannels( - osmoClient, - osmoIcs721 - ); - const beforeOsmoIncomingClassTokenToChannelList = await incomingChannels( - osmoClient, - osmoIcs721 - ); - const beforeOsmoNftContractsToClassIdList = await nftContracts( - osmoClient, - osmoIcs721 - ); + t.log(`transfering to osmo chain via unknown ${otherChannel.channel.src.channelId}`); + const beforeWasmOutgoingClassTokenToChannelList = await outgoingChannels(wasmClient, wasmIcs721); + const beforeWasmIncomingClassTokenToChannelList = await incomingChannels(wasmClient, wasmIcs721); + const beforeWasmNftContractsToClassIdList = await nftContracts(wasmClient, wasmIcs721); + const beforeOsmoOutgoingClassTokenToChannelList = await outgoingChannels(osmoClient, osmoIcs721); + const beforeOsmoIncomingClassTokenToChannelList = await incomingChannels(osmoClient, osmoIcs721); + const beforeOsmoNftContractsToClassIdList = await nftContracts(osmoClient, osmoIcs721); ibcMsg = { receiver: osmoAddr, @@ -457,32 +354,17 @@ test.serial("transfer NFT: wasmd -> osmo", async (t) => { }, }, }; - transferResponse = await sendNft( - wasmClient, - wasmCw721, - wasmCw721OutgoingProxy, - ibcMsg, - tokenId - ); + transferResponse = await sendNft(wasmClient, wasmCw721, wasmCw721OutgoingProxy, ibcMsg, tokenId); t.truthy(transferResponse); // Relay and verify we got an error - t.log("relaying packets"); + t.log('relaying packets'); info = await otherChannel.link.relayAll(); assertAckErrors(info.acksFromA); // assert no change before and after relay - const afterWasmOutgoingClassTokenToChannelList = await outgoingChannels( - wasmClient, - wasmIcs721 - ); - const afterWasmIncomingClassTokenToChannelList = await incomingChannels( - wasmClient, - wasmIcs721 - ); - const afterWasmNftContractsToClassIdList = await nftContracts( - wasmClient, - wasmIcs721 - ); + const afterWasmOutgoingClassTokenToChannelList = await outgoingChannels(wasmClient, wasmIcs721); + const afterWasmIncomingClassTokenToChannelList = await incomingChannels(wasmClient, wasmIcs721); + const afterWasmNftContractsToClassIdList = await nftContracts(wasmClient, wasmIcs721); t.deepEqual( beforeWasmOutgoingClassTokenToChannelList, afterWasmOutgoingClassTokenToChannelList, @@ -504,18 +386,9 @@ test.serial("transfer NFT: wasmd -> osmo", async (t) => { - wasm before: ${JSON.stringify(beforeWasmNftContractsToClassIdList)} - wasm after: ${JSON.stringify(afterWasmNftContractsToClassIdList)}` ); - const afterOsmoOutgoingClassTokenToChannelList = await outgoingChannels( - osmoClient, - osmoIcs721 - ); - const afterOsmoIncomingClassTokenToChannelList = await incomingChannels( - osmoClient, - osmoIcs721 - ); - const afterOsmoNftContractsToClassIdList = await nftContracts( - osmoClient, - osmoIcs721 - ); + const afterOsmoOutgoingClassTokenToChannelList = await outgoingChannels(osmoClient, osmoIcs721); + const afterOsmoIncomingClassTokenToChannelList = await incomingChannels(osmoClient, osmoIcs721); + const afterOsmoNftContractsToClassIdList = await nftContracts(osmoClient, osmoIcs721); t.deepEqual( beforeOsmoOutgoingClassTokenToChannelList, afterOsmoOutgoingClassTokenToChannelList, @@ -543,16 +416,14 @@ test.serial("transfer NFT: wasmd -> osmo", async (t) => { t.is(wasmAddr, tokenOwner.owner); // ==== test transfer NFT to osmo chain via channel WLed ONLY on osmo incoming proxy and back to wasm chain ==== - tokenId = "3"; + tokenId = '3'; await mint(wasmClient, wasmCw721, tokenId, wasmAddr, undefined); // assert token is minted tokenOwner = await ownerOf(wasmClient, wasmCw721, tokenId); t.is(wasmAddr, tokenOwner.owner); // test transfer NFT to osmo chain - t.log( - `transfering to osmo chain via ${onlyOsmoIncomingChannel.channel.src.channelId}` - ); + t.log(`transfering to osmo chain via ${onlyOsmoIncomingChannel.channel.src.channelId}`); ibcMsg = { receiver: osmoAddr, channel_id: onlyOsmoIncomingChannel.channel.src.channelId, @@ -563,36 +434,18 @@ test.serial("transfer NFT: wasmd -> osmo", async (t) => { }, }, }; - transferResponse = await sendNft( - wasmClient, - wasmCw721, - wasmCw721OutgoingProxy, - ibcMsg, - tokenId - ); + transferResponse = await sendNft(wasmClient, wasmCw721, wasmCw721OutgoingProxy, ibcMsg, tokenId); t.truthy(transferResponse); // Relay and verify we got a success - t.log("relaying packets"); + t.log('relaying packets'); info = await onlyOsmoIncomingChannel.link.relayAll(); assertAckSuccess(info.acksFromA); // assert 1 entry for outgoing channels - let wasmOutgoingClassTokenToChannelList = await outgoingChannels( - wasmClient, - wasmIcs721 - ); - t.log( - `- outgoing channels: ${JSON.stringify( - wasmOutgoingClassTokenToChannelList - )}` - ); - t.true( - wasmOutgoingClassTokenToChannelList.length === 1, - `outgoing channels must have one entry: ${JSON.stringify( - wasmOutgoingClassTokenToChannelList - )}` - ); + let wasmOutgoingClassTokenToChannelList = await outgoingChannels(wasmClient, wasmIcs721); + t.log(`- outgoing channels: ${JSON.stringify(wasmOutgoingClassTokenToChannelList)}`); + t.true(wasmOutgoingClassTokenToChannelList.length === 1, `outgoing channels must have one entry: ${JSON.stringify(wasmOutgoingClassTokenToChannelList)}`); // assert NFT minted on chain B osmoClassId = `${onlyOsmoIncomingChannel.channel.dest.portId}/${onlyOsmoIncomingChannel.channel.dest.channelId}/${t.context.wasmCw721}`; @@ -616,9 +469,7 @@ test.serial("transfer NFT: wasmd -> osmo", async (t) => { t.is(osmoAddr, tokenOwner.owner); // test back transfer NFT to wasm chain, where onlyOsmoIncomingChannel is not WLed on wasm chain - t.log( - `transfering back to wasm chain via unknown ${onlyOsmoIncomingChannel.channel.dest.channelId}` - ); + t.log(`transfering back to wasm chain via unknown ${onlyOsmoIncomingChannel.channel.dest.channelId}`); transferResponse = await sendNft( osmoClient, osmoCw721, @@ -641,7 +492,7 @@ test.serial("transfer NFT: wasmd -> osmo", async (t) => { t.is(osmoIcs721, tokenOwner.owner); // Relay and verify we got an error - t.log("relaying packets"); + t.log('relaying packets'); info = await onlyOsmoIncomingChannel.link.relayAll(); for (const ack of info.acksFromB) { const parsed = JSON.parse(fromUtf8(ack.acknowledgement)); @@ -657,23 +508,11 @@ test.serial("transfer NFT: wasmd -> osmo", async (t) => { t.is(osmoAddr, tokenOwner.owner); // ==== WL channel on wasm chain and test back transfer again ==== - t.log( - `migrate ${wasmCw721IncomingProxy} contract and add channel ${onlyOsmoIncomingChannel.channel.src.channelId}` - ); - await migrateIncomingProxy( - wasmClient, - wasmCw721IncomingProxy, - wasmCw721IncomingProxyId, - [ - channel.channel.src.channelId, - onlyOsmoIncomingChannel.channel.src.channelId, - ] - ); + t.log(`migrate ${wasmCw721IncomingProxy} contract and add channel ${onlyOsmoIncomingChannel.channel.src.channelId}`); + await migrateIncomingProxy(wasmClient, wasmCw721IncomingProxy, wasmCw721IncomingProxyId, [channel.channel.src.channelId, onlyOsmoIncomingChannel.channel.src.channelId]); // test back transfer NFT to wasm chain, where onlyOsmoIncomingChannel is not WLed on wasm chain - t.log( - `transfering back to wasm chain via WLed ${onlyOsmoIncomingChannel.channel.dest.channelId}` - ); + t.log(`transfering back to wasm chain via WLed ${onlyOsmoIncomingChannel.channel.dest.channelId}`); transferResponse = await sendNft( osmoClient, osmoCw721, @@ -701,15 +540,10 @@ test.serial("transfer NFT: wasmd -> osmo", async (t) => { // query nft contracts let nftContractsToClassIdList = await nftContracts(wasmClient, wasmIcs721); t.log(`- nft contracts: ${JSON.stringify(nftContractsToClassIdList)}`); - t.true( - nftContractsToClassIdList.length === 1, - `nft contracts must have exactly one entry: ${JSON.stringify( - nftContractsToClassIdList - )}` - ); + t.true(nftContractsToClassIdList.length === 1, `nft contracts must have exactly one entry: ${JSON.stringify(nftContractsToClassIdList)}`); // Relay and verify success - t.log("relaying packets"); + t.log('relaying packets'); info = await onlyOsmoIncomingChannel.link.relayAll(); for (const ack of info.acksFromB) { const parsed = JSON.parse(fromUtf8(ack.acknowledgement)); @@ -718,16 +552,8 @@ test.serial("transfer NFT: wasmd -> osmo", async (t) => { assertAckSuccess(info.acksFromB); // assert outgoing channels is empty - wasmOutgoingClassTokenToChannelList = await outgoingChannels( - wasmClient, - wasmIcs721 - ); - t.true( - wasmOutgoingClassTokenToChannelList.length === 0, - `outgoing channels not empty: ${JSON.stringify( - wasmOutgoingClassTokenToChannelList - )}` - ); + wasmOutgoingClassTokenToChannelList = await outgoingChannels(wasmClient, wasmIcs721); + t.true(wasmOutgoingClassTokenToChannelList.length === 0, `outgoing channels not empty: ${JSON.stringify(wasmOutgoingClassTokenToChannelList)}`); // assert after success relay, NFT on chain B is burned allNFTs = await allTokens(osmoClient, osmoCw721); @@ -736,33 +562,18 @@ test.serial("transfer NFT: wasmd -> osmo", async (t) => { // assert list is unchanged nftContractsToClassIdList = await nftContracts(wasmClient, wasmIcs721); t.log(`- nft contracts: ${JSON.stringify(nftContractsToClassIdList)}`); - t.true( - nftContractsToClassIdList.length === 1, - `nft contracts must have exactly one entry: ${JSON.stringify( - nftContractsToClassIdList - )}` - ); + t.true(nftContractsToClassIdList.length === 1, `nft contracts must have exactly one entry: ${JSON.stringify(nftContractsToClassIdList)}`); // assert NFT is returned to sender on wasm chain tokenOwner = await ownerOf(wasmClient, wasmCw721, tokenId); t.is(wasmAddr, tokenOwner.owner); }); -test.serial("admin unescrow and burn NFT: wasmd -> osmo", async (t) => { +test.serial('admin unescrow and burn NFT: wasmd -> osmo', async (t) => { await standardSetup(t); - const { - wasmClient, - wasmAddr, - wasmCw721, - wasmIcs721, - wasmCw721OutgoingProxy, - osmoClient, - osmoAddr, - osmoIcs721, - channel, - } = t.context; + const { wasmClient, wasmAddr, wasmCw721, wasmIcs721, wasmCw721OutgoingProxy, osmoClient, osmoAddr, osmoIcs721, channel } = t.context; - const tokenId = "1"; + const tokenId = '1'; await mint(wasmClient, wasmCw721, tokenId, wasmAddr, undefined); // assert token is minted let tokenOwner = await ownerOf(wasmClient, wasmCw721, tokenId); @@ -781,17 +592,11 @@ test.serial("admin unescrow and burn NFT: wasmd -> osmo", async (t) => { }, }, }; - const transferResponse = await sendNft( - wasmClient, - wasmCw721, - wasmCw721OutgoingProxy, - ibcMsg, - tokenId - ); + const transferResponse = await sendNft(wasmClient, wasmCw721, wasmCw721OutgoingProxy, ibcMsg, tokenId); t.truthy(transferResponse); // Relay and verify we got a success - t.log("relaying packets"); + t.log('relaying packets'); const info = await channel.link.relayAll(); assertAckSuccess(info.acksFromA); @@ -809,10 +614,7 @@ test.serial("admin unescrow and burn NFT: wasmd -> osmo", async (t) => { tokenOwner = await ownerOf(osmoClient, osmoCw721, tokenId); t.is(osmoAddr, tokenOwner.owner); - const beforeWasmOutgoingClassTokenToChannelList = await outgoingChannels( - wasmClient, - wasmIcs721 - ); + const beforeWasmOutgoingClassTokenToChannelList = await outgoingChannels(wasmClient, wasmIcs721); // there should be one outgoing channel entry t.deepEqual( beforeWasmOutgoingClassTokenToChannelList, @@ -821,10 +623,7 @@ test.serial("admin unescrow and burn NFT: wasmd -> osmo", async (t) => { - before: ${JSON.stringify(beforeWasmOutgoingClassTokenToChannelList)}` ); // no incoming channel entry - const beforeWasmIncomingClassTokenToChannelList = await incomingChannels( - wasmClient, - wasmIcs721 - ); + const beforeWasmIncomingClassTokenToChannelList = await incomingChannels(wasmClient, wasmIcs721); t.deepEqual( beforeWasmIncomingClassTokenToChannelList, [], @@ -832,10 +631,7 @@ test.serial("admin unescrow and burn NFT: wasmd -> osmo", async (t) => { - before: ${JSON.stringify(beforeWasmIncomingClassTokenToChannelList)}` ); // one nft contract entry - const beforeWasmNftContractsToClassIdList = await nftContracts( - wasmClient, - wasmIcs721 - ); + const beforeWasmNftContractsToClassIdList = await nftContracts(wasmClient, wasmIcs721); t.deepEqual( beforeWasmNftContractsToClassIdList, [[wasmCw721, wasmCw721]], @@ -844,10 +640,7 @@ test.serial("admin unescrow and burn NFT: wasmd -> osmo", async (t) => { ); // no outgoing channel entry - const beforeOsmoOutgoingClassTokenToChannelList = await outgoingChannels( - osmoClient, - osmoIcs721 - ); + const beforeOsmoOutgoingClassTokenToChannelList = await outgoingChannels(osmoClient, osmoIcs721); t.deepEqual( beforeOsmoOutgoingClassTokenToChannelList, [], @@ -855,10 +648,7 @@ test.serial("admin unescrow and burn NFT: wasmd -> osmo", async (t) => { - before: ${JSON.stringify(beforeOsmoOutgoingClassTokenToChannelList)}` ); // there should be one incoming channel entry - const beforeOsmoIncomingClassTokenToChannelList = await incomingChannels( - osmoClient, - osmoIcs721 - ); + const beforeOsmoIncomingClassTokenToChannelList = await incomingChannels(osmoClient, osmoIcs721); t.deepEqual( beforeOsmoIncomingClassTokenToChannelList, [[[osmoClassId, tokenId], channel.channel.dest.channelId]], @@ -866,10 +656,7 @@ test.serial("admin unescrow and burn NFT: wasmd -> osmo", async (t) => { - before: ${JSON.stringify(beforeOsmoIncomingClassTokenToChannelList)}` ); // one nft contract entry - const beforeOsmoNftContractsToClassIdList = await nftContracts( - osmoClient, - osmoIcs721 - ); + const beforeOsmoNftContractsToClassIdList = await nftContracts(osmoClient, osmoIcs721); t.deepEqual( beforeOsmoNftContractsToClassIdList, [[osmoClassId, osmoCw721]], @@ -879,19 +666,9 @@ test.serial("admin unescrow and burn NFT: wasmd -> osmo", async (t) => { // ==== test unescrow NFT on wasm chain ==== t.log(`unescrow NFT on wasm chain`); - await adminCleanAndUnescrowNft( - wasmClient, - wasmIcs721, - wasmAddr, - tokenId, - wasmCw721, - wasmCw721 - ); + await adminCleanAndUnescrowNft(wasmClient, wasmIcs721, wasmAddr, tokenId, wasmCw721, wasmCw721); // there should be no outgoing channel entry - const afterWasmOutgoingClassTokenToChannelList = await outgoingChannels( - wasmClient, - wasmIcs721 - ); + const afterWasmOutgoingClassTokenToChannelList = await outgoingChannels(wasmClient, wasmIcs721); t.deepEqual( afterWasmOutgoingClassTokenToChannelList, [], @@ -908,22 +685,12 @@ test.serial("admin unescrow and burn NFT: wasmd -> osmo", async (t) => { const response = await approve(osmoClient, osmoCw721, osmoIcs721, tokenId); t.log(`- response: ${JSON.stringify(response, bigIntReplacer, 2)}`); t.log(`burn NFT on osmo chain`); - await adminCleanAndBurnNft( - osmoClient, - osmoIcs721, - osmoAddr, - tokenId, - osmoClassId, - osmoCw721 - ); + await adminCleanAndBurnNft(osmoClient, osmoIcs721, osmoAddr, tokenId, osmoClassId, osmoCw721); t.log(`- response: ${JSON.stringify(response, bigIntReplacer, 2)}`); allNFTs = await allTokens(osmoClient, osmoCw721); t.is(allNFTs.tokens.length, 0); // there should be no incoming channel entry - const afterOsmoIncomingClassTokenToChannelList = await incomingChannels( - osmoClient, - osmoIcs721 - ); + const afterOsmoIncomingClassTokenToChannelList = await incomingChannels(osmoClient, osmoIcs721); t.deepEqual( afterOsmoIncomingClassTokenToChannelList, [], @@ -932,30 +699,20 @@ test.serial("admin unescrow and burn NFT: wasmd -> osmo", async (t) => { ); }); -test.serial("malicious NFT", async (t) => { +test.serial('malicious NFT', async (t) => { await standardSetup(t); - const { - wasmClient, - wasmAddr, - wasmIcs721, - wasmCw721OutgoingProxy, - osmoClient, - osmoAddr, - osmoIcs721, - osmoCw721OutgoingProxy, - channel, - } = t.context; - const tokenId = "1"; + const { wasmClient, wasmAddr, wasmIcs721, wasmCw721OutgoingProxy, osmoClient, osmoAddr, osmoIcs721, osmoCw721OutgoingProxy, channel } = t.context; + const tokenId = '1'; // instantiate malicious cw721 contract const res = await uploadAndInstantiate(wasmClient, { cw721_gas_tester: { path: MALICIOUS_CW721, instantiateMsg: { - name: "evil", - symbol: "evil", + name: 'evil', + symbol: 'evil', minter: wasmClient.senderAddress, - banned_recipient: "banned_recipient", // panic every time, on back transfer, when ICS721 tries to transfer/unescrow NFT to this address + banned_recipient: 'banned_recipient', // panic every time, on back transfer, when ICS721 tries to transfer/unescrow NFT to this address }, }, }); @@ -963,7 +720,7 @@ test.serial("malicious NFT", async (t) => { // ==== test malicious NFT transfer to osmo chain ==== await mint(wasmClient, cw721, tokenId, wasmAddr, undefined); - t.log("transferring to osmo chain"); + t.log('transferring to osmo chain'); let ibcMsg = { receiver: osmoAddr, channel_id: channel.channel.src.channelId, @@ -974,16 +731,10 @@ test.serial("malicious NFT", async (t) => { }, }, }; - let transferResponse = await sendNft( - wasmClient, - cw721, - wasmCw721OutgoingProxy, - ibcMsg, - tokenId - ); + let transferResponse = await sendNft(wasmClient, cw721, wasmCw721OutgoingProxy, ibcMsg, tokenId); t.truthy(transferResponse); - t.log("relaying packets"); + t.log('relaying packets'); let info = await channel.link.relayAll(); assertAckSuccess(info.acksFromB); @@ -999,9 +750,9 @@ test.serial("malicious NFT", async (t) => { t.is(osmoAddr, tokenOwner.owner); // ==== test malicious NFT back transfer to banned recipient on wasm chain ==== - t.log("transferring back to wasm chain to banned recipient"); + t.log('transferring back to wasm chain to banned recipient'); ibcMsg = { - receiver: "banned_recipient", + receiver: 'banned_recipient', channel_id: channel.channel.dest.channelId, timeout: { block: { @@ -1010,20 +761,14 @@ test.serial("malicious NFT", async (t) => { }, }, }; - transferResponse = await sendNft( - osmoClient, - osmoCw721, - osmoCw721OutgoingProxy, - ibcMsg, - tokenId - ); + transferResponse = await sendNft(osmoClient, osmoCw721, osmoCw721OutgoingProxy, ibcMsg, tokenId); t.truthy(transferResponse); // before relay NFT escrowed by ICS721 tokenOwner = await ownerOf(osmoClient, osmoCw721, tokenId); t.is(osmoIcs721, tokenOwner.owner); - t.log("relaying packets"); - let pending = await channel.link.getPendingPackets("B"); + t.log('relaying packets'); + let pending = await channel.link.getPendingPackets('B'); t.is(pending.length, 1); // Despite the transfer panicking, a fail ack should be returned. info = await channel.link.relayAll(); @@ -1034,7 +779,7 @@ test.serial("malicious NFT", async (t) => { t.log(`NFT #${tokenId} returned to owner`); // ==== test malicious NFT transfer to regular recipient wasm chain ==== - t.log("transferring back to wasm chain to recipient", wasmAddr); + t.log('transferring back to wasm chain to recipient', wasmAddr); ibcMsg = { receiver: wasmAddr, channel_id: channel.channel.dest.channelId, @@ -1046,18 +791,12 @@ test.serial("malicious NFT", async (t) => { }, }; - transferResponse = await sendNft( - osmoClient, - osmoCw721, - osmoCw721OutgoingProxy, - ibcMsg, - tokenId - ); + transferResponse = await sendNft(osmoClient, osmoCw721, osmoCw721OutgoingProxy, ibcMsg, tokenId); t.truthy(transferResponse); // Relay and verify we got a success - t.log("relaying packets"); - pending = await channel.link.getPendingPackets("B"); + t.log('relaying packets'); + pending = await channel.link.getPendingPackets('B'); t.is(pending.length, 1); info = await channel.link.relayAll(); assertAckSuccess(info.acksFromB);