diff --git a/clients/js/test/v1/capture.test.ts b/clients/js/test/v1/capture.test.ts index 80bcad3..c5ff5a2 100644 --- a/clients/js/test/v1/capture.test.ts +++ b/clients/js/test/v1/capture.test.ts @@ -25,7 +25,7 @@ import { } from '../../src'; import { createCoreCollection, createUmi } from '../_setup'; -test('it can swap tokens for an asset', async (t) => { +test('it can swap tokens for an asset with reroll', async (t) => { // Given a Umi instance using the project's plugin. const umi = await createUmi(); const feeLocation = generateSigner(umi); @@ -71,7 +71,7 @@ test('it can swap tokens for an asset', async (t) => { token: tokenMint.publicKey, feeLocation: feeLocation.publicKey, name: 'Test Escrow', - uri: 'www.test.com', + uri: 'www.test.com/', max: 9, min: 0, amount: 5, @@ -88,7 +88,7 @@ test('it can swap tokens for an asset', async (t) => { token: tokenMint.publicKey, feeLocation: feeLocation.publicKey, name: 'Test Escrow', - uri: 'www.test.com', + uri: 'www.test.com/', max: 9n, min: 0n, amount: 5n, @@ -148,9 +148,13 @@ test('it can swap tokens for an asset', async (t) => { t.deepEqual(feeTokenAfter.token.amount, 1n); const assetAfter = await fetchAsset(umi, assets[0].publicKey); t.is(assetAfter.owner, umi.identity.publicKey); + + // Use a Regex to check the URI + const uriRegex = new RegExp(`${escrowData.uri}\\d+\\.json`); + t.regex(assetAfter.uri, uriRegex); }); -test('it can swap tokens for an asset as UpdateDelegate', async (t) => { +test('it can swap tokens for an asset as UpdateDelegate with reroll', async (t) => { // Given a Umi instance using the project's plugin. const umi = await createUmi(); const feeLocation = generateSigner(umi); @@ -196,13 +200,12 @@ test('it can swap tokens for an asset as UpdateDelegate', async (t) => { token: tokenMint.publicKey, feeLocation: feeLocation.publicKey, name: 'Test Escrow', - uri: 'www.test.com', + uri: 'www.test.com/', max: 9, min: 0, amount: 5, feeAmount: 1, - // eslint-disable-next-line no-bitwise - path: 1 << Path.RerollMetadata, + path: Path.RerollMetadata, solFeeAmount: 1000000n, }).sendAndConfirm(umi); @@ -223,14 +226,13 @@ test('it can swap tokens for an asset as UpdateDelegate', async (t) => { token: tokenMint.publicKey, feeLocation: feeLocation.publicKey, name: 'Test Escrow', - uri: 'www.test.com', + uri: 'www.test.com/', max: 9n, min: 0n, amount: 5n, feeAmount: 1n, count: 1n, - // eslint-disable-next-line no-bitwise - path: 1 << Path.RerollMetadata, + path: Path.RerollMetadata, bump: escrow[1], solFeeAmount: 1_000_000n, }); @@ -244,4 +246,29 @@ test('it can swap tokens for an asset as UpdateDelegate', async (t) => { feeProjectAccount: escrowData.feeLocation, token: tokenMint.publicKey, }).sendAndConfirm(umi); + + const escrowTokenAfter = await fetchDigitalAssetWithAssociatedToken( + umi, + tokenMint.publicKey, + publicKey(escrow) + ); + t.deepEqual(escrowTokenAfter.token.amount, 5n); + const userTokenAfter = await fetchDigitalAssetWithAssociatedToken( + umi, + tokenMint.publicKey, + umi.identity.publicKey + ); + t.deepEqual(userTokenAfter.token.amount, 994n); + const feeTokenAfter = await fetchDigitalAssetWithAssociatedToken( + umi, + tokenMint.publicKey, + escrowData.feeLocation + ); + t.deepEqual(feeTokenAfter.token.amount, 1n); + const assetAfter = await fetchAsset(umi, assets[0].publicKey); + t.is(assetAfter.owner, umi.identity.publicKey); + + // Use a Regex to check the URI + const uriRegex = new RegExp(`${escrowData.uri}\\d+\\.json`); + t.regex(assetAfter.uri, uriRegex); }); diff --git a/clients/js/test/v1/initEscrow.test.ts b/clients/js/test/v1/initEscrow.test.ts index bc1cb05..3e64dba 100644 --- a/clients/js/test/v1/initEscrow.test.ts +++ b/clients/js/test/v1/initEscrow.test.ts @@ -46,7 +46,7 @@ test('it can initialize the escrow', async (t) => { token: tokenMint.publicKey, feeLocation: feeLocation.publicKey, name: 'Test Escrow', - uri: 'www.test.com', + uri: 'www.test.com/', max: 2, min: 1, amount: 3, @@ -66,7 +66,7 @@ test('it can initialize the escrow', async (t) => { token: tokenMint.publicKey, feeLocation: feeLocation.publicKey, name: 'Test Escrow', - uri: 'www.test.com', + uri: 'www.test.com/', max: 2n, min: 1n, amount: 3n, @@ -106,7 +106,7 @@ test('it cannot use an invalid collection', async (t) => { token: tokenMint.publicKey, feeLocation: feeLocation.publicKey, name: 'Test Escrow', - uri: 'www.test.com', + uri: 'www.test.com/', max: 2, min: 1, amount: 3, @@ -184,7 +184,7 @@ test('it cannot set min higher than max', async (t) => { token: tokenMint.publicKey, feeLocation: feeLocation.publicKey, name: 'Test Escrow', - uri: 'www.test.com', + uri: 'www.test.com/', max: 1, min: 2, amount: 3, diff --git a/clients/js/test/v1/initNftData.test.ts b/clients/js/test/v1/initNftData.test.ts index ba63881..347e2e3 100644 --- a/clients/js/test/v1/initNftData.test.ts +++ b/clients/js/test/v1/initNftData.test.ts @@ -42,7 +42,7 @@ test('it can initialize the nft data', async (t) => { token: tokenMint.publicKey, feeLocation: feeLocation.publicKey, name: 'Test Escrow', - uri: 'www.test.com', + uri: 'www.test.com/', max: 2, min: 1, amount: 3, @@ -57,7 +57,7 @@ test('it can initialize the nft data', async (t) => { token: tokenMint.publicKey, feeLocation: feeLocation.publicKey, name: 'Test Escrow', - uri: 'www.test.com', + uri: 'www.test.com/', max: 2n, min: 1n, amount: 3n, @@ -98,7 +98,7 @@ test('it cannot use an invalid asset', async (t) => { token: tokenMint.publicKey, feeLocation: feeLocation.publicKey, name: 'Test Escrow', - uri: 'www.test.com', + uri: 'www.test.com/', max: 2, min: 1, amount: 3, @@ -129,7 +129,7 @@ test('it cannot use an invalid token mint', async (t) => { token: tokenMint.publicKey, feeLocation: feeLocation.publicKey, name: 'Test Escrow', - uri: 'www.test.com', + uri: 'www.test.com/', max: 2, min: 1, amount: 3, @@ -173,7 +173,7 @@ test('it cannot set min higher than max', async (t) => { token: tokenMint.publicKey, feeLocation: feeLocation.publicKey, name: 'Test Escrow', - uri: 'www.test.com', + uri: 'www.test.com/', max: 1, min: 2, amount: 3, diff --git a/clients/js/test/v1/release.test.ts b/clients/js/test/v1/release.test.ts index 8aa5495..cf7c77a 100644 --- a/clients/js/test/v1/release.test.ts +++ b/clients/js/test/v1/release.test.ts @@ -21,7 +21,7 @@ import { } from '../../src'; import { createCoreCollection, createUmi } from '../_setup'; -test('it can swap an asset for tokens', async (t) => { +test('it can swap an asset for tokens with reroll', async (t) => { // Given a Umi instance using the project's plugin. const umi = await createUmi(); const feeLocation = generateSigner(umi); @@ -56,7 +56,7 @@ test('it can swap an asset for tokens', async (t) => { token: tokenMint.publicKey, feeLocation: feeLocation.publicKey, name: 'Test Escrow', - uri: 'www.test.com', + uri: 'www.test.com/', max: 9, min: 0, amount: 5, @@ -73,7 +73,7 @@ test('it can swap an asset for tokens', async (t) => { token: tokenMint.publicKey, feeLocation: feeLocation.publicKey, name: 'Test Escrow', - uri: 'www.test.com', + uri: 'www.test.com/', max: 9n, min: 0n, amount: 5n, @@ -126,9 +126,12 @@ test('it can swap an asset for tokens', async (t) => { t.deepEqual(userTokenAfter.token.amount, 5n); const assetAfter = await fetchAsset(umi, assets[0].publicKey); t.is(assetAfter.owner, publicKey(escrow)); + + // Confirm that an asset in the escrow has the correct URI + t.is(assetAfter.uri, `${escrowData.uri}captured.json`); }); -test('it can swap an asset for tokens as UpdateDelegate', async (t) => { +test('it can swap an asset for tokens as UpdateDelegate with reroll', async (t) => { // Given a Umi instance using the project's plugin. const umi = await createUmi(); const feeLocation = generateSigner(umi); @@ -163,13 +166,12 @@ test('it can swap an asset for tokens as UpdateDelegate', async (t) => { token: tokenMint.publicKey, feeLocation: feeLocation.publicKey, name: 'Test Escrow', - uri: 'www.test.com', + uri: 'www.test.com/', max: 9, min: 0, amount: 5, feeAmount: 1, - // eslint-disable-next-line no-bitwise - path: 1 << Path.RerollMetadata, + path: Path.RerollMetadata, solFeeAmount: 1000000n, }).sendAndConfirm(umi); @@ -190,14 +192,13 @@ test('it can swap an asset for tokens as UpdateDelegate', async (t) => { token: tokenMint.publicKey, feeLocation: feeLocation.publicKey, name: 'Test Escrow', - uri: 'www.test.com', + uri: 'www.test.com/', max: 9n, min: 0n, amount: 5n, feeAmount: 1n, count: 1n, - // eslint-disable-next-line no-bitwise - path: 1 << Path.RerollMetadata, + path: Path.RerollMetadata, bump: escrow[1], solFeeAmount: 1_000_000n, }); @@ -245,4 +246,7 @@ test('it can swap an asset for tokens as UpdateDelegate', async (t) => { t.deepEqual(userTokenAfter.token.amount, 5n); const assetAfter = await fetchAsset(umi, assets[0].publicKey); t.is(assetAfter.owner, publicKey(escrow)); + + // Confirm that an asset in the escrow has the correct URI + t.is(assetAfter.uri, `${escrowData.uri}captured.json`); }); diff --git a/clients/js/test/v2/captureV2.test.ts b/clients/js/test/v2/captureV2.test.ts index ef23c17..a89b67d 100644 --- a/clients/js/test/v2/captureV2.test.ts +++ b/clients/js/test/v2/captureV2.test.ts @@ -27,7 +27,7 @@ import { } from '../../src'; import { createCoreCollection, createUmi } from '../_setup'; -test('it can swap tokens for an asset', async (t) => { +test('it can swap tokens for an asset with reroll', async (t) => { // Given a Umi instance using the project's plugin. const umi = await createUmi(); const feeLocation = generateSigner(umi); @@ -84,7 +84,7 @@ test('it can swap tokens for an asset', async (t) => { token: tokenMint.publicKey, feeLocation: feeLocation.publicKey, name: 'Test Escrow', - uri: 'www.test.com', + uri: 'www.test.com/', max: 9, min: 0, amount: 5, @@ -95,14 +95,15 @@ test('it can swap tokens for an asset', async (t) => { path: Path.RerollMetadata, }).sendAndConfirm(umi); - t.like(await fetchRecipeV1(umi, recipe), { + const recipeData = await fetchRecipeV1(umi, recipe); + t.like(recipeData, { publicKey: publicKey(recipe), collection: collection.publicKey, authority: umi.identity.publicKey, token: tokenMint.publicKey, feeLocation: feeLocation.publicKey, name: 'Test Escrow', - uri: 'www.test.com', + uri: 'www.test.com/', max: 9n, min: 0n, amount: 5n, @@ -166,9 +167,13 @@ test('it can swap tokens for an asset', async (t) => { t.deepEqual(feeTokenAfter.token.amount, 1n); const assetAfter = await fetchAsset(umi, assets[0].publicKey); t.is(assetAfter.owner, umi.identity.publicKey); + + // Use a Regex to check the URI + const uriRegex = new RegExp(`${recipeData.uri}\\d+\\.json`); + t.regex(assetAfter.uri, uriRegex); }); -test('it can swap tokens for an asset as UpdateDelegate', async (t) => { +test('it can swap tokens for an asset as UpdateDelegate with reroll', async (t) => { // Given a Umi instance using the project's plugin. const umi = await createUmi(); const feeLocation = generateSigner(umi); @@ -225,7 +230,7 @@ test('it can swap tokens for an asset as UpdateDelegate', async (t) => { token: tokenMint.publicKey, feeLocation: feeLocation.publicKey, name: 'Test Escrow', - uri: 'www.test.com', + uri: 'www.test.com/', max: 9, min: 0, amount: 5, @@ -245,14 +250,15 @@ test('it can swap tokens for an asset as UpdateDelegate', async (t) => { }, }).sendAndConfirm(umi); - t.like(await fetchRecipeV1(umi, recipe), { + const recipeData = await fetchRecipeV1(umi, recipe); + t.like(recipeData, { publicKey: publicKey(recipe), collection: collection.publicKey, authority: umi.identity.publicKey, token: tokenMint.publicKey, feeLocation: feeLocation.publicKey, name: 'Test Escrow', - uri: 'www.test.com', + uri: 'www.test.com/', max: 9n, min: 0n, amount: 5n, @@ -275,4 +281,29 @@ test('it can swap tokens for an asset as UpdateDelegate', async (t) => { feeProjectAccount: feeLocation.publicKey, token: tokenMint.publicKey, }).sendAndConfirm(umi); + + const escrowTokenAfter = await fetchDigitalAssetWithAssociatedToken( + umi, + tokenMint.publicKey, + publicKey(escrow) + ); + t.deepEqual(escrowTokenAfter.token.amount, 5n); + const userTokenAfter = await fetchDigitalAssetWithAssociatedToken( + umi, + tokenMint.publicKey, + umi.identity.publicKey + ); + t.deepEqual(userTokenAfter.token.amount, 994n); + const feeTokenAfter = await fetchDigitalAssetWithAssociatedToken( + umi, + tokenMint.publicKey, + feeLocation.publicKey + ); + t.deepEqual(feeTokenAfter.token.amount, 1n); + const assetAfter = await fetchAsset(umi, assets[0].publicKey); + t.is(assetAfter.owner, umi.identity.publicKey); + + // Use a Regex to check the URI + const uriRegex = new RegExp(`${recipeData.uri}\\d+\\.json`); + t.regex(assetAfter.uri, uriRegex); }); diff --git a/clients/js/test/v2/initRecipe.test.ts b/clients/js/test/v2/initRecipe.test.ts index 3b5832b..429b49e 100644 --- a/clients/js/test/v2/initRecipe.test.ts +++ b/clients/js/test/v2/initRecipe.test.ts @@ -40,7 +40,7 @@ test('it can initialize the recipe', async (t) => { token: tokenMint.publicKey, feeLocation: feeLocation.publicKey, name: 'Test Escrow', - uri: 'www.test.com', + uri: 'www.test.com/', max: 2, min: 1, amount: 3, @@ -58,7 +58,7 @@ test('it can initialize the recipe', async (t) => { token: tokenMint.publicKey, feeLocation: feeLocation.publicKey, name: 'Test Escrow', - uri: 'www.test.com', + uri: 'www.test.com/', max: 2n, min: 1n, amount: 3n, @@ -94,7 +94,7 @@ test('it cannot use an invalid collection', async (t) => { token: tokenMint.publicKey, feeLocation: feeLocation.publicKey, name: 'Test Escrow', - uri: 'www.test.com', + uri: 'www.test.com/', max: 2, min: 1, amount: 3, @@ -120,7 +120,7 @@ test('it cannot use an invalid token mint', async (t) => { token: tokenMint.publicKey, feeLocation: feeLocation.publicKey, name: 'Test Escrow', - uri: 'www.test.com', + uri: 'www.test.com/', max: 2, min: 1, amount: 3, @@ -159,7 +159,7 @@ test('it cannot set min higher than max', async (t) => { token: tokenMint.publicKey, feeLocation: feeLocation.publicKey, name: 'Test Escrow', - uri: 'www.test.com', + uri: 'www.test.com/', max: 1, min: 2, amount: 3, diff --git a/clients/js/test/v2/releaseV2.test.ts b/clients/js/test/v2/releaseV2.test.ts index fe72d5e..0f23f5d 100644 --- a/clients/js/test/v2/releaseV2.test.ts +++ b/clients/js/test/v2/releaseV2.test.ts @@ -64,7 +64,7 @@ test('it can swap an asset for tokens', async (t) => { token: tokenMint.publicKey, feeLocation: feeLocation.publicKey, name: 'Test Escrow', - uri: 'www.test.com', + uri: 'www.test.com/', max: 9, min: 0, amount: 5, @@ -87,7 +87,7 @@ test('it can swap an asset for tokens', async (t) => { token: tokenMint.publicKey, feeLocation: feeLocation.publicKey, name: 'Test Escrow', - uri: 'www.test.com', + uri: 'www.test.com/', max: 9n, min: 0n, amount: 5n, @@ -186,7 +186,7 @@ test('it can swap an asset for tokens as UpdateDelegate', async (t) => { token: tokenMint.publicKey, feeLocation: feeLocation.publicKey, name: 'Test Escrow', - uri: 'www.test.com', + uri: 'www.test.com/', max: 9, min: 0, amount: 5, @@ -218,7 +218,7 @@ test('it can swap an asset for tokens as UpdateDelegate', async (t) => { token: tokenMint.publicKey, feeLocation: feeLocation.publicKey, name: 'Test Escrow', - uri: 'www.test.com', + uri: 'www.test.com/', max: 9n, min: 0n, amount: 5n,