diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index ba7611e..7c1ae6a 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -23,4 +23,4 @@ jobs: - name: Run unit tests run: cargo test - name: Build and run sample/rust - run: cd samples/rust && cargo run && cd ../.. + run: cd samples/rust && cargo run && cargo test && cd ../.. diff --git a/samples/python/main.py b/samples/python/main.py index df8fcb9..b6be45a 100644 --- a/samples/python/main.py +++ b/samples/python/main.py @@ -3,7 +3,7 @@ def sample(): print("Dlccryptlib sample app, Python") - entropy_hex = "99d33a674ce99d33a674ce99d33a674c" # oil x 12 + entropy_hex = "00000000000000000000000000000001" # abandon x 11 actual network = "signet"; xpub = dlccryptlib_py.init_with_entropy(entropy_hex, network) diff --git a/samples/rust/src/main.rs b/samples/rust/src/main.rs index 3ec744b..82ef91c 100644 --- a/samples/rust/src/main.rs +++ b/samples/rust/src/main.rs @@ -1,12 +1,16 @@ /// /// Sample Rust program to use dlccryptlib. /// + +#[cfg(test)] +mod test_lib; + use dlccryptlib; fn main() { println!("Dlccryptlib sample (Rust)"); - let entropy_hex = "99d33a674ce99d33a674ce99d33a674c"; // oil x 12 + let entropy_hex = "00000000000000000000000000000001"; // abandon x 11 actual let network = "signet"; let xpub = dlccryptlib::init_with_entropy_intern(entropy_hex, network).unwrap(); diff --git a/samples/rust/src/test_lib.rs b/samples/rust/src/test_lib.rs new file mode 100644 index 0000000..d81c3bc --- /dev/null +++ b/samples/rust/src/test_lib.rs @@ -0,0 +1,54 @@ +/// +/// Sample Rust program to use dlccryptlib. +/// +use dlccryptlib; + +const DUMMY_ENTROPY_STR: &str = "00000000000000000000000000000001"; +const DUMMY_HASH07_STR: &str = "0000000000000000000000000000000000000000000000000000000000000007"; +const NETWORK_SIGNET: &str = "signet"; +const DEFAULT_NETWORK: &str = NETWORK_SIGNET; + +#[test] +fn test_init_with_entropy() { + let xpub = dlccryptlib::init_with_entropy_intern(DUMMY_ENTROPY_STR, DEFAULT_NETWORK).unwrap(); + assert_eq!( + xpub, + "tpubDCxVvuZwEu4oZypCT3pzos1MUoVJyjTHjfrhKFXNBkAEqBmkkzEb2dUgzpZmBWbd6wZnNmm3Ex2suMnEFUMmayH2a6S49R4pTnoQttGrxUm" + ); +} + +#[test] +fn test_get_public_key() { + let _xpub = dlccryptlib::init_with_entropy_intern(DUMMY_ENTROPY_STR, DEFAULT_NETWORK).unwrap(); + + let pubkey0 = dlccryptlib::get_public_key_intern(0).unwrap(); + assert_eq!( + pubkey0.to_string(), + "031941e84b8d111e094aefc46e7181757c93a1da87c93ab519a40d9d765176e704" + ); + + let pubkey3 = dlccryptlib::get_public_key_intern(3).unwrap(); + assert_eq!( + pubkey3.to_string(), + "02a9569875400df2b7af9360fc5025de31fcd48ca8b658d61e535c3ff2f55aa128" + ); +} + +#[test] +fn test_sign_hash_ecdsa() { + let _xpub = dlccryptlib::init_with_entropy_intern(DUMMY_ENTROPY_STR, DEFAULT_NETWORK).unwrap(); + + let pubkey3 = dlccryptlib::get_public_key_intern(3).unwrap(); + assert_eq!( + pubkey3.to_string(), + "02a9569875400df2b7af9360fc5025de31fcd48ca8b658d61e535c3ff2f55aa128" + ); + + let hash = DUMMY_HASH07_STR; + let sig = dlccryptlib::sign_hash_ecdsa_intern(&hash, 3, &pubkey3).unwrap(); + + assert!(sig.len() >= 140 && sig.len() <= 146); + + // negative test, wrong index + assert!(dlccryptlib::sign_hash_ecdsa_intern(&hash, 31, &pubkey3).is_err()); +}