Skip to content

Commit

Permalink
Adding the ability to change the update authority or collection as th…
Browse files Browse the repository at this point in the history
…e update delegate.
  • Loading branch information
blockiosaurus committed Dec 16, 2024
1 parent 729fde8 commit ea8324b
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 26 deletions.
22 changes: 16 additions & 6 deletions clients/js/test/plugins/asset/updateDelegate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ test('it cannot add updateDelegate plugin with additional delegate as additional
await t.throwsAsync(result, { name: 'NoApprovals' });
});

test('it cannot update the update authority of the asset as an updateDelegate additional delegate', async (t) => {
test('it can update the update authority of the asset as an updateDelegate additional delegate', async (t) => {
const umi = await createUmi();
const updateDelegate = generateSigner(umi);
const updateDelegate2 = generateSigner(umi);
Expand All @@ -703,16 +703,21 @@ test('it cannot update the update authority of the asset as an updateDelegate ad
],
});

const result = update(umi, {
await update(umi, {
asset,
authority: updateDelegate,
newUpdateAuthority: updateAuthority('Address', [updateDelegate2.publicKey]),
}).sendAndConfirm(umi);

await t.throwsAsync(result, { name: 'NoApprovals' });
await assertAsset(t, umi, {
...DEFAULT_ASSET,
asset: asset.publicKey,
owner: umi.identity.publicKey,
updateAuthority: { type: 'Address', address: updateDelegate2.publicKey },
});
});

test('it cannot update the update authority of the asset as an updateDelegate root authority', async (t) => {
test('it can update the update authority of the asset as an updateDelegate root authority', async (t) => {
const umi = await createUmi();
const updateDelegate = generateSigner(umi);
const updateDelegate2 = generateSigner(umi);
Expand All @@ -727,13 +732,18 @@ test('it cannot update the update authority of the asset as an updateDelegate ro
],
});

const result = update(umi, {
await update(umi, {
asset,
authority: updateDelegate,
newUpdateAuthority: updateAuthority('Address', [updateDelegate2.publicKey]),
}).sendAndConfirm(umi);

await t.throwsAsync(result, { name: 'NoApprovals' });
await assertAsset(t, umi, {
...DEFAULT_ASSET,
asset: asset.publicKey,
owner: umi.identity.publicKey,
updateAuthority: { type: 'Address', address: updateDelegate2.publicKey },
});
});

test('an updateDelegate can add a plugin to an asset', async (t) => {
Expand Down
20 changes: 14 additions & 6 deletions clients/js/test/plugins/collection/updateDelegate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ test('it can approve/revoke non-updateDelegate plugin on an asset as collection
});
});

test('it cannot update the update authority of the collection as an updateDelegate additional delegate', async (t) => {
test('it can update the update authority of the collection as an updateDelegate additional delegate', async (t) => {
const umi = await createUmi();
const updateDelegate = generateSigner(umi);
const updateDelegate2 = generateSigner(umi);
Expand All @@ -668,16 +668,20 @@ test('it cannot update the update authority of the collection as an updateDelega
],
});

const result = updateCollection(umi, {
await updateCollection(umi, {
collection: collection.publicKey,
authority: updateDelegate,
newUpdateAuthority: updateDelegate2.publicKey,
}).sendAndConfirm(umi);

await t.throwsAsync(result, { name: 'InvalidAuthority' });
await assertCollection(t, umi, {
...DEFAULT_COLLECTION,
collection: collection.publicKey,
updateAuthority: updateDelegate2.publicKey,
});
});

test('it cannot update the update authority of the collection as an updateDelegate root authority', async (t) => {
test('it can update the update authority of the collection as an updateDelegate root authority', async (t) => {
const umi = await createUmi();
const updateDelegate = generateSigner(umi);
const updateDelegate2 = generateSigner(umi);
Expand All @@ -692,13 +696,17 @@ test('it cannot update the update authority of the collection as an updateDelega
],
});

const result = updateCollection(umi, {
await updateCollection(umi, {
collection: collection.publicKey,
authority: updateDelegate,
newUpdateAuthority: updateDelegate2.publicKey,
}).sendAndConfirm(umi);

await t.throwsAsync(result, { name: 'InvalidAuthority' });
await assertCollection(t, umi, {
...DEFAULT_COLLECTION,
collection: collection.publicKey,
updateAuthority: updateDelegate2.publicKey,
});
});

test('it can update collection details as an updateDelegate additional delegate', async (t) => {
Expand Down
22 changes: 16 additions & 6 deletions clients/js/test/updateV2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,7 @@ test('it can change an asset collection using same update authority (delegate ex
});
});

test('it cannot remove an asset from collection using update delegate', async (t) => {
test('it can remove an asset from collection using update delegate', async (t) => {
const umi = await createUmi();
const collectionAuthority = generateSigner(umi);
const { asset, collection } = await createAssetWithCollection(
Expand Down Expand Up @@ -1107,17 +1107,22 @@ test('it cannot remove an asset from collection using update delegate', async (t
numMinted: 1,
});

const result = update(umi, {
await update(umi, {
asset,
collection,
newUpdateAuthority: updateAuthority('Address', [umi.identity.publicKey]),
authority: updateDelegate,
}).sendAndConfirm(umi);

await t.throwsAsync(result, { name: 'NoApprovals' });
await assertAsset(t, umi, {
...DEFAULT_ASSET,
asset: asset.publicKey,
owner: umi.identity.publicKey,
updateAuthority: { type: 'Address', address: umi.identity.publicKey },
});
});

test('it cannot remove an asset from collection using additional update delegate', async (t) => {
test('it can remove an asset from collection using additional update delegate', async (t) => {
const umi = await createUmi();
const collectionAuthority = generateSigner(umi);
const { asset, collection } = await createAssetWithCollection(
Expand Down Expand Up @@ -1157,14 +1162,19 @@ test('it cannot remove an asset from collection using additional update delegate
numMinted: 1,
});

const result = update(umi, {
await update(umi, {
asset,
collection,
newUpdateAuthority: updateAuthority('Address', [umi.identity.publicKey]),
authority: additionalDelegate,
}).sendAndConfirm(umi);

await t.throwsAsync(result, { name: 'NoApprovals' });
await assertAsset(t, umi, {
...DEFAULT_ASSET,
asset: asset.publicKey,
owner: umi.identity.publicKey,
updateAuthority: { type: 'Address', address: umi.identity.publicKey },
});
});

test('it cannot add asset to collection using additional update delegate on new collection', async (t) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,12 @@ impl PluginValidation for UpdateDelegate {
&self,
ctx: &PluginValidationContext,
) -> Result<ValidationResult, ProgramError> {
if ((ctx.resolved_authorities.is_some()
&& ctx
.resolved_authorities
.unwrap()
.contains(ctx.self_authority))
|| self.additional_delegates.contains(ctx.authority_info.key))
// We do not allow the root authority (either Collection or Address) to be changed by this delegate.
&& ctx.new_collection_authority.is_none() && ctx.new_asset_authority.is_none()
if (ctx.resolved_authorities.is_some()
&& ctx
.resolved_authorities
.unwrap()
.contains(ctx.self_authority))
|| self.additional_delegates.contains(ctx.authority_info.key)
{
approve!()
} else {
Expand Down

0 comments on commit ea8324b

Please sign in to comment.