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 some test cases for empty creator array #100

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Changes from all commits
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
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));
});
Loading