Skip to content

e2e: add client tests #88

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

Merged
merged 8 commits into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 4 additions & 4 deletions scripts/tests.e2e.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#!/usr/bin/env bash
set -e

# build spacesvm-rs binary
# build spacesvm binary
# ./scripts/build.release.sh
#
# download from github, keep network running
# VM_PLUGIN_PATH=$(pwd)/target/release/spacesvm-rs ./scripts/tests.e2e.sh
# VM_PLUGIN_PATH=$(pwd)/target/release/spacesvm ./scripts/tests.e2e.sh
#
# download from github, shut down network
# NETWORK_RUNNER_ENABLE_SHUTDOWN=1 VM_PLUGIN_PATH=$(pwd)/target/release/spacesvm-rs ./scripts/tests.e2e.sh
# NETWORK_RUNNER_ENABLE_SHUTDOWN=1 VM_PLUGIN_PATH=$(pwd)/target/release/spacesvm ./scripts/tests.e2e.sh
#
# use custom avalanchego binary
# VM_PLUGIN_PATH=$(pwd)/target/release/timestampvm ./scripts/tests.e2e.sh ~/go/src/github.com/ava-labs/avalanchego/build/avalanchego
# VM_PLUGIN_PATH=$(pwd)/target/release/spacesvm ./scripts/tests.e2e.sh ~/go/src/github.com/ava-labs/avalanchego/build/avalanchego
#
if ! [[ "$0" =~ scripts/tests.e2e.sh ]]; then
echo "must be run from repository root"
Expand Down
6 changes: 3 additions & 3 deletions spaces-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ clap = { version = "4.0", features = ["derive"] }
hex = "0.4.3"
jsonrpc-core = "18.0.0"
log = "0.4.17"
serde = { version = "1.0.147", features = ["derive"] }
serde_json = "1.0.87"
serde = { version = "1.0.148", features = ["derive"] }
serde_json = "1.0.89"
spacesvm = { path = "../spacesvm" }
tokio = { version = "1.22.0", features = ["full"] }
tokio = { version = "1.22.0", features = [] }
46 changes: 18 additions & 28 deletions spaces-cli/src/bin/spaces-cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ use std::error;
use clap::{Parser, Subcommand};
use jsonrpc_core::futures;
use spacesvm::{
api::{
client::{claim_tx, delete_tx, get_or_create_pk, set_tx, Client, Uri},
DecodeTxArgs, IssueTxArgs, ResolveArgs,
},
chain::tx::{decoder, unsigned::TransactionData},
api::client::{claim_tx, delete_tx, get_or_create_pk, set_tx, Client, Uri},
chain::tx::unsigned::TransactionData,
};

#[derive(Subcommand, Debug)]
Expand Down Expand Up @@ -46,51 +43,44 @@ struct Cli {
#[command(subcommand)]
command: Command,
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn error::Error>> {
let cli = Cli::parse();

let secret_key = get_or_create_pk(&cli.private_key_file)?;
let private_key = get_or_create_pk(&cli.private_key_file)?;
let uri = cli.endpoint.parse::<Uri>()?;
let mut client = Client::new(uri);
let client = Client::new(uri);
client.set_private_key(private_key).await;

if let Command::Get { space, key } = &cli.command {
let resp = futures::executor::block_on(client.resolve(ResolveArgs {
space: space.as_bytes().to_vec(),
key: key.as_bytes().to_vec(),
}))
.map_err(|e| e.to_string())?;
let resp = client
.resolve(space, key)
.await
.map_err(|e| e.to_string())?;
log::debug!("resolve response: {:?}", resp);

println!("{}", serde_json::to_string(&resp)?);
return Ok(());
}

if let Command::Ping {} = &cli.command {
let resp = futures::executor::block_on(client.ping()).map_err(|e| e.to_string())?;
let resp = client.ping().await.map_err(|e| e.to_string())?;

println!("{}", serde_json::to_string(&resp)?);
return Ok(());
}

// decode tx
let tx_data = command_to_tx(cli.command)?;
let resp = futures::executor::block_on(client.decode_tx(DecodeTxArgs { tx_data }))
.map_err(|e| e.to_string())?;
let resp = futures::executor::block_on(client.decode_tx(tx_data)).map_err(|e| e.to_string())?;

let typed_data = &resp.typed_data;

// create signature
let dh = decoder::hash_structured_data(typed_data)?;
let sig = secret_key.sign_digest(&dh.as_bytes())?;

// issue tx
let resp = futures::executor::block_on(client.issue_tx(IssueTxArgs {
typed_data: resp.typed_data,
signature: sig.to_bytes().to_vec(),
}))
.map_err(|e| e.to_string())?;
let resp = client
.issue_tx(typed_data)
.await
.map_err(|e| e.to_string())?;
println!("{}", serde_json::to_string(&resp)?);

Ok(())
Expand All @@ -99,9 +89,9 @@ async fn main() -> Result<(), Box<dyn error::Error>> {
/// Takes a TX command and returns transaction data.
fn command_to_tx(command: Command) -> std::io::Result<TransactionData> {
match command {
Command::Claim { space } => Ok(claim_tx(space)),
Command::Set { space, key, value } => Ok(set_tx(space, key, value.as_bytes().to_vec())),
Command::Delete { space, key } => Ok(delete_tx(space, key)),
Command::Claim { space } => Ok(claim_tx(&space)),
Command::Set { space, key, value } => Ok(set_tx(&space, &key, &value)),
Command::Delete { space, key } => Ok(delete_tx(&space, &key)),
_ => Err(std::io::Error::new(
std::io::ErrorKind::Other,
"not a supported tx",
Expand Down
18 changes: 9 additions & 9 deletions spacesvm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,40 @@ name = "spacesvm"
path = "src/bin/spaces/main.rs"

[dependencies]
avalanche-types = { version = "0.0.140", features = ["subnet"] }
avalanche-types = { version = "0.0.144", features = ["subnet"] }
byteorder = "1.4.3"
chrono = "0.4.22"
chrono = "0.4.23"
crossbeam-channel = "0.5.6"
derivative = "2.2.0"
dyn-clone = "1.0.9"
ethereum-types = { version = "0.14.0" }
clap = { version = "4.0.22", features = ["cargo", "derive"] }
clap = { version = "4.0.27", features = ["cargo", "derive"] }
eip-712 = "0.1.0"
env_logger = "0.9.3"
env_logger = "0.10.0"
hex = "0.4.3"
http = "0.2.8"
hyper = "0.14.23"
jsonrpc-core = "18.0.0"
jsonrpc-core-client = { version = "18.0.0" }
jsonrpc-derive = "18.0"
log = "0.4.17"
lru = "0.8.0"
lru = "0.8.1"
prost = "0.11.2"
ripemd = "0.1.3"
semver = "1.0.14"
serde = { version = "1.0.147", features = ["derive"] }
serde_json = "1.0.87"
serde = { version = "1.0.148", features = ["derive"] }
serde_json = "1.0.89"
serde_yaml = "0.9.14"
sha3 = "0.10.6"
tokio = { version = "1.21.2", features = ["fs", "rt-multi-thread"] }
tokio = { version = "1.22.0", features = ["fs", "rt-multi-thread"] }
tokio-stream = { version = "0.1.11", features = ["net"] }
tonic = { version = "0.8.2", features = ["gzip"] }
tonic-health = "0.7"
typetag = "0.2"

[dev-dependencies]
jsonrpc-tcp-server = "18.0.0"
futures-test = "0.3.24"
futures-test = "0.3.25"

[[test]]
name = "integration"
Expand Down
Loading