generated from metaplex-foundation/solana-project-template
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Master edition collection plugin (#81)
- allow specifying max supply, name and uri on the collection - the fields are informational only and can be freely updated by the creator
- Loading branch information
Showing
22 changed files
with
358 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* This code was AUTOGENERATED using the kinobi library. | ||
* Please DO NOT EDIT THIS FILE, instead use visitors | ||
* to add features, then rerun kinobi to update it. | ||
* | ||
* @see https://github.com/metaplex-foundation/kinobi | ||
*/ | ||
|
||
import { Option, OptionOrNullable } from '@metaplex-foundation/umi'; | ||
import { | ||
Serializer, | ||
option, | ||
string, | ||
struct, | ||
u32, | ||
} from '@metaplex-foundation/umi/serializers'; | ||
|
||
export type MasterEdition = { | ||
maxSupply: Option<number>; | ||
name: Option<string>; | ||
uri: Option<string>; | ||
}; | ||
|
||
export type MasterEditionArgs = { | ||
maxSupply: OptionOrNullable<number>; | ||
name: OptionOrNullable<string>; | ||
uri: OptionOrNullable<string>; | ||
}; | ||
|
||
export function getMasterEditionSerializer(): Serializer< | ||
MasterEditionArgs, | ||
MasterEdition | ||
> { | ||
return struct<MasterEdition>( | ||
[ | ||
['maxSupply', option(u32())], | ||
['name', option(string())], | ||
['uri', option(string())], | ||
], | ||
{ description: 'MasterEdition' } | ||
) as Serializer<MasterEditionArgs, MasterEdition>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
155 changes: 155 additions & 0 deletions
155
clients/js/test/plugins/collection/masterEdition.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
import test from 'ava'; | ||
import { none, some } from '@metaplex-foundation/umi'; | ||
import { | ||
pluginAuthorityPair, | ||
updatePluginAuthority, | ||
createPlugin, | ||
addPluginV1, | ||
addCollectionPluginV1, | ||
} from '../../../src'; | ||
import { | ||
DEFAULT_COLLECTION, | ||
assertCollection, | ||
createAsset, | ||
createCollection, | ||
createUmi, | ||
} from '../../_setup'; | ||
|
||
test('it can add masterEdition to collection', async (t) => { | ||
const umi = await createUmi(); | ||
const collection = await createCollection(umi); | ||
|
||
await addCollectionPluginV1(umi, { | ||
collection: collection.publicKey, | ||
plugin: createPlugin({ | ||
type: 'MasterEdition', | ||
data: { | ||
maxSupply: 100, | ||
name: 'name', | ||
uri: 'uri', | ||
}, | ||
}), | ||
}).sendAndConfirm(umi); | ||
|
||
await assertCollection(t, umi, { | ||
...DEFAULT_COLLECTION, | ||
collection: collection.publicKey, | ||
updateAuthority: umi.identity.publicKey, | ||
masterEdition: { | ||
authority: { | ||
type: 'UpdateAuthority', | ||
}, | ||
maxSupply: some(100), | ||
name: some('name'), | ||
uri: some('uri'), | ||
}, | ||
}); | ||
}); | ||
|
||
test('it can create collection with masterEdition', async (t) => { | ||
const umi = await createUmi(); | ||
|
||
const collection = await createCollection(umi, { | ||
plugins: [ | ||
pluginAuthorityPair({ | ||
type: 'MasterEdition', | ||
data: { | ||
maxSupply: 100, | ||
name: 'name', | ||
uri: 'uri', | ||
}, | ||
authority: updatePluginAuthority(), | ||
}), | ||
], | ||
}); | ||
|
||
await assertCollection(t, umi, { | ||
...DEFAULT_COLLECTION, | ||
collection: collection.publicKey, | ||
updateAuthority: umi.identity.publicKey, | ||
masterEdition: { | ||
authority: { | ||
type: 'UpdateAuthority', | ||
}, | ||
maxSupply: some(100), | ||
name: some('name'), | ||
uri: some('uri'), | ||
}, | ||
}); | ||
}); | ||
|
||
test('it can create master edition with default values', async (t) => { | ||
const umi = await createUmi(); | ||
|
||
const collection = await createCollection(umi, { | ||
plugins: [ | ||
pluginAuthorityPair({ | ||
type: 'MasterEdition', | ||
data: { | ||
maxSupply: null, | ||
name: null, | ||
uri: null, | ||
}, | ||
authority: updatePluginAuthority(), | ||
}), | ||
], | ||
}); | ||
|
||
await assertCollection(t, umi, { | ||
...DEFAULT_COLLECTION, | ||
collection: collection.publicKey, | ||
updateAuthority: umi.identity.publicKey, | ||
masterEdition: { | ||
authority: { | ||
type: 'UpdateAuthority', | ||
}, | ||
maxSupply: none(), | ||
name: none(), | ||
uri: none(), | ||
}, | ||
}); | ||
}); | ||
|
||
test('it cannot add masterEdition to asset', async (t) => { | ||
const umi = await createUmi(); | ||
|
||
const asset = await createAsset(umi); | ||
|
||
const result = addPluginV1(umi, { | ||
asset: asset.publicKey, | ||
plugin: createPlugin({ | ||
type: 'MasterEdition', | ||
data: { | ||
maxSupply: 100, | ||
name: 'name', | ||
uri: 'uri', | ||
}, | ||
}), | ||
}).sendAndConfirm(umi); | ||
|
||
await t.throwsAsync(result, { | ||
name: 'InvalidPlugin', | ||
}); | ||
}); | ||
|
||
test('it cannot create asset with masterEdition', async (t) => { | ||
const umi = await createUmi(); | ||
|
||
const result = createAsset(umi, { | ||
plugins: [ | ||
pluginAuthorityPair({ | ||
type: 'MasterEdition', | ||
data: { | ||
maxSupply: 100, | ||
name: 'name', | ||
uri: 'uri', | ||
}, | ||
authority: updatePluginAuthority(), | ||
}), | ||
], | ||
}); | ||
|
||
await t.throwsAsync(result, { | ||
name: 'InvalidPlugin', | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
//! This code was AUTOGENERATED using the kinobi library. | ||
//! Please DO NOT EDIT THIS FILE, instead use visitors | ||
//! to add features, then rerun kinobi to update it. | ||
//! | ||
//! [https://github.com/metaplex-foundation/kinobi] | ||
//! | ||
use borsh::BorshDeserialize; | ||
use borsh::BorshSerialize; | ||
|
||
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] | ||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] | ||
pub struct MasterEdition { | ||
pub max_supply: Option<u32>, | ||
pub name: Option<String>, | ||
pub uri: Option<String>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,4 +24,5 @@ pub enum PluginType { | |
PermanentTransferDelegate, | ||
PermanentBurnDelegate, | ||
Edition, | ||
MasterEdition, | ||
} |
Oops, something went wrong.