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

Umi lint fixes and fix leaf index for one test #73

Merged
merged 2 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
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
23 changes: 18 additions & 5 deletions clients/js/src/leafAssetId.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import { Context, Pda, PublicKey, TransactionSignature } from '@metaplex-foundation/umi';
import {
Context,
Pda,
PublicKey,
TransactionSignature,
} from '@metaplex-foundation/umi';
import { publicKey, string, u64 } from '@metaplex-foundation/umi/serializers';
import { LeafSchema, MPL_BUBBLEGUM_PROGRAM_ID, getLeafSchemaSerializer } from './generated';
import {
LeafSchema,
MPL_BUBBLEGUM_PROGRAM_ID,
getLeafSchemaSerializer,
} from './generated';

export function findLeafAssetIdPda(
context: Pick<Context, 'programs' | 'eddsa'>,
Expand Down Expand Up @@ -28,7 +37,9 @@ export async function parseLeafFromMintV1Transaction(
const innerInstructions = transaction?.meta.innerInstructions;

if (innerInstructions) {
const leaf = getLeafSchemaSerializer().deserialize(innerInstructions[0].instructions[0].data.slice(8));
const leaf = getLeafSchemaSerializer().deserialize(
innerInstructions[0].instructions[0].data.slice(8)
);
return leaf[0];
}

Expand All @@ -43,9 +54,11 @@ export async function parseLeafFromMintToCollectionV1Transaction(
const innerInstructions = transaction?.meta.innerInstructions;

if (innerInstructions) {
const leaf = getLeafSchemaSerializer().deserialize(innerInstructions[0].instructions[1].data.slice(8));
const leaf = getLeafSchemaSerializer().deserialize(
innerInstructions[0].instructions[1].data.slice(8)
);
return leaf[0];
}

throw new Error('Could not parse leaf from transaction');
}
}
25 changes: 20 additions & 5 deletions clients/js/test/parseMintV1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@ import {
} from '@metaplex-foundation/umi';
import { createNft } from '@metaplex-foundation/mpl-token-metadata';
import test from 'ava';
import { MetadataArgsArgs, fetchMerkleTree, findLeafAssetIdPda, mintToCollectionV1, mintV1, parseLeafFromMintToCollectionV1Transaction, parseLeafFromMintV1Transaction } from '../src';
import {
MetadataArgsArgs,
fetchMerkleTree,
findLeafAssetIdPda,
mintToCollectionV1,
mintV1,
parseLeafFromMintToCollectionV1Transaction,
parseLeafFromMintV1Transaction,
} from '../src';
import { createTree, createUmi } from './_setup';

test('it can parse the leaf from mint instructions', async (t) => {
Expand All @@ -32,13 +40,17 @@ test('it can parse the leaf from mint instructions', async (t) => {

// Test with 10 different leaves to be sure they increment correctly.
for (let nonce = 0; nonce < 10; nonce += 1) {
const { signature } = await mintV1(umi, { leafOwner, merkleTree, metadata }).sendAndConfirm(umi, { confirm: { commitment: 'confirmed' } });
const { signature } = await mintV1(umi, {
leafOwner,
merkleTree,
metadata,
}).sendAndConfirm(umi, { confirm: { commitment: 'confirmed' } });
const leaf = await parseLeafFromMintV1Transaction(umi, signature);
const assetId = findLeafAssetIdPda(umi, { merkleTree, leafIndex: nonce });

t.is(leafOwner, leaf.owner);
t.is(Number(leaf.nonce), nonce);
t.is(leaf.id, assetId[0])
t.is(leaf.id, assetId[0]);
}
});

Expand Down Expand Up @@ -85,11 +97,14 @@ test('it can parse the leaf from mintToCollection instructions)', async (t) => {
collectionMint: collectionMint.publicKey,
}).sendAndConfirm(umi);

const leaf = await parseLeafFromMintToCollectionV1Transaction(umi, signature);
const leaf = await parseLeafFromMintToCollectionV1Transaction(
umi,
signature
);
const assetId = findLeafAssetIdPda(umi, { merkleTree, leafIndex: nonce });

t.is(leafOwner, leaf.owner);
t.is(Number(leaf.nonce), nonce);
t.is(leaf.id, assetId[0])
t.is(leaf.id, assetId[0]);
}
});
4 changes: 1 addition & 3 deletions clients/js/test/updateMetadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,8 @@ test('it can update metadata using the getAssetWithProof helper with verified co
},
creators: [],
};
const leafIndex = Number(
(await fetchMerkleTree(umi, merkleTree)).tree.activeIndex
);
const leafOwner = generateSigner(umi).publicKey;
const leafIndex = 8;
await mintToCollectionV1(umi, {
leafOwner,
merkleTree,
Expand Down