Skip to content

Commit

Permalink
test: add unit test for pop test contract (#70)
Browse files Browse the repository at this point in the history
* add unit test for pop test contract
  • Loading branch information
brunopgalvao authored Mar 22, 2024
1 parent 7781723 commit 2458c20
Showing 1 changed file with 33 additions and 8 deletions.
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(())
}
}

0 comments on commit 2458c20

Please sign in to comment.