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';1112describe('integration test: accept NFT', () => {13 let api: any;14 before(async () => { api = await getApiConnection(); });1516 const alice = '//Alice';17 const bob = '//Bob';1819 const createTestCollection = async (issuerUri: string) => {20 return await createCollection(21 api,22 issuerUri,23 'accept-metadata',24 null,25 'acpt',26 );27 };2829 it('accept NFT', async () => {30 const ownerAlice = alice;31 const ownerBob = bob;3233 const aliceCollectionId = await createTestCollection(alice);34 const bobCollectionId = await createTestCollection(bob);3536 const parentNftId = await mintNft(api, alice, ownerAlice, aliceCollectionId, 'parent-nft-metadata');37 const childNftId = await mintNft(api, bob, ownerBob, bobCollectionId, 'child-nft-metadata');3839 const newOwnerNFT: NftIdTuple = [aliceCollectionId, parentNftId];4041 await sendNft(api, 'pending', ownerBob, bobCollectionId, childNftId, newOwnerNFT);42 await acceptNft(api, alice, bobCollectionId, childNftId, newOwnerNFT);4344 const isChild = await isNftChildOfAnother(api, bobCollectionId, childNftId, newOwnerNFT);45 expect(isChild).to.be.true;46 });4748 it('[negative] unable to accept NFT by a not-an-owner', async () => {49 const ownerAlice = alice;50 const ownerBob = bob;5152 const aliceCollectionId = await createTestCollection(alice);53 const bobCollectionId = await createTestCollection(bob);5455 const parentNftId = await mintNft(api, alice, ownerAlice, aliceCollectionId, 'parent-nft-metadata');56 const childNftId = await mintNft(api, bob, ownerBob, bobCollectionId, 'child-nft-metadata');5758 const newOwnerNFT: NftIdTuple = [aliceCollectionId, parentNftId];5960 await sendNft(api, 'pending', ownerBob, bobCollectionId, childNftId, newOwnerNFT);61 const tx = acceptNft(api, bob, bobCollectionId, childNftId, newOwnerNFT);6263 await expectTxFailure(/rmrkCore\.NoPermission/, tx);64 });6566 it('[negative] unable to accept non-existing NFT', async () => {67 const collectionId = 0;68 const maxNftId = 0xFFFFFFFF;6970 const owner = alice;71 const aliceCollectionId = await createTestCollection(alice);7273 const parentNftId = await mintNft(api, alice, owner, aliceCollectionId, 'parent-nft-metadata');7475 const newOwnerNFT: NftIdTuple = [aliceCollectionId, parentNftId];7677 const tx = acceptNft(api, alice, collectionId, maxNftId, newOwnerNFT);7879 await expectTxFailure(/rmrkCore\.NoAvailableNftId/, tx);80 });8182 it('[negative] unable to accept NFT which is not sent', async () => {83 const ownerAlice = alice;84 const ownerBob = bob;8586 const aliceCollectionId = await createTestCollection(alice);87 const bobCollectionId = await createTestCollection(bob);8889 const parentNftId = await mintNft(api, alice, ownerAlice, aliceCollectionId, 'parent-nft-metadata');90 const childNftId = await mintNft(api, bob, ownerBob, bobCollectionId, 'child-nft-metadata');9192 const newOwnerNFT: NftIdTuple = [aliceCollectionId, parentNftId];9394 const tx = acceptNft(api, alice, bobCollectionId, childNftId, newOwnerNFT);9596 await expectTxFailure(/rmrkCore\.NoPermission/, tx);9798 const isChild = await isNftChildOfAnother(api, bobCollectionId, childNftId, newOwnerNFT);99 expect(isChild).to.be.false;100 });101102 after(() => { api.disconnect(); });103});