git.delta.rocks / unique-network / refs/commits / 467da923cc78

difftreelog

source

tests/src/rmrk/rejectNft.test.ts2.9 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';1112describe('integration test: reject 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      'reject-metadata',24      null,25      'rjct',26    );27  };2829  it('reject 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 rejectNft(api, alice, bobCollectionId, childNftId);4344    const isChild = await isNftChildOfAnother(api, bobCollectionId, childNftId, newOwnerNFT);45    expect(isChild, 'Error: rejected NFT is still a child of the target NFT').to.be.false;46  });4748  it('[negative] unable to reject 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 = rejectNft(api, bob, bobCollectionId, childNftId);6263    await expectTxFailure(/rmrkCore\.CannotRejectNonOwnedNft/, tx);64  });6566  it('[negative] unable to reject non-existing NFT', async () => {67    const maxNftId = 0xFFFFFFFF;6869    const collectionId = await createTestCollection(alice);7071    const tx = rejectNft(api, alice, collectionId, maxNftId);7273    await expectTxFailure(/rmrkCore\.NoAvailableNftId/, tx);74  });7576  it('[negative] unable to reject NFT which is not sent', async () => {77    const ownerAlice = alice;7879    const collectionId = await createTestCollection(alice);8081    const nftId = await mintNft(api, alice, ownerAlice, collectionId, 'parent-nft-metadata');8283    const tx = rejectNft(api, alice, collectionId, nftId);8485    await expectTxFailure(/rmrkCore\.CannotRejectNonPendingNft/, tx);86  });8788  after(() => { api.disconnect(); });89});