diff --git a/libdevcore/RLP.h b/libdevcore/RLP.h index 60403107bef..a193936f148 100644 --- a/libdevcore/RLP.h +++ b/libdevcore/RLP.h @@ -240,7 +240,7 @@ class RLP template std::array toArray(int _flags = LaissezFaire) const { - if (itemCountStrict() != N) + if (itemCount() != N) { if (_flags & ThrowOnFail) BOOST_THROW_EXCEPTION(BadCast()); diff --git a/test/unittests/libdevcore/RLP.cpp b/test/unittests/libdevcore/RLP.cpp index 28850276b39..83162a77b69 100644 --- a/test/unittests/libdevcore/RLP.cpp +++ b/test/unittests/libdevcore/RLP.cpp @@ -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 const expected = {{1, 2, 3}}; + EXPECT_EQ((rlp.toArray()), expected); +} + +TEST(RLP, toArrayFail) +{ + // non-list RLP data + auto const data = rlp(0); + RLP rlp{data}; + + // toArray doesn't throw by default + array const expected = {}; + EXPECT_EQ((rlp.toArray()), expected); + + // toArray throws in strict mode + EXPECT_THROW((rlp.toArray(RLP::VeryStrict)), BadCast); +}