-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrlp_test.cpp
93 lines (72 loc) · 2.26 KB
/
rlp_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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*!
* minter_tx.
* rlp_test
*
* \date 23.05.19
* \author Eduard Maximovich (edward.vstock@gmail.com)
* \link https://github.com/edwardstock
*/
#include <bip3x/utils.h>
#include <gtest/gtest.h>
#include <minter/eth/RLP.h>
#include <minter/tx/utils.h>
TEST(RLP, NullZeroEncoding) {
eth::RLPStream out;
{
eth::RLPStream lst;
dev::bigint zero("0");
dev::bytes res = zero.export_bytes();
ASSERT_EQ(1, res.size());
ASSERT_EQ((uint8_t) 0x00, res.at(0));
lst.append(zero);
out.appendList(lst);
}
dev::bytes_data tmp = out.out();
ASSERT_STREQ("c180", tmp.to_hex().c_str());
eth::RLP s(tmp.get());
ASSERT_EQ(dev::bigint("0"), (dev::bigint) s[0]);
}
TEST(RLP, EmptyListEncoding) {
eth::RLPStream out;
eth::RLPStream lst;
out.appendList(lst);
dev::bytes_data res = out.out();
eth::RLP decoded(res.get());
// // convert ot RLP list
// eth::RLP sub_list = (eth::RLP) decoded[0];
// ASSERT_EQ(0, sub_list.size());
// decode to bytes directly will throw badrlp exception
// dev::bytes empty_bytes = (dev::bytes) decoded[0];
// Alternative
dev::bigint val;
if (decoded[0].isNull()) {
val = dev::bigint("0");
} else {
val = (dev::bigint) decoded[0];
}
}
TEST(RLP, StringEncoding) {
eth::RLPStream out;
std::string s = " ";
out.append(s);
}
TEST(RLP, EncodeBigInt128) {
dev::bigint nonce = dev::bigint("128");
eth::RLPStream out;
{
eth::RLPStream lst;
lst.append(nonce);
out.appendList(lst);
}
auto _i = nonce;
dev::bytes num;
{
num.resize(2);
dev::byte* b = &num.back();
for (; _i; _i >>= 8)
*(b--) = (uint8_t)(_i & 0xff);
}
auto data = out.out();
dev::bytes_data d = data;
dev::bytes_data numd = num;
}