Skip to content

Commit

Permalink
Format JS tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danenbm committed Feb 29, 2024
1 parent 1d1b166 commit e5cfd1c
Show file tree
Hide file tree
Showing 16 changed files with 94 additions and 62 deletions.
3 changes: 2 additions & 1 deletion clients/js/src/hooked/fetchCollectionWithPlugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export async function fetchCollectionWithPlugins(
);
assertAccountExists(maybeAccount, 'Collection');
const collection = deserializeCollectionData(maybeAccount);
const collectionData = getCollectionDataAccountDataSerializer().serialize(collection);
const collectionData =
getCollectionDataAccountDataSerializer().serialize(collection);

let pluginHeader: PluginHeaderAccountData | undefined;
let pluginRegistry: PluginRegistryAccountData | undefined;
Expand Down
12 changes: 6 additions & 6 deletions clients/js/src/hooked/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ export * from './fetchAssetWithPlugins';
export * from './fetchCollectionWithPlugins';

export type PluginWithAuthorities = {
plugin: Plugin;
authorities: Authority[];
plugin: Plugin;
authorities: Authority[];
};

export type PluginList = {
pluginHeader?: Omit<PluginHeader, 'publicKey' | 'header'>;
plugins?: PluginWithAuthorities[];
pluginRegistry?: Omit<PluginRegistry, 'publicKey' | 'header'>;
};
pluginHeader?: Omit<PluginHeader, 'publicKey' | 'header'>;
plugins?: PluginWithAuthorities[];
pluginRegistry?: Omit<PluginRegistry, 'publicKey' | 'header'>;
};
4 changes: 2 additions & 2 deletions clients/js/test/addAuthority.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ test('it can add an authority to a plugin', async (t) => {
// console.log("Account State:", asset);
t.like(asset, <Asset>{
publicKey: assetAddress.publicKey,
updateAuthority: updateAuthority("Address", [umi.identity.publicKey]),
updateAuthority: updateAuthority('Address', [umi.identity.publicKey]),
owner: umi.identity.publicKey,
name: 'Test Bread',
uri: 'https://example.com/bread',
Expand Down Expand Up @@ -64,7 +64,7 @@ test('it can add an authority to a plugin', async (t) => {
// console.log(JSON.stringify(asset1, (_, v) => typeof v === 'bigint' ? v.toString() : v, 2));
t.like(asset1, <AssetWithPlugins>{
publicKey: assetAddress.publicKey,
updateAuthority: updateAuthority("Address", [umi.identity.publicKey]),
updateAuthority: updateAuthority('Address', [umi.identity.publicKey]),
owner: umi.identity.publicKey,
name: 'Test Bread',
uri: 'https://example.com/bread',
Expand Down
4 changes: 2 additions & 2 deletions clients/js/test/addPlugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ test('it can add a plugin to an asset', async (t) => {
// console.log("Account State:", asset);
t.like(asset, <Asset>{
publicKey: assetAddress.publicKey,
updateAuthority: updateAuthority("Address", [umi.identity.publicKey]),
updateAuthority: updateAuthority('Address', [umi.identity.publicKey]),
owner: umi.identity.publicKey,
name: 'Test Bread',
uri: 'https://example.com/bread',
Expand All @@ -50,7 +50,7 @@ test('it can add a plugin to an asset', async (t) => {
// console.log(JSON.stringify(asset1, (_, v) => typeof v === 'bigint' ? v.toString() : v, 2));
t.like(asset1, <AssetWithPlugins>{
publicKey: assetAddress.publicKey,
updateAuthority: updateAuthority("Address", [umi.identity.publicKey]),
updateAuthority: updateAuthority('Address', [umi.identity.publicKey]),
owner: umi.identity.publicKey,
name: 'Test Bread',
uri: 'https://example.com/bread',
Expand Down
6 changes: 3 additions & 3 deletions clients/js/test/compress.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ test('it can compress an asset without any plugins as the owner', async (t) => {
// console.log("Account State:", beforeAsset);
t.like(beforeAsset, <Asset>{
publicKey: assetAddress.publicKey,
updateAuthority: updateAuthority("Address", [umi.identity.publicKey]),
updateAuthority: updateAuthority('Address', [umi.identity.publicKey]),
owner: umi.identity.publicKey,
name: 'Test Bread',
uri: 'https://example.com/bread',
Expand Down Expand Up @@ -84,7 +84,7 @@ test('it cannot compress an asset if not the owner', async (t) => {
// console.log("Account State:", beforeAsset);
t.like(beforeAsset, <Asset>{
publicKey: assetAddress.publicKey,
updateAuthority: updateAuthority("Address", [umi.identity.publicKey]),
updateAuthority: updateAuthority('Address', [umi.identity.publicKey]),
owner: umi.identity.publicKey,
name: 'Test Bread',
uri: 'https://example.com/bread',
Expand All @@ -101,7 +101,7 @@ test('it cannot compress an asset if not the owner', async (t) => {
// console.log("Account State:", afterAsset);
t.like(afterAsset, <Asset>{
publicKey: assetAddress.publicKey,
updateAuthority: updateAuthority("Address", [umi.identity.publicKey]),
updateAuthority: updateAuthority('Address', [umi.identity.publicKey]),
owner: umi.identity.publicKey,
name: 'Test Bread',
uri: 'https://example.com/bread',
Expand Down
6 changes: 3 additions & 3 deletions clients/js/test/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test('it can create a new asset in account state', async (t) => {
// console.log("Account State:", asset);
t.like(asset, <Asset>{
publicKey: assetAddress.publicKey,
updateAuthority: updateAuthority("Address", [umi.identity.publicKey]),
updateAuthority: updateAuthority('Address', [umi.identity.publicKey]),
owner: umi.identity.publicKey,
name: 'Test Bread',
uri: 'https://example.com/bread',
Expand Down Expand Up @@ -70,7 +70,7 @@ test('it can create a new asset in ledger state', async (t) => {
const parsed = getAssetAccountDataSerializer().deserialize(data)[0];
// console.log("Ledger State:", parsed);
t.like(parsed, <Asset>{
updateAuthority: updateAuthority("Address", [umi.identity.publicKey]),
updateAuthority: updateAuthority('Address', [umi.identity.publicKey]),
owner: umi.identity.publicKey,
name: 'Test Bread',
uri: 'https://example.com/bread',
Expand All @@ -97,7 +97,7 @@ test('it can create a new asset with plugins', async (t) => {
// console.log("Account State:", asset);
t.like(asset, <AssetWithPlugins>{
publicKey: assetAddress.publicKey,
updateAuthority: updateAuthority("Address", [umi.identity.publicKey]),
updateAuthority: updateAuthority('Address', [umi.identity.publicKey]),
owner: umi.identity.publicKey,
name: 'Test Bread',
uri: 'https://example.com/bread',
Expand Down
31 changes: 21 additions & 10 deletions clients/js/test/createCollection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ test('it can create a new collection', async (t) => {
collectionAddress,
name: 'Test Bread Collection',
uri: 'https://example.com/bread',
plugins: []
plugins: [],
}).sendAndConfirm(umi);

// Then an account was created with the correct data.
const collection = await fetchCollectionData(umi, collectionAddress.publicKey);
const collection = await fetchCollectionData(
umi,
collectionAddress.publicKey
);
// console.log("Account State:", collection);
t.like(collection, <CollectionData>{
publicKey: collectionAddress.publicKey,
Expand All @@ -48,11 +51,14 @@ test('it can create a new collection with plugins', async (t) => {
collectionAddress,
name: 'Test Bread Collection',
uri: 'https://example.com/bread',
plugins: [{ __kind: 'Freeze', fields: [{ frozen: false }] }]
plugins: [{ __kind: 'Freeze', fields: [{ frozen: false }] }],
}).sendAndConfirm(umi);

// Then an account was created with the correct data.
const collection = await fetchCollectionWithPlugins(umi, collectionAddress.publicKey);
const collection = await fetchCollectionWithPlugins(
umi,
collectionAddress.publicKey
);
// console.log("Account State:", collection);
t.like(collection, <CollectionWithPlugins>{
publicKey: collectionAddress.publicKey,
Expand Down Expand Up @@ -96,7 +102,7 @@ test('it can create a new asset with a collection', async (t) => {
collectionAddress,
name: 'Test Bread Collection',
uri: 'https://example.com/bread',
plugins: [{ __kind: 'Freeze', fields: [{ frozen: false }] }]
plugins: [{ __kind: 'Freeze', fields: [{ frozen: false }] }],
}).sendAndConfirm(umi);

// When we create a new account.
Expand All @@ -114,7 +120,9 @@ test('it can create a new asset with a collection', async (t) => {
// console.log("Account State:", asset);
t.like(asset, <AssetWithPlugins>{
publicKey: assetAddress.publicKey,
updateAuthority: updateAuthority("Collection", [collectionAddress.publicKey]),
updateAuthority: updateAuthority('Collection', [
collectionAddress.publicKey,
]),
owner: umi.identity.publicKey,
name: 'Test Bread',
uri: 'https://example.com/bread',
Expand Down Expand Up @@ -144,10 +152,13 @@ test('it cannot create a new asset with a collection if it is not the collection
updateAuthority: collectionAuth.publicKey,
name: 'Test Bread Collection',
uri: 'https://example.com/bread',
plugins: [{ __kind: 'Freeze', fields: [{ frozen: false }] }]
plugins: [{ __kind: 'Freeze', fields: [{ frozen: false }] }],
}).sendAndConfirm(umi);

const collection = await fetchCollectionWithPlugins(umi, collectionAddress.publicKey);
const collection = await fetchCollectionWithPlugins(
umi,
collectionAddress.publicKey
);
// console.log("Account State:", collection);
t.like(collection, <CollectionWithPlugins>{
publicKey: collectionAddress.publicKey,
Expand Down Expand Up @@ -189,5 +200,5 @@ test('it cannot create a new asset with a collection if it is not the collection
plugins: [],
}).sendAndConfirm(umi);

await t.throwsAsync(result, { name: "InvalidAuthority" });
});
await t.throwsAsync(result, { name: 'InvalidAuthority' });
});
8 changes: 4 additions & 4 deletions clients/js/test/decompress.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ test('it can decompress a previously compressed asset as the owner', async (t) =
// console.log("Account State:", beforeAsset);
t.like(beforeAsset, <Asset>{
publicKey: assetAddress.publicKey,
updateAuthority: updateAuthority("Address", [umi.identity.publicKey]),
updateAuthority: updateAuthority('Address', [umi.identity.publicKey]),
owner: umi.identity.publicKey,
name: 'Test Bread',
uri: 'https://example.com/bread',
Expand Down Expand Up @@ -69,11 +69,11 @@ test('it can decompress a previously compressed asset as the owner', async (t) =
assetAddress: assetAddress.publicKey,
owner: umi.identity,
compressionProof: {
updateAuthority: updateAuthority("Address", [umi.identity.publicKey]),
updateAuthority: updateAuthority('Address', [umi.identity.publicKey]),
owner: umi.identity.publicKey,
name: 'Test Bread',
uri: 'https://example.com/bread',
plugins: []
plugins: [],
},
}).sendAndConfirm(umi);

Expand All @@ -82,7 +82,7 @@ test('it can decompress a previously compressed asset as the owner', async (t) =

t.like(afterDecompressedAsset, <Asset>{
publicKey: assetAddress.publicKey,
updateAuthority: updateAuthority("Address", [umi.identity.publicKey]),
updateAuthority: updateAuthority('Address', [umi.identity.publicKey]),
owner: umi.identity.publicKey,
name: 'Test Bread',
uri: 'https://example.com/bread',
Expand Down
16 changes: 12 additions & 4 deletions clients/js/test/plugins/burn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@ import {
} from '@metaplex-foundation/umi';
import test from 'ava';
// import { base58 } from '@metaplex-foundation/umi/serializers';
import { Asset, DataState, create, fetchAsset, burn, Key, updateAuthority } from '../../src';
import {
Asset,
DataState,
create,
fetchAsset,
burn,
Key,
updateAuthority,
} from '../../src';
import { createUmi } from '../_setup';

test('it can burn an asset as the owner', async (t) => {
Expand All @@ -27,7 +35,7 @@ test('it can burn an asset as the owner', async (t) => {
// console.log("Account State:", beforeAsset);
t.like(beforeAsset, <Asset>{
publicKey: assetAddress.publicKey,
updateAuthority: updateAuthority("Address", [umi.identity.publicKey]),
updateAuthority: updateAuthority('Address', [umi.identity.publicKey]),
owner: umi.identity.publicKey,
name: 'Test Bread',
uri: 'https://example.com/bread',
Expand Down Expand Up @@ -67,7 +75,7 @@ test('it cannot burn an asset if not the owner', async (t) => {
// console.log("Account State:", beforeAsset);
t.like(beforeAsset, <Asset>{
publicKey: assetAddress.publicKey,
updateAuthority: updateAuthority("Address", [umi.identity.publicKey]),
updateAuthority: updateAuthority('Address', [umi.identity.publicKey]),
owner: umi.identity.publicKey,
name: 'Test Bread',
uri: 'https://example.com/bread',
Expand All @@ -85,7 +93,7 @@ test('it cannot burn an asset if not the owner', async (t) => {
// console.log("Account State:", afterAsset);
t.like(afterAsset, <Asset>{
publicKey: assetAddress.publicKey,
updateAuthority: updateAuthority("Address", [umi.identity.publicKey]),
updateAuthority: updateAuthority('Address', [umi.identity.publicKey]),
owner: umi.identity.publicKey,
name: 'Test Bread',
uri: 'https://example.com/bread',
Expand Down
21 changes: 13 additions & 8 deletions clients/js/test/plugins/collectionUpdateDelegate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ test('it can create a new asset with a collection if it is the collection update
collectionAddress,
name: 'Test Bread Collection',
uri: 'https://example.com/bread',
plugins: []
plugins: [],
}).sendAndConfirm(umi);

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

// console.log(JSON.stringify(await fetchCollectionWithPlugins(umi, collectionAddress.publicKey), (_, v) => typeof v === 'bigint' ? v.toString() : v, 2));
Expand All @@ -46,10 +46,13 @@ test('it can create a new asset with a collection if it is the collection update
newAuthority: {
__kind: 'Pubkey',
address: updateDelegate.publicKey,
}
},
}).sendAndConfirm(umi);

const collection = await fetchCollectionWithPlugins(umi, collectionAddress.publicKey);
const collection = await fetchCollectionWithPlugins(
umi,
collectionAddress.publicKey
);
// console.log("Account State:", collection);
t.like(collection, <CollectionWithPlugins>{
publicKey: collectionAddress.publicKey,
Expand All @@ -68,7 +71,7 @@ test('it can create a new asset with a collection if it is the collection update
offset: BigInt(104),
authorities: [
{ __kind: 'UpdateAuthority' },
{ __kind: 'Pubkey', address: updateDelegate.publicKey }
{ __kind: 'Pubkey', address: updateDelegate.publicKey },
],
},
],
Expand All @@ -77,7 +80,7 @@ test('it can create a new asset with a collection if it is the collection update
{
authorities: [
{ __kind: 'UpdateAuthority' },
{ __kind: 'Pubkey', address: updateDelegate.publicKey }
{ __kind: 'Pubkey', address: updateDelegate.publicKey },
],
plugin: {
__kind: 'UpdateDelegate',
Expand All @@ -101,7 +104,9 @@ test('it can create a new asset with a collection if it is the collection update
// console.log("Asset State:", asset);
t.like(asset, <AssetWithPlugins>{
publicKey: assetAddress.publicKey,
updateAuthority: updateAuthority("Collection", [collectionAddress.publicKey]),
updateAuthority: updateAuthority('Collection', [
collectionAddress.publicKey,
]),
owner: umi.identity.publicKey,
name: 'Test Bread',
uri: 'https://example.com/bread',
Expand All @@ -116,4 +121,4 @@ test('it can create a new asset with a collection if it is the collection update

t.assert(asset.pluginRegistry?.registry.length === 0);
t.assert(asset.plugins?.length === 0);
});
});
2 changes: 1 addition & 1 deletion clients/js/test/plugins/delegate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ test('a delegate can freeze the token', async (t) => {
// console.log(asset);
t.like(asset, <AssetWithPlugins>{
publicKey: assetAddress.publicKey,
updateAuthority: updateAuthority("Address", [umi.identity.publicKey]),
updateAuthority: updateAuthority('Address', [umi.identity.publicKey]),
owner: umi.identity.publicKey,
name: 'Test Bread',
uri: 'https://example.com/bread',
Expand Down
2 changes: 1 addition & 1 deletion clients/js/test/plugins/delegateTransfer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ test('a delegate can transfer the asset', async (t) => {
// console.log(asset);
t.like(asset, <AssetWithPlugins>{
publicKey: assetAddress.publicKey,
updateAuthority: updateAuthority("Address", [umi.identity.publicKey]),
updateAuthority: updateAuthority('Address', [umi.identity.publicKey]),
owner: newOwnerAddress.publicKey,
name: 'Test Bread',
uri: 'https://example.com/bread',
Expand Down
Loading

0 comments on commit e5cfd1c

Please sign in to comment.