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

Prepare test CLI for use in Programs repo #856

Merged
merged 8 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
22 changes: 11 additions & 11 deletions crates/test-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ repository ='https://github.com/entropyxyz/entropy-core'
edition ='2021'

[dependencies]
entropy-client ={ version="0.1.0", path="../client" }
clap ={ version="4.4.6", features=["derive"] }
colored ="2.0.4"
subxt ="0.35.3"
sp-core ="31.0.0"
anyhow ="1.0.86"
tokio ={ version="1.16", features=["macros", "rt-multi-thread", "io-util", "process"] }
hex ="0.4.3"
bincode ="1.3.3"
x25519-dalek ="2.0.1"
sp-runtime ={ version="32.0.0", default-features=false }
entropy-client={ version="0.1.0", path="../client" }
clap ={ version="4.4.6", features=["derive"] }
colored ="2.0.4"
subxt ="0.35.3"
sp-core ="31.0.0"
anyhow ="1.0.86"
tokio ={ version="1.16", features=["macros", "rt-multi-thread", "io-util", "process"] }
hex ="0.4.3"
bincode ="1.3.3"
x25519-dalek ="2.0.1"
sp-runtime ={ version="32.0.0", default-features=false }
29 changes: 8 additions & 21 deletions crates/test-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,9 @@ When using the local docker compose setup, be aware you need to set the TSS host

## Usage

### Account names
### Mnemonic

As this is a test client, there is no private key storage. Instead we use 'account names'. An 'account
name' is a string from which to derive a substrate sr25519 keypair. They are the same as
the account names the command line tool [`subkey`](https://docs.substrate.io/reference/command-line-tools/subkey) uses.

For example the name `Alice` will give you the same keypair as `subkey inspect //Alice` will give you.

You can use `subkey inspect` to find the seed, private key and account ID associated with a name you choose.

With this `test-cli`, giving the `//` prefix is optional. That is, `Alice` and `//Alice` are identical. Note
however that account names are case sensitive, so `//Alice` and `//alice` are different accounts.
As this is a test client, there is no private key storage. Instead we pass in a mnemonic that can be stored as an enviroment variable or passed in on the command line

### Help

Expand Down Expand Up @@ -88,18 +79,14 @@ You also need to decide which ['access mode' or 'key visibility'](https://docs.e
you want to register with: private or public. If you are not sure, 'public' is the simplest 'vanilla'
access mode.

For example, to register with `//Alice` as the signature request account and `//Bob` as the program
modification account, in permissioned access mode, using the `template_barebones` program:
For example, to register with `//Alice` as the signature request account in public access mode, using the `template_barebones` program:

`entropy-test-cli register Alice public template_barebones.wasm`
`entropy-test-cli register public template_barebones.wasm //Alice`

Example of registering in private access mode, with two programs, one given as a binary file and one
Example of registering in public access mode, with two programs, one given as a binary file and one
given as a hash of an existing program:

`entropy-test-cli register Alice private my-program.wasm 3b3993c957ed9342cbb011eb9029c53fb253345114eff7da5951e98a41ba5ad5`

When registering with private access mode, a keyshare file will be written to the directory where you
run the command. You must make subsequent `sign` commands in the same directory.
`entropy-test-cli register public my-program.wasm 3b3993c957ed9342cbb011eb9029c53fb253345114eff7da5951e98a41ba5ad5 //Alice`

If registration was successful you will see the verifying key of your account, which is the public
secp256k1 key of your distributed keypair. You will need this in order to specify the account when
Expand Down Expand Up @@ -129,7 +116,7 @@ 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 Alice ./crates/testing-utils/example_barebones_with_auxilary.wasm`
`entropy-test-cli store-program ./crates/testing-utils/example_barebones_with_auxilary.wasm //Alice`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here


### Update programs

Expand All @@ -138,6 +125,6 @@ account. It takes the signature verifying key, and the program modification acco
programs to evaluate when signing. Programs may be given as either the path to a .wasm binary file
or hashes of existing programs.

`entropy-test-cli update-programs 039fa2a16982fa6176e3fa9ae8dc408386ff040bf91196d3ec0aa981e5ba3fc1bb Alice my-new-program.wasm`
`entropy-test-cli update-programs 039fa2a16982fa6176e3fa9ae8dc408386ff040bf91196d3ec0aa981e5ba3fc1bb my-new-program.wasm //Alice`

Note that the program modification account must be funded for this to work.
10 changes: 5 additions & 5 deletions crates/test-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ pub async fn run_command(
std::env::var("ENTROPY_DEVNET").unwrap_or("ws://localhost:9944".to_string())
});

let passed_mnemonic = std::env::var("DEPLOYER_MNEMONIC").unwrap_or("//Alice".to_string());
let passed_mnemonic = std::env::var("DEPLOYER_MNEMONIC");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok got it this is good, i missed this before and thought passed_mnemonic was one of the arguments to run_command.


let api = get_api(&endpoint_addr).await?;
let rpc = get_rpc(&endpoint_addr).await?;
Expand All @@ -189,7 +189,7 @@ pub async fn run_command(
let mnemonic = if let Some(mnemonic_option) = mnemonic_option {
mnemonic_option
} else {
passed_mnemonic
passed_mnemonic.expect("No mnemonic set")
};

let program_keypair = <sr25519::Pair as Pair>::from_string(&mnemonic, None)?;
Expand Down Expand Up @@ -236,7 +236,7 @@ pub async fn run_command(
let mnemonic = if let Some(mnemonic_option) = mnemonic_option {
mnemonic_option
} else {
passed_mnemonic
passed_mnemonic.unwrap_or("//Alice".to_string())
};
// If an account name is not provided, use the Alice key
let user_keypair = <sr25519::Pair as Pair>::from_string(&mnemonic, None)?;
Expand Down Expand Up @@ -280,7 +280,7 @@ pub async fn run_command(
let mnemonic = if let Some(mnemonic_option) = mnemonic_option {
mnemonic_option
} else {
passed_mnemonic
passed_mnemonic.expect("No Mnemonic set")
};
let keypair = <sr25519::Pair as Pair>::from_string(&mnemonic, None)?;
println!("Storing program using account: {}", keypair.public());
Expand Down Expand Up @@ -320,7 +320,7 @@ pub async fn run_command(
let mnemonic = if let Some(mnemonic_option) = mnemonic_option {
mnemonic_option
} else {
passed_mnemonic
passed_mnemonic.expect("No Mnemonic set")
};
let program_keypair = <sr25519::Pair as Pair>::from_string(&mnemonic, None)?;
println!("Program account: {}", program_keypair.public());
Expand Down