diff --git a/mls-rs-uniffi/Cargo.toml b/mls-rs-uniffi/Cargo.toml index e7fb4919..45005ad8 100644 --- a/mls-rs-uniffi/Cargo.toml +++ b/mls-rs-uniffi/Cargo.toml @@ -24,3 +24,7 @@ uniffi = "0.26.0" [target.'cfg(mls_build_async)'.dependencies] tokio = { version = "1.36.0", features = ["sync"] } + +[dev-dependencies] +tempfile = "3.10.0" +uniffi_bindgen = "0.26.0" diff --git a/mls-rs-uniffi/src/lib.rs b/mls-rs-uniffi/src/lib.rs index c7221750..48eca2a0 100644 --- a/mls-rs-uniffi/src/lib.rs +++ b/mls-rs-uniffi/src/lib.rs @@ -17,6 +17,9 @@ //! //! [UniFFI]: https://mozilla.github.io/uniffi-rs/ +#[cfg(test)] +pub mod test_utils; + use std::sync::Arc; #[cfg(not(mls_build_async))] @@ -572,3 +575,20 @@ impl Group { } } } + +#[cfg(all(test, not(mls_build_async)))] +mod sync_tests { + use crate::test_utils::run_python; + + #[test] + fn test_generate_signature_keypair() -> Result<(), Box> { + run_python( + r#" +from mls_rs_uniffi import CipherSuite, generate_signature_keypair + +signature_keypair = generate_signature_keypair(CipherSuite.CURVE25519_AES128) +assert signature_keypair.cipher_suite == CipherSuite.CURVE25519_AES128 +"#, + ) + } +} diff --git a/mls-rs-uniffi/src/test_utils.rs b/mls-rs-uniffi/src/test_utils.rs new file mode 100644 index 00000000..904443e7 --- /dev/null +++ b/mls-rs-uniffi/src/test_utils.rs @@ -0,0 +1,21 @@ +use uniffi_bindgen::bindings::python; + +/// Run Python code in `script`. +/// +/// The script can use `import mls_rs_uniffi` to get access to the +/// Python bindings. +pub fn run_python(script: &str) -> Result<(), Box> { + let tmp_dir = tempfile::TempDir::with_prefix("run-python-")?; + let script_path = tmp_dir.path().join("script.py"); + std::fs::write(&script_path, script)?; + + python::run_script( + tmp_dir.path().to_str().unwrap(), + "mls-rs-uniffi", + script_path.to_str().unwrap(), + vec![], + &uniffi_bindgen::bindings::RunScriptOptions::default(), + )?; + + Ok(()) +}