()
| 999 | |
| 1000 | #[test] |
| 1001 | fn test_leaf_node_encode() { |
| 1002 | let node = Node::new_leaf( |
| 1003 | &RawPath::new(), |
| 1004 | &TrieValue::Account(Account::new(0, U256::from(1), B256::ZERO, B256::ZERO)), |
| 1005 | ) |
| 1006 | .expect("can create node"); |
| 1007 | let mut bytes = vec![]; |
| 1008 | node.encode(&mut bytes); |
| 1009 | assert_eq!(bytes, hex!("0xf84920b846f8448001a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a00000000000000000000000000000000000000000000000000000000000000000")); |
| 1010 | |
| 1011 | let node = Node::new_leaf( |
| 1012 | &RawPath::from_nibbles(&[0xa, 0xb]), |
| 1013 | &TrieValue::Account(Account::new(1, U256::from(100), B256::ZERO, B256::ZERO)), |
| 1014 | ) |
| 1015 | .expect("can create node"); |
| 1016 | let mut bytes = vec![]; |
| 1017 | node.encode(&mut bytes); |
| 1018 | assert_eq!(bytes, hex!("0xf84b8220abb846f8440164a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a00000000000000000000000000000000000000000000000000000000000000000")); |
| 1019 | |
| 1020 | let node = Node::new_leaf( |
| 1021 | &RawPath::from_nibbles(&[0xa, 0xb, 0xc, 0xd, 0xe]), |
| 1022 | &TrieValue::Account(Account::new(999, U256::from(123456789), B256::ZERO, B256::ZERO)), |
| 1023 | ) |
| 1024 | .expect("can create node"); |
| 1025 | let mut bytes = vec![]; |
| 1026 | node.encode(&mut bytes); |
| 1027 | assert_eq!(bytes, hex!("0xf852833abcdeb84cf84a8203e784075bcd15a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a00000000000000000000000000000000000000000000000000000000000000000")); |
| 1028 | |
| 1029 | let node = Node::new_leaf( |
| 1030 | &RawPath::unpack(&hex!( |
| 1031 | "0x761d5c42184a02cc64585ed2ff339fc39a907e82731d70313c83d2212b2da36b" |
| 1032 | )), |
| 1033 | &TrieValue::Account(Account::new( |
| 1034 | 0, |
| 1035 | U256::from(10_000_000_000_000_000_000u64), |
| 1036 | EMPTY_ROOT_HASH, |
| 1037 | KECCAK_EMPTY, |
| 1038 | )), |
| 1039 | ) |
| 1040 | .expect("can create node"); |
| 1041 | let mut bytes = vec![]; |
| 1042 | node.encode(&mut bytes); |
| 1043 | assert_eq!(bytes, hex!("0xf872a120761d5c42184a02cc64585ed2ff339fc39a907e82731d70313c83d2212b2da36bb84ef84c80888ac7230489e80000a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a0c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470")); |
| 1044 | let rlp_encoded = node.to_rlp_node(); |
| 1045 | // hash prefixed with 0xa0 (length 32) |
| 1046 | assert_eq!( |
| 1047 | rlp_encoded.as_slice(), |
| 1048 | hex!("0xa0337e249c268401079fc728c58142710845805285dbc90e7c71bb1b79b9d7a745") |
| 1049 | ); |
| 1050 | } |
| 1051 | |
| 1052 | #[test] |
| 1053 | fn test_branch_node_encode() { |
nothing calls this directly
no test coverage detected