Skip to content

Commit

Permalink
[+] tests
Browse files Browse the repository at this point in the history
  • Loading branch information
0xMaka committed Sep 29, 2024
1 parent ebc5c62 commit 040ffb6
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 43 deletions.
12 changes: 4 additions & 8 deletions tests/bai_con.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
//-----------------------------------------------------------------------------------------------//

//-------- -------- BAI::CON TEST -------- --------//
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------//
#[cfg(test)]
mod bai_con {
use kawala::bai::con;
//-----------------------------------------------------------------------------------------------//

//-------- -------- BYTES TO HEX -------- --------//

Expand Down Expand Up @@ -35,8 +32,6 @@ mod bai_con {
con::bytes_to_hex(&[0x100]); // we will unwrap or default
}

//-----------------------------------------------------------------------------------------------//

//-------- -------- HEX TO BYTES -------- --------//

// empty input
Expand All @@ -52,7 +47,8 @@ mod bai_con {
}

// multi byte input
#[test] fn hex_to_bytes_multiple_bytes() {
#[test]
fn hex_to_bytes_multiple_bytes() {
assert_eq!(con::bytes_to_hex(&[0xBA, 0x11]), "ba11");
}

Expand All @@ -64,7 +60,7 @@ mod bai_con {

// error handling - unwrap or default
#[test]
fn test_hex_to_bytes_invalid_char() {
fn hex_to_bytes_invalid_char() {
con::hex_to_bytes("g0");
}

Expand Down
66 changes: 56 additions & 10 deletions tests/bytes.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,61 @@
//---------------------------------------- BYTES TYPE --------------------------------------------//
//------------------------------------------------------------------------------------------------//
#[cfg(test)]
mod tests {
mod bytes {
use kawala::Bytes;
// ----------------------------------------------------------------------------------------------//

// ----------------------------------- CREATION AND ACCESS --------------------------------------//

#[test]
fn bytes4_creation_and_access() {
let bytes = Bytes::Bytes4([0x01,0x02,0x03,0x04]);
assert_eq!(bytes.bytes(), [0x01,0x02,0x03,0x04]);
assert_eq!(bytes.len(), 4);
assert_eq!(bytes[0], 1);
}

#[test]
fn bytes32_creation_and_access() {
let bytes = Bytes::Bytes32([0; 32]);
assert_eq!(bytes.bytes().len(), 32);
assert_eq!(bytes[0], 0);
}

#[test]
fn array_creation_and_access() {
let bytes = Bytes::Array(vec![0x01,0x02,0x03]);
assert_eq!(bytes.bytes(), [1, 2, 3]);
assert_eq!(bytes.len(), 3);
assert_eq!(bytes[1], 2);
}

#[test]
fn array_empty() {
let bytes = Bytes::Array(vec![]);
assert_eq!(bytes.bytes().len(), 0);
}

// ---------------------------------------- LEN & HEX -------------------------------------------//

#[test]
fn hex_conversion() {
let bytes = Bytes::Bytes32([0xFF; 32]);
assert_eq!(bytes.hex(), "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
}

#[test]
fn len_wrapper() {
let bytes1 = Bytes::Bytes4([1, 2, 3, 4]);
let bytes2 = Bytes::Bytes32([0; 32]);
let bytes3 = Bytes::Array(vec![1, 2, 3, 4, 5]);

assert_eq!(bytes1.len(), 4);
assert_eq!(bytes2.len(), 32);
assert_eq!(bytes3.len(), 5);
}

// --------------------------------------- GENERAL USE ------------------------------------------//

#[test]
fn bytes32() -> () {
Expand Down Expand Up @@ -34,14 +89,5 @@ mod tests {
assert_eq!(bytes.len(), 4);
assert_eq!(bytes.hex() . chars() . count(), 8);
}

/*
//won't accept over
#[test]
fn bytes_overflow() -> () {
/* initialize a bytes4 with 8 bytes */
let bytes = Bytes::Bytes4([0u8;8]);
}
*/
}

23 changes: 2 additions & 21 deletions tests/kwl32_util.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@

//-----------------------------------------------------------------------------------------------//

//-------- -------- KWL32::CON TEST -------- --------//
//-----------------------------------------------------------------------------------------------//

#[cfg(test)]
mod kwl32_util {
use kawala::kwl32::util;

//-----------------------------------------------------------------------------------------------//

//-------- -------- PAD32 -------- --------//

// empty 32
Expand Down Expand Up @@ -66,8 +62,6 @@ mod kwl32_util {
assert_eq!(util::pad32l(&input), expected);
}

//-----------------------------------------------------------------------------------------------//

//-------- -------- ROLL32 -------- --------//

// no shift:
Expand Down Expand Up @@ -145,23 +139,15 @@ mod kwl32_util {
assert_eq!(util::roll32l(&input, 64), expected);
}

//-----------------------------------------------------------------------------------------------//

//-------- -------- XOR32 -------- --------//


//-----------------------------------------------------------------------------------------------//

//-------- -------- AND32 -------- --------//


//-----------------------------------------------------------------------------------------------//

//-------- -------- OR32 -------- --------//


//-----------------------------------------------------------------------------------------------//

//-------- -------- NOT32 -------- --------//


Expand All @@ -179,14 +165,13 @@ mod kwl32_util {
fn and32() {
let a = [0xFFu8; 32];
let b = [0x00u8; 32];

assert_eq!(util::and32(&a, &b), [0u8; 32]);
}

#[test]
fn or32() {
let a = [0xFFu8; 32];
let b = [0x00u8; 32];

assert_eq!(util::or32(&a, &b), a);
}

Expand All @@ -196,10 +181,6 @@ mod kwl32_util {
assert_eq!(util::not32(&a), [0u8;32]);
}



//-----------------------------------------------------------------------------------------------//

//-------- -------- EDGE CASES -------- --------//

#[test]
Expand Down
4 changes: 1 addition & 3 deletions tests/signature.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#[cfg(test)]
mod tests {
mod signature {
use kawala::Signature;

#[test]
fn signature() -> () {
/* initialize a kawala::Signature */
let sig = Signature::from_hex("0x791ac94700d00d1e");

// will truncate
assert_eq!(sig.hex() . chars() . count(), 8);
assert_eq!(sig.bytes() . len(), 4);
Expand All @@ -15,7 +14,6 @@ mod tests {
#[test]
fn less_than_4() {
let sig = Signature::from_hex("0x791ac9");

// if it's less than 4 it can't be a signature
// unwrap or default
assert_eq!(sig.hex(), "00000000");
Expand Down
2 changes: 1 addition & 1 deletion tests/view.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[cfg(test)]
mod tests {
mod view {

use kawala::{ View, Calldata, WithSig };
#[test]
Expand Down

0 comments on commit 040ffb6

Please sign in to comment.