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

Commit

Permalink
Tests for RLP::toArray
Browse files Browse the repository at this point in the history
  • Loading branch information
gumb0 committed May 16, 2019
1 parent 1631435 commit e607992
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/unittests/libdevcore/RLP.cpp
Original file line number Diff line number Diff line change
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 e607992

Please sign in to comment.