Skip to content

Commit

Permalink
Being a little more thorough with tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
blockiosaurus committed Nov 19, 2024
1 parent 1ba75a6 commit 64d7af2
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 46 deletions.
47 changes: 37 additions & 10 deletions clients/js/test/v1/capture.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand All @@ -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,
});
Expand All @@ -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);
});
8 changes: 4 additions & 4 deletions clients/js/test/v1/initEscrow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions clients/js/test/v1/initNftData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
24 changes: 14 additions & 10 deletions clients/js/test/v1/release.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand All @@ -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,
});
Expand Down Expand Up @@ -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`);
});
47 changes: 39 additions & 8 deletions clients/js/test/v2/captureV2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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);
});
Loading

0 comments on commit 64d7af2

Please sign in to comment.