Skip to content

Commit

Permalink
Fixing formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
blockiosaurus committed Jun 24, 2024
1 parent b30aa9f commit 291881a
Show file tree
Hide file tree
Showing 8 changed files with 583 additions and 512 deletions.
2 changes: 1 addition & 1 deletion clients/js/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './generated';
export * from './plugin';
export * from './plugin';
8 changes: 4 additions & 4 deletions clients/js/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { UmiPlugin } from '@metaplex-foundation/umi';
import { createMplHybridProgram } from './generated';

export const mplHybrid = (): UmiPlugin => ({
install(umi) {
umi.programs.add(createMplHybridProgram(), false);
},
});
install(umi) {
umi.programs.add(createMplHybridProgram(), false);
},
});
66 changes: 38 additions & 28 deletions clients/js/test/_setup.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,56 @@
/* eslint-disable import/no-extraneous-dependencies */
import { createUmi as basecreateUmi } from '@metaplex-foundation/umi-bundle-tests';
import { AssetV1, create, createCollection, fetchAsset, fetchCollection, mplCore } from '@metaplex-foundation/mpl-core';
import {
AssetV1,
create,
createCollection,
fetchAsset,
fetchCollection,
mplCore,
} from '@metaplex-foundation/mpl-core';
import { generateSigner, PublicKey, Umi } from '@metaplex-foundation/umi';
import { mplTokenMetadata } from '@metaplex-foundation/mpl-token-metadata';
import { mplHybrid } from '../src';

export const DEFAULT_ASSET = {
name: 'Test Asset',
uri: 'https://example.com/asset',
name: 'Test Asset',
uri: 'https://example.com/asset',
};

export const DEFAULT_COLLECTION = {
name: 'Test Collection',
uri: 'https://example.com/collection',
name: 'Test Collection',
uri: 'https://example.com/collection',
};

export const createUmi = async () =>
(await basecreateUmi()).use(mplHybrid()).use(mplCore()).use(mplTokenMetadata());
(await basecreateUmi())
.use(mplHybrid())
.use(mplCore())
.use(mplTokenMetadata());

export async function createCoreCollection(umi: Umi, owner?: PublicKey) {
const collectionAddress = generateSigner(umi);
await createCollection(umi, {
collection: collectionAddress,
...DEFAULT_COLLECTION,
}).sendAndConfirm(umi);
const collectionAddress = generateSigner(umi);
await createCollection(umi, {
collection: collectionAddress,
...DEFAULT_COLLECTION,
}).sendAndConfirm(umi);

const collection = await fetchCollection(umi, collectionAddress.publicKey);
const newOwner = owner || umi.identity.publicKey;
const collection = await fetchCollection(umi, collectionAddress.publicKey);
const newOwner = owner || umi.identity.publicKey;

const assets: AssetV1[] = [];
for (let i = 0; i < 10; i += 1) {
const assetAddress = generateSigner(umi);
// eslint-disable-next-line no-await-in-loop
await create(umi, {
asset: assetAddress,
collection,
owner: newOwner,
...DEFAULT_ASSET,
}).sendAndConfirm(umi);
// eslint-disable-next-line no-await-in-loop
assets.push(await fetchAsset(umi, assetAddress.publicKey));
}
const assets: AssetV1[] = [];
for (let i = 0; i < 10; i += 1) {
const assetAddress = generateSigner(umi);
// eslint-disable-next-line no-await-in-loop
await create(umi, {
asset: assetAddress,
collection,
owner: newOwner,
...DEFAULT_ASSET,
}).sendAndConfirm(umi);
// eslint-disable-next-line no-await-in-loop
assets.push(await fetchAsset(umi, assetAddress.publicKey));
}

return { collection, assets };
}
return { collection, assets };
}
176 changes: 95 additions & 81 deletions clients/js/test/capture.test.ts
Original file line number Diff line number Diff line change
@@ -1,91 +1,105 @@
import test from "ava";
import { generateSigner, publicKey } from "@metaplex-foundation/umi";
import { createFungible, mintV1, TokenStandard } from "@metaplex-foundation/mpl-token-metadata";
import { string, publicKey as publicKeySerializer } from "@metaplex-foundation/umi/serializers";
import { transfer } from "@metaplex-foundation/mpl-core";
import { captureV1, EscrowV1, fetchEscrowV1, initEscrowV1, MPL_HYBRID_PROGRAM_ID, Path } from "../src";
import { createCoreCollection, createUmi } from "./_setup";
import test from 'ava';
import { generateSigner, publicKey } from '@metaplex-foundation/umi';
import {
createFungible,
mintV1,
TokenStandard,
} from '@metaplex-foundation/mpl-token-metadata';
import {
string,
publicKey as publicKeySerializer,
} from '@metaplex-foundation/umi/serializers';
import { transfer } from '@metaplex-foundation/mpl-core';
import {
captureV1,
EscrowV1,
fetchEscrowV1,
initEscrowV1,
MPL_HYBRID_PROGRAM_ID,
Path,
} from '../src';
import { createCoreCollection, createUmi } from './_setup';

