-
Notifications
You must be signed in to change notification settings - Fork 2
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
Add remove program function to entropy-client
#1023
Changes from 3 commits
720966f
03a4be9
26287f6
9d10088
3e3db5f
399d2d8
a349405
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -228,14 +228,14 @@ pub async fn store_program( | |
auxiliary_data_interface: Vec<u8>, | ||
oracle_data_pointer: Vec<u8>, | ||
) -> Result<<EntropyConfig as Config>::Hash, ClientError> { | ||
let update_program_tx = entropy::tx().programs().set_program( | ||
let set_program_tx = entropy::tx().programs().set_program( | ||
program, | ||
configuration_interface, | ||
auxiliary_data_interface, | ||
oracle_data_pointer, | ||
); | ||
let in_block = | ||
submit_transaction_with_pair(api, rpc, deployer_pair, &update_program_tx, None).await?; | ||
submit_transaction_with_pair(api, rpc, deployer_pair, &set_program_tx, None).await?; | ||
let result_event = in_block.find_first::<entropy::programs::events::ProgramCreated>()?; | ||
Ok(result_event.ok_or(ClientError::CannotConfirmProgramCreated)?.program_hash) | ||
} | ||
|
@@ -254,6 +254,35 @@ pub async fn update_programs( | |
submit_transaction_with_pair(entropy_api, rpc, deployer_pair, &update_pointer_tx, None).await?; | ||
Ok(()) | ||
} | ||
|
||
/// Removed a stored a program with a given hash | ||
#[tracing::instrument( | ||
skip_all, | ||
fields( | ||
signature_request_account, | ||
deployer = ?deployer_pair.public(), | ||
) | ||
)] | ||
pub async fn remove_program( | ||
api: &OnlineClient<EntropyConfig>, | ||
rpc: &LegacyRpcMethods<EntropyConfig>, | ||
deployer_pair: &sr25519::Pair, | ||
program_hash: <EntropyConfig as Config>::Hash, | ||
) -> Result<(), ClientError> { | ||
let remove_program_tx = entropy::tx().programs().remove_program(program_hash); | ||
let in_block = | ||
submit_transaction_with_pair(api, rpc, deployer_pair, &remove_program_tx, None).await?; | ||
Comment on lines
+271
to
+273
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something we might want to do is check if the error we get here is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I find these dispatch errors not so easy to do anything with, because you get a module error which contains the actual error from the pallet but doesnt directly publicly expose it, you have to get 'ModuleErrorDetails'. |
||
|
||
let event = in_block | ||
.find_first::<entropy::programs::events::ProgramRemoved>()? | ||
.ok_or(ClientError::CannotConfirmProgramRemoved)?; | ||
|
||
if event.old_program_hash != program_hash { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dunno if this is really needed but why not |
||
return Err(ClientError::CannotConfirmProgramRemoved); | ||
} | ||
Ok(()) | ||
} | ||
|
||
/// Get info on all registered accounts | ||
pub async fn get_accounts( | ||
api: &OnlineClient<EntropyConfig>, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
use crate::{ | ||
chain_api::{ | ||
entropy::{ | ||
runtime_types::pallet_staking_extension::pallet::ServerInfo, staking_extension::events, | ||
self, runtime_types::pallet_staking_extension::pallet::ServerInfo, | ||
staking_extension::events, | ||
}, | ||
get_api, get_rpc, | ||
}, | ||
change_endpoint, change_threshold_accounts, | ||
change_endpoint, change_threshold_accounts, remove_program, store_program, | ||
substrate::query_chain, | ||
}; | ||
use entropy_testing_utils::{ | ||
constants::TEST_PROGRAM_WASM_BYTECODE, substrate_context::test_context_stationary, | ||
}; | ||
use entropy_testing_utils::substrate_context::test_context_stationary; | ||
use serial_test::serial; | ||
use sp_core::Pair; | ||
use sp_keyring::AccountKeyring; | ||
|
@@ -68,3 +72,41 @@ async fn test_change_threshold_accounts() { | |
) | ||
); | ||
} | ||
|
||
#[tokio::test] | ||
#[serial] | ||
async fn test_store_and_remove_program() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if it's worth testing since I'm pretty sure we check this elsewhere, but this should fail if the program's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok i have added an extra test for that. |
||
let program_owner = AccountKeyring::Ferdie.pair(); | ||
let substrate_context = test_context_stationary().await; | ||
|
||
let api = get_api(&substrate_context.node_proc.ws_url).await.unwrap(); | ||
let rpc = get_rpc(&substrate_context.node_proc.ws_url).await.unwrap(); | ||
|
||
// Store a program | ||
let program_hash = store_program( | ||
&api, | ||
&rpc, | ||
&program_owner, | ||
TEST_PROGRAM_WASM_BYTECODE.to_owned(), | ||
vec![], | ||
vec![], | ||
vec![], | ||
) | ||
.await | ||
.unwrap(); | ||
|
||
// Check that the program was stored | ||
let program_query = entropy::storage().programs().programs(program_hash); | ||
let program_info = query_chain(&api, &rpc, program_query, None).await.unwrap().unwrap(); | ||
assert_eq!(program_info.deployer.0, program_owner.public().0); | ||
|
||
// Remove the program | ||
remove_program(&api, &rpc, &program_owner, program_hash).await.unwrap(); | ||
|
||
// Check that the program is no longer stored | ||
let program_query = entropy::storage().programs().programs(program_hash); | ||
assert!(query_chain(&api, &rpc, program_query, None).await.unwrap().is_none()); | ||
|
||
// Removing program fails because program has already been removed | ||
assert!(remove_program(&api, &rpc, &program_owner, program_hash).await.is_err()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated to this PR but just to tidy