-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b30aa9f
commit 291881a
Showing
8 changed files
with
583 additions
and
512 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export * from './generated'; | ||
export * from './plugin'; | ||
export * from './plugin'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.