Skip to content
This repository was archived by the owner on Oct 28, 2021. It is now read-only.

Commit b094d0c

Browse files
authored
Minor fix in RLP (#5597)
Minor fix in RLP
2 parents 821ac9e + e607992 commit b094d0c

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

libdevcore/RLP.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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());

test/unittests/libdevcore/RLP.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
}

0 commit comments

Comments
 (0)