Skip to content

Commit

Permalink
fmt + clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
prozacchiwawa committed May 20, 2024
1 parent 4bf340b commit 8cc4f39
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions src/compiler/clvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ pub fn convert_from_clvm_rs(
// Ensure that atom values that don't evaluate equal to integers
// are represented faithfully as atoms.
if u8_from_number(integer.clone()) == atom_data {
if atom_data == &[0] {
if atom_data == [0] {
Ok(Rc::new(SExp::QuotedString(loc, b'x', atom_data.to_vec())))
} else {
Ok(Rc::new(SExp::Integer(loc, integer)))
Expand All @@ -296,18 +296,19 @@ fn test_convert_from_clvm_rs_00_byte() {
let mut allocator = Allocator::new();
let allocator_atom = allocator.new_atom(&[0]).expect("should convert");
let srcloc = Srcloc::start("*test*");
let result = convert_from_clvm_rs(
&mut allocator,
srcloc.clone(),
allocator_atom
).expect("should convert to mod");
let result = convert_from_clvm_rs(&mut allocator, srcloc.clone(), allocator_atom)
.expect("should convert to mod");
assert_eq!(result, Rc::new(SExp::Atom(srcloc, vec![0])));
assert_eq!(sha256tree(result.clone()), &[0x47, 0xdc, 0x54, 0x0c, 0x94, 0xce, 0xb7, 0x04, 0xa2, 0x38, 0x75, 0xc1, 0x12, 0x73, 0xe1, 0x6b, 0xb0, 0xb8, 0xa8, 0x7a, 0xed, 0x84, 0xde, 0x91, 0x1f, 0x21, 0x33, 0x56, 0x81, 0x15, 0xf2, 0x54]);

let node = convert_to_clvm_rs(
&mut allocator,
result
).expect("should convert from mod");
assert_eq!(
sha256tree(result.clone()),
&[
0x47, 0xdc, 0x54, 0x0c, 0x94, 0xce, 0xb7, 0x04, 0xa2, 0x38, 0x75, 0xc1, 0x12, 0x73,
0xe1, 0x6b, 0xb0, 0xb8, 0xa8, 0x7a, 0xed, 0x84, 0xde, 0x91, 0x1f, 0x21, 0x33, 0x56,
0x81, 0x15, 0xf2, 0x54
]
);

let node = convert_to_clvm_rs(&mut allocator, result).expect("should convert from mod");
assert_eq!(allocator.atom(node), &[0]);
}

Expand All @@ -316,12 +317,16 @@ fn test_convert_to_clvm_rs_m129() {
let mut allocator = Allocator::new();
let srcloc = Srcloc::start("*test*");
let result = Rc::new(SExp::Integer(srcloc, -129_i32.to_bigint().unwrap()));
assert_eq!(sha256tree(result.clone()), &[0x5a, 0x0c, 0x1f, 0xec, 0x64, 0x75, 0x1e, 0x82, 0xc0, 0xd4, 0x86, 0x1d, 0x0b, 0xc1, 0x9c, 0x75, 0x80, 0x52, 0x5d, 0x2f, 0x47, 0x66, 0x79, 0x56, 0xbb, 0xd9, 0xd7, 0x9e, 0x26, 0x0a, 0xae, 0x00]);

let node = convert_to_clvm_rs(
&mut allocator,
result
).expect("should convert from mod");
assert_eq!(
sha256tree(result.clone()),
&[
0x5a, 0x0c, 0x1f, 0xec, 0x64, 0x75, 0x1e, 0x82, 0xc0, 0xd4, 0x86, 0x1d, 0x0b, 0xc1,
0x9c, 0x75, 0x80, 0x52, 0x5d, 0x2f, 0x47, 0x66, 0x79, 0x56, 0xbb, 0xd9, 0xd7, 0x9e,
0x26, 0x0a, 0xae, 0x00
]
);

let node = convert_to_clvm_rs(&mut allocator, result).expect("should convert from mod");
assert_eq!(allocator.atom(node), &[255, 127]);
}

Expand Down

0 comments on commit 8cc4f39

Please sign in to comment.