Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding remove plugin. #83

Merged
merged 8 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
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
13 changes: 13 additions & 0 deletions clients/js/src/generated/errors/mplCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,19 @@ export class InvalidLogWrapperProgramError extends ProgramError {
codeToErrorMap.set(0x1e, InvalidLogWrapperProgramError);
nameToErrorMap.set('InvalidLogWrapperProgram', InvalidLogWrapperProgramError);

/** ExternalPluginNotFound: External Plugin not found */
export class ExternalPluginNotFoundError extends ProgramError {
override readonly name: string = 'ExternalPluginNotFound';

readonly code: number = 0x1f; // 31

constructor(program: Program, cause?: Error) {
super('External Plugin not found', program, cause);
}
}
codeToErrorMap.set(0x1f, ExternalPluginNotFoundError);
nameToErrorMap.set('ExternalPluginNotFound', ExternalPluginNotFoundError);

/**
* Attempts to resolve a custom program error from the provided error code.
* @category Errors
Expand Down
3 changes: 3 additions & 0 deletions clients/rust/src/generated/errors/mpl_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ pub enum MplCoreError {
/// 30 (0x1E) - Invalid Log Wrapper Program
#[error("Invalid Log Wrapper Program")]
InvalidLogWrapperProgram,
/// 31 (0x1F) - External Plugin not found
#[error("External Plugin not found")]
ExternalPluginNotFound,
}

impl solana_program::program_error::PrintProgramError for MplCoreError {
Expand Down
21 changes: 18 additions & 3 deletions clients/rust/src/hooked/advanced_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ use std::{cmp::Ordering, io::ErrorKind};
use crate::{
accounts::{BaseAssetV1, BaseCollectionV1, PluginHeaderV1},
types::{
Attributes, BurnDelegate, DataStore, Edition, ExternalCheckResult, FreezeDelegate, Key,
LifecycleHook, Oracle, PermanentBurnDelegate, PermanentFreezeDelegate,
PermanentTransferDelegate, PluginAuthority, Royalties, TransferDelegate, UpdateDelegate,
Attributes, BurnDelegate, DataStore, Edition, ExternalCheckResult, ExternalPlugin,
ExternalPluginKey, FreezeDelegate, Key, LifecycleHook, Oracle, PermanentBurnDelegate,
PermanentFreezeDelegate, PermanentTransferDelegate, PluginAuthority, Royalties,
TransferDelegate, UpdateDelegate,
},
};

Expand Down Expand Up @@ -250,3 +251,17 @@ impl PluginRegistryV1Safe {
})
}
}

impl From<&ExternalPlugin> for ExternalPluginKey {
fn from(plugin: &ExternalPlugin) -> Self {
match plugin {
ExternalPlugin::DataStore(data_store) => {
ExternalPluginKey::DataStore(data_store.data_authority.clone())
}
ExternalPlugin::Oracle(oracle) => ExternalPluginKey::Oracle(oracle.base_address),
ExternalPlugin::LifecycleHook(lifecycle_hook) => {
ExternalPluginKey::LifecycleHook(lifecycle_hook.hooked_program)
}
}
}
}
90 changes: 60 additions & 30 deletions clients/rust/tests/add_external_plugins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ pub mod setup;
use mpl_core::{
instructions::AddExternalPluginV1Builder,
types::{
DataStoreInitInfo, ExternalCheckResult, ExternalPluginInitInfo, HookableLifecycleEvent,
LifecycleHookInitInfo, OracleInitInfo, PluginAuthority, UpdateAuthority,
DataStore, DataStoreInitInfo, ExternalCheckResult, ExternalPlugin, ExternalPluginInitInfo,
ExternalPluginSchema, HookableLifecycleEvent, LifecycleHook, LifecycleHookInitInfo, Oracle,
OracleInitInfo, PluginAuthority, UpdateAuthority,
},
Asset,
};
pub use setup::*;

Expand Down Expand Up @@ -49,6 +49,7 @@ async fn test_add_lifecycle_hook() {
name: None,
uri: None,
plugins: vec![],
external_plugins: vec![],
},
)
.await;
Expand Down Expand Up @@ -80,15 +81,26 @@ async fn test_add_lifecycle_hook() {

context.banks_client.process_transaction(tx).await.unwrap();

let asset_account = context
.banks_client
.get_account(asset.pubkey())
.await
.unwrap()
.unwrap();

let asset_data = Asset::from_bytes(&asset_account.data).unwrap();
println!("{:#?}", asset_data);
assert_asset(
&mut context,
AssertAssetHelperArgs {
asset: asset.pubkey(),
owner,
update_authority: Some(UpdateAuthority::Address(update_authority)),
name: None,
uri: None,
plugins: vec![],
external_plugins: vec![ExternalPlugin::LifecycleHook(LifecycleHook {
hooked_program: pubkey!("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),
extra_accounts: None,
data_authority: Some(PluginAuthority::UpdateAuthority),
schema: ExternalPluginSchema::Binary,
data_offset: 119,
data_len: 0,
})],
},
)
.await;
}

#[tokio::test]
Expand Down Expand Up @@ -126,6 +138,7 @@ async fn test_add_oracle() {
name: None,
uri: None,
plugins: vec![],
external_plugins: vec![],
},
)
.await;
Expand Down Expand Up @@ -153,15 +166,22 @@ async fn test_add_oracle() {

context.banks_client.process_transaction(tx).await.unwrap();

let asset_account = context
.banks_client
.get_account(asset.pubkey())
.await
.unwrap()
.unwrap();

let asset_data = Asset::from_bytes(&asset_account.data).unwrap();
println!("{:#?}", asset_data);
assert_asset(
&mut context,
AssertAssetHelperArgs {
asset: asset.pubkey(),
owner,
update_authority: Some(UpdateAuthority::Address(update_authority)),
name: None,
uri: None,
plugins: vec![],
external_plugins: vec![ExternalPlugin::Oracle(Oracle {
base_address: Pubkey::default(),
pda: None,
})],
},
)
.await;
}

#[tokio::test]
Expand Down Expand Up @@ -199,6 +219,7 @@ async fn test_add_data_store() {
name: None,
uri: None,
plugins: vec![],
external_plugins: vec![],
},
)
.await;
Expand All @@ -222,13 +243,22 @@ async fn test_add_data_store() {

context.banks_client.process_transaction(tx).await.unwrap();

let asset_account = context
.banks_client
.get_account(asset.pubkey())
.await
.unwrap()
.unwrap();

let asset_data = Asset::from_bytes(&asset_account.data).unwrap();
println!("{:#?}", asset_data);
assert_asset(
&mut context,
AssertAssetHelperArgs {
asset: asset.pubkey(),
owner,
update_authority: Some(UpdateAuthority::Address(update_authority)),
name: None,
uri: None,
plugins: vec![],
external_plugins: vec![ExternalPlugin::DataStore(DataStore {
data_authority: PluginAuthority::UpdateAuthority,
schema: ExternalPluginSchema::Binary,
data_offset: 119,
data_len: 0,
})],
},
)
.await;
}
5 changes: 5 additions & 0 deletions clients/rust/tests/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ async fn create_asset_in_account_state() {
name: None,
uri: None,
plugins: vec![],
external_plugins: vec![],
},
)
.await;
Expand Down Expand Up @@ -85,6 +86,7 @@ async fn create_asset_with_different_payer() {
name: None,
uri: None,
plugins: vec![],
external_plugins: vec![],
},
)
.await;
Expand Down Expand Up @@ -131,6 +133,7 @@ async fn create_asset_with_plugins() {
plugin: Plugin::FreezeDelegate(FreezeDelegate { frozen: false }),
authority: Some(PluginAuthority::Owner),
}],
external_plugins: vec![],
},
)
.await;
Expand Down Expand Up @@ -174,6 +177,7 @@ async fn create_asset_with_different_update_authority() {
name: None,
uri: None,
plugins: vec![],
external_plugins: vec![],
},
)
.await;
Expand Down Expand Up @@ -223,6 +227,7 @@ async fn create_asset_with_plugins_with_different_update_authority() {
plugin: Plugin::FreezeDelegate(FreezeDelegate { frozen: false }),
authority: Some(PluginAuthority::Owner),
}],
external_plugins: vec![],
},
)
.await;
Expand Down
64 changes: 25 additions & 39 deletions clients/rust/tests/create_with_external_plugins.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#![cfg(feature = "test-sbf")]
pub mod setup;
use mpl_core::{
types::{
DataStoreInitInfo, ExternalCheckResult, ExternalPluginInitInfo, HookableLifecycleEvent,
LifecycleHookInitInfo, OracleInitInfo, PluginAuthority, UpdateAuthority,
},
Asset,
use mpl_core::types::{
DataStore, DataStoreInitInfo, ExternalCheckResult, ExternalPlugin, ExternalPluginInitInfo,
ExternalPluginSchema, HookableLifecycleEvent, LifecycleHook, LifecycleHookInitInfo, Oracle,
OracleInitInfo, PluginAuthority, UpdateAuthority,
};
pub use setup::*;

Expand All @@ -14,7 +12,7 @@ use solana_program_test::tokio;
use solana_sdk::{pubkey::Pubkey, signature::Keypair, signer::Signer};

#[tokio::test]
async fn test_add_lifecycle_hook() {
async fn test_create_lifecycle_hook() {
let mut context = program_test().start_with_context().await;

let asset = Keypair::new();
Expand Down Expand Up @@ -60,23 +58,21 @@ async fn test_add_lifecycle_hook() {
name: None,
uri: None,
plugins: vec![],
external_plugins: vec![ExternalPlugin::LifecycleHook(LifecycleHook {
hooked_program: pubkey!("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),
extra_accounts: None,
data_authority: Some(PluginAuthority::UpdateAuthority),
schema: ExternalPluginSchema::Binary,
data_offset: 119,
data_len: 0,
})],
},
)
.await;

let asset_account = context
.banks_client
.get_account(asset.pubkey())
.await
.unwrap()
.unwrap();

let asset_data = Asset::from_bytes(&asset_account.data).unwrap();
println!("{:#?}", asset_data);
}

#[tokio::test]
async fn test_add_oracle() {
async fn test_create_oracle() {
let mut context = program_test().start_with_context().await;

let asset = Keypair::new();
Expand Down Expand Up @@ -118,23 +114,17 @@ async fn test_add_oracle() {
name: None,
uri: None,
plugins: vec![],
external_plugins: vec![ExternalPlugin::Oracle(Oracle {
base_address: Pubkey::default(),
pda: None,
})],
},
)
.await;

let asset_account = context
.banks_client
.get_account(asset.pubkey())
.await
.unwrap()
.unwrap();

let asset_data = Asset::from_bytes(&asset_account.data).unwrap();
println!("{:#?}", asset_data);
}

#[tokio::test]
async fn test_add_data_store() {
async fn test_create_data_store() {
let mut context = program_test().start_with_context().await;

let asset = Keypair::new();
Expand Down Expand Up @@ -172,17 +162,13 @@ async fn test_add_data_store() {
name: None,
uri: None,
plugins: vec![],
external_plugins: vec![ExternalPlugin::DataStore(DataStore {
data_authority: PluginAuthority::UpdateAuthority,
schema: ExternalPluginSchema::Binary,
data_offset: 119,
data_len: 0,
})],
},
)
.await;

let asset_account = context
.banks_client
.get_account(asset.pubkey())
.await
.unwrap()
.unwrap();

let asset_data = Asset::from_bytes(&asset_account.data).unwrap();
println!("{:#?}", asset_data);
}
3 changes: 3 additions & 0 deletions clients/rust/tests/plugins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ async fn test_fetch_plugin() {
}),
},
],
external_plugins: vec![],
},
)
.await;
Expand Down Expand Up @@ -193,6 +194,7 @@ async fn test_fetch_plugins() {
}),
},
],
external_plugins: vec![],
},
)
.await;
Expand Down Expand Up @@ -303,6 +305,7 @@ async fn test_list_plugins() {
}),
},
],
external_plugins: vec![],
},
)
.await;
Expand Down
Loading