Skip to content

Commit

Permalink
Merge pull request #131 from metaplex-foundation/feat/additional-upda…
Browse files Browse the repository at this point in the history
…te-delegates

Adding support for additional delegates in Update Delegate plugin.
  • Loading branch information
blockiosaurus authored Jun 15, 2024
2 parents 43a4419 + a2c8846 commit a1f028a
Show file tree
Hide file tree
Showing 27 changed files with 3,156 additions and 1,658 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Main

on:
push:
branches: [main, third-party-plugins-staging]
branches: [main, jun-2024-feature-staging]
pull_request:
branches: [main, third-party-plugins-staging]
branches: [main, jun-2024-feature-staging]

env:
CACHE: true
Expand Down
3,164 changes: 1,774 additions & 1,390 deletions clients/js/pnpm-lock.yaml

Large diffs are not rendered by default.

98 changes: 97 additions & 1 deletion clients/js/test/collect.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
PublicKey,
Umi,
generateSigner,
publicKey,
sol,
subtractAmounts,
Expand All @@ -15,8 +16,9 @@ import {
createPlugin,
pluginAuthorityPair,
removePluginV1,
transfer,
} from '../src';
import { createAsset, createUmi } from './_setupRaw';
import { assertAsset, createAsset, createUmi } from './_setupRaw';

const recipient1 = publicKey('8AT6o8Qk5T9QnZvPThMrF9bcCQLTGkyGvVZZzHgCw11v');
const recipient2 = publicKey('MmHsqX4LxTfifxoH8BVRLUKrwDn1LPCac6YcCZTHhwt');
Expand Down Expand Up @@ -131,3 +133,97 @@ test.serial('it can collect burned asset', async (t) => {
t.deepEqual(subtractAmounts(balEnd1, balStart1), sol(0.0015 / 2));
t.deepEqual(subtractAmounts(balEnd2, balStart2), sol(0.0015 / 2));
});

test.serial(
'it can collect multiple times on same asset idempotently',
async (t) => {
const umi = await createUmi();
const asset = await createAsset(umi);
const balStart1 = await umi.rpc.getBalance(recipient1);
const balStart2 = await umi.rpc.getBalance(recipient2);
await collect(umi, {})
.addRemainingAccounts({
isSigner: false,
isWritable: true,
pubkey: asset.publicKey,
})
.sendAndConfirm(umi);
const balMid1 = await umi.rpc.getBalance(recipient1);
const balMid2 = await umi.rpc.getBalance(recipient2);
t.is(await hasCollectAmount(umi, asset.publicKey), false);
t.deepEqual(subtractAmounts(balMid1, balStart1), sol(0.0015 / 2));
t.deepEqual(subtractAmounts(balMid2, balStart2), sol(0.0015 / 2));
await collect(umi, {})
.addRemainingAccounts({
isSigner: false,
isWritable: true,
pubkey: asset.publicKey,
})
.sendAndConfirm(umi);
const balEnd1 = await umi.rpc.getBalance(recipient1);
const balEnd2 = await umi.rpc.getBalance(recipient2);
t.is(await hasCollectAmount(umi, asset.publicKey), false);
t.deepEqual(subtractAmounts(balEnd1, balStart1), sol(0.0015 / 2));
t.deepEqual(subtractAmounts(balEnd2, balStart2), sol(0.0015 / 2));
}
);

test.serial('it can collect multiple assets at once', async (t) => {
const umi = await createUmi();
const asset = await createAsset(umi);
const asset2 = await createAsset(umi);
const asset3 = await createAsset(umi);
const balStart1 = await umi.rpc.getBalance(recipient1);
const balStart2 = await umi.rpc.getBalance(recipient2);
await collect(umi, {})
.addRemainingAccounts([
{
isSigner: false,
isWritable: true,
pubkey: asset.publicKey,
},
{
isSigner: false,
isWritable: true,
pubkey: asset2.publicKey,
},
{
isSigner: false,
isWritable: true,
pubkey: asset3.publicKey,
},
])
.sendAndConfirm(umi);
const balEnd1 = await umi.rpc.getBalance(recipient1);
const balEnd2 = await umi.rpc.getBalance(recipient2);
t.is(await hasCollectAmount(umi, asset.publicKey), false);
t.is(await hasCollectAmount(umi, asset2.publicKey), false);
t.is(await hasCollectAmount(umi, asset3.publicKey), false);
t.deepEqual(subtractAmounts(balEnd1, balStart1), sol((0.0015 / 2) * 3));
t.deepEqual(subtractAmounts(balEnd2, balStart2), sol((0.0015 / 2) * 3));
});

test('it can transfer after collecting', async (t) => {
const umi = await createUmi();
const asset = await createAsset(umi);
await collect(umi, {})
.addRemainingAccounts({
isSigner: false,
isWritable: true,
pubkey: asset.publicKey,
})
.sendAndConfirm(umi);
t.is(await hasCollectAmount(umi, asset.publicKey), false);
const newOwner = generateSigner(umi);

await transfer(umi, {
asset,
newOwner: newOwner.publicKey,
}).sendAndConfirm(umi);

await assertAsset(t, umi, {
asset: asset.publicKey,
owner: newOwner.publicKey,
updateAuthority: { type: 'Address', address: umi.identity.publicKey },
});
});
12 changes: 10 additions & 2 deletions clients/js/test/plugins/asset/delegateTransfer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
revokePluginAuthority,
} from '../../../src';
import { DEFAULT_ASSET, assertAsset, createUmi } from '../../_setupRaw';
import { createAsset, createAssetWithCollection } from '../../_setupSdk';
import { createAsset, createCollection } from '../../_setupSdk';

test('a delegate can transfer the asset', async (t) => {
const umi = await createUmi();
Expand Down Expand Up @@ -167,9 +167,15 @@ test('it can transfer using delegated update authority from collection', async (
const umi = await createUmi();
const owner = generateSigner(umi);
const newOwner = generateSigner(umi);
const updateAuthority = generateSigner(umi);

const { asset, collection } = await createAssetWithCollection(umi, {
const collection = await createCollection(umi, {
updateAuthority: updateAuthority.publicKey,
});

const asset = await createAsset(umi, {
owner: owner.publicKey,
collection: collection.publicKey,
plugins: [
{
type: 'TransferDelegate',
Expand All @@ -178,12 +184,14 @@ test('it can transfer using delegated update authority from collection', async (
},
},
],
authority: updateAuthority,
});

await transfer(umi, {
asset,
collection,
newOwner: newOwner.publicKey,
authority: updateAuthority,
}).sendAndConfirm(umi);

await assertAsset(t, umi, {
Expand Down
Loading

0 comments on commit a1f028a

Please sign in to comment.