Skip to content

Commit

Permalink
Merge branch 'main' of github.com:blockiosaurus/blob-asset into main
Browse files Browse the repository at this point in the history
  • Loading branch information
blockiosaurus committed Mar 11, 2024
2 parents e8e9228 + 25cf4f3 commit 1182ae1
Show file tree
Hide file tree
Showing 14 changed files with 168 additions and 124 deletions.
2 changes: 1 addition & 1 deletion clients/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-prettier": "^4.2.1",
"prettier": "^2.5.1",
"prettier": "^2.8.8",
"rimraf": "^3.0.2",
"typedoc": "^0.23.16",
"typedoc-plugin-expand-object-like-types": "^0.1.1",
Expand Down
26 changes: 13 additions & 13 deletions clients/js/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions clients/js/src/hooked/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import {
} from '../generated';

export type BaseAuthority = {
type: PluginAuthorityType
address?: PublicKey
type: PluginAuthorityType;
address?: PublicKey;
};

export type PluginAuthorityType = Pick<Authority, '__kind'>['__kind'];
Expand Down
21 changes: 12 additions & 9 deletions clients/js/test/_setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ export const createAssetWithCollection: (
const collection = assetInput.collection
? await fetchCollectionWithPlugins(umi, publicKey(assetInput.collection))
: await createCollection(umi, {
payer: assetInput.payer,
updateAuthority: assetInput.updateAuthority,
...collectionInput,
});
payer: assetInput.payer,
updateAuthority: assetInput.updateAuthority,
...collectionInput,
});

