use merkletreers::merkle_root::merkle_root; use merkletreers::{Leaf, Root}; #[cfg(test)] mod tests { use super::*; mod merkle_root_leaves_even { use super::*; const SETUP_ROOT: Root = [ 144, 18, 241, 225, 138, 135, 121, 13, 46, 1, 250, 172, 231, 90, 170, 202, 56, 229, 61, 244, 55, 205, 206, 44, 5, 82, 70, 77, 218, 74, 244, 156, ]; const SETUP_LEAVES: [Leaf; 6] = [ [ 58, 194, 37, 22, 141, 245, 66, 18, 162, 92, 28, 1, 253, 53, 190, 191, 234, 64, 143, 218, 194, 227, 29, 221, 111, 128, 164, 187, 249, 165, 241, 203, ], [ 181, 85, 61, 227, 21, 224, 237, 245, 4, 217, 21, 10, 248, 45, 175, 165, 196, 102, 127, 166, 24, 237, 10, 111, 25, 198, 155, 65, 22, 108, 85, 16, ], [ 11, 66, 182, 57, 60, 31, 83, 6, 15, 227, 221, 191, 205, 122, 173, 204, 168, 148, 70, 90, 90, 67, 143, 105, 200, 125, 121, 11, 34, 153, 185, 178, ], [ 241, 145, 142, 133, 98, 35, 110, 177, 122, 220, 133, 2, 51, 47, 76, 156, 130, 188, 20, 225, 155, 252, 10, 161, 10, 182, 116, 255, 117, 179, 210, 243, ], [ 168, 152, 44, 137, 216, 9, 135, 251, 154, 81, 14, 37, 152, 30, 233, 23, 2, 6, 190, 33, 175, 60, 142, 14, 179, 18, 239, 29, 51, 130, 231, 97, ], [ 209, 232, 174, 183, 149, 0, 73, 110, 243, 220, 46, 87, 186, 116, 106, 131, 21, 208, 72, 183, 166, 100, 162, 191, 148, 141, 180, 250, 145, 150, 4, 131, ], ]; #[test] fn test_merkle_root_leaves_even_make_root() { let result = merkle_root(&SETUP_LEAVES); assert_eq!(result, SETUP_ROOT); } } mod merkle_root_leaves_odd { use super::*; const SETUP_ROOT: Root = [ 29, 208, 210, 166, 174, 70, 109, 102, 92, 178, 110, 26, 49, 240, 124, 87, 174, 93, 247, 210, 188, 85, 156, 213, 130, 109, 65, 123, 233, 20, 26, 93, ]; const SETUP_LEAVES: [Leaf; 5] = [ [ 58, 194, 37, 22, 141, 245, 66, 18, 162, 92, 28, 1, 253, 53, 190, 191, 234, 64, 143, 218, 194, 227, 29, 221, 111, 128, 164, 187, 249, 165, 241, 203, ], [ 181, 85, 61, 227, 21, 224, 237, 245, 4, 217, 21, 10, 248, 45, 175, 165, 196, 102, 127, 166, 24, 237, 10, 111, 25, 198, 155, 65, 22, 108, 85, 16, ], [ 11, 66, 182, 57, 60, 31, 83, 6, 15, 227, 221, 191, 205, 122, 173, 204, 168, 148, 70, 90, 90, 67, 143, 105, 200, 125, 121, 11, 34, 153, 185, 178, ], [ 241, 145, 142, 133, 98, 35, 110, 177, 122, 220, 133, 2, 51, 47, 76, 156, 130, 188, 20, 225, 155, 252, 10, 161, 10, 182, 116, 255, 117, 179, 210, 243, ], [ 168, 152, 44, 137, 216, 9, 135, 251, 154, 81, 14, 37, 152, 30, 233, 23, 2, 6, 190, 33, 175, 60, 142, 14, 179, 18, 239, 29, 51, 130, 231, 97, ], ]; #[test] fn test_merkle_root_leaves_odd_make_root() { let result = merkle_root(&SETUP_LEAVES); assert_eq!(result, SETUP_ROOT); } } mod merkle_root_leaves_base_2 { use super::*; const SETUP_ROOT: Root = [ 104, 32, 63, 144, 233, 208, 125, 197, 133, 146, 89, 215, 83, 110, 135, 166, 186, 157, 52, 95, 37, 82, 181, 185, 222, 41, 153, 221, 206, 156, 225, 191, ]; const SETUP_LEAVES: [Leaf; 4] = [ // keccak256(a) [ 58, 194, 37, 22, 141, 245, 66, 18, 162, 92, 28, 1, 253, 53, 190, 191, 234, 64, 143, 218, 194, 227, 29, 221, 111, 128, 164, 187, 249, 165, 241, 203, ], // keccak256(b) [ 181, 85, 61, 227, 21, 224, 237, 245, 4, 217, 21, 10, 248, 45, 175, 165, 196, 102, 127, 166, 24, 237, 10, 111, 25, 198, 155, 65, 22, 108, 85, 16, ], // keccak256(c) [ 11, 66, 182, 57, 60, 31, 83, 6, 15, 227, 221, 191, 205, 122, 173, 204, 168, 148, 70, 90, 90, 67, 143, 105, 200, 125, 121, 11, 34, 153, 185, 178, ], // keccak256(d) [ 241, 145, 142, 133, 98, 35, 110, 177, 122, 220, 133, 2, 51, 47, 76, 156, 130, 188, 20, 225, 155, 252, 10, 161, 10, 182, 116, 255, 117, 179, 210, 243, ], ]; #[test] fn test_merkle_root_leaves_base_2_make_root() { let result = merkle_root(&SETUP_LEAVES); assert_eq!(result, SETUP_ROOT); } } }