From 9f2b378ee7dbfe490af3429e99bcbaeaefaa8395 Mon Sep 17 00:00:00 2001 From: Kacper Koza Date: Thu, 23 May 2024 16:57:42 +0200 Subject: [PATCH] fix(sdk/nftSDKFunctions): fix mintToken fn and update tests Signed-off-by: Kacper Koza --- src/nftSDKFunctions/mint-token.ts | 6 +-- .../mint-unique-metadata-function.test.ts | 50 ------------------- 2 files changed, 3 insertions(+), 53 deletions(-) diff --git a/src/nftSDKFunctions/mint-token.ts b/src/nftSDKFunctions/mint-token.ts index 6fe65d8..de155a7 100644 --- a/src/nftSDKFunctions/mint-token.ts +++ b/src/nftSDKFunctions/mint-token.ts @@ -22,12 +22,12 @@ import { mintingMaxTransactionFee } from '../utils/const'; import { dictionary } from '../utils/constants/dictionary'; export async function mintToken(metaData: string[], tokenId: string, supplyKey: PrivateKey, client: Client) { - const CIDs = metaData.map((data) => new TextEncoder().encode(data)); - - if (CIDs.some((cid) => cid.toString().length > 100)) { + if (metaData.some((cid) => cid.length > 100)) { throw new Error(dictionary.mintToken.tooLongCID); } + const CIDs = metaData.map((data) => new TextEncoder().encode(data)); + const transaction = new TokenMintTransaction() .setTokenId(tokenId) .setMaxTransactionFee(new Hbar(mintingMaxTransactionFee)) diff --git a/src/test/unit/minting/mint-unique-metadata-function.test.ts b/src/test/unit/minting/mint-unique-metadata-function.test.ts index e28076b..8a736b3 100644 --- a/src/test/unit/minting/mint-unique-metadata-function.test.ts +++ b/src/test/unit/minting/mint-unique-metadata-function.test.ts @@ -17,18 +17,12 @@ * limitations under the License. * */ -import * as fs from 'fs'; import { MintUniqueTokenType } from '../../../types/mint-token'; import { mintUniqueMetadataFunction } from '../../../nftSDKFunctions/mint-unique-metadata-function'; import { Client } from '@hashgraph/sdk'; import { myPrivateKey } from '../../__mocks__/consts'; import { mintToken } from '../../../nftSDKFunctions/mint-token'; -interface MockReadStream { - pipe: jest.Mock; - on: jest.Mock; -} - jest.mock('fs'); jest.mock('csv-parser'); jest.mock('../../../nftSDKFunctions/mint-token'); @@ -38,50 +32,6 @@ describe('mintUniqueMetadataFunction', () => { jest.clearAllMocks(); }); - it('should return success metadata when given valid input from file path', async () => { - const mockClient = {} as Client; - const supplyKey = myPrivateKey; - - const mockReadStream: MockReadStream = { - pipe: jest.fn().mockReturnThis(), - on: jest.fn().mockImplementation(function (event, handler) { - if (event === 'data') { - handler({ '0': 'url1,url2' }); - } - if (event === 'end') { - handler(); - } - - return mockReadStream; - }), - }; - (fs.createReadStream as jest.Mock).mockReturnValue(mockReadStream); - - (mintToken as jest.Mock).mockResolvedValueOnce({ - serials: Array.from({ length: 2 }, (_, i) => ({ - toNumber: () => i + 1, - })), - }); - - const input: MintUniqueTokenType = { - client: mockClient, - tokenId: '0.0.123', - batchSize: 5, - pathToMetadataURIsFile: 'mockPath', - supplyKey: supplyKey, - }; - - const result = await mintUniqueMetadataFunction(input); - - expect(result).toEqual([ - { content: 'url1', serialNumber: 1 }, - { content: 'url2', serialNumber: 2 }, - ]); - expect(fs.createReadStream).toHaveBeenCalledWith('mockPath'); - expect(mintToken).toHaveBeenCalledTimes(1); - expect(mintToken).toHaveBeenNthCalledWith(1, ['url1', 'url2'], '0.0.123', supplyKey, {}); - }); - it('should return success metadata when given valid input from array', async () => { const mockClient = {} as Client; const supplyKey = myPrivateKey;