Skip to content

Commit

Permalink
Move test
Browse files Browse the repository at this point in the history
  • Loading branch information
Rigidity committed Nov 27, 2024
1 parent 51d9a32 commit 4ab98e2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 33 deletions.
38 changes: 38 additions & 0 deletions src/collect_dialect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,41 @@ where
Ok(Reduction(cost, NodePtr::NIL))
}
}

#[cfg(test)]
mod tests {
use crate::{run_program, ChiaDialect, SExp};

use super::*;

#[test]
fn test_signature_collection() -> anyhow::Result<()> {
let mut a = Allocator::new();

let op = a.new_atom(&[0x13, 0xd6, 0x1f, 0x00])?;
let fake_arg = a.new_atom(&[1, 2, 3])?;
let op_q = a.one();
let quoted_fake_arg = a.new_pair(op_q, fake_arg)?;
let args = a.new_pair(quoted_fake_arg, NodePtr::NIL)?;
let program = a.new_pair(op, args)?;

let dialect = CollectDialect::new(ChiaDialect::new(0));

let reduction = run_program(&mut a, &dialect, program, NodePtr::NIL, u64::MAX).unwrap();
let collected = dialect.collect();

assert!(a.atom(reduction.1).is_empty());
assert_eq!(collected.len(), 1);

let collected = collected[0];
assert_eq!(collected.op, op);

let SExp::Pair(f, r) = a.sexp(collected.args) else {
unreachable!();
};
assert!(a.atom(r).is_empty());
assert_eq!(f, fake_arg);

Ok(())
}
}
33 changes: 0 additions & 33 deletions src/run_program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,9 +549,7 @@ mod tests {
use super::*;

use crate::chia_dialect::{ENABLE_KECCAK, ENABLE_KECCAK_OPS_OUTSIDE_GUARD, NO_UNKNOWN_OPS};
use crate::collect_dialect::CollectDialect;
use crate::test_ops::parse_exp;
use crate::ChiaDialect;

use rstest::rstest;

Expand Down Expand Up @@ -1581,35 +1579,4 @@ mod tests {

assert_eq!(result.unwrap().0, cost);
}

#[test]
fn test_signature_collection() -> anyhow::Result<()> {
let mut a = Allocator::new();

let op = a.new_atom(&[0x13, 0xd6, 0x1f, 0x00])?;
let fake_arg = a.new_atom(&[1, 2, 3])?;
let op_q = a.one();
let quoted_fake_arg = a.new_pair(op_q, fake_arg)?;
let args = a.new_pair(quoted_fake_arg, NodePtr::NIL)?;
let program = a.new_pair(op, args)?;

let dialect = CollectDialect::new(ChiaDialect::new(0));

let reduction = run_program(&mut a, &dialect, program, NodePtr::NIL, u64::MAX).unwrap();
let collected = dialect.collect();

assert!(a.atom(reduction.1).is_empty());
assert_eq!(collected.len(), 1);

let collected = collected[0];
assert_eq!(collected.op, op);

let SExp::Pair(f, r) = a.sexp(collected.args) else {
unreachable!();
};
assert!(a.atom(r).is_empty());
assert_eq!(f, fake_arg);

Ok(())
}
}

0 comments on commit 4ab98e2

Please sign in to comment.