Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
add a couple of tests for % and modpow
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-o-how committed Aug 30, 2023
1 parent 647a749 commit 6a3acb5
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 20 deletions.
7 changes: 6 additions & 1 deletion src/classic/clvm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct KwAtomPair {
version: usize,
}

const KW_PAIRS: [KwAtomPair; 46] = [
const KW_PAIRS: [KwAtomPair; 48] = [
KwAtomPair {
v: &[0x01],
n: "q",
Expand Down Expand Up @@ -246,6 +246,11 @@ const KW_PAIRS: [KwAtomPair; 46] = [
n: "modpow",
version: 1,
},
KwAtomPair {
v: &[0x3d],
n: "%",
version: 1,
},
KwAtomPair {
v: &[0x13, 0xd6, 0x1f, 0x00],
n: "secp256k1_verify",
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/prims.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ pub fn prims() -> Vec<(Vec<u8>, SExp)> {
"modpow".as_bytes().to_vec(),
SExp::Integer(primloc.clone(), 60_u32.to_bigint().unwrap()),
),
(
"%".as_bytes().to_vec(),
SExp::Integer(primloc.clone(), 61_u32.to_bigint().unwrap()),
),
]
}

Expand Down
58 changes: 39 additions & 19 deletions src/tests/classic/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,25 +88,25 @@ fn brun_y_1_test() {
)
).trim(),
indoc! {"0x375f00
(\"fact\" 10) => 0x375f00
(\"fact\" 9) => 0x058980
(\"fact\" 8) => 0x009d80
(\"fact\" 7) => 5040
(\"fact\" 6) => 720
(\"fact\" 5) => 120
(\"fact\" 4) => 24
(\"fact\" 3) => 6
(\"fact\" 2) => 2
(\"fact\" 1) => 1"}
);
}
Expand All @@ -121,23 +121,23 @@ fn brun_v_test() {
))
.trim(),
indoc! {"8
(a 2 3) [((a (q 16 (q . 3) (q . 5)) 1))] => 8
3 [((a (q 16 (q . 3) (q . 5)) 1))] => ()
2 [((a (q 16 (q . 3) (q . 5)) 1))] => (a (q 16 (q . 3) (q . 5)) 1)
(a (q 16 (q . 3) (q . 5)) 1) [()] => 8
1 [()] => ()
(q 16 (q . 3) (q . 5)) [()] => (+ (q . 3) (q . 5))
(+ (q . 3) (q . 5)) [()] => 8
(q . 5) [()] => 5
(q . 3) [()] => 3"}
);
}
Expand Down Expand Up @@ -2573,3 +2573,23 @@ fn test_classic_obeys_operator_choice_at_compile_time_version_0() {
.to_string();
assert_eq!(compiled, "FAIL: unimplemented operator 48");
}

#[test]
fn test_op_mod_modern() {
let program = "(mod (S) (include *standard-cl-21*) (% 101 S))";
let compiled = do_basic_run(&vec!["run".to_string(), program.to_string()]);
let output = do_basic_brun(&vec!["brun".to_string(), compiled, "(10)".to_string()])
.trim()
.to_string();
assert_eq!(output, "1");
}

#[test]
fn test_op_modpow_modern() {
let program = "(mod (S) (include *standard-cl-21*) (modpow 2 4 S))"; // 2^4 % S
let compiled = do_basic_run(&vec!["run".to_string(), program.to_string()]);
let output = do_basic_brun(&vec!["brun".to_string(), compiled, "(10)".to_string()])
.trim()
.to_string();
assert_eq!(output, "6");
}

0 comments on commit 6a3acb5

Please sign in to comment.