Skip to content

Commit

Permalink
Nits + clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
bigspider committed Oct 11, 2024
1 parent 7936ef9 commit 3985722
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
10 changes: 6 additions & 4 deletions apps/test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ This will be a test V-app.
- [app](app) contains the Risc-V app, based on the V-app Sdk.
- [client](client) folder contains the client of the app, based on the V-app Client Sdk.

The client is a library crate (see [lib.rs](client/src/lib.rs)), but it also has a test executable ([main.rs](client/src/main.rs)) to interact with the app from the command line.

## Build the V-App

### Risc-V
Expand All @@ -21,7 +23,7 @@ In order to build the app for the native target, enter the `app` folder and run:
cargo build --release --target=x86_64-unknown-linux-gnu
```

## Run the V-App on Vanadium
## Run the V-App

Make sure you built the V-App for the Risc-V target.

Expand All @@ -39,7 +41,7 @@ If you want to run the V-app on a real device, execute instead:
cargo run -- --hid
```

If you want to run the V-app natively, use:
If you want to run the V-app natively, after building it for the native target, use:

```sh
cargo run -- --native
Expand All @@ -50,10 +52,10 @@ If you want to run the V-app natively, use:

Once the client is running, these are the available commands:

- `reverse <hex_buffer>` - Reversed the given buffer.
- `reverse <hex_buffer>` - Reverses the given buffer.
- `sha256 <hex_buffer>` - Computes the sha256 hash of the given buffer.
- `b58enc <hex_buffer>` - Computes the base58 encoding of the given buffer (the output is in hex as well).
- `addnumbers <n>` - Computes the sum of the numbers between `1` and `n`.
- `nprimes <n>` - Counts the number of primes up to `n` using the Sieve of Erathostenes.
- `nprimes <n>` - Counts the number of primes up to `n` using the Sieve of Eratosthenes.
- `panic <panic message>` - Cause the V-App to panic. Everything written after 'panic' is the panic message.
- An empty command will exit the V-App.
2 changes: 1 addition & 1 deletion apps/test/app/src/handlers/sha256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ use alloc::vec::Vec;
use sha2::Digest;

pub fn handle_sha256(data: &[u8]) -> Vec<u8> {
sha2::Sha256::digest(&data).to_vec()
sha2::Sha256::digest(data).to_vec()
}
6 changes: 4 additions & 2 deletions apps/test/app/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#![feature(start)]
#![cfg_attr(target_arch = "riscv32", no_std, no_main)]

use core::ptr::addr_of;

#[cfg(target_arch = "riscv32")]
use sdk::fatal;

Expand Down Expand Up @@ -47,7 +49,7 @@ pub fn main(_: isize, _: *const *const u8) -> isize {

// TODO: remove
unsafe {
core::ptr::read_volatile(&APP_NAME);
core::ptr::read_volatile(addr_of!(APP_NAME));
}

// TODO: remove
Expand All @@ -64,7 +66,7 @@ pub fn main(_: isize, _: *const *const u8) -> isize {

// sdk::ux::app_loading_start("Handling request...\x00");

if msg.len() == 0 {
if msg.is_empty() {
sdk::exit(0);
}

Expand Down
4 changes: 1 addition & 3 deletions apps/test/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,7 @@ impl TestClient {

pub async fn exit(&mut self) -> Result<i32, &'static str> {
match self.app_client.send_message(Vec::new()).await {
Ok(_) => {
return Err("Exit message shouldn't return!");
}
Ok(_) => Err("Exit message shouldn't return!"),
Err(e) => match e {
VAppExecutionError::AppExited(status) => Ok(status),
_ => Err("Unexpected error"),
Expand Down
6 changes: 3 additions & 3 deletions apps/test/client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ fn parse_u32(s: &str) -> Result<u32, String> {
}

fn parse_command(line: &str) -> Result<CliCommand, String> {
let mut tokens = line.trim().split_whitespace();
let mut tokens = line.split_whitespace();
if let Some(command) = tokens.next() {
match command {
"reverse" | "sha256" | "b58enc" | "b58encode" => {
"reverse" | "sha256" | "b58enc" => {
let arg = tokens.next().unwrap_or("");
let buffer = parse_hex_buffer(arg).map_err(|e| e.to_string())?;
match command {
Expand Down Expand Up @@ -94,7 +94,7 @@ fn parse_command(line: &str) -> Result<CliCommand, String> {
_ => Err(format!("Unknown command: '{}'", command)),
}
} else {
return Ok(CliCommand::Exit);
Ok(CliCommand::Exit)
}
}

Expand Down

0 comments on commit 3985722

Please sign in to comment.