From e9a09346de20b8fb17aaa2c2cec313a90da57e69 Mon Sep 17 00:00:00 2001 From: Michael Danenberg <56533526+danenbm@users.noreply.github.com> Date: Fri, 12 Jan 2024 12:18:54 -0800 Subject: [PATCH] Umi lint fixes and fix leaf index for one test (#73) * Umi lint and formatting fixes * Fix leaf index in test --- clients/js/src/leafAssetId.ts | 23 ++++++++++++++++++----- clients/js/test/parseMintV1.test.ts | 25 ++++++++++++++++++++----- clients/js/test/updateMetadata.test.ts | 4 +--- 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/clients/js/src/leafAssetId.ts b/clients/js/src/leafAssetId.ts index 2e487b80..fcc3675c 100644 --- a/clients/js/src/leafAssetId.ts +++ b/clients/js/src/leafAssetId.ts @@ -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, @@ -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]; } @@ -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'); -} \ No newline at end of file +} diff --git a/clients/js/test/parseMintV1.test.ts b/clients/js/test/parseMintV1.test.ts index bcf80e4b..738dc1fe 100644 --- a/clients/js/test/parseMintV1.test.ts +++ b/clients/js/test/parseMintV1.test.ts @@ -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) => { @@ -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]); } }); @@ -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]); } }); diff --git a/clients/js/test/updateMetadata.test.ts b/clients/js/test/updateMetadata.test.ts index 7f86fd14..3dce43b0 100644 --- a/clients/js/test/updateMetadata.test.ts +++ b/clients/js/test/updateMetadata.test.ts @@ -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,