Skip to content

Commit

Permalink
Add (mock) API ed25519 (basic) tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maurolacy committed Feb 12, 2021
1 parent 145bab0 commit 78ed1dd
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions packages/std/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,11 @@ mod tests {
const SECP256K1_SIG_HEX: &str = "207082eb2c3dfa0b454e0906051270ba4074ac93760ba9e7110cd9471475111151eb0dbbc9920e72146fb564f99d039802bf6ef2561446eb126ef364d21ee9c4";
const SECP256K1_PUBKEY_HEX: &str = "04051c1ee2190ecfb174bfe4f90763f2b4ff7517b70a2aec1876ebcfd644c4633fb03f3cfbd94b1f376e34592d9d41ccaf640bb751b00a1fadeb0c01157769eb73";

const ED25519_MSG_HEX: &str = "72";
const ED25519_SIG_HEX: &str = "92a009a9f0d4cab8720e820b5f642540a2b27b5416503f8fb3762223ebdb69da085ac1e43e15996e458f3613d0f11d8c387b2eaeb4302aeeb00d291612bb0c00";
const ED25519_PUBKEY_HEX: &str =
"3d4017c3e843895a92b70aa74d1b7ebc9c982ccf2ec4968cc0cd55f12af4660c";

#[test]
fn mock_info_arguments() {
let name = HumanAddr("my name".to_string());
Expand Down Expand Up @@ -572,6 +577,45 @@ mod tests {
assert!(!api.secp256k1_verify(&hash, &signature, &public_key));
}

// Basic "works" test. Exhaustive tests on VM's side (packages/vm/src/imports.rs)
#[test]
fn ed25519_verify_works() {
let api = MockApi::default();

let hash = hex::decode(ED25519_MSG_HEX).unwrap();
let signature = hex::decode(ED25519_SIG_HEX).unwrap();
let public_key = hex::decode(ED25519_PUBKEY_HEX).unwrap();

assert!(api.ed25519_verify(&hash, &signature, &public_key));
}

// Basic "fails" test. Exhaustive tests on VM's side (packages/vm/src/imports.rs)
#[test]
fn ed25519_verify_fails() {
let api = MockApi::default();

let mut msg = hex::decode(ED25519_MSG_HEX).unwrap();
// alter msg
msg[0] ^= 0x01;
let signature = hex::decode(ED25519_SIG_HEX).unwrap();
let public_key = hex::decode(ED25519_PUBKEY_HEX).unwrap();

assert!(!api.ed25519_verify(&msg, &signature, &public_key));
}

// Basic "panics" test. Exhaustive tests on VM's side (packages/vm/src/imports.rs)
#[test]
#[should_panic(expected = "empty")]
fn ed25519_verify_panics() {
let api = MockApi::default();

let msg = hex::decode(ED25519_MSG_HEX).unwrap();
let signature = hex::decode(ED25519_SIG_HEX).unwrap();
let public_key = vec![];

assert!(!api.ed25519_verify(&msg, &signature, &public_key));
}

#[test]
fn bank_querier_all_balances() {
let addr = HumanAddr::from("foobar");
Expand Down

0 comments on commit 78ed1dd

Please sign in to comment.