This repository has been archived by the owner on Apr 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 25-as-a-user-i-want-to-define-fees-for-the-c…
…ollection # Conflicts: # src/HederaNFTSDK.ts # src/types/validateProps.ts # src/utils/validateProps.ts # test/e2e/createCollectionE2E.test.ts # test/e2e/e2eConsts.ts # test/unit/validateProps.test.ts
- Loading branch information
Showing
17 changed files
with
354 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { NftId } from '@hashgraph/sdk'; | ||
import axios from 'axios'; | ||
import { IncreaseNFTSupplyType } from '../types/mintToken'; | ||
import { validatePropsForIncreaseNFTSupply } from '../utils/validateProps'; | ||
import { mintSharedMetadataFunction } from './mintSharedMetadataFunction'; | ||
|
||
export const increaseNFTSupply = async ({ | ||
client, | ||
network, | ||
nftId, | ||
amount, | ||
batchSize, | ||
supplyKey, | ||
mirrorNodeUrl | ||
}: IncreaseNFTSupplyType) => { | ||
validatePropsForIncreaseNFTSupply({ nftId, amount, supplyKey, batchSize }); | ||
return getMetaDataFromMirrorNode(network, nftId, mirrorNodeUrl) | ||
.then((metaData) => mintSharedMetadataFunction({ client, tokenId: nftId.tokenId.toString(), amount, batchSize, metaData, supplyKey })); | ||
}; | ||
|
||
async function getMetaDataFromMirrorNode(network: string, nftId: NftId, mirrorNodeUrl?: string): Promise<string> { | ||
const url = mirrorNodeUrl || getMirrorNodeUrlForNetwork(network); | ||
return axios.get(`${url}/tokens/${nftId.tokenId.toString()}/nfts/${nftId.serial.toString()}`) | ||
.then((response) => { | ||
//atob is used to decode the base64 encoded metadata | ||
return atob(response.data.metadata); | ||
}) | ||
} | ||
|
||
function getMirrorNodeUrlForNetwork(network: string): string { | ||
return `https://${network === 'mainnet' ? 'mainnet-public' : network}.mirrornode.hedera.com/api/v1`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export type LogInType = { | ||
myAccountId: string; | ||
myPrivateKey: string; | ||
network: string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { NftId, PrivateKey, TokenId, TokenNftInfoQuery } from '@hashgraph/sdk'; | ||
import { nftSDK, operatorPrivateKey } from './e2eConsts'; | ||
import { LONG_E2E_TIMEOUT, MIRROR_NODE_DELAY } from '../__mocks__/consts'; | ||
|
||
afterAll(async () => { | ||
nftSDK.client.close(); | ||
}); | ||
|
||
describe('increaseNFTSupply function e2e', () => { | ||
const testCases = [{ amount: 1 }, { amount: 3 }, { amount: 10 }]; | ||
|
||
testCases.forEach(({ amount }) => { | ||
it( | ||
`Increasing a token supply by ${amount}`, | ||
async () => { | ||
const tokenId = await nftSDK.createCollection({ | ||
collectionName: 'test_name', | ||
collectionSymbol: 'test_symbol', | ||
}); | ||
const baseNFT = await nftSDK.mintUniqueMetadata({ | ||
tokenId, | ||
batchSize: 10, | ||
metadata: ['www.youtube.com'], | ||
supplyKey: PrivateKey.fromString(operatorPrivateKey), | ||
}); | ||
const nftInfo = await new TokenNftInfoQuery() | ||
.setNftId(new NftId(TokenId.fromString(tokenId), baseNFT[0].serialNumber)) | ||
.execute(nftSDK.client); | ||
|
||
//wait for the collection and nfts to be available on mirror node | ||
await new Promise((r) => setTimeout(r, MIRROR_NODE_DELAY)); | ||
|
||
const increaseSupplyResult = await nftSDK.increaseNFTSupply({ | ||
nftId: nftInfo[0].nftId, | ||
amount, | ||
batchSize: 10, | ||
supplyKey: PrivateKey.fromString(operatorPrivateKey), | ||
}); | ||
|
||
for (const mintedNft of increaseSupplyResult) { | ||
const nftInfos = await new TokenNftInfoQuery() | ||
.setNftId(new NftId(TokenId.fromString(tokenId), mintedNft.serialNumber)) | ||
.execute(nftSDK.client); | ||
|
||
expect(nftInfos[0].metadata!.toString()).toEqual(baseNFT[0].content); | ||
} | ||
|
||
}, | ||
LONG_E2E_TIMEOUT | ||
); | ||
}); | ||
}); |
Oops, something went wrong.