-
Notifications
You must be signed in to change notification settings - Fork 2
/
keccak256_test.cpp
78 lines (68 loc) · 2.05 KB
/
keccak256_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#define BOOST_TEST_MODULE Keccak Tests
#include <boost/test/included/unit_test.hpp>
#include "keccak256.cpp"
BOOST_AUTO_TEST_CASE(test_hash_empty) {
BOOST_TEST(
keccak_256("")
==
"0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"
);
}
BOOST_AUTO_TEST_CASE(test_hash_simple) {
BOOST_TEST(
keccak_256("hi")
==
"0x7624778dedc75f8b322b9fa1632a610d40b85e106c7d9bf0e743a9ce291b9c6f"
);
}
BOOST_AUTO_TEST_CASE(test_hash_signature) {
BOOST_TEST(
keccak_256("transfer(address,uint256)")
==
"0xa9059cbb2ab09eb219583f4a59a5d0623ade346d962bcd4e46b11da047c9049b"
);
}
// output has leading zeros, we normalize that
BOOST_AUTO_TEST_CASE(test_hash_signature_needs_normalization) {
BOOST_TEST(
keccak_256("approve(address,uint256)")
==
"0x95ea7b334ae44009aa867bfb386f5c3b4b443ac6f0ee573fa91c4608fbadfba"
);
}
BOOST_AUTO_TEST_CASE(test_hex_to_str) {
BOOST_TEST(
hex_to_str("0x72656365697665417070726f76616c28616464726573732c75696e743235362c616464726573732c627974657329")
==
"receiveApproval(address,uint256,address,bytes)"
);
}
BOOST_AUTO_TEST_CASE(test_hash_hex_to_str) {
BOOST_TEST(
keccak_256(hex_to_str("0x7472616e7366657228616464726573732c75696e7432353629"))
==
"0xa9059cbb2ab09eb219583f4a59a5d0623ade346d962bcd4e46b11da047c9049b"
);
}
BOOST_AUTO_TEST_CASE(test_hash_hex_keccak_256_single_byte) {
BOOST_TEST(
hex_keccak_256("0x61")
==
"0x3ac225168df54212a25c1c01fd35bebfea408fdac2e31ddd6f80a4bbf9a5f1cb"
);
}
BOOST_AUTO_TEST_CASE(test_hash_hex_keccak_256_two_bytes) {
BOOST_TEST(
hex_keccak_256("0x6162")
==
"0x67fad3bfa1e0321bd021ca805ce14876e50acac8ca8532eda8cbf924da565160"
);
}
// output has leading zeros, we normalize that
BOOST_AUTO_TEST_CASE(test_hash_hex_keccak_256_needs_normalization) {
BOOST_TEST(
hex_keccak_256("0x0000000000000000000000000000000000000000000000000000000000000005")
==
"0x36b6384b5eca791c62761152d0c79bb0604c104a5fb6f4eb0703f3154bb3db0"
);
}