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

Commit

Permalink
Minor fix in RLP (#5597)
Browse files Browse the repository at this point in the history
Minor fix in RLP
  • Loading branch information
gumb0 committed May 16, 2019
2 parents 821ac9e + e607992 commit b094d0c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion libdevcore/RLP.h
Expand Up @@ -240,7 +240,7 @@ class RLP
template <class T, size_t N>
std::array<T, N> toArray(int _flags = LaissezFaire) const
{
if (itemCountStrict() != N)
if (itemCount() != N)
{
if (_flags & ThrowOnFail)
BOOST_THROW_EXCEPTION(BadCast());
Expand Down
23 changes: 23 additions & 0 deletions test/unittests/libdevcore/RLP.cpp
Expand Up @@ -64,3 +64,26 @@ TEST(RLP, bignumSerialization)

EXPECT_EQ(bignum, bignumPost) << "The post-processed bignum does not match the original.";
}

TEST(RLP, toArray)
{
auto const data = rlpList(1, 2, 3);
RLP rlp{data};

array<uint8_t, 3> const expected = {{1, 2, 3}};
EXPECT_EQ((rlp.toArray<uint8_t, 3>()), expected);
}

TEST(RLP, toArrayFail)
{
// non-list RLP data
auto const data = rlp(0);
RLP rlp{data};

// toArray doesn't throw by default
array<uint8_t, 3> const expected = {};
EXPECT_EQ((rlp.toArray<uint8_t, 3>()), expected);

// toArray throws in strict mode
EXPECT_THROW((rlp.toArray<uint8_t, 3>(RLP::VeryStrict)), BadCast);
}

0 comments on commit b094d0c

Please sign in to comment.