From 3db67345382152e9070dd814f99a9c73f9aa0729 Mon Sep 17 00:00:00 2001 From: arty Date: Sat, 20 Jul 2024 15:14:30 -0700 Subject: [PATCH] Add tests --- src/classic/clvm_tools/stages/stage_0.rs | 2 +- .../clvm_tools/stages/stage_2/operators.rs | 6 +++-- src/tests/classic/run.rs | 12 ++++++++++ src/tests/compiler/cldb.rs | 24 +++++++++++++++++++ 4 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/classic/clvm_tools/stages/stage_0.rs b/src/classic/clvm_tools/stages/stage_0.rs index 638b050d..f99ee3f6 100644 --- a/src/classic/clvm_tools/stages/stage_0.rs +++ b/src/classic/clvm_tools/stages/stage_0.rs @@ -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; diff --git a/src/classic/clvm_tools/stages/stage_2/operators.rs b/src/classic/clvm_tools/stages/stage_2/operators.rs index 19f00c63..11c3b8d0 100644 --- a/src/classic/clvm_tools/stages/stage_2/operators.rs +++ b/src/classic/clvm_tools/stages/stage_2/operators.rs @@ -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}; @@ -122,7 +122,9 @@ impl Drop for CompilerOperators { impl CompilerOperatorsInternal { pub fn new(source_file: &str, search_paths: Vec, 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, diff --git a/src/tests/classic/run.rs b/src/tests/classic/run.rs index ec6a31f2..4c3f687b 100644 --- a/src/tests/classic/run.rs +++ b/src/tests/classic/run.rs @@ -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" + ); +} diff --git a/src/tests/compiler/cldb.rs b/src/tests/compiler/cldb.rs index c22074a2..1a72143b 100644 --- a/src/tests/compiler/cldb.rs +++ b/src/tests/compiler/cldb.rs @@ -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; @@ -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()) + ); +}