Skip to content

Commit

Permalink
fix(sdk/nftSDKFunctions): fix mintToken fn and update tests
Browse files Browse the repository at this point in the history
Signed-off-by: Kacper Koza <[email protected]>
  • Loading branch information
Kacper Koza committed May 23, 2024
1 parent 0ff3155 commit 9f2b378
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 53 deletions.
6 changes: 3 additions & 3 deletions src/nftSDKFunctions/mint-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
50 changes: 0 additions & 50 deletions src/test/unit/minting/mint-unique-metadata-function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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;
Expand Down

0 comments on commit 9f2b378

Please sign in to comment.