From 7741c09a2c5bdec15897fbb9a5643bb99c03e3a3 Mon Sep 17 00:00:00 2001 From: Nhan Phan Date: Sun, 10 Mar 2024 19:23:07 -0700 Subject: [PATCH] refactor plugin authoirty mapping, refactor revoke, remove plugin tests --- clients/js/src/hooked/authorityHelpers.ts | 16 +- clients/js/src/hooked/types.ts | 10 +- clients/js/test/addPlugin.test.ts | 7 +- clients/js/test/approveAuthority.test.ts | 3 +- clients/js/test/burn.test.ts | 4 +- clients/js/test/create.test.ts | 2 +- clients/js/test/createCollection.test.ts | 4 +- .../js/test/plugins/asset/delegate.test.ts | 6 +- .../plugins/asset/delegateTransfer.test.ts | 3 +- clients/js/test/plugins/asset/freeze.test.ts | 4 +- .../js/test/plugins/asset/royalties.test.ts | 4 +- .../collectionUpdateDelegate.test.ts | 3 +- clients/js/test/removePlugin.test.ts | 70 +---- clients/js/test/revokeAuthority.test.ts | 263 +++--------------- clients/js/test/update.test.ts | 4 +- 15 files changed, 89 insertions(+), 314 deletions(-) diff --git a/clients/js/src/hooked/authorityHelpers.ts b/clients/js/src/hooked/authorityHelpers.ts index 4b54f409..c0ac865b 100644 --- a/clients/js/src/hooked/authorityHelpers.ts +++ b/clients/js/src/hooked/authorityHelpers.ts @@ -1,7 +1,6 @@ import { PublicKey } from '@metaplex-foundation/umi'; import { Authority, authority as authorityHelper } from '../generated'; import { BaseAuthority } from './types'; -import { toWords } from './utils'; // Authorities data helpers export function getNoneAuthority() { @@ -25,15 +24,8 @@ export function getPermanentAuthority(address: PublicKey) { } export function mapAuthority(authority: Authority): BaseAuthority { - const authorityKey = toWords(authority.__kind) - .split(' ')[0] - .toLowerCase() as keyof BaseAuthority; - - if (Object.keys(authority).length > 1) { - return { - [authorityKey]: Object.values(authority).slice(1), - }; - } - - return { [authorityKey]: true }; + return { + type: authority.__kind, + address: (authority as any).address, + }; } diff --git a/clients/js/src/hooked/types.ts b/clients/js/src/hooked/types.ts index ac712b67..8c216847 100644 --- a/clients/js/src/hooked/types.ts +++ b/clients/js/src/hooked/types.ts @@ -1,6 +1,7 @@ import { PublicKey } from '@metaplex-foundation/umi'; import { Asset, + Authority, Burn, Collection, Freeze, @@ -11,13 +12,12 @@ import { } from '../generated'; export type BaseAuthority = { - none?: boolean; - owner?: boolean; - update?: boolean; - pubkey?: Array; - permanent?: Array; + type: PluginAuthorityType + address?: PublicKey }; +export type PluginAuthorityType = Pick['__kind']; + export type BasePlugin = { authority: BaseAuthority; offset?: bigint; diff --git a/clients/js/test/addPlugin.test.ts b/clients/js/test/addPlugin.test.ts index 4180b5f5..43720f7f 100644 --- a/clients/js/test/addPlugin.test.ts +++ b/clients/js/test/addPlugin.test.ts @@ -45,7 +45,7 @@ test('it can add a plugin to an asset', async (t) => { updateAuthority: updateAuthority('Address', [umi.identity.publicKey]), freeze: { authority: { - owner: true, + type: 'Owner', }, frozen: false, }, @@ -79,7 +79,8 @@ test('it can add a plugin to an asset with a different authority than the defaul updateAuthority: updateAuthority('Address', [umi.identity.publicKey]), freeze: { authority: { - pubkey: [delegateAddress.publicKey], + type: 'Pubkey', + address: delegateAddress.publicKey, }, frozen: false, }, @@ -115,7 +116,7 @@ test('it can add a plugin to a collection', async (t) => { updateAuthority: umi.identity.publicKey, royalties: { authority: { - update: true, + type: 'UpdateAuthority', }, percentage: 5, creators: [], diff --git a/clients/js/test/approveAuthority.test.ts b/clients/js/test/approveAuthority.test.ts index a13403b5..0e6117cd 100644 --- a/clients/js/test/approveAuthority.test.ts +++ b/clients/js/test/approveAuthority.test.ts @@ -43,7 +43,8 @@ test('it can add an authority to a plugin', async (t) => { updateAuthority: updateAuthority('Address', [umi.identity.publicKey]), freeze: { authority: { - pubkey: [delegateAddress.publicKey], + type: 'Pubkey', + address: delegateAddress.publicKey, }, frozen: false, }, diff --git a/clients/js/test/burn.test.ts b/clients/js/test/burn.test.ts index d1bb440b..a3df4a90 100644 --- a/clients/js/test/burn.test.ts +++ b/clients/js/test/burn.test.ts @@ -79,7 +79,7 @@ test('it cannot burn an asset if it is frozen', async (t) => { updateAuthority: updateAuthority('Address', [umi.identity.publicKey]), freeze: { authority: { - owner: true, + type: 'Owner', }, frozen: true, }, @@ -97,7 +97,7 @@ test('it cannot burn an asset if it is frozen', async (t) => { updateAuthority: updateAuthority('Address', [umi.identity.publicKey]), freeze: { authority: { - owner: true, + type: 'Owner', }, frozen: true, }, diff --git a/clients/js/test/create.test.ts b/clients/js/test/create.test.ts index 40be8021..60900cfd 100644 --- a/clients/js/test/create.test.ts +++ b/clients/js/test/create.test.ts @@ -136,7 +136,7 @@ test('it can create a new asset in account state with plugins', async (t) => { // pluginHeader: formPluginHeader(BigInt(120)), freeze: { authority: { - owner: true, + type: 'Owner', }, offset: BigInt(118), frozen: false, diff --git a/clients/js/test/createCollection.test.ts b/clients/js/test/createCollection.test.ts index fb39027f..3db1f55c 100644 --- a/clients/js/test/createCollection.test.ts +++ b/clients/js/test/createCollection.test.ts @@ -48,7 +48,7 @@ test('it can create a new collection with plugins', async (t) => { updateAuthority: umi.identity.publicKey, freeze: { authority: { - owner: true, + type: 'Owner', }, frozen: false, }, @@ -72,7 +72,7 @@ test('it can create a new asset with a collection', async (t) => { updateAuthority: umi.identity.publicKey, updateDelegate: { authority: { - update: true, + type: 'UpdateAuthority' }, }, }); diff --git a/clients/js/test/plugins/asset/delegate.test.ts b/clients/js/test/plugins/asset/delegate.test.ts index 30ca90ea..4131571b 100644 --- a/clients/js/test/plugins/asset/delegate.test.ts +++ b/clients/js/test/plugins/asset/delegate.test.ts @@ -37,7 +37,8 @@ test('it can delegate a new authority', async (t) => { updateAuthority: updateAuthority('Address', [umi.identity.publicKey]), freeze: { authority: { - pubkey: [delegateAddress.publicKey], + type: 'Pubkey', + address: delegateAddress.publicKey, }, frozen: false, }, @@ -73,7 +74,8 @@ test('a delegate can freeze the token', async (t) => { updateAuthority: updateAuthority('Address', [umi.identity.publicKey]), freeze: { authority: { - pubkey: [delegateAddress.publicKey], + type: 'Pubkey', + address: delegateAddress.publicKey, }, frozen: true, }, diff --git a/clients/js/test/plugins/asset/delegateTransfer.test.ts b/clients/js/test/plugins/asset/delegateTransfer.test.ts index 1b318b56..6bd166d9 100644 --- a/clients/js/test/plugins/asset/delegateTransfer.test.ts +++ b/clients/js/test/plugins/asset/delegateTransfer.test.ts @@ -44,7 +44,8 @@ test('a delegate can transfer the asset', async (t) => { updateAuthority: updateAuthority('Address', [umi.identity.publicKey]), transfer: { authority: { - pubkey: [delegateAddress.publicKey], + type: 'Pubkey', + address: delegateAddress.publicKey, }, }, }); diff --git a/clients/js/test/plugins/asset/freeze.test.ts b/clients/js/test/plugins/asset/freeze.test.ts index aa276ded..f7d98db9 100644 --- a/clients/js/test/plugins/asset/freeze.test.ts +++ b/clients/js/test/plugins/asset/freeze.test.ts @@ -25,7 +25,7 @@ test('it can freeze and unfreeze an asset', async (t) => { updateAuthority: updateAuthority('Address', [umi.identity.publicKey]), freeze: { authority: { - owner: true, + type: 'Owner', }, frozen: true, }, @@ -43,7 +43,7 @@ test('it can freeze and unfreeze an asset', async (t) => { updateAuthority: updateAuthority('Address', [umi.identity.publicKey]), freeze: { authority: { - owner: true, + type: 'Owner', }, frozen: false, }, diff --git a/clients/js/test/plugins/asset/royalties.test.ts b/clients/js/test/plugins/asset/royalties.test.ts index b48bbd33..0aa6aaef 100644 --- a/clients/js/test/plugins/asset/royalties.test.ts +++ b/clients/js/test/plugins/asset/royalties.test.ts @@ -45,7 +45,7 @@ test('it can transfer an asset with royalties', async (t) => { royalties: { authority: { - update: true, + type: 'UpdateAuthority' }, percentage: 5, creators: [{ address: umi.identity.publicKey, percentage: 100 }], @@ -91,7 +91,7 @@ test('it can transfer an asset with royalties to an allowlisted program address' updateAuthority: updateAuthority('Address', [umi.identity.publicKey]), royalties: { authority: { - update: true, + type: 'UpdateAuthority' }, percentage: 5, creators: [{ address: umi.identity.publicKey, percentage: 100 }], diff --git a/clients/js/test/plugins/collection/collectionUpdateDelegate.test.ts b/clients/js/test/plugins/collection/collectionUpdateDelegate.test.ts index 653f811e..02bbe8b9 100644 --- a/clients/js/test/plugins/collection/collectionUpdateDelegate.test.ts +++ b/clients/js/test/plugins/collection/collectionUpdateDelegate.test.ts @@ -40,7 +40,8 @@ test('it can create a new asset with a collection if it is the collection update updateAuthority: umi.identity.publicKey, updateDelegate: { authority: { - pubkey: [updateDelegate.publicKey], + type: 'Pubkey', + address: updateDelegate.publicKey, }, }, }); diff --git a/clients/js/test/removePlugin.test.ts b/clients/js/test/removePlugin.test.ts index 7399c883..4a77ef10 100644 --- a/clients/js/test/removePlugin.test.ts +++ b/clients/js/test/removePlugin.test.ts @@ -1,84 +1,38 @@ -import { generateSigner } from '@metaplex-foundation/umi'; import test from 'ava'; -// import { base58 } from '@metaplex-foundation/umi/serializers'; + import { - Asset, - AssetWithPlugins, - DataState, PluginType, - addPlugin, - create, - fetchAsset, fetchAssetWithPlugins, removePlugin, - updateAuthority, - formPluginHeader, plugin, } from '../src'; -import { createUmi } from './_setup'; +import { assertAsset, createAsset, createUmi } from './_setup'; test('it can remove a plugin from an asset', async (t) => { // Given a Umi instance and a new signer. const umi = await createUmi(); - const assetAddress = generateSigner(umi); - - // When we create a new account. - await create(umi, { - dataState: DataState.AccountState, - asset: assetAddress, - name: 'Test Bread', - uri: 'https://example.com/bread', - plugins: [], - }).sendAndConfirm(umi); - // Then an account was created with the correct data. - const asset = await fetchAsset(umi, assetAddress.publicKey); - // console.log("Account State:", asset); - t.like(asset, { - publicKey: assetAddress.publicKey, - updateAuthority: updateAuthority('Address', [umi.identity.publicKey]), - owner: umi.identity.publicKey, - name: 'Test Bread', - uri: 'https://example.com/bread', + const asset = await createAsset(umi, { + plugins: [plugin('Freeze', [{ frozen: false }])], }); - await addPlugin(umi, { - asset: assetAddress.publicKey, - plugin: plugin('Freeze', [{ frozen: false }]), - initAuthority: null, - }).sendAndConfirm(umi); - - const asset1 = await fetchAssetWithPlugins(umi, assetAddress.publicKey); - // console.log(JSON.stringify(asset1, (_, v) => typeof v === 'bigint' ? v.toString() : v, 2)); - t.like(asset1, { - publicKey: assetAddress.publicKey, - updateAuthority: updateAuthority('Address', [umi.identity.publicKey]), + await assertAsset(t, umi, { + asset: asset.publicKey, owner: umi.identity.publicKey, - name: 'Test Bread', - uri: 'https://example.com/bread', - pluginHeader: formPluginHeader(BigInt(120)), freeze: { authority: { - owner: true, + type: 'Owner', }, - offset: BigInt(118), frozen: false, }, - }); + }) await removePlugin(umi, { - asset: assetAddress.publicKey, + asset: asset.publicKey, pluginType: PluginType.Freeze, }).sendAndConfirm(umi); - const asset2 = await fetchAssetWithPlugins(umi, assetAddress.publicKey); - // console.log(JSON.stringify(asset2, (_, v) => typeof v === 'bigint' ? v.toString() : v, 2)); - t.like(asset2, ({ - publicKey: assetAddress.publicKey, - updateAuthority: updateAuthority('Address', [umi.identity.publicKey]), - owner: umi.identity.publicKey, - name: 'Test Bread', - uri: 'https://example.com/bread', - pluginHeader: formPluginHeader(BigInt(118)), - })); + const asset2 = await fetchAssetWithPlugins(umi, asset.publicKey); + + t.is(asset2.freeze, undefined); }); diff --git a/clients/js/test/revokeAuthority.test.ts b/clients/js/test/revokeAuthority.test.ts index c9257869..4d223d2b 100644 --- a/clients/js/test/revokeAuthority.test.ts +++ b/clients/js/test/revokeAuthority.test.ts @@ -1,103 +1,58 @@ import { generateSigner } from '@metaplex-foundation/umi'; import test from 'ava'; -// import { base58 } from '@metaplex-foundation/umi/serializers'; import { generateSignerWithSol } from '@metaplex-foundation/umi-bundle-tests'; import { - Asset, - AssetWithPlugins, - DataState, PluginType, approvePluginAuthority, - addPlugin, - create, - fetchAsset, - fetchAssetWithPlugins, plugin, revokePluginAuthority, updateAuthority, getPubkeyAuthority, - formPluginHeader, getNoneAuthority, } from '../src'; -import { createUmi } from './_setup'; +import { assertAsset, createAsset, createUmi } from './_setup'; test('it can remove an authority from a plugin', async (t) => { // Given a Umi instance and a new signer. const umi = await createUmi(); - const assetAddress = generateSigner(umi); const delegateAddress = generateSigner(umi); - // When we create a new account. - await create(umi, { - dataState: DataState.AccountState, - asset: assetAddress, - name: 'Test Bread', - uri: 'https://example.com/bread', - plugins: [], - }).sendAndConfirm(umi); - - // Then an account was created with the correct data. - const asset = await fetchAsset(umi, assetAddress.publicKey); - // console.log("Account State:", asset); - t.like(asset, { - publicKey: assetAddress.publicKey, - updateAuthority: updateAuthority('Address', [umi.identity.publicKey]), - owner: umi.identity.publicKey, - name: 'Test Bread', - uri: 'https://example.com/bread', + const asset = await createAsset(umi, { + plugins: [plugin('Freeze', [{ frozen: false }])], }); - await addPlugin(umi, { - asset: assetAddress.publicKey, - plugin: plugin('Freeze', [{ frozen: false }]), - initAuthority: null, - }) - .append( - approvePluginAuthority(umi, { - asset: assetAddress.publicKey, - pluginType: PluginType.Freeze, - newAuthority: getPubkeyAuthority(delegateAddress.publicKey), - }) - ) - .sendAndConfirm(umi); + await approvePluginAuthority(umi, { + asset: asset.publicKey, + pluginType: PluginType.Freeze, + newAuthority: getPubkeyAuthority(delegateAddress.publicKey), + }).sendAndConfirm(umi); - const asset1 = await fetchAssetWithPlugins(umi, assetAddress.publicKey); - // console.log(JSON.stringify(asset1, (_, v) => typeof v === 'bigint' ? v.toString() : v, 2)); - t.like(asset1, { - publicKey: assetAddress.publicKey, - updateAuthority: updateAuthority('Address', [umi.identity.publicKey]), + await assertAsset(t, umi, { + asset: asset.publicKey, owner: umi.identity.publicKey, - name: 'Test Bread', - uri: 'https://example.com/bread', - pluginHeader: formPluginHeader(BigInt(120)), + updateAuthority: updateAuthority('Address', [umi.identity.publicKey]), freeze: { authority: { - pubkey: [delegateAddress.publicKey], + type: 'Pubkey', + address: delegateAddress.publicKey, }, - offset: BigInt(118), frozen: false, }, }); await revokePluginAuthority(umi, { - asset: assetAddress.publicKey, + asset: asset.publicKey, pluginType: PluginType.Freeze, }).sendAndConfirm(umi); - const asset2 = await fetchAssetWithPlugins(umi, assetAddress.publicKey); - // console.log(JSON.stringify(asset1, (_, v) => typeof v === 'bigint' ? v.toString() : v, 2)); - t.like(asset2, { - publicKey: assetAddress.publicKey, - updateAuthority: updateAuthority('Address', [umi.identity.publicKey]), + await assertAsset(t, umi, { + asset: asset.publicKey, owner: umi.identity.publicKey, - name: 'Test Bread', - uri: 'https://example.com/bread', - pluginHeader: formPluginHeader(BigInt(120)), + updateAuthority: updateAuthority('Address', [umi.identity.publicKey]), freeze: { authority: { - owner: true, + type: 'Owner', }, - offset: BigInt(118), frozen: false, }, }); @@ -106,57 +61,24 @@ test('it can remove an authority from a plugin', async (t) => { test('it can remove the default authority from a plugin to make it immutable', async (t) => { // Given a Umi instance and a new signer. const umi = await createUmi(); - const assetAddress = generateSigner(umi); - - // When we create a new account. - await create(umi, { - dataState: DataState.AccountState, - asset: assetAddress, - name: 'Test Bread', - uri: 'https://example.com/bread', - plugins: [], - }).sendAndConfirm(umi); - - // Then an account was created with the correct data. - const asset = await fetchAsset(umi, assetAddress.publicKey); - // console.log("Account State:", asset); - t.like(asset, { - publicKey: assetAddress.publicKey, - updateAuthority: updateAuthority('Address', [umi.identity.publicKey]), - owner: umi.identity.publicKey, - name: 'Test Bread', - uri: 'https://example.com/bread', + const asset = await createAsset(umi, { + plugins: [plugin('Freeze', [{ frozen: false }])], }); - await addPlugin(umi, { - asset: assetAddress.publicKey, - plugin: { - __kind: 'Freeze', - fields: [{ frozen: false }], - }, - initAuthority: null, - }).sendAndConfirm(umi); - await approvePluginAuthority(umi, { - asset: assetAddress.publicKey, + asset: asset.publicKey, pluginType: PluginType.Freeze, newAuthority: getNoneAuthority(), }).sendAndConfirm(umi); - const asset1 = await fetchAssetWithPlugins(umi, assetAddress.publicKey); - // console.log(JSON.stringify(asset1, (_, v) => typeof v === 'bigint' ? v.toString() : v, 2)); - t.like(asset1, { - publicKey: assetAddress.publicKey, - updateAuthority: updateAuthority('Address', [umi.identity.publicKey]), + await assertAsset(t, umi, { + asset: asset.publicKey, owner: umi.identity.publicKey, - name: 'Test Bread', - uri: 'https://example.com/bread', - pluginHeader: formPluginHeader(BigInt(120)), + updateAuthority: updateAuthority('Address', [umi.identity.publicKey]), freeze: { authority: { - none: true, + type: 'None', }, - offset: BigInt(118), frozen: false, }, }); @@ -165,41 +87,26 @@ test('it can remove the default authority from a plugin to make it immutable', a test('it can remove a pubkey authority from a plugin if that pubkey is the signer authority', async (t) => { // Given a Umi instance and a new signer. const umi = await createUmi(); - const assetAddress = generateSigner(umi); const pubkeyAuth = await generateSignerWithSol(umi); - // When we create a new account. - await create(umi, { - dataState: DataState.AccountState, - asset: assetAddress, - name: 'Test Bread', - uri: 'https://example.com/bread', - plugins: [], - }).sendAndConfirm(umi); - - await addPlugin(umi, { - asset: assetAddress.publicKey, - plugin: plugin('Freeze', [{ frozen: false }]), - initAuthority: null, - }).sendAndConfirm(umi); + const asset = await createAsset(umi, { + plugins: [plugin('Freeze', [{ frozen: false }])], + }); await approvePluginAuthority(umi, { - asset: assetAddress.publicKey, + asset: asset.publicKey, pluginType: PluginType.Freeze, newAuthority: getPubkeyAuthority(pubkeyAuth.publicKey), }).sendAndConfirm(umi); - const asset1 = await fetchAssetWithPlugins(umi, assetAddress.publicKey); - // console.log(JSON.stringify(asset1, (_, v) => typeof v === 'bigint' ? v.toString() : v, 2)); - t.like(asset1, { - publicKey: assetAddress.publicKey, - updateAuthority: updateAuthority('Address', [umi.identity.publicKey]), + await assertAsset(t, umi, { + asset: asset.publicKey, owner: umi.identity.publicKey, - name: 'Test Bread', - uri: 'https://example.com/bread', + updateAuthority: updateAuthority('Address', [umi.identity.publicKey]), freeze: { authority: { - pubkey: [pubkeyAuth.publicKey], + type: 'Pubkey', + address: pubkeyAuth.publicKey, }, frozen: false, }, @@ -209,89 +116,18 @@ test('it can remove a pubkey authority from a plugin if that pubkey is the signe await revokePluginAuthority(umi2, { payer: umi2.identity, - asset: assetAddress.publicKey, + asset: asset.publicKey, authority: pubkeyAuth, pluginType: PluginType.Freeze, }).sendAndConfirm(umi); - const asset2 = await fetchAssetWithPlugins(umi, assetAddress.publicKey); - // console.log(JSON.stringify(asset1, (_, v) => typeof v === 'bigint' ? v.toString() : v, 2)); - t.like(asset2, { - publicKey: assetAddress.publicKey, - updateAuthority: updateAuthority('Address', [umi.identity.publicKey]), - owner: umi.identity.publicKey, - name: 'Test Bread', - uri: 'https://example.com/bread', - freeze: { - authority: { - owner: true, - }, - frozen: false, - }, - }); -}); - -test('it can remove a owner authority from a plugin with other authority', async (t) => { - // Given a Umi instance and a new signer. - const umi = await createUmi(); - const assetAddress = generateSigner(umi); - const pubkeyAuth = await generateSignerWithSol(umi); - - // When we create a new account. - await create(umi, { - dataState: DataState.AccountState, - asset: assetAddress, - name: 'Test Bread', - uri: 'https://example.com/bread', - plugins: [], - }).sendAndConfirm(umi); - - await addPlugin(umi, { - asset: assetAddress.publicKey, - plugin: plugin('Freeze', [{ frozen: false }]), - initAuthority: null, - }).sendAndConfirm(umi); - - await approvePluginAuthority(umi, { - asset: assetAddress.publicKey, - pluginType: PluginType.Freeze, - newAuthority: getPubkeyAuthority(pubkeyAuth.publicKey), - }).sendAndConfirm(umi); - - const asset1 = await fetchAssetWithPlugins(umi, assetAddress.publicKey); - // console.log(JSON.stringify(asset1, (_, v) => typeof v === 'bigint' ? v.toString() : v, 2)); - t.like(asset1, { - publicKey: assetAddress.publicKey, - updateAuthority: updateAuthority('Address', [umi.identity.publicKey]), + await assertAsset(t, umi, { + asset: asset.publicKey, owner: umi.identity.publicKey, - name: 'Test Bread', - uri: 'https://example.com/bread', - freeze: { - authority: { - pubkey: [pubkeyAuth.publicKey], - }, - frozen: false, - }, - }); - - await revokePluginAuthority(umi, { - payer: umi.identity, - asset: assetAddress.publicKey, - authority: umi.identity, - pluginType: PluginType.Freeze, - }).sendAndConfirm(umi); - - const asset2 = await fetchAssetWithPlugins(umi, assetAddress.publicKey); - // console.log(JSON.stringify(asset1, (_, v) => typeof v === 'bigint' ? v.toString() : v, 2)); - t.like(asset2, { - publicKey: assetAddress.publicKey, updateAuthority: updateAuthority('Address', [umi.identity.publicKey]), - owner: umi.identity.publicKey, - name: 'Test Bread', - uri: 'https://example.com/bread', freeze: { authority: { - owner: true, + type: 'Owner', }, frozen: false, }, @@ -301,26 +137,13 @@ test('it can remove a owner authority from a plugin with other authority', async test('it cannot remove a none authority from a plugin', async (t) => { // Given a Umi instance and a new signer. const umi = await createUmi(); - const assetAddress = generateSigner(umi); - - // When we create a new account. - await create(umi, { - dataState: DataState.AccountState, - asset: assetAddress, - name: 'Test Bread', - uri: 'https://example.com/bread', - plugins: [], - }).sendAndConfirm(umi); - - await addPlugin(umi, { - asset: assetAddress.publicKey, - plugin: plugin('Freeze', [{ frozen: false }]), - initAuthority: null, - }).sendAndConfirm(umi); + const asset = await createAsset(umi, { + plugins: [plugin('Freeze', [{ frozen: false }])], + }); await approvePluginAuthority(umi, { payer: umi.identity, - asset: assetAddress.publicKey, + asset: asset.publicKey, authority: umi.identity, pluginType: PluginType.Freeze, newAuthority: getNoneAuthority(), @@ -329,7 +152,7 @@ test('it cannot remove a none authority from a plugin', async (t) => { const err = await t.throwsAsync(() => revokePluginAuthority(umi, { payer: umi.identity, - asset: assetAddress.publicKey, + asset: asset.publicKey, authority: umi.identity, pluginType: PluginType.Freeze, }).sendAndConfirm(umi) diff --git a/clients/js/test/update.test.ts b/clients/js/test/update.test.ts index 9bbe885b..ef180125 100644 --- a/clients/js/test/update.test.ts +++ b/clients/js/test/update.test.ts @@ -115,7 +115,7 @@ test('it can update an asset with plugins to be larger', async (t) => { pluginHeader: formPluginHeader(BigInt(123)), freeze: { authority: { - owner: true, + type: 'Owner', }, offset: BigInt(121), frozen: false, @@ -160,7 +160,7 @@ test('it can update an asset with plugins to be smaller', async (t) => { pluginHeader: formPluginHeader(BigInt(85)), freeze: { authority: { - owner: true, + type: 'Owner', }, offset: BigInt(83), frozen: false,