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

difftreelog

source

tests/src/rmrk/rejectNft.test.ts3.0 KiBsourcehistory
1import {expect} from 'chai';2import {getApiConnection} from '../substrate/substrate-api';3import {4  createCollection,5  mintNft,6  sendNft,7  rejectNft,8} from './util/tx';9import {getChildren, NftIdTuple} from './util/fetch';10import {isNftChildOfAnother, expectTxFailure} from './util/helpers';11import {requirePallets, Pallets} from '../util/helpers';1213describe('integration test: reject NFT', () => {14  let api: any;15  before(async function () {16    api = await getApiConnection();17    await requirePallets(this, [Pallets.RmrkCore]);18  });19202122  const alice = '//Alice';23  const bob = '//Bob';2425  const createTestCollection = async (issuerUri: string) => {26    return await createCollection(27      api,28      issuerUri,29      'reject-metadata',30      null,31      'rjct',32    );33  };3435  it('reject NFT', async () => {36    const ownerAlice = alice;37    const ownerBob = bob;3839    const aliceCollectionId = await createTestCollection(alice);40    const bobCollectionId = await createTestCollection(bob);4142    const parentNftId = await mintNft(api, alice, ownerAlice, aliceCollectionId, 'parent-nft-metadata');43    const childNftId = await mintNft(api, bob, ownerBob, bobCollectionId, 'child-nft-metadata');4445    const newOwnerNFT: NftIdTuple = [aliceCollectionId, parentNftId];4647    await sendNft(api, 'pending', ownerBob, bobCollectionId, childNftId, newOwnerNFT);48    await rejectNft(api, alice, bobCollectionId, childNftId);4950    const isChild = await isNftChildOfAnother(api, bobCollectionId, childNftId, newOwnerNFT);51    expect(isChild, 'Error: rejected NFT is still a child of the target NFT').to.be.false;52  });5354  it('[negative] unable to reject NFT by a not-an-owner', async () => {55    const ownerAlice = alice;56    const ownerBob = bob;5758    const aliceCollectionId = await createTestCollection(alice);59    const bobCollectionId = await createTestCollection(bob);6061    const parentNftId = await mintNft(api, alice, ownerAlice, aliceCollectionId, 'parent-nft-metadata');62    const childNftId = await mintNft(api, bob, ownerBob, bobCollectionId, 'child-nft-metadata');6364    const newOwnerNFT: NftIdTuple = [aliceCollectionId, parentNftId];6566    await sendNft(api, 'pending', ownerBob, bobCollectionId, childNftId, newOwnerNFT);67    const tx = rejectNft(api, bob, bobCollectionId, childNftId);6869    await expectTxFailure(/rmrkCore\.CannotRejectNonOwnedNft/, tx);70  });7172  it('[negative] unable to reject non-existing NFT', async () => {73    const maxNftId = 0xFFFFFFFF;7475    const collectionId = await createTestCollection(alice);7677    const tx = rejectNft(api, alice, collectionId, maxNftId);7879    await expectTxFailure(/rmrkCore\.NoAvailableNftId/, tx);80  });8182  it('[negative] unable to reject NFT which is not sent', async () => {83    const ownerAlice = alice;8485    const collectionId = await createTestCollection(alice);8687    const nftId = await mintNft(api, alice, ownerAlice, collectionId, 'parent-nft-metadata');8889    const tx = rejectNft(api, alice, collectionId, nftId);9091    await expectTxFailure(/rmrkCore\.CannotRejectNonPendingNft/, tx);92  });9394  after(() => { api.disconnect(); });95});