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

Make access to the validator app sequential #2

Merged
merged 1 commit into from
Feb 12, 2019
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ ledger = "0.0.9"
quick-error = "1.2.2"
byteorder = "1.2.4"
matches = "0.1.8"
lazy_static = "1.2.0"

[dev-dependencies]
ed25519-dalek = "0.8.1"
Expand Down
56 changes: 32 additions & 24 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,19 @@ extern crate sha2;
#[cfg(test)]
extern crate ed25519_dalek;

#[cfg(test)]
#[macro_use]
extern crate lazy_static;

#[cfg(test)]
mod tests {
use CosmosValidatorApp;
use std::sync::Mutex;

lazy_static! {
static ref APP: Mutex<CosmosValidatorApp> = Mutex::new(CosmosValidatorApp::connect().unwrap());
}

#[test]
fn derivation_path() {
use to_bip32array;
Expand Down Expand Up @@ -264,27 +275,30 @@ mod tests {

#[test]
fn version() {
use CosmosValidatorApp;

let app = CosmosValidatorApp::connect().unwrap();
let app = APP.lock().unwrap();

let version = app.version().unwrap();
let resp = app.version();

println!("mode {}", version.mode);
println!("major {}", version.major);
println!("minor {}", version.minor);
println!("patch {}", version.patch);

assert_eq!(version.mode, 0xFF);
assert_eq!(version.major, 0x00);
assert!(version.minor >= 0x04);
match resp {
Ok(version) => {
println!("mode {}", version.mode);
println!("major {}", version.major);
println!("minor {}", version.minor);
println!("patch {}", version.patch);

assert_eq!(version.mode, 0xFF);
assert_eq!(version.major, 0x00);
assert!(version.minor >= 0x04);
}
Err(err) => {
eprintln!("Error: {:?}", err);
}
}
}

#[test]
fn public_key() {
use CosmosValidatorApp;

let app = CosmosValidatorApp::connect().unwrap();
let app = APP.lock().unwrap();
let resp = app.public_key();

match resp {
Expand All @@ -300,10 +314,9 @@ mod tests {

#[test]
fn sign_empty() {
use CosmosValidatorApp;
use Error;

let app = CosmosValidatorApp::connect().unwrap();
let app = APP.lock().unwrap();

let some_message0 = b"";

Expand All @@ -314,9 +327,7 @@ mod tests {

#[test]
fn sign_verify() {
use CosmosValidatorApp;

let app = CosmosValidatorApp::connect().unwrap();
let app = APP.lock().unwrap();

let some_message1 = [
0x8, // (field_number << 3) | wire_type
Expand Down Expand Up @@ -348,7 +359,6 @@ mod tests {
match app.sign(&some_message2) {
Ok(sig) => {
use sha2::Sha512;
use sha2::Digest;
use ed25519_dalek::PublicKey;
use ed25519_dalek::Signature;

Expand All @@ -368,9 +378,7 @@ mod tests {

#[test]
fn sign_many() {
use CosmosValidatorApp;

let app = CosmosValidatorApp::connect().unwrap();
let app = APP.lock().unwrap();

// First, get public key
let resp = app.public_key();
Expand Down