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 4 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
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)
}
}
}
}
3 changes: 3 additions & 0 deletions clients/rust/tests/add_external_plugins.rs
Original file line number Diff line number Diff line change
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 @@ -126,6 +127,7 @@ async fn test_add_oracle() {
name: None,
uri: None,
plugins: vec![],
external_plugins: vec![],
},
)
.await;
Expand Down Expand Up @@ -199,6 +201,7 @@ async fn test_add_data_store() {
name: None,
uri: None,
plugins: vec![],
external_plugins: vec![],
},
)
.await;
Expand Down
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
3 changes: 3 additions & 0 deletions clients/rust/tests/create_with_external_plugins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ async fn test_add_lifecycle_hook() {
name: None,
uri: None,
plugins: vec![],
external_plugins: vec![],
blockiosaurus marked this conversation as resolved.
Show resolved Hide resolved
},
)
.await;
Expand Down Expand Up @@ -118,6 +119,7 @@ async fn test_add_oracle() {
name: None,
uri: None,
plugins: vec![],
external_plugins: vec![],
blockiosaurus marked this conversation as resolved.
Show resolved Hide resolved
},
)
.await;
Expand Down Expand Up @@ -172,6 +174,7 @@ async fn test_add_data_store() {
name: None,
uri: None,
plugins: vec![],
external_plugins: vec![],
blockiosaurus marked this conversation as resolved.
Show resolved Hide resolved
},
)
.await;
Expand Down
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
245 changes: 245 additions & 0 deletions clients/rust/tests/remove_external_plugins.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,245 @@
#![cfg(feature = "test-sbf")]
pub mod setup;
use mpl_core::{
instructions::RemoveExternalPluginV1Builder,
types::{
DataStoreInitInfo, ExternalCheckResult, ExternalPluginInitInfo, ExternalPluginKey,
HookableLifecycleEvent, LifecycleHookInitInfo, OracleInitInfo, PluginAuthority,
UpdateAuthority,
},
Asset,
};
pub use setup::*;

use solana_program::pubkey;
use solana_program_test::tokio;
use solana_sdk::{pubkey::Pubkey, signature::Keypair, signer::Signer, transaction::Transaction};

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

let asset = Keypair::new();
create_asset(
&mut context,
CreateAssetHelperArgs {
owner: None,
payer: None,
asset: &asset,
data_state: None,
name: None,
uri: None,
authority: None,
update_authority: None,
collection: None,
plugins: vec![],
external_plugins: vec![ExternalPluginInitInfo::LifecycleHook(
LifecycleHookInitInfo {
hooked_program: pubkey!("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),
init_plugin_authority: Some(PluginAuthority::UpdateAuthority),
lifecycle_checks: Some(vec![(
HookableLifecycleEvent::Transfer,
ExternalCheckResult { flags: 1 },
)]),
extra_accounts: None,
data_authority: Some(PluginAuthority::UpdateAuthority),
schema: None,
},
)],
},
)
.await
.unwrap();

blockiosaurus marked this conversation as resolved.
Show resolved Hide resolved
let owner = context.payer.pubkey();
let update_authority = context.payer.pubkey();

let ix = RemoveExternalPluginV1Builder::new()
.asset(asset.pubkey())
.payer(context.payer.pubkey())
.key(ExternalPluginKey::LifecycleHook(pubkey!(
"MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"
)))
.instruction();

let tx = Transaction::new_signed_with_payer(
&[ix],
Some(&context.payer.pubkey()),
&[&context.payer],
context.last_blockhash,
);

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

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![],
},
)
.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);
}
blockiosaurus marked this conversation as resolved.
Show resolved Hide resolved

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

let asset = Keypair::new();
create_asset(
&mut context,
CreateAssetHelperArgs {
owner: None,
payer: None,
asset: &asset,
data_state: None,
name: None,
uri: None,
authority: None,
update_authority: None,
collection: None,
plugins: vec![],
external_plugins: vec![ExternalPluginInitInfo::Oracle(OracleInitInfo {
base_address: Pubkey::default(),
init_plugin_authority: Some(PluginAuthority::UpdateAuthority),
lifecycle_checks: Some(vec![(
HookableLifecycleEvent::Transfer,
ExternalCheckResult { flags: 1 },
)]),
pda: None,
})],
},
)
.await
.unwrap();

let owner = context.payer.pubkey();
let update_authority = context.payer.pubkey();

let ix = RemoveExternalPluginV1Builder::new()
.asset(asset.pubkey())
.payer(context.payer.pubkey())
.key(ExternalPluginKey::Oracle(Pubkey::default()))
.instruction();

let tx = Transaction::new_signed_with_payer(
&[ix],
Some(&context.payer.pubkey()),
&[&context.payer],
context.last_blockhash,
);

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

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![],
},
)
.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_remove_data_store() {
let mut context = program_test().start_with_context().await;

let asset = Keypair::new();
create_asset(
&mut context,
CreateAssetHelperArgs {
owner: None,
payer: None,
asset: &asset,
data_state: None,
name: None,
uri: None,
authority: None,
update_authority: None,
collection: None,
plugins: vec![],
external_plugins: vec![ExternalPluginInitInfo::DataStore(DataStoreInitInfo {
init_plugin_authority: Some(PluginAuthority::UpdateAuthority),
data_authority: PluginAuthority::UpdateAuthority,
schema: None,
})],
},
)
.await
.unwrap();

let owner = context.payer.pubkey();
let update_authority = context.payer.pubkey();

let ix = RemoveExternalPluginV1Builder::new()
.asset(asset.pubkey())
.payer(context.payer.pubkey())
.key(ExternalPluginKey::DataStore(
PluginAuthority::UpdateAuthority,
))
.instruction();

let tx = Transaction::new_signed_with_payer(
&[ix],
Some(&context.payer.pubkey()),
&[&context.payer],
context.last_blockhash,
);

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

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![],
},
)
.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);
}
Loading