Skip to content

Commit

Permalink
Moving some tests and adding a collection plugin test.
Browse files Browse the repository at this point in the history
  • Loading branch information
blockiosaurus committed Mar 1, 2024
1 parent f501efc commit 60c94ed
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 10 deletions.
70 changes: 70 additions & 0 deletions clients/js/test/addPlugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@ import test from 'ava';
import {
Asset,
AssetWithPlugins,
CollectionData,
CollectionWithPlugins,
DataState,
PluginType,
addPlugin,
create,
createCollection,
fetchAsset,
fetchAssetWithPlugins,
fetchCollectionData,
fetchCollectionWithPlugins,
updateAuthority,
} from '../src';
import { createUmi } from './_setup';
Expand Down Expand Up @@ -79,3 +85,67 @@ test('it can add a plugin to an asset', async (t) => {
],
});
});

test('it can add a plugin to a collection', async (t) => {
// Given a Umi instance and a new signer.
const umi = await createUmi();
const collectionAddress = generateSigner(umi);

// When we create a new account.
await createCollection(umi, {
collectionAddress,
name: 'Test Bread',
uri: 'https://example.com/bread',
plugins: [],
}).sendAndConfirm(umi);

// Then an account was created with the correct data.
const collection = await fetchCollectionData(umi, collectionAddress.publicKey);
// console.log("Account State:", collection);
t.like(collection, <CollectionData>{
publicKey: collectionAddress.publicKey,
updateAuthority: umi.identity.publicKey,
name: 'Test Bread',
uri: 'https://example.com/bread',
});

await addPlugin(umi, {
assetAddress: collectionAddress.publicKey,
plugin: {
__kind: 'Freeze',
fields: [{ frozen: false }],
},
}).sendAndConfirm(umi);

const asset1 = await fetchCollectionWithPlugins(umi, collectionAddress.publicKey);
// console.log(JSON.stringify(asset1, (_, v) => typeof v === 'bigint' ? v.toString() : v, 2));
t.like(asset1, <CollectionWithPlugins>{
publicKey: collectionAddress.publicKey,
updateAuthority: umi.identity.publicKey,
name: 'Test Bread',
uri: 'https://example.com/bread',
pluginHeader: {
key: 3,
pluginRegistryOffset: BigInt(95),
},
pluginRegistry: {
key: 4,
registry: [
{
pluginType: PluginType.Freeze,
offset: BigInt(93),
authorities: [{ __kind: 'Owner' }],
},
],
},
plugins: [
{
authorities: [{ __kind: 'Owner' }],
plugin: {
__kind: 'Freeze',
fields: [{ frozen: false }],
},
},
],
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import {
burn,
Key,
updateAuthority,
} from '../../src';
import { createUmi } from '../_setup';
} from '../../../src';
import { createUmi } from '../../_setup';

test('it can burn an asset as the owner', async (t) => {
// Given a Umi instance and a new signer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {
fetchAssetWithPlugins,
updateAuthority,
updatePlugin,
} from '../../src';
import { createUmi } from '../_setup';
} from '../../../src';
import { createUmi } from '../../_setup';

test('it can delegate a new authority', async (t) => {
// Given a Umi instance and a new signer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {
fetchAssetWithPlugins,
transfer,
updateAuthority,
} from '../../src';
import { createUmi } from '../_setup';
} from '../../../src';
import { createUmi } from '../../_setup';

test('a delegate can transfer the asset', async (t) => {
// Given a Umi instance and a new signer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import {
ruleSet,
transfer,
updateAuthority,
} from '../../src';
import { createUmi } from '../_setup';
} from '../../../src';
import { createUmi } from '../../_setup';

test('it can transfer an asset with royalties', async (t) => {
// Given a Umi instance and a new signer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
fetchAssetWithPlugins,
fetchCollectionWithPlugins,
updateAuthority,
} from '../../src';
import { createUmi } from '../_setup';
} from '../../../src';
import { createUmi } from '../../_setup';

test('it can create a new asset with a collection if it is the collection update delegate', async (t) => {
// Given a Umi instance and a new signer.
Expand Down

0 comments on commit 60c94ed

Please sign in to comment.