const asset = await createAsset(umi, {
...assetInput,
Expand All @@ -136,7 +136,7 @@ export const assertAsset = async (
uri?: string | RegExp;
} & PluginsList
) => {
const { asset, owner, name, uri, ...rest } = input
const { asset, owner, name, uri, ...rest } = input;
const assetAddress = publicKey(input.asset);
const assetWithPlugins = await fetchAssetWithPlugins(umi, assetAddress);

Expand All @@ -152,7 +152,7 @@ export const assertAsset = async (
key: Key.Asset,
publicKey: assetAddress,
owner: publicKey(owner),
...rest
...rest,
};

t.like(assetWithPlugins, testObj);
Expand All @@ -170,10 +170,13 @@ export const assertCollection = async (
currentSize?: number;
} & PluginsList
) => {
const { collection, name, uri, updateAuthority, ...rest } = input
const { collection, name, uri, updateAuthority, ...rest } = input;

const collectionAddress = publicKey(collection);
const collectionWithPlugins = await fetchCollectionWithPlugins(umi, collectionAddress);
const collectionWithPlugins = await fetchCollectionWithPlugins(
umi,
collectionAddress
);

// Name.
if (typeof name === 'string') t.is(collectionWithPlugins.name, name);
Expand All @@ -186,7 +189,7 @@ export const assertCollection = async (
const testObj = <CollectionWithPlugins>{
key: Key.Collection,
publicKey: collectionAddress,
...rest
...rest,
};

if (updateAuthority) {
Expand Down
4 changes: 2 additions & 2 deletions clients/js/test/approveAuthority.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ test('it can add an authority to a plugin', async (t) => {
const umi = await createUmi();
const delegateAddress = generateSigner(umi);

const asset = await createAsset(umi, {})
const asset = await createAsset(umi, {});

await assertAsset(t, umi, {
asset: asset.publicKey,
owner: umi.identity.publicKey,
updateAuthority: updateAuthority('Address', [umi.identity.publicKey]),
})
});

await addPlugin(umi, {
asset: asset.publicKey,
Expand Down
17 changes: 7 additions & 10 deletions clients/js/test/burn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ import {
} from '@metaplex-foundation/umi';
import test from 'ava';

import {
burn,
Key,
updateAuthority,
plugin,
} from '../src';
import { burn, Key, updateAuthority, plugin } from '../src';
import { DEFAULT_ASSET, assertAsset, createAsset, createUmi } from './_setup';

test('it can burn an asset as the owner', async (t) => {
Expand All @@ -22,7 +17,7 @@ test('it can burn an asset as the owner', async (t) => {
asset: asset.publicKey,
owner: umi.identity.publicKey,
updateAuthority: updateAuthority('Address', [umi.identity.publicKey]),
})
});

await burn(umi, {
asset: asset.publicKey,
Expand All @@ -48,7 +43,7 @@ test('it cannot burn an asset if not the owner', async (t) => {
asset: asset.publicKey,
owner: umi.identity.publicKey,
updateAuthority: updateAuthority('Address', [umi.identity.publicKey]),
})
});

const result = burn(umi, {
asset: asset.publicKey,
Expand All @@ -61,15 +56,17 @@ test('it cannot burn an asset if not the owner', async (t) => {
asset: asset.publicKey,
owner: umi.identity.publicKey,
updateAuthority: updateAuthority('Address', [umi.identity.publicKey]),
})
});
});

test('it cannot burn an asset if it is frozen', async (t) => {
// Given a Umi instance and a new signer.
const umi = await createUmi();

const asset = await createAsset(umi, {
plugins: [{ plugin: plugin('Freeze', [{ frozen: true }]), authority: null }],
plugins: [
{ plugin: plugin('Freeze', [{ frozen: true }]), authority: null },
],
});

await assertAsset(t, umi, {
Expand Down
51 changes: 30 additions & 21 deletions clients/js/test/collect.test.ts
Original file line number Diff line number Diff line change
@@ -1,58 +1,67 @@
import { PublicKey, Umi, sol } from '@metaplex-foundation/umi';
import test from 'ava';

import {
PluginType,
addPlugin,
plugin,
removePlugin,
} from '../src';
import { PluginType, addPlugin, plugin, removePlugin } from '../src';
import { createAsset, createUmi } from './_setup';

const hasCollectAmount = async (umi: Umi, address: PublicKey) => {
const account = await umi.rpc.getAccount(address);
if (account.exists) {
const rent = await umi.rpc.getRent(account.data.length)
const diff = account.lamports.basisPoints - rent.basisPoints
return diff === sol(0.0015).basisPoints
const rent = await umi.rpc.getRent(account.data.length);
const diff = account.lamports.basisPoints - rent.basisPoints;
return diff === sol(0.0015).basisPoints;
}
return false
}
return false;
};

test('it can create a new asset with collect amount', async (t) => {
// Given a Umi instance and a new signer.
const umi = await createUmi();
const asset = await createAsset(umi, {})
const asset = await createAsset(umi, {});

t.assert(await hasCollectAmount(umi, asset.publicKey), 'Collect amount not found')
t.assert(
await hasCollectAmount(umi, asset.publicKey),
'Collect amount not found'
);
});

test('it can add asset plugin with collect amount', async (t) => {
// Given a Umi instance and a new signer.
const umi = await createUmi();
const asset = await createAsset(umi, {})
const asset = await createAsset(umi, {});

await addPlugin(umi, {
asset: asset.publicKey,
plugin: plugin('Freeze', [{ frozen: true }]),
initAuthority: null
initAuthority: null,
}).sendAndConfirm(umi);

t.assert(await hasCollectAmount(umi, asset.publicKey), 'Collect amount not found')
t.assert(
await hasCollectAmount(umi, asset.publicKey),
'Collect amount not found'
);
});

test('it can add remove asset plugin with collect amount', async (t) => {
// Given a Umi instance and a new signer.
const umi = await createUmi();
const asset = await createAsset(umi, {
plugins: [{ plugin: plugin('Freeze', [{ frozen: true }]), authority: null }]
})
plugins: [
{ plugin: plugin('Freeze', [{ frozen: true }]), authority: null },
],
});

t.assert(await hasCollectAmount(umi, asset.publicKey), 'Collect amount not found')
t.assert(
await hasCollectAmount(umi, asset.publicKey),
'Collect amount not found'
);

await removePlugin(umi, {
asset: asset.publicKey,
pluginType: PluginType.Freeze,
}).sendAndConfirm(umi);
t.assert(await hasCollectAmount(umi, asset.publicKey), 'Collect amount not found')
});
t.assert(
await hasCollectAmount(umi, asset.publicKey),
'Collect amount not found'
);
});
4 changes: 2 additions & 2 deletions clients/js/test/compress.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { createAsset, createUmi } from './_setup';
test.skip('it can compress an asset without any plugins as the owner', async (t) => {
// Given a Umi instance and a new signer.
const umi = await createUmi();
const asset = await createAsset(umi, {});
const asset = await createAsset(umi, {});

// And when we compress the asset.
await compress(umi, {
Expand Down Expand Up @@ -114,7 +114,7 @@ test('it cannot compress an asset because it is not available', async (t) => {
});

// And when we compress the asset.
const result = compress(umi, {
const result = compress(umi, {
asset: assetAddress.publicKey,
authority: umi.identity,
logWrapper: publicKey('noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV'),
Expand Down
Loading

0 comments on commit 1182ae1

Please sign in to comment.