-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Give default to tokenRecord for PNFTs in mintV1
- Loading branch information
1 parent
64b0ddb
commit 1749edc
Showing
2 changed files
with
248 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,226 @@ | ||
import { fetchMint, Mint } from '@metaplex-foundation/mpl-essentials'; | ||
import { | ||
generateSigner, | ||
none, | ||
percentAmount, | ||
publicKey, | ||
some, | ||
} from '@metaplex-foundation/umi'; | ||
import test from 'ava'; | ||
import { | ||
createFungible, | ||
createFungibleAsset, | ||
createNft, | ||
createProgrammableNft, | ||
fetchMasterEdition, | ||
fetchMetadata, | ||
findMasterEditionPda, | ||
findMetadataPda, | ||
MasterEdition, | ||
Metadata, | ||
programmableConfig, | ||
TokenStandard, | ||
} from '../src'; | ||
import { createUmi } from './_setup'; | ||
|
||
test('it can create a new NonFungible', async (t) => { | ||
// Given a new mint Signer. | ||
const umi = await createUmi(); | ||
const mint = generateSigner(umi); | ||
const masterEdition = findMasterEditionPda(umi, { mint: mint.publicKey }); | ||
|
||
// When we create a new NonFungible at this address. | ||
await createNft(umi, { | ||
mint, | ||
name: 'My NFT', | ||
uri: 'https://example.com/my-nft.json', | ||
sellerFeeBasisPoints: percentAmount(5.5), | ||
}).sendAndConfirm(umi); | ||
|
||
// Then a Mint account was created with 1 supply. | ||
const mintAccount = await fetchMint(umi, mint.publicKey); | ||
t.like(mintAccount, <Mint>{ | ||
publicKey: publicKey(mint), | ||
supply: 1n, | ||
decimals: 0, | ||
mintAuthority: some(publicKey(masterEdition)), | ||
freezeAuthority: some(publicKey(masterEdition)), | ||
}); | ||
|
||
// And a Metadata account was created. | ||
const metadata = findMetadataPda(umi, { mint: mint.publicKey }); | ||
const metadataAccount = await fetchMetadata(umi, metadata); | ||
t.like(metadataAccount, <Metadata>{ | ||
publicKey: publicKey(metadata), | ||
updateAuthority: publicKey(umi.identity), | ||
mint: publicKey(mint), | ||
tokenStandard: some(TokenStandard.NonFungible), | ||
name: 'My NFT', | ||
uri: 'https://example.com/my-nft.json', | ||
sellerFeeBasisPoints: 550, | ||
primarySaleHappened: false, | ||
isMutable: true, | ||
creators: some([ | ||
{ address: publicKey(umi.identity), verified: true, share: 100 }, | ||
]), | ||
collection: none(), | ||
uses: none(), | ||
collectionDetails: none(), | ||
programmableConfig: none(), | ||
}); | ||
|
||
// And a MasterEdition account was created. | ||
const masterEditionAccount = await fetchMasterEdition(umi, masterEdition); | ||
t.like(masterEditionAccount, <MasterEdition>{ | ||
publicKey: publicKey(masterEdition), | ||
supply: 0n, | ||
maxSupply: some(0n), | ||
}); | ||
}); | ||
|
||
test('it can create a new ProgrammableNonFungible', async (t) => { | ||
// Given a new mint Signer. | ||
const umi = await createUmi(); | ||
const mint = generateSigner(umi); | ||
|
||
// When we create a new ProgrammableNonFungible at this address. | ||
await createProgrammableNft(umi, { | ||
mint, | ||
name: 'My Programmable NFT', | ||
uri: 'https://example.com/my-programmable-nft.json', | ||
sellerFeeBasisPoints: percentAmount(5.5), | ||
}).sendAndConfirm(umi); | ||
|
||
// Then a Mint account was created with 1 supply. | ||
const mintAccount = await fetchMint(umi, mint.publicKey); | ||
const masterEdition = findMasterEditionPda(umi, { mint: mint.publicKey }); | ||
t.like(mintAccount, <Mint>{ | ||
publicKey: publicKey(mint), | ||
supply: 1n, | ||
decimals: 0, | ||
mintAuthority: some(publicKey(masterEdition)), | ||
freezeAuthority: some(publicKey(masterEdition)), | ||
}); | ||
|
||
// And a Metadata account was created. | ||
const metadata = findMetadataPda(umi, { mint: mint.publicKey }); | ||
const metadataAccount = await fetchMetadata(umi, metadata); | ||
t.like(metadataAccount, <Metadata>{ | ||
publicKey: publicKey(metadata), | ||
updateAuthority: publicKey(umi.identity), | ||
mint: publicKey(mint), | ||
tokenStandard: some(TokenStandard.ProgrammableNonFungible), | ||
name: 'My Programmable NFT', | ||
uri: 'https://example.com/my-programmable-nft.json', | ||
sellerFeeBasisPoints: 550, | ||
primarySaleHappened: false, | ||
isMutable: true, | ||
creators: some([ | ||
{ address: publicKey(umi.identity), verified: true, share: 100 }, | ||
]), | ||
collection: none(), | ||
uses: none(), | ||
collectionDetails: none(), | ||
programmableConfig: some(programmableConfig('V1', { ruleSet: none() })), | ||
}); | ||
|
||
// And a MasterEdition account was created. | ||
const masterEditionAccount = await fetchMasterEdition(umi, masterEdition); | ||
t.like(masterEditionAccount, <MasterEdition>{ | ||
publicKey: publicKey(masterEdition), | ||
supply: 0n, | ||
maxSupply: some(0n), | ||
}); | ||
}); | ||
|
||
test('it can create a new Fungible', async (t) => { | ||
// Given a new mint Signer. | ||
const umi = await createUmi(); | ||
const mint = generateSigner(umi); | ||
|
||
// When we create a new Fungible at this address. | ||
await createFungible(umi, { | ||
mint, | ||
name: 'My Fungible', | ||
uri: 'https://example.com/my-fungible.json', | ||
sellerFeeBasisPoints: percentAmount(5.5), | ||
}).sendAndConfirm(umi); | ||
|
||
// Then a Mint account was created with no supply. | ||
const mintAccount = await fetchMint(umi, mint.publicKey); | ||
t.like(mintAccount, <Mint>{ | ||
publicKey: publicKey(mint), | ||
supply: 0n, | ||
decimals: 0, | ||
mintAuthority: some(publicKey(umi.identity)), | ||
freezeAuthority: some(publicKey(umi.identity)), | ||
}); | ||
|
||
// And a Metadata account was created. | ||
const metadata = findMetadataPda(umi, { mint: mint.publicKey }); | ||
const metadataAccount = await fetchMetadata(umi, metadata); | ||
t.like(metadataAccount, <Metadata>{ | ||
publicKey: publicKey(metadata), | ||
updateAuthority: publicKey(umi.identity), | ||
mint: publicKey(mint), | ||
tokenStandard: some(TokenStandard.Fungible), | ||
name: 'My Fungible', | ||
uri: 'https://example.com/my-fungible.json', | ||
sellerFeeBasisPoints: 550, | ||
primarySaleHappened: false, | ||
isMutable: true, | ||
creators: some([ | ||
{ address: publicKey(umi.identity), verified: true, share: 100 }, | ||
]), | ||
collection: none(), | ||
uses: none(), | ||
collectionDetails: none(), | ||
programmableConfig: none(), | ||
}); | ||
}); | ||
|
||
test('it can create a new FungibleAsset', async (t) => { | ||
// Given a new mint Signer. | ||
const umi = await createUmi(); | ||
const mint = generateSigner(umi); | ||
|
||
// When we create a new FungibleAsset at this address. | ||
await createFungibleAsset(umi, { | ||
mint, | ||
name: 'My Fungible Asset', | ||
uri: 'https://example.com/my-fungible-asset.json', | ||
sellerFeeBasisPoints: percentAmount(5.5), | ||
}).sendAndConfirm(umi); | ||
|
||
// Then a Mint account was created with no supply. | ||
const mintAccount = await fetchMint(umi, mint.publicKey); | ||
t.like(mintAccount, <Mint>{ | ||
publicKey: publicKey(mint), | ||
supply: 0n, | ||
decimals: 0, | ||
mintAuthority: some(publicKey(umi.identity)), | ||
freezeAuthority: some(publicKey(umi.identity)), | ||
}); | ||
|
||
// And a Metadata account was created. | ||
const metadata = findMetadataPda(umi, { mint: mint.publicKey }); | ||
const metadataAccount = await fetchMetadata(umi, metadata); | ||
t.like(metadataAccount, <Metadata>{ | ||
publicKey: publicKey(metadata), | ||
updateAuthority: publicKey(umi.identity), | ||
mint: publicKey(mint), | ||
tokenStandard: some(TokenStandard.FungibleAsset), | ||
name: 'My Fungible Asset', | ||
uri: 'https://example.com/my-fungible-asset.json', | ||
sellerFeeBasisPoints: 550, | ||
primarySaleHappened: false, | ||
isMutable: true, | ||
creators: some([ | ||
{ address: publicKey(umi.identity), verified: true, share: 100 }, | ||
]), | ||
collection: none(), | ||
uses: none(), | ||
collectionDetails: none(), | ||
programmableConfig: none(), | ||
}); | ||
}); |