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

Execute UniFFI bindings via a simple Python test #87

Merged
merged 1 commit into from
Feb 26, 2024
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
4 changes: 4 additions & 0 deletions mls-rs-uniffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
20 changes: 20 additions & 0 deletions mls-rs-uniffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
//!
//! [UniFFI]: https://mozilla.github.io/uniffi-rs/

#[cfg(test)]
mulmarta marked this conversation as resolved.
Show resolved Hide resolved
pub mod test_utils;

use std::sync::Arc;

#[cfg(not(mls_build_async))]
Expand Down Expand Up @@ -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<dyn std::error::Error>> {
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
"#,
)
}
}
21 changes: 21 additions & 0 deletions mls-rs-uniffi/src/test_utils.rs
Original file line number Diff line number Diff line change
@@ -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<dyn std::error::Error>> {
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(())
}
Loading