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

Commit e607992

Browse files
committed
Tests for RLP::toArray
1 parent 1631435 commit e607992

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

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)