Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
prozacchiwawa committed Jul 20, 2024
1 parent 026fda1 commit 3db6734
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/classic/clvm_tools/stages/stage_0.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use clvm_rs::allocator::{Allocator, NodePtr};
use clvm_rs::chia_dialect::{ChiaDialect, NO_UNKNOWN_OPS, ENABLE_BLS_OPS_OUTSIDE_GUARD};
use clvm_rs::chia_dialect::{ChiaDialect, ENABLE_BLS_OPS_OUTSIDE_GUARD, NO_UNKNOWN_OPS};
use clvm_rs::cost::Cost;
use clvm_rs::reduction::Response;

Expand Down
6 changes: 4 additions & 2 deletions src/classic/clvm_tools/stages/stage_2/operators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::path::PathBuf;
use std::rc::Rc;

use clvm_rs::allocator::{Allocator, NodePtr, SExp};
use clvm_rs::chia_dialect::{ChiaDialect, NO_UNKNOWN_OPS, ENABLE_BLS_OPS_OUTSIDE_GUARD};
use clvm_rs::chia_dialect::{ChiaDialect, ENABLE_BLS_OPS_OUTSIDE_GUARD, NO_UNKNOWN_OPS};
use clvm_rs::cost::Cost;
use clvm_rs::dialect::{Dialect, OperatorSet};
use clvm_rs::reduction::{EvalErr, Reduction, Response};
Expand Down Expand Up @@ -122,7 +122,9 @@ impl Drop for CompilerOperators {

impl CompilerOperatorsInternal {
pub fn new(source_file: &str, search_paths: Vec<String>, symbols_extra_info: bool) -> Self {
let base_dialect = Rc::new(ChiaDialect::new(NO_UNKNOWN_OPS | ENABLE_BLS_OPS_OUTSIDE_GUARD));
let base_dialect = Rc::new(ChiaDialect::new(
NO_UNKNOWN_OPS | ENABLE_BLS_OPS_OUTSIDE_GUARD,
));
let base_runner = Rc::new(DefaultProgramRunner::new());
CompilerOperatorsInternal {
base_dialect,
Expand Down
12 changes: 12 additions & 0 deletions src/tests/classic/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2543,3 +2543,15 @@ fn test_include_bin_should_not_be_parsed() {
let result = do_basic_brun(&vec!["brun".to_string(), program]);
assert_eq!(result.trim(), "\"'test\"");
}

#[test]
fn test_coinid_outside_guard() {
let result = do_basic_run(&vec![
"run".to_string(),
"(coinid (sha256 3) (sha256 3) 4)".to_string(),
]);
assert_eq!(
result.trim(),
"0x9f7f12b86a583805a4442879b7b5b531469e45c7e753e5fd431058e90bf3fbec"
);
}
24 changes: 24 additions & 0 deletions src/tests/compiler/cldb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ where
}

if let Some(result) = cldbrun.step(&mut allocator) {
eprintln!("{:?}", result);
output = result;
if !viewer.show(&cldbrun.current_step(), Some(output.clone())) {
return None;
Expand Down Expand Up @@ -455,3 +456,26 @@ fn test_cldb_hierarchy_before_hex() {

compare_run_output(result, run_entries);
}

#[test]
fn test_cldb_coinid_outside_guard() {
let filename = "coinid.clvm";
let loc = Srcloc::start(filename);
let program = "(coinid (sha256 (q . 3)) (sha256 (q . 3)) (q . 4))";
let parsed = parse_sexp(loc.clone(), program.as_bytes().iter().copied()).expect("should parse");
let args = Rc::new(SExp::Nil(loc));
let program_lines = Rc::new(vec![program.to_string()]);

assert_eq!(
run_clvm_in_cldb(
filename,
program_lines,
parsed[0].clone(),
HashMap::new(),
args,
&mut DoesntWatchCldb {},
FAVOR_HEX,
),
Some("0x9f7f12b86a583805a4442879b7b5b531469e45c7e753e5fd431058e90bf3fbec".to_string())
);
}

0 comments on commit 3db6734

Please sign in to comment.