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
41 changes: 33 additions & 8 deletions src/engines/contract_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,21 +170,46 @@ pub async fn dry_run_call(
#[cfg(test)]
mod tests {
use super::*;
use std::fs;
use std::{fs, path::PathBuf};
use anyhow::{Result, Error};

fn setup_test_environment() -> Result<tempfile::TempDir, Error> {
let temp_contract_dir = tempfile::tempdir().expect("Could not create temp dir");
let result: anyhow::Result<()> = create_smart_contract(
"test_contract".to_string(),
&Some(PathBuf::from(temp_contract_dir.path())),
);

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

Ok(temp_contract_dir)
}

#[test]
fn test_create_smart_contract() -> Result<(), Box<dyn std::error::Error>> {
let temp_dir = tempfile::tempdir()?;
let result: anyhow::Result<()> =
create_smart_contract("test".to_string(), &Some(PathBuf::from(temp_dir.path())));
assert!(result.is_ok());
fn test_contract_create() -> Result<(), Error> {
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_contract/lib.rs"))
.expect("Could not read file");

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

// Verify that the generated Cargo.toml file contains the expected content
fs::read_to_string(temp_contract_dir.path().join("test_contract/Cargo.toml"))
.expect("Could not read file");
Ok(())
}

#[test]
fn test_contract_test() -> Result<(), Error> {
let temp_contract_dir = setup_test_environment()?;

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

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