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

test: add unit test for pop test contract #70

Merged
merged 12 commits into from
Mar 22, 2024
30 changes: 23 additions & 7 deletions src/engines/contract_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,21 +171,37 @@ pub async fn dry_run_call(
mod tests {
use super::*;
use std::fs;
use tempdir;
use std::path::PathBuf;
brunopgalvao marked this conversation as resolved.
Show resolved Hide resolved
use tempdir::TempDir;

fn setup_test_environment() -> Result<TempDir, Box<dyn std::error::Error>> {
brunopgalvao marked this conversation as resolved.
Show resolved Hide resolved
let temp_contract_dir = TempDir::new("test_folder")?;
let result: anyhow::Result<()> = create_smart_contract("test".to_string(), &Some(PathBuf::from(temp_contract_dir.path())));
assert!(result.is_ok(), "Failed to create smart contract");
brunopgalvao marked this conversation as resolved.
Show resolved Hide resolved

Ok(temp_contract_dir)
}

#[test]
fn test_create_smart_contract() -> Result<(), Box<dyn std::error::Error>> {
let temp_dir = tempdir::TempDir::new("test_folder")?;
let result: anyhow::Result<()> =
create_smart_contract("test".to_string(), &Some(PathBuf::from(temp_dir.path())));
assert!(result.is_ok());
let temp_contract_dir = setup_test_environment()?;

// Verify that the generated smart contract contains the expected content
let generated_file_content = fs::read_to_string(temp_dir.path().join("test/lib.rs"))?;
let generated_file_content = fs::read_to_string(temp_contract_dir.path().join("test/lib.rs"))?;
brunopgalvao marked this conversation as resolved.
Show resolved Hide resolved

assert!(generated_file_content.contains("#[ink::contract]"));
assert!(generated_file_content.contains("mod test {"));

Ok(())
}
}

#[test]
fn test_test_smart_contract() -> Result<(), Box<dyn std::error::Error>> {
brunopgalvao marked this conversation as resolved.
Show resolved Hide resolved
let temp_contract_dir = setup_test_environment()?;
brunopgalvao marked this conversation as resolved.
Show resolved Hide resolved

let result = test_smart_contract(&Some(temp_contract_dir.path().join("test")));

assert!(result.is_ok(), "Result should be Ok");
Ok(())
}
}
Loading