This repository was archived by the owner on Oct 28, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed
test/unittests/libdevcore Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -240,7 +240,7 @@ class RLP
240240 template <class T , size_t N>
241241 std::array<T, N> toArray (int _flags = LaissezFaire) const
242242 {
243- if (itemCountStrict () != N)
243+ if (itemCount () != N)
244244 {
245245 if (_flags & ThrowOnFail)
246246 BOOST_THROW_EXCEPTION (BadCast ());
Original file line number Diff line number Diff line change @@ -64,3 +64,26 @@ TEST(RLP, bignumSerialization)
6464
6565 EXPECT_EQ (bignum, bignumPost) << " The post-processed bignum does not match the original." ;
6666}
67+
68+ TEST (RLP, toArray)
69+ {
70+ auto const data = rlpList (1 , 2 , 3 );
71+ RLP rlp{data};
72+
73+ array<uint8_t , 3 > const expected = {{1 , 2 , 3 }};
74+ EXPECT_EQ ((rlp.toArray <uint8_t , 3 >()), expected);
75+ }
76+
77+ TEST (RLP, toArrayFail)
78+ {
79+ // non-list RLP data
80+ auto const data = rlp (0 );
81+ RLP rlp{data};
82+
83+ // toArray doesn't throw by default
84+ array<uint8_t , 3 > const expected = {};
85+ EXPECT_EQ ((rlp.toArray <uint8_t , 3 >()), expected);
86+
87+ // toArray throws in strict mode
88+ EXPECT_THROW ((rlp.toArray <uint8_t , 3 >(RLP::VeryStrict)), BadCast);
89+ }
You can’t perform that action at this time.
0 commit comments