Skip to content

Commit

Permalink
Add test for immutable metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
danenbm committed Jan 13, 2024
1 parent b8c5655 commit d0e2b5c
Showing 1 changed file with 70 additions and 7 deletions.
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));
});

0 comments on commit d0e2b5c

Please sign in to comment.