Skip to content

Commit 78ed1dd

Browse files
committed
Add (mock) API ed25519 (basic) tests
1 parent 145bab0 commit 78ed1dd

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

packages/std/src/mock.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,11 @@ mod tests {
485485
const SECP256K1_SIG_HEX: &str = "207082eb2c3dfa0b454e0906051270ba4074ac93760ba9e7110cd9471475111151eb0dbbc9920e72146fb564f99d039802bf6ef2561446eb126ef364d21ee9c4";
486486
const SECP256K1_PUBKEY_HEX: &str = "04051c1ee2190ecfb174bfe4f90763f2b4ff7517b70a2aec1876ebcfd644c4633fb03f3cfbd94b1f376e34592d9d41ccaf640bb751b00a1fadeb0c01157769eb73";
487487

488+
const ED25519_MSG_HEX: &str = "72";
489+
const ED25519_SIG_HEX: &str = "92a009a9f0d4cab8720e820b5f642540a2b27b5416503f8fb3762223ebdb69da085ac1e43e15996e458f3613d0f11d8c387b2eaeb4302aeeb00d291612bb0c00";
490+
const ED25519_PUBKEY_HEX: &str =
491+
"3d4017c3e843895a92b70aa74d1b7ebc9c982ccf2ec4968cc0cd55f12af4660c";
492+
488493
#[test]
489494
fn mock_info_arguments() {
490495
let name = HumanAddr("my name".to_string());
@@ -572,6 +577,45 @@ mod tests {
572577
assert!(!api.secp256k1_verify(&hash, &signature, &public_key));
573578
}
574579

580+
// Basic "works" test. Exhaustive tests on VM's side (packages/vm/src/imports.rs)
581+
#[test]
582+
fn ed25519_verify_works() {
583+
let api = MockApi::default();
584+
585+
let hash = hex::decode(ED25519_MSG_HEX).unwrap();
586+
let signature = hex::decode(ED25519_SIG_HEX).unwrap();
587+
let public_key = hex::decode(ED25519_PUBKEY_HEX).unwrap();
588+
589+
assert!(api.ed25519_verify(&hash, &signature, &public_key));
590+
}
591+
592+
// Basic "fails" test. Exhaustive tests on VM's side (packages/vm/src/imports.rs)
593+
#[test]
594+
fn ed25519_verify_fails() {
595+
let api = MockApi::default();
596+
597+
let mut msg = hex::decode(ED25519_MSG_HEX).unwrap();
598+
// alter msg
599+
msg[0] ^= 0x01;
600+
let signature = hex::decode(ED25519_SIG_HEX).unwrap();
601+
let public_key = hex::decode(ED25519_PUBKEY_HEX).unwrap();
602+
603+
assert!(!api.ed25519_verify(&msg, &signature, &public_key));
604+
}
605+
606+
// Basic "panics" test. Exhaustive tests on VM's side (packages/vm/src/imports.rs)
607+
#[test]
608+
#[should_panic(expected = "empty")]
609+
fn ed25519_verify_panics() {
610+
let api = MockApi::default();
611+
612+
let msg = hex::decode(ED25519_MSG_HEX).unwrap();
613+
let signature = hex::decode(ED25519_SIG_HEX).unwrap();
614+
let public_key = vec![];
615+
616+
assert!(!api.ed25519_verify(&msg, &signature, &public_key));
617+
}
618+
575619
#[test]
576620
fn bank_querier_all_balances() {
577621
let addr = HumanAddr::from("foobar");

0 commit comments

Comments
 (0)