UNPKG

@apillon/sdk

Version:

▶◀ Apillon SDK for NodeJS ▶◀

150 lines 7.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const nft_1 = require("../modules/nft/nft"); const nft_collection_1 = require("../modules/nft/nft-collection"); const nfts_1 = require("../types/nfts"); const helper_1 = require("./helpers/helper"); const nftData = { collectionType: nfts_1.CollectionType.GENERIC, name: 'SDK Test', description: 'Created from SDK tests', symbol: 'SDKT', royaltiesFees: 0, baseUri: 'https://test.com/metadata/', baseExtension: '.json', maxSupply: 5, drop: false, }; describe('Nft tests', () => { let nft; let collectionUuid; let receivingAddress; beforeAll(async () => { nft = new nft_1.Nft((0, helper_1.getConfig)()); collectionUuid = (0, helper_1.getCollectionUUID)(); receivingAddress = (0, helper_1.getMintAddress)(); }); test('creates a new collection', async () => { const collection = await nft.create(Object.assign(Object.assign({}, nftData), { chain: nfts_1.EvmChain.MOONBASE, isRevokable: false, isSoulbound: true })); expect(collection.uuid).toBeDefined(); expect(collection.contractAddress).toBeDefined(); expect(collection.symbol).toEqual('SDKT'); expect(collection.name).toEqual('SDK Test'); expect(collection.description).toEqual('Created from SDK tests'); expect(collection.isAutoIncrement).toEqual(true); expect(collection.isRevokable).toEqual(false); expect(collection.isSoulbound).toEqual(true); collectionUuid = collection.uuid; }); test('list nft collections', async () => { const { items: collections } = await nft.listCollections(); expect(collections.length).toBeGreaterThan(0); expect(collections[0]).toBeInstanceOf(nft_collection_1.NftCollection); }); test.skip('creates a new substrate collection', async () => { const collection = await nft.createSubstrate(Object.assign(Object.assign({}, nftData), { chain: nfts_1.SubstrateChain.ASTAR, royaltiesAddress: 'b3k5JvUnYjdZrCCNkf15PFpqChMunu11aeRoLropayUmhR4' })); expect(collection.uuid).toBeDefined(); expect(collection.contractAddress).toBeDefined(); expect(collection.symbol).toEqual('SDKT'); expect(collection.name).toEqual('SDK Test'); expect(collection.description).toEqual('Created from SDK tests'); expect(collection.isAutoIncrement).toEqual(true); expect(collection.isRevokable).toEqual(false); expect(collection.isSoulbound).toEqual(false); }); test.only('creates a new unique collection', async () => { const uniqueCollectionData = Object.assign(Object.assign({}, nftData), { maxSupply: 1000, isRevokable: true, isSoulbound: false, metadata: { '1': { name: 'Unique NFT 1', description: 'Description for Unique NFT 1', image: 'https://example.com/nft1.png', attributes: [ { value: 'Attribute Value 1', trait_type: 'Attribute Type 1', display_type: 'string', }, ], }, '2': { name: 'Unique NFT 2', description: 'Description for Unique NFT 2', image: 'https://example.com/nft2.png', attributes: [ { value: 'Attribute Value 2', trait_type: 'Attribute Type 2', display_type: 'string', }, ], }, } }); const collection = await nft.createUnique(uniqueCollectionData); expect(collection.uuid).toBeDefined(); expect(collection.contractAddress).toBeDefined(); expect(collection.symbol).toEqual('SDKT'); expect(collection.name).toEqual('SDK Test'); expect(collection.description).toEqual('Created from SDK tests'); expect(collection.isAutoIncrement).toEqual(true); expect(collection.isRevokable).toEqual(true); expect(collection.isSoulbound).toEqual(false); // collectionUuid = collection.uuid; }); test('mints a new nft', async () => { const collection = nft.collection(collectionUuid); const res = await collection.mint({ receivingAddress, quantity: 1, }); expect(res.success).toBe(true); expect(res.transactionHash).toBeDefined(); }); test('get nft collection transactions', async () => { const { items: transactions } = await nft .collection(collectionUuid) .listTransactions(); expect(transactions.length).toBeGreaterThan(0); expect(transactions[0].transactionHash).toBeDefined(); }); test('get nft collection details', async () => { const collection = await nft.collection(collectionUuid).get(); console.log(collection); expect(collection.name).toBe('SDK Test'); }); test('should fail nest minting for collection that is not nestable if collection populated', async () => { const collection = await nft.collection(collectionUuid).get(); await expect(collection.nestMint('', 1, 1)).rejects.toThrow('Collection is not nestable.'); }); // TODO: unhandled error in api test('should fail nest minting', async () => { const collection = nft.collection(collectionUuid); await expect(collection.nestMint(collectionUuid, 1, 1)).rejects.toThrow(); }); test('should fail revoking for collection that is not revokable if collection populated', async () => { const collection = await nft.collection(collectionUuid).get(); await expect(collection.burn('1')).rejects.toThrow('Collection is not revokable.'); }); describe('NFT with custom IDs mint', () => { test('creates a new collection', async () => { const collection = await nft.create(Object.assign(Object.assign({}, nftData), { name: 'SDK Test isAutoIncrement=false', chain: nfts_1.EvmChain.MOONBASE, isAutoIncrement: false, isRevokable: false, isSoulbound: false })); expect(collection.uuid).toBeDefined(); expect(collection.contractAddress).toBeDefined(); expect(collection.symbol).toEqual('SDKT'); expect(collection.name).toEqual('SDK Test isAutoIncrement=false'); expect(collection.description).toEqual('Created from SDK tests'); expect(collection.isAutoIncrement).toEqual(false); collectionUuid = collection.uuid; }); test('mints new nfts with custom IDs', async () => { const collection = nft.collection(collectionUuid); const res = await collection.mint({ receivingAddress, quantity: 2, idsToMint: [10, 20], }); expect(res.success).toBe(true); expect(res.transactionHash).toBeDefined(); }); }); }); //# sourceMappingURL=nft.test.js.map