Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for immutable metadata #76

Merged
merged 3 commits into from
Jan 13, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 70 additions & 7 deletions clients/js/test/updateMetadata.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
createNft,
findMetadataPda,
} from '@metaplex-foundation/mpl-token-metadata';
import { createNft } from '@metaplex-foundation/mpl-token-metadata';
import {
defaultPublicKey,
generateSigner,
Expand Down Expand Up @@ -222,9 +219,6 @@ test('it cannot update metadata using collection update authority when collectio
updateArgs,
authority: collectionAuthority,
collectionMint: collectionMint.publicKey,
collectionMetadata: findMetadataPda(umi, {
mint: collectionMint.publicKey,
}),
}).sendAndConfirm(umi);

// Then we expect a program error.
Expand Down Expand Up @@ -493,3 +487,72 @@ test('it cannot update metadata using tree owner when collection is verified', a
merkleTreeAccount = await fetchMerkleTree(umi, merkleTree);
t.is(merkleTreeAccount.tree.rightMostPath.leaf, publicKey(notUpdatedLeaf));
});

test('it cannot update immutable metadata', async (t) => {
// Given an empty Bubblegum tree.
const umi = await createUmi();
const merkleTree = await createTree(umi);
const leafOwner = generateSigner(umi).publicKey;
let merkleTreeAccount = await fetchMerkleTree(umi, merkleTree);

// When we mint a new NFT from the tree.
const { metadata, leafIndex } = await mint(umi, {
leafOwner,
merkleTree,
});

// And we set the NFT to immutable.
await updateMetadata(umi, {
leafOwner,
merkleTree,
root: getCurrentRoot(merkleTreeAccount.tree),
nonce: leafIndex,
index: leafIndex,
currentMetadata: metadata,
proof: [],
updateArgs: { isMutable: false },
}).sendAndConfirm(umi);

// And the leaf was updated in the merkle tree.
let immutableMetadata = {
...metadata,
isMutable: false,
};
const updatedLeaf = hashLeaf(umi, {
merkleTree,
owner: leafOwner,
leafIndex: 0,
metadata: immutableMetadata,
});
merkleTreeAccount = await fetchMerkleTree(umi, merkleTree);
t.is(merkleTreeAccount.tree.rightMostPath.leaf, publicKey(updatedLeaf));

// Then we attempt to update metadata.
const updateArgs: UpdateArgsArgs = {
name: some('New name'),
uri: some('https://updated-example.com/my-nft.json'),
};
let promise = updateMetadata(umi, {
leafOwner,
merkleTree,
root: getCurrentRoot(merkleTreeAccount.tree),
nonce: leafIndex,
index: leafIndex,
currentMetadata: immutableMetadata,
proof: [],
updateArgs,
}).sendAndConfirm(umi);

// Then we expect a program error.
await t.throwsAsync(promise, { name: 'MetadataImmutable' });

// And the leaf was not updated in the merkle tree.
const notUpdatedLeaf = hashLeaf(umi, {
merkleTree,
owner: leafOwner,
leafIndex,
metadata: immutableMetadata,
});
merkleTreeAccount = await fetchMerkleTree(umi, merkleTree);
t.is(merkleTreeAccount.tree.rightMostPath.leaf, publicKey(notUpdatedLeaf));
});
Loading