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

fix and test for collectionV2 #124

Merged
merged 6 commits into from
Jul 18, 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
2 changes: 1 addition & 1 deletion .github/workflows/build-programs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
PROGRAMS: ${{ env.PROGRAMS }}

- name: Upload program builds
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: program-builds
# First wildcard ensures exported paths are consistently under the programs folder.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-rust-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
run: cargo build --all-features --release

- name: Upload Rust client builds
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: rust-client-builds
# First wildcard ensures exported paths are consistently under the clients folder.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/create-proposal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ jobs:
echo PROGRAM_NAME="token_metadata" >> $GITHUB_ENV

- name: Download program builds
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: program-builds

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-rust-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
key: rust-client-test

- name: Download program builds
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: program-builds

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/version-program.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ jobs:
echo PROGRAM_VERSION="${PROGRAM_VERSION}" >> $GITHUB_ENV

- name: Download Program Builds
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: program-builds

Expand Down
4 changes: 3 additions & 1 deletion clients/js/src/hooked/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ export const resolveCollectionDetails = (
args: { isCollection?: boolean },
...rest: any[]
): Option<CollectionDetailsArgs> =>
args.isCollection ? some(collectionDetails('V1', { size: 0 })) : none();
args.isCollection
? some(collectionDetails('V2', { padding: new Array(8).fill(0) }))
: none();

export const resolveIsNonFungible = (
context: any,
Expand Down
2 changes: 2 additions & 0 deletions clients/js/test/_setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export const SPL_TOKEN_2022_PROGRAM_ID: PublicKey = publicKey(
'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb'
);

export const collectionV2Padding = new Array(8).fill(0);

export const createUmi = async () =>
(await baseCreateUmi()).use(mplTokenMetadata());

Expand Down
62 changes: 60 additions & 2 deletions clients/js/test/createV1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ import {
programmableConfig,
TokenStandard,
} from '../src';
import { createUmi, SPL_TOKEN_2022_PROGRAM_ID } from './_setup';
import {
collectionV2Padding,
createUmi,
SPL_TOKEN_2022_PROGRAM_ID,
} from './_setup';

test('it can create a new NonFungible', async (t) => {
// Given a new mint Signer.
Expand Down Expand Up @@ -235,7 +239,32 @@ test('it can create a new FungibleAsset', async (t) => {
});
});

test('it can create a collection NonFungible', async (t) => {
test('it can create a collection and defaults to collectionV2', async (t) => {
// Given a new mint Signer.
const umi = await createUmi();
const mint = generateSigner(umi);

// When we create a new NonFungible at this address.
await createV1(umi, {
mint,
name: 'My Collection NFT',
uri: 'https://example.com/my-collection-nft.json',
sellerFeeBasisPoints: percentAmount(5.5),
isCollection: true,
}).sendAndConfirm(umi);

// Then a Metadata account was created with the collection details set.
const metadata = findMetadataPda(umi, { mint: mint.publicKey });
const metadataAccount = await fetchMetadata(umi, metadata);
t.like(metadataAccount, <Metadata>{
publicKey: publicKey(metadata),
collectionDetails: some(
collectionDetails('V2', { padding: collectionV2Padding })
),
});
});

test('it can create a collectionV1 NonFungible', async (t) => {
// Given a new mint Signer.
const umi = await createUmi();
const mint = generateSigner(umi);
Expand All @@ -247,6 +276,7 @@ test('it can create a collection NonFungible', async (t) => {
uri: 'https://example.com/my-collection-nft.json',
sellerFeeBasisPoints: percentAmount(5.5),
isCollection: true,
collectionDetails: some(collectionDetails('V1', { size: 0n })),
}).sendAndConfirm(umi);

// Then a Metadata account was created with the collection details set.
Expand All @@ -258,6 +288,34 @@ test('it can create a collection NonFungible', async (t) => {
});
});

test('it can create a collectionV2 NonFungible', async (t) => {
// Given a new mint Signer.
const umi = await createUmi();
const mint = generateSigner(umi);

// When we create a new NonFungible at this address.
await createV1(umi, {
mint,
name: 'My Collection NFT',
uri: 'https://example.com/my-collection-nft.json',
sellerFeeBasisPoints: percentAmount(5.5),
isCollection: true,
collectionDetails: collectionDetails('V2', {
padding: collectionV2Padding,
}),
}).sendAndConfirm(umi);

// Then a Metadata account was created with the collection details set.
const metadata = findMetadataPda(umi, { mint: mint.publicKey });
const metadataAccount = await fetchMetadata(umi, metadata);
t.like(metadataAccount, <Metadata>{
publicKey: publicKey(metadata),
collectionDetails: some(
collectionDetails('V2', { padding: collectionV2Padding })
),
});
});

test('it can create a NonFungible from an existing mint', async (t) => {
// Given an existing mint account.
const umi = await createUmi();
Expand Down
2 changes: 1 addition & 1 deletion programs/token-metadata/program/src/utils/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ pub fn process_create_metadata_accounts_logic(
metadata.collection_details = Some(CollectionDetails::V1 { size: 0 });
}
CollectionDetails::V2 { padding: _ } => {
metadata.collection_details = None;
metadata.collection_details = Some(CollectionDetails::V2 { padding: [0; 8] });
}
}
} else {
Expand Down
Loading