test('it can swap tokens for an asset', async (t) => {
// Given a Umi instance using the project's plugin.
const umi = await createUmi();
const feeLocation = generateSigner(umi);
const { assets, collection } = await createCoreCollection(umi);
const tokenMint = generateSigner(umi);
await createFungible(umi, {
name: 'Test Token',
uri: 'www.fungible.com',
sellerFeeBasisPoints: {
basisPoints: 0n,
identifier: '%',
decimals: 2
},
mint: tokenMint,
}).sendAndConfirm(umi);

await mintV1(umi, {
mint: tokenMint.publicKey,
tokenStandard: TokenStandard.Fungible,
tokenOwner: umi.identity.publicKey,
amount: 1000,
}).sendAndConfirm(umi);
// Given a Umi instance using the project's plugin.
const umi = await createUmi();
const feeLocation = generateSigner(umi);
const { assets, collection } = await createCoreCollection(umi);
const tokenMint = generateSigner(umi);
await createFungible(umi, {
name: 'Test Token',
uri: 'www.fungible.com',
sellerFeeBasisPoints: {
basisPoints: 0n,
identifier: '%',
decimals: 2,
},
mint: tokenMint,
}).sendAndConfirm(umi);

const escrow = umi.eddsa.findPda(MPL_HYBRID_PROGRAM_ID, [
string({ size: 'variable' }).serialize('escrow'),
publicKeySerializer().serialize(collection.publicKey)
]);
await mintV1(umi, {
mint: tokenMint.publicKey,
tokenStandard: TokenStandard.Fungible,
tokenOwner: umi.identity.publicKey,
amount: 1000,
}).sendAndConfirm(umi);

// Transfer the assets to the escrow.
// eslint-disable-next-line no-restricted-syntax
for (const asset of assets) {
// eslint-disable-next-line no-await-in-loop
await transfer(umi, {
asset,
collection,
newOwner: escrow,
}).sendAndConfirm(umi);
}
const escrow = umi.eddsa.findPda(MPL_HYBRID_PROGRAM_ID, [
string({ size: 'variable' }).serialize('escrow'),
publicKeySerializer().serialize(collection.publicKey),
]);

await initEscrowV1(umi, {
escrow,
collection: collection.publicKey,
token: tokenMint.publicKey,
feeLocation: feeLocation.publicKey,
name: 'Test Escrow',
uri: 'www.test.com',
max: 9,
min: 0,
amount: 5,
feeAmount: 1,
path: Path.RerollMetadata,
solFeeAmount: 1000000n,
// Transfer the assets to the escrow.
// eslint-disable-next-line no-restricted-syntax
for (const asset of assets) {
// eslint-disable-next-line no-await-in-loop
await transfer(umi, {
asset,
collection,
newOwner: escrow,
}).sendAndConfirm(umi);
}

const escrowData = await fetchEscrowV1(umi, escrow);
await initEscrowV1(umi, {
escrow,
collection: collection.publicKey,
token: tokenMint.publicKey,
feeLocation: feeLocation.publicKey,
name: 'Test Escrow',
uri: 'www.test.com',
max: 9,
min: 0,
amount: 5,
feeAmount: 1,
path: Path.RerollMetadata,
solFeeAmount: 1000000n,
}).sendAndConfirm(umi);

t.like(escrowData, <EscrowV1>{
publicKey: publicKey(escrow),
collection: collection.publicKey,
token: tokenMint.publicKey,
feeLocation: feeLocation.publicKey,
name: 'Test Escrow',
uri: 'www.test.com',
max: 9n,
min: 0n,
amount: 5n,
feeAmount: 1n,
count: 1n,
path: Path.RerollMetadata,
bump: escrow[1],
solFeeAmount: 1_000_000n,
});
const escrowData = await fetchEscrowV1(umi, escrow);

await captureV1(umi, {
owner: umi.identity,
escrow,
asset: assets[0].publicKey,
collection: collection.publicKey,
feeProjectAccount: escrowData.feeLocation,
token: tokenMint.publicKey,
}).sendAndConfirm(umi);
t.like(escrowData, <EscrowV1>{
publicKey: publicKey(escrow),
collection: collection.publicKey,
token: tokenMint.publicKey,
feeLocation: feeLocation.publicKey,
name: 'Test Escrow',
uri: 'www.test.com',
max: 9n,
min: 0n,
amount: 5n,
feeAmount: 1n,
count: 1n,
path: Path.RerollMetadata,
bump: escrow[1],
solFeeAmount: 1_000_000n,
});

await captureV1(umi, {
owner: umi.identity,
escrow,
asset: assets[0].publicKey,
collection: collection.publicKey,
feeProjectAccount: escrowData.feeLocation,
token: tokenMint.publicKey,
}).sendAndConfirm(umi);
});
14 changes: 7 additions & 7 deletions clients/js/test/getProgram.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { MPL_HYBRID_PROGRAM_ID } from '../src';
import { createUmi } from './_setup';

test('it registers the program', async (t) => {
// Given a Umi instance using the project's plugin.
const umi = await createUmi();
// Given a Umi instance using the project's plugin.
const umi = await createUmi();

// When we fetch the registered program.
const program = umi.programs.get('mplHybrid');
// When we fetch the registered program.
const program = umi.programs.get('mplHybrid');

// Then we expect it to be the same as the program ID constant.
t.true(program.publicKey === MPL_HYBRID_PROGRAM_ID);
});
// Then we expect it to be the same as the program ID constant.
t.true(program.publicKey === MPL_HYBRID_PROGRAM_ID);
});
Loading

0 comments on commit 291881a

Please sign in to comment.