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} from './util/helpers';11import {requirePallets, Pallets} from '../deprecated-helpers/helpers';1213describe('integration test: accept NFT', () => {14 let api: any;15 before(async function() {16 api = await getApiConnection();17 await requirePallets(this, [Pallets.RmrkCore]);18 });19 20 21 const alice = '//Alice';22 const bob = '//Bob';23 24 const createTestCollection = async (issuerUri: string) => {25 return await createCollection(26 api,27 issuerUri,28 'accept-metadata',29 null,30 'acpt',31 );32 };3334 it('accept NFT', async () => {35 const ownerAlice = alice;36 const ownerBob = bob;3738 const aliceCollectionId = await createTestCollection(alice);39 const bobCollectionId = await createTestCollection(bob);4041 const parentNftId = await mintNft(api, alice, ownerAlice, aliceCollectionId, 'parent-nft-metadata');42 const childNftId = await mintNft(api, bob, ownerBob, bobCollectionId, 'child-nft-metadata');4344 const newOwnerNFT: NftIdTuple = [aliceCollectionId, parentNftId];4546 await sendNft(api, 'pending', ownerBob, bobCollectionId, childNftId, newOwnerNFT);47 await acceptNft(api, alice, bobCollectionId, childNftId, newOwnerNFT);4849 const isChild = await isNftChildOfAnother(api, bobCollectionId, childNftId, newOwnerNFT);50 expect(isChild).to.be.true;51 });5253 it('[negative] unable to accept NFT by a not-an-owner', async () => {54 const ownerAlice = alice;55 const ownerBob = bob;5657 const aliceCollectionId = await createTestCollection(alice);58 const bobCollectionId = await createTestCollection(bob);5960 const parentNftId = await mintNft(api, alice, ownerAlice, aliceCollectionId, 'parent-nft-metadata');61 const childNftId = await mintNft(api, bob, ownerBob, bobCollectionId, 'child-nft-metadata');6263 const newOwnerNFT: NftIdTuple = [aliceCollectionId, parentNftId];6465 await sendNft(api, 'pending', ownerBob, bobCollectionId, childNftId, newOwnerNFT);66 const tx = acceptNft(api, bob, bobCollectionId, childNftId, newOwnerNFT);6768 await expectTxFailure(/rmrkCore\.NoPermission/, tx);69 });7071 it('[negative] unable to accept non-existing NFT', async () => {72 const collectionId = 0;73 const maxNftId = 0xFFFFFFFF;7475 const owner = alice;76 const aliceCollectionId = await createTestCollection(alice);7778 const parentNftId = await mintNft(api, alice, owner, aliceCollectionId, 'parent-nft-metadata');7980 const newOwnerNFT: NftIdTuple = [aliceCollectionId, parentNftId];8182 const tx = acceptNft(api, alice, collectionId, maxNftId, newOwnerNFT);8384 await expectTxFailure(/rmrkCore\.NoAvailableNftId/, tx);85 });8687 it('[negative] unable to accept NFT which is not sent', async () => {88 const ownerAlice = alice;89 const ownerBob = bob;9091 const aliceCollectionId = await createTestCollection(alice);92 const bobCollectionId = await createTestCollection(bob);9394 const parentNftId = await mintNft(api, alice, ownerAlice, aliceCollectionId, 'parent-nft-metadata');95 const childNftId = await mintNft(api, bob, ownerBob, bobCollectionId, 'child-nft-metadata');9697 const newOwnerNFT: NftIdTuple = [aliceCollectionId, parentNftId];9899 const tx = acceptNft(api, alice, bobCollectionId, childNftId, newOwnerNFT);100101 await expectTxFailure(/rmrkCore\.NoPermission/, tx);102103 const isChild = await isNftChildOfAnother(api, bobCollectionId, childNftId, newOwnerNFT);104 expect(isChild).to.be.false;105 });106107 after(() => { api.disconnect(); });108});