Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adding some extra tests
  • Loading branch information
blockiosaurus committed Sep 16, 2025
commit cfdb554b9d4433a1fc194765d7d0465da17c325e
107 changes: 107 additions & 0 deletions clients/js/test/plugins/asset/permanentFreezeExecute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,3 +458,110 @@ test('PermanentFreezeExecute blocks execute but allows burn', async (t) => {
'Owner balance did not increase after burn refund'
);
});

test('owner cannot remove or unfreeze PermanentFreezeExecute plugin', async (t) => {
const umi = await createUmi();
const owner = generateSigner(umi);

// Create an asset with PermanentFreezeExecute plugin (frozen)
const assetSigner = generateSigner(umi);

await create(umi, {
asset: assetSigner,
owner: owner.publicKey,
name: 'Test Asset',
uri: 'https://example.com/asset',
plugins: [
{
type: 'PermanentFreezeExecute',
frozen: true,
},
],
}).sendAndConfirm(umi);

const asset = await fetchAssetV1(umi, publicKey(assetSigner));

// Verify initial state
await assertAsset(t, umi, {
...DEFAULT_ASSET,
asset: asset.publicKey,
owner: owner.publicKey,
updateAuthority: { type: 'Address', address: umi.identity.publicKey },
permanentFreezeExecute: {
authority: {
type: 'UpdateAuthority',
},
frozen: true,
},
});

// Owner should not be able to unfreeze the plugin
const unfreezeResult = updatePluginV1(umi, {
asset: asset.publicKey,
plugin: createPlugin({
type: 'PermanentFreezeExecute',
data: { frozen: false },
}),
authority: owner,
}).sendAndConfirm(umi);

await t.throwsAsync(unfreezeResult, { name: 'NoApprovals' });

// Owner should not be able to remove the plugin (even when frozen)
const removeResult = removePluginV1(umi, {
asset: asset.publicKey,
pluginType: PluginType.PermanentFreezeExecute,
authority: owner,
}).sendAndConfirm(umi);

await t.throwsAsync(removeResult, { name: 'InvalidAuthority' });

// Plugin should still be there and frozen
await assertAsset(t, umi, {
...DEFAULT_ASSET,
asset: asset.publicKey,
owner: owner.publicKey,
updateAuthority: { type: 'Address', address: umi.identity.publicKey },
permanentFreezeExecute: {
authority: {
type: 'UpdateAuthority',
},
frozen: true,
},
});

// Only update authority should be able to unfreeze
await updatePluginV1(umi, {
asset: asset.publicKey,
plugin: createPlugin({
type: 'PermanentFreezeExecute',
data: { frozen: false },
}),
authority: umi.identity, // Update authority
}).sendAndConfirm(umi);

// Now owner still cannot remove it even when unfrozen
const removeUnfrozenResult = removePluginV1(umi, {
asset: asset.publicKey,
pluginType: PluginType.PermanentFreezeExecute,
authority: owner,
}).sendAndConfirm(umi);

await t.throwsAsync(removeUnfrozenResult, { name: 'NoApprovals' });

// But update authority can remove it when unfrozen
await removePluginV1(umi, {
asset: asset.publicKey,
pluginType: PluginType.PermanentFreezeExecute,
authority: umi.identity,
}).sendAndConfirm(umi);

// Verify plugin is removed
await assertAsset(t, umi, {
...DEFAULT_ASSET,
asset: asset.publicKey,
owner: owner.publicKey,
updateAuthority: { type: 'Address', address: umi.identity.publicKey },
permanentFreezeExecute: undefined,
});
});
100 changes: 100 additions & 0 deletions clients/js/test/plugins/collection/permanentFreezeExecute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,3 +510,103 @@ test('collection PermanentFreezeExecute persists through asset transfer and stil
const recipientBalance = await umi.rpc.getBalance(recipient2.publicKey);
t.true(recipientBalance.basisPoints >= sol(0.1).basisPoints);
});

test('collection owner cannot remove or unfreeze PermanentFreezeExecute plugin', async (t) => {
const umi = await createUmi();
const collectionOwner = generateSigner(umi);

// Create collection with PermanentFreezeExecute plugin (frozen) and specific owner
const collection = await createCollection(umi, {
updateAuthority: collectionOwner.publicKey,
plugins: [
{
type: 'PermanentFreezeExecute',
frozen: true,
},
],
});

// Verify initial state
await assertCollection(t, umi, {
...DEFAULT_COLLECTION,
collection: collection.publicKey,
updateAuthority: collectionOwner.publicKey,
permanentFreezeExecute: {
authority: {
type: 'UpdateAuthority',
},
frozen: true,
},
});

// Create a different user who will try to modify the plugin (not the update authority)
const unauthorizedUser = generateSigner(umi);

// Unauthorized user should not be able to unfreeze the plugin
const unfreezeResult = updateCollectionPluginV1(umi, {
collection: collection.publicKey,
plugin: createPlugin({
type: 'PermanentFreezeExecute',
data: { frozen: false },
}),
authority: unauthorizedUser,
}).sendAndConfirm(umi);

await t.throwsAsync(unfreezeResult, { name: 'InvalidAuthority' });

// Unauthorized user should not be able to remove the plugin (even when frozen)
const removeResult = removeCollectionPluginV1(umi, {
collection: collection.publicKey,
pluginType: PluginType.PermanentFreezeExecute,
authority: unauthorizedUser,
}).sendAndConfirm(umi);

await t.throwsAsync(removeResult, { name: 'InvalidAuthority' });

// Plugin should still be there and frozen
await assertCollection(t, umi, {
...DEFAULT_COLLECTION,
collection: collection.publicKey,
updateAuthority: collectionOwner.publicKey,
permanentFreezeExecute: {
authority: {
type: 'UpdateAuthority',
},
frozen: true,
},
});

// Only the collection's update authority should be able to unfreeze
await updateCollectionPluginV1(umi, {
collection: collection.publicKey,
plugin: createPlugin({
type: 'PermanentFreezeExecute',
data: { frozen: false },
}),
authority: collectionOwner, // Collection update authority
}).sendAndConfirm(umi);

// Unauthorized user still cannot remove it even when unfrozen
const removeUnfrozenResult = removeCollectionPluginV1(umi, {
collection: collection.publicKey,
pluginType: PluginType.PermanentFreezeExecute,
authority: unauthorizedUser,
}).sendAndConfirm(umi);

await t.throwsAsync(removeUnfrozenResult, { name: 'InvalidAuthority' });

// But collection update authority can remove it when unfrozen
await removeCollectionPluginV1(umi, {
collection: collection.publicKey,
pluginType: PluginType.PermanentFreezeExecute,
authority: collectionOwner,
}).sendAndConfirm(umi);

// Verify plugin is removed
await assertCollection(t, umi, {
...DEFAULT_COLLECTION,
collection: collection.publicKey,
updateAuthority: collectionOwner.publicKey,
permanentFreezeExecute: undefined,
});
});