git.delta.rocks / unique-network / refs/commits / 8c823a622616

difftreelog

source

tests/src/rmrk/acceptNft.seqtest.ts3.6 KiBsourcehistory
1import {expect} from 'chai';2import {getApiConnection} from '../substrate/substrate-api';3import {4  createCollection,5  mintNft,6  sendNft,7  acceptNft,8} from './util/tx';9import {NftIdTuple} from './util/fetch';10import {isNftChildOfAnother, expectTxFailure, requirePallets, Pallets} from './util/helpers';1112describe('integration test: accept NFT', () => {13  let api: any;14  before(async function() {15    api = await getApiConnection();16    await requirePallets(this, [Pallets.RmrkCore]);17  });18  19  20  const alice = '//Alice';21  const bob = '//Bob';22  23  const createTestCollection = async (issuerUri: string) => {24    return await createCollection(25      api,26      issuerUri,27      'accept-metadata',28      null,29      'acpt',30    );31  };3233  it('accept NFT', async () => {34    const ownerAlice = alice;35    const ownerBob = bob;3637    const aliceCollectionId = await createTestCollection(alice);38    const bobCollectionId = await createTestCollection(bob);3940    const parentNftId = await mintNft(api, alice, ownerAlice, aliceCollectionId, 'parent-nft-metadata');41    const childNftId = await mintNft(api, bob, ownerBob, bobCollectionId, 'child-nft-metadata');4243    const newOwnerNFT: NftIdTuple = [aliceCollectionId, parentNftId];4445    await sendNft(api, 'pending', ownerBob, bobCollectionId, childNftId, newOwnerNFT);46    await acceptNft(api, alice, bobCollectionId, childNftId, newOwnerNFT);4748    const isChild = await isNftChildOfAnother(api, bobCollectionId, childNftId, newOwnerNFT);49    expect(isChild).to.be.true;50  });5152  it('[negative] unable to accept NFT by a not-an-owner', async () => {53    const ownerAlice = alice;54    const ownerBob = bob;5556    const aliceCollectionId = await createTestCollection(alice);57    const bobCollectionId = await createTestCollection(bob);5859    const parentNftId = await mintNft(api, alice, ownerAlice, aliceCollectionId, 'parent-nft-metadata');60    const childNftId = await mintNft(api, bob, ownerBob, bobCollectionId, 'child-nft-metadata');6162    const newOwnerNFT: NftIdTuple = [aliceCollectionId, parentNftId];6364    await sendNft(api, 'pending', ownerBob, bobCollectionId, childNftId, newOwnerNFT);65    const tx = acceptNft(api, bob, bobCollectionId, childNftId, newOwnerNFT);6667    await expectTxFailure(/rmrkCore\.NoPermission/, tx);68  });6970  it('[negative] unable to accept non-existing NFT', async () => {71    const collectionId = 0;72    const maxNftId = 0xFFFFFFFF;7374    const owner = alice;75    const aliceCollectionId = await createTestCollection(alice);7677    const parentNftId = await mintNft(api, alice, owner, aliceCollectionId, 'parent-nft-metadata');7879    const newOwnerNFT: NftIdTuple = [aliceCollectionId, parentNftId];8081    const tx = acceptNft(api, alice, collectionId, maxNftId, newOwnerNFT);8283    await expectTxFailure(/rmrkCore\.NoAvailableNftId/, tx);84  });8586  it('[negative] unable to accept NFT which is not sent', async () => {87    const ownerAlice = alice;88    const ownerBob = bob;8990    const aliceCollectionId = await createTestCollection(alice);91    const bobCollectionId = await createTestCollection(bob);9293    const parentNftId = await mintNft(api, alice, ownerAlice, aliceCollectionId, 'parent-nft-metadata');94    const childNftId = await mintNft(api, bob, ownerBob, bobCollectionId, 'child-nft-metadata');9596    const newOwnerNFT: NftIdTuple = [aliceCollectionId, parentNftId];9798    const tx = acceptNft(api, alice, bobCollectionId, childNftId, newOwnerNFT);99100    await expectTxFailure(/rmrkCore\.NoPermission/, tx);101102    const isChild = await isNftChildOfAnother(api, bobCollectionId, childNftId, newOwnerNFT);103    expect(isChild).to.be.false;104  });105106  after(async() => { await api.disconnect(); });107});