Skip to content

Commit

Permalink
Add some test cases for empty creator array (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
danenbm authored Jun 18, 2024
1 parent ec267f6 commit 45f9f54
Showing 1 changed file with 118 additions and 0 deletions.
118 changes: 118 additions & 0 deletions clients/js/test/updateMetadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -772,3 +772,121 @@ test('it can unverify currently verified creator if signer', async (t) => {
merkleTreeAccount = await fetchMerkleTree(umi, merkleTree);
t.is(merkleTreeAccount.tree.rightMostPath.leaf, publicKey(updatedLeaf));
});

test('it can remove currently verified creator using empty creator array if signer', async (t) => {
const umi = await createUmi();
const creatorA = umi.identity;
const creatorB = generateSigner(umi);
const merkleTree = await createTree(umi);
let merkleTreeAccount = await fetchMerkleTree(umi, merkleTree);
const leafOwner = generateSigner(umi).publicKey;
const { metadata, leafIndex } = await mint(umi, {
merkleTree,
leafOwner,
metadata: {
creators: [
{ address: creatorA.publicKey, verified: true, share: 60 },
{ address: creatorB.publicKey, verified: false, share: 40 },
],
},
});

const updateArgs = {
name: 'New name',
creators: [],
};

await updateMetadata(umi, {
leafOwner,
merkleTree,
root: getCurrentRoot(merkleTreeAccount.tree),
nonce: leafIndex,
index: leafIndex,
currentMetadata: metadata,
proof: [],
updateArgs,
}).sendAndConfirm(umi);

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

test('it cannot unverify currently verified creator using empty creator array if not signer', async (t) => {
const umi = await createUmi();
const creatorA = generateSigner(umi);
const creatorB = generateSigner(umi);
const merkleTree = await createTree(umi);
let merkleTreeAccount = await fetchMerkleTree(umi, merkleTree);
const leafOwner = generateSigner(umi).publicKey;
const { metadata, leafIndex } = await mint(umi, {
merkleTree,
leafOwner,
metadata: {
creators: [
{ address: creatorA.publicKey, verified: false, share: 60 },
{ address: creatorB.publicKey, verified: false, share: 40 },
],
},
});

await verifyCreator(umi, {
leafOwner,
creator: creatorA,
merkleTree,
root: getCurrentRoot(merkleTreeAccount.tree),
nonce: leafIndex,
index: leafIndex,
metadata,
proof: [],
}).sendAndConfirm(umi);

const updateArgs = {
name: 'New name',
creators: [],
};

const promise = updateMetadata(umi, {
leafOwner,
merkleTree,
root: getCurrentRoot(merkleTreeAccount.tree),
nonce: leafIndex,
index: leafIndex,
currentMetadata: {
...metadata,
creators: [
{ address: creatorA.publicKey, verified: true, share: 60 },
{ address: creatorB.publicKey, verified: false, share: 40 },
],
},
proof: [],
updateArgs,
}).sendAndConfirm(umi);

await t.throwsAsync(promise, { name: 'CreatorDidNotUnverify' });

// And the leaf was not updated in the merkle tree.
const notUpdatedLeaf = hashLeaf(umi, {
merkleTree,
owner: leafOwner,
leafIndex,
metadata: {
...metadata,
creators: [
{ address: creatorA.publicKey, verified: true, share: 60 },
{ address: creatorB.publicKey, verified: false, share: 40 },
],
},
});
merkleTreeAccount = await fetchMerkleTree(umi, merkleTree);
t.is(merkleTreeAccount.tree.rightMostPath.leaf, publicKey(notUpdatedLeaf));
});

0 comments on commit 45f9f54

Please sign in to comment.