git.delta.rocks / unique-network / refs/commits / ddcf89abd283

difftreelog

source

tests/src/rmrk/setNftProperty.test.ts3.2 KiBsourcehistory
1import {getApiConnection} from '../substrate/substrate-api';2import {requirePallets, Pallets} from '../util/helpers';3import {NftIdTuple} from './util/fetch';4import {expectTxFailure} from './util/helpers';5import {createCollection, mintNft, sendNft, setNftProperty} from './util/tx';67describe('integration test: set NFT property', () => {8  let api: any;9  before(async function () {10    api = await getApiConnection();11    await requirePallets(this, [Pallets.RmrkCore]);12  });1314  const alice = '//Alice';15  const bob = '//Bob';1617  const createTestCollection = async (issuerUri: string) => {18    return await createCollection(19      api,20      issuerUri,21      'setprop-nft-collection-metadata',22      null,23      'setprop',24    );25  };2627  it('set NFT property', async () => {28    const ownerAlice = alice;2930    const collectionId = await createTestCollection(alice);31    const nftId = await mintNft(api, alice, ownerAlice, collectionId, 'prop-nft');3233    await setNftProperty(api, alice, collectionId, nftId, 'test-key', 'test-key-value');34    await setNftProperty(api, alice, collectionId, nftId, 'test-key', 'updated-key-value');35    await setNftProperty(api, alice, collectionId, nftId, 'second-test-key', 'second-test-key-value');36  });3738  it('[negative] unable to set a property of non-existing NFT', async () => {39    const collectionId = 0;40    const maxNftId = 0xFFFFFFFF;4142    const tx = setNftProperty(api, alice, collectionId, maxNftId, 'test-key', 'test-value');4344    await expectTxFailure(/rmrkCore\.NoAvailableNftId/, tx);45  });4647  it('[negative] unable to set a property by not-an-owner', async () => {48    const ownerAlice = alice;4950    const collectionId = await createTestCollection(alice);51    const nftId = await mintNft(api, alice, ownerAlice, collectionId, 'prop-nft');5253    const tx = setNftProperty(api, bob, collectionId, nftId, 'test-key', 'test-key-value');5455    await expectTxFailure(/rmrkCore\.NoPermission/, tx);56  });5758  it('set a property to nested NFT', async () => {59    const ownerAlice = alice;6061    const collectionId = await createTestCollection(alice);62    const parentNftId = await mintNft(api, alice, ownerAlice, collectionId, 'prop-parent-nft');63    const childNftId = await mintNft(api, alice, ownerAlice, collectionId, 'prop-child-nft');6465    const ownerNft: NftIdTuple = [collectionId, parentNftId];6667    await sendNft(api, 'sent', ownerAlice, collectionId, childNftId, ownerNft);6869    await setNftProperty(api, alice, collectionId, childNftId, 'test-key', 'test-key-value');70  });7172  it('[negative] set a property to nested NFT (by not-root-owner)', async () => {73    const ownerAlice = alice;7475    const collectionId = await createTestCollection(alice);76    const parentNftId = await mintNft(api, alice, ownerAlice, collectionId, 'prop-parent-nft');77    const childNftId = await mintNft(api, alice, ownerAlice, collectionId, 'prop-child-nft');7879    const ownerNft: NftIdTuple = [collectionId, parentNftId];8081    await sendNft(api, 'sent', ownerAlice, collectionId, childNftId, ownerNft);8283    const tx = setNftProperty(api, bob, collectionId, childNftId, 'test-key', 'test-key-value');8485    await expectTxFailure(/rmrkCore\.NoPermission/, tx);86  });8788  after(() => { api.disconnect(); });89});