generated from metaplex-foundation/solana-project-template
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing wrong check and adding tests.
- Loading branch information
1 parent
4f1f016
commit efd6173
Showing
4 changed files
with
196 additions
and
5 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,188 @@ | ||
import { TransactionBuilder, generateSigner, percentAmount, some } from '@metaplex-foundation/umi'; | ||
import test from 'ava'; | ||
import { | ||
TokenStandard, | ||
createV1, | ||
mintV1, | ||
mplTokenMetadata, | ||
} from '@metaplex-foundation/mpl-token-metadata'; | ||
import { | ||
AssociatedInscription, | ||
DataType, | ||
InscriptionMetadata, | ||
Key, | ||
fetchInscriptionMetadata, | ||
findInscriptionMetadataPda, | ||
findMintInscriptionPda, | ||
initialize, | ||
initializeFromMint, | ||
setMint, | ||
} from '../src'; | ||
import { createUmi } from './_setup'; | ||
|
||
test('it can set the mint on a Mint Inscription account', async (t) => { | ||
// Given a Umi instance and a new signer. | ||
const umi = await createUmi(); | ||
umi.use(mplTokenMetadata()); | ||
|
||
const mint = generateSigner(umi); | ||
await createV1(umi, { | ||
mint, | ||
name: 'My NFT', | ||
uri: 'https://arweave.net/LcjCf-NDr5bhCJ0YMKGlc8m8qT_J6TDWtIuW8lbu0-A', | ||
sellerFeeBasisPoints: percentAmount(5.5), | ||
tokenStandard: TokenStandard.NonFungible, | ||
}).sendAndConfirm(umi); | ||
|
||
await mintV1(umi, { | ||
mint: mint.publicKey, | ||
tokenStandard: TokenStandard.NonFungible, | ||
}).sendAndConfirm(umi); | ||
|
||
const inscriptionAccount = await findMintInscriptionPda(umi, { | ||
mint: mint.publicKey, | ||
}); | ||
const inscriptionMetadataAccount = await findInscriptionMetadataPda(umi, { | ||
inscriptionAccount: inscriptionAccount[0], | ||
}); | ||
|
||
// const asset = await fetchDigitalAsset(umi, mint.publicKey); | ||
|
||
let builder = new TransactionBuilder(); | ||
|
||
// When we create a new account. | ||
builder = builder.append(initializeFromMint(umi, { | ||
mintAccount: mint.publicKey, | ||
})); | ||
|
||
// Set the mint on the account. | ||
builder = builder.append(setMint(umi, { | ||
mintInscriptionAccount: inscriptionAccount, | ||
inscriptionMetadataAccount, | ||
mintAccount: mint.publicKey | ||
})); | ||
|
||
await builder.sendAndConfirm(umi); | ||
|
||
// Then an account was created with the correct data. | ||
const inscriptionMetadata = await fetchInscriptionMetadata( | ||
umi, | ||
inscriptionMetadataAccount | ||
); | ||
|
||
t.like(inscriptionMetadata, <InscriptionMetadata>{ | ||
key: Key.MintInscriptionMetadataAccount, | ||
inscriptionAccount: inscriptionAccount[0], | ||
bump: inscriptionMetadataAccount[1], | ||
dataType: DataType.Uninitialized, | ||
updateAuthorities: [umi.identity.publicKey], | ||
associatedInscriptions: [] as AssociatedInscription[], | ||
mint: some(mint.publicKey), | ||
}); | ||
}); | ||
|
||
test('it cannot set the mint on an Inscription account', async (t) => { | ||
// Given a Umi instance and a new signer. | ||
const umi = await createUmi(); | ||
umi.use(mplTokenMetadata()); | ||
|
||
const mint = generateSigner(umi); | ||
await createV1(umi, { | ||
mint, | ||
name: 'My NFT', | ||
uri: 'https://arweave.net/LcjCf-NDr5bhCJ0YMKGlc8m8qT_J6TDWtIuW8lbu0-A', | ||
sellerFeeBasisPoints: percentAmount(5.5), | ||
tokenStandard: TokenStandard.NonFungible, | ||
}).sendAndConfirm(umi); | ||
|
||
await mintV1(umi, { | ||
mint: mint.publicKey, | ||
tokenStandard: TokenStandard.NonFungible, | ||
}).sendAndConfirm(umi); | ||
|
||
const inscriptionAccount = generateSigner(umi); | ||
|
||
const inscriptionMetadataAccount = await findInscriptionMetadataPda(umi, { | ||
inscriptionAccount: inscriptionAccount.publicKey, | ||
}); | ||
|
||
let builder = new TransactionBuilder(); | ||
|
||
// When we create a new account. | ||
builder = builder.append(initialize(umi, { | ||
inscriptionAccount, | ||
})); | ||
|
||
// Set the mint on the account. | ||
builder = builder.append(setMint(umi, { | ||
mintInscriptionAccount: inscriptionAccount.publicKey, | ||
inscriptionMetadataAccount, | ||
mintAccount: mint.publicKey, | ||
})); | ||
|
||
const promise = builder.sendAndConfirm(umi); | ||
// Then an error is thrown. | ||
await t.throwsAsync(promise, { name: 'DerivedKeyInvalid' }); | ||
}); | ||
|
||
test('it cannot set the wrong mint on a Mint Inscription account', async (t) => { | ||
// Given a Umi instance and a new signer. | ||
const umi = await createUmi(); | ||
umi.use(mplTokenMetadata()); | ||
|
||
const mint = generateSigner(umi); | ||
await createV1(umi, { | ||
mint, | ||
name: 'My NFT', | ||
uri: 'https://arweave.net/LcjCf-NDr5bhCJ0YMKGlc8m8qT_J6TDWtIuW8lbu0-A', | ||
sellerFeeBasisPoints: percentAmount(5.5), | ||
tokenStandard: TokenStandard.NonFungible, | ||
}).sendAndConfirm(umi); | ||
|
||
await mintV1(umi, { | ||
mint: mint.publicKey, | ||
tokenStandard: TokenStandard.NonFungible, | ||
}).sendAndConfirm(umi); | ||
|
||
const wrongMint = generateSigner(umi); | ||
await createV1(umi, { | ||
mint: wrongMint, | ||
name: 'My NFT', | ||
uri: 'https://arweave.net/LcjCf-NDr5bhCJ0YMKGlc8m8qT_J6TDWtIuW8lbu0-A', | ||
sellerFeeBasisPoints: percentAmount(5.5), | ||
tokenStandard: TokenStandard.NonFungible, | ||
}).sendAndConfirm(umi); | ||
|
||
await mintV1(umi, { | ||
mint: wrongMint.publicKey, | ||
tokenStandard: TokenStandard.NonFungible, | ||
}).sendAndConfirm(umi); | ||
|
||
const inscriptionAccount = await findMintInscriptionPda(umi, { | ||
mint: mint.publicKey, | ||
}); | ||
const inscriptionMetadataAccount = await findInscriptionMetadataPda(umi, { | ||
inscriptionAccount: inscriptionAccount[0], | ||
}); | ||
|
||
// const asset = await fetchDigitalAsset(umi, mint.publicKey); | ||
|
||
let builder = new TransactionBuilder(); | ||
|
||
// When we create a new account. | ||
builder = builder.append(initializeFromMint(umi, { | ||
mintAccount: mint.publicKey, | ||
})); | ||
|
||
// Set the mint on the account. | ||
builder = builder.append(setMint(umi, { | ||
mintInscriptionAccount: inscriptionAccount, | ||
inscriptionMetadataAccount, | ||
mintAccount: wrongMint.publicKey | ||
})); | ||
|
||
const promise = builder.sendAndConfirm(umi); | ||
|
||
// Then an error is thrown. | ||
await t.throwsAsync(promise, { name: 'DerivedKeyInvalid' }); | ||
}); |
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