Skip to content

Commit

Permalink
Add a command to the test-cli to remove a program
Browse files Browse the repository at this point in the history
  • Loading branch information
ameba23 committed Aug 22, 2024
1 parent 720966f commit 03a4be9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
9 changes: 8 additions & 1 deletion crates/test-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,14 @@ a program you can use the `store-program` command.
You need to give the account which will store the program, and the path to a program binary file you
wish to store, for example:

`entropy-test-cli store-program ./crates/testing-utils/example_barebones_with_auxilary.wasm //Alice`
`entropy-test-cli store-program ./crates/testing-utils/example_barebones_with_auxilary.wasm -m //Alice`

### Remove program

To remove a program you need to give the account which will 'owns' the program (the one which stored
it) and the hex-encoded hash of the program you wish to remove, for example:

`entropy-test-cli remove-program a2a16982fa6176e3fa9ae8dc408386ff040bf91196d3ec0aa981e5ba3fc1bbac -m //Alice`

### Update programs

Expand Down
28 changes: 27 additions & 1 deletion crates/test-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ use entropy_client::{
},
client::{
change_endpoint, change_threshold_accounts, get_accounts, get_api, get_programs, get_rpc,
jumpstart_network, register, sign, store_program, update_programs, VERIFYING_KEY_LENGTH,
jumpstart_network, register, remove_program, sign, store_program, update_programs,
VERIFYING_KEY_LENGTH,
},
};
use sp_core::{sr25519, Hasher, Pair};
Expand Down Expand Up @@ -127,6 +128,14 @@ enum CliCommand {
#[arg(short, long)]
mnemonic_option: Option<String>,
},
/// Remove a given program from chain
RemoveProgram {
/// The 32 bytes hash of the program to remove, encoded as hex
hash: String,
/// The mnemonic to use for the call, which must be the program deployer
#[arg(short, long)]
mnemonic_option: Option<String>,
},
/// Allows a validator to change their endpoint
ChangeEndpoint {
/// New endpoint to change to (ex. "127.0.0.1:3001")
Expand Down Expand Up @@ -283,6 +292,23 @@ pub async fn run_command(
.await?;
Ok(format!("Program stored {hash}"))
},
CliCommand::RemoveProgram { mnemonic_option, hash } => {
let mnemonic = if let Some(mnemonic_option) = mnemonic_option {
mnemonic_option
} else {
passed_mnemonic.expect("No Mnemonic set")
};
let keypair = <sr25519::Pair as Pair>::from_string(&mnemonic, None)?;
println!("Removing program using account: {}", keypair.public());

let hash: [u8; 32] = hex::decode(hash)?
.try_into()
.map_err(|_| anyhow!("Program hash must be 32 bytes"))?;

remove_program(&api, &rpc, &keypair, H256(hash)).await?;

Ok("Program removed".to_string())
},
CliCommand::UpdatePrograms { signature_verifying_key, mnemonic_option, programs } => {
let mnemonic = if let Some(mnemonic_option) = mnemonic_option {
mnemonic_option
Expand Down

0 comments on commit 03a4be9

Please sign in to comment.