git.delta.rocks / unique-network / refs/commits / 71a39d07af30

difftreelog

source

tests/src/rmrk/mintNft.seqtest.ts4.7 KiBsourcehistory
1import {expect} from 'chai';2import {getApiConnection} from '../substrate/substrate-api';3import {getNft} from './util/fetch';4import {expectTxFailure, requirePallets, Pallets} from './util/helpers';5import {createCollection, mintNft} from './util/tx';67describe('integration test: mint new NFT', () => {8  let api: any;9 10  before(async function () {11    api = await getApiConnection();12    await requirePallets(this, [Pallets.RmrkCore]);13  });141516  const alice = '//Alice';17  const bob = '//Bob';18  const maxCollectionId = 0xFFFFFFFF;19  const maxNftId = 0xFFFFFFFF;2021  it('mint NFT', async () => {22    const owner = null;23    const collectionMetadata = 'mintingCollectionMetadata';24    const collectionMax = null;25    const collectionSymbol = 'MCS';26    const recipientUri = null;27    const royalty = null;28    const nftMetadata = 'NFT-test-metadata';2930    const collectionId = await createCollection(31      api,32      alice,33      collectionMetadata,34      collectionMax,35      collectionSymbol,36    );3738    await mintNft(39      api,40      alice,41      owner,42      collectionId,43      nftMetadata,44      recipientUri,45      royalty,46    );47  });4849  it('mint NFT and set another owner', async () => {50    const owner = bob;51    const collectionMetadata = 'setOwnerCollectionMetadata';52    const collectionMax = null;53    const collectionSymbol = 'SOCS';54    const recipientUri = null;55    const royalty = null;56    const nftMetadata = 'setOwner-NFT-metadata';5758    const collectionId = await createCollection(59      api,60      alice,61      collectionMetadata,62      collectionMax,63      collectionSymbol,64    );6566    await mintNft(67      api,68      alice,69      owner,70      collectionId,71      nftMetadata,72      recipientUri,73      royalty,74    );75  });7677  it('mint NFT with recipient and roalty', async () => {78    const owner = alice;79    const collectionMetadata = 'mintingCollectionMetadata';80    const collectionMax = null;81    const collectionSymbol = 'MCS';82    const recipientUri = bob;83    const royalty = 70000;84    const nftMetadata = 'recipient-royalty-NFT-test-metadata';8586    const collectionId = await createCollection(87      api,88      alice,89      collectionMetadata,90      collectionMax,91      collectionSymbol,92    );9394    await mintNft(95      api,96      alice,97      owner,98      collectionId,99      nftMetadata,100      recipientUri,101      royalty,102    );103  });104105  it('mint NFT with resources', async () => {106    const owner = alice;107    const collectionMetadata = 'mintingCollectionMetadata';108    const collectionMax = null;109    const collectionSymbol = 'MCS';110    const nftMetadata = 'NFT-with-resources-test-metadata';111    const resources = [112      {113        basic: {114          metadata: 'basic-resource-nft-minting',115        },116      }, {117        slot: {118          metadata: 'slot-resource-nft-minting',119          slot: 9,120        },121      }, {122        composable: {123          metadata: 'composable-resource-nft-minting',124          parts: [0, 5, 2],125        },126      }, {127        slot: {128          metadata: 'slot-resource-nft-minting-2',129          thumb: 'srnm2',130          base: 5,131        },132      },133    ];134135    const collectionId = await createCollection(136      api,137      alice,138      collectionMetadata,139      collectionMax,140      collectionSymbol,141    );142143    await mintNft(144      api,145      alice,146      owner,147      collectionId,148      nftMetadata,149      null,150      null,151      true,152      resources,153    );154  });155156  it('[negative] unable to mint NFT within non-existing collection', async () => {157    const owner = alice;158    const recipientUri = null;159    const royalty = null;160    const nftMetadata = 'NFT-test-metadata';161162    const tx = mintNft(163      api,164      alice,165      owner,166      maxCollectionId,167      nftMetadata,168      recipientUri,169      royalty,170    );171172    await expectTxFailure(/rmrkCore\.CollectionUnknown/, tx);173  });174175  it("[negative] unable to mint NFT by a user that isn't the owner of the collection", async () => {176    const owner = alice;177    const collectionMetadata = 'mintingCollectionMetadata';178    const collectionMax = null;179    const collectionSymbol = 'MCS';180    const recipientUri = null;181    const royalty = null;182    const nftMetadata = 'NFT-test-metadata';183184    const collectionId = await createCollection(185      api,186      alice,187      collectionMetadata,188      collectionMax,189      collectionSymbol,190    );191192    const tx = mintNft(193      api,194      bob,195      owner,196      collectionId,197      nftMetadata,198      recipientUri,199      royalty,200    );201202    await expectTxFailure(/rmrkCore\.NoPermission/, tx);203  });204205  it('[negative] unable to fetch non-existing NFT', async () => {206    const nft = await getNft(api, maxCollectionId, maxNftId);207    expect(nft.isSome).to.be.false;208  });209210  after(async() => { await api.disconnect(); });211});