Add CashAddr Address Format
Ported from Bitcoin Unlimited, Bitcoin ABC
This commit is contained in:
@@ -484,4 +484,59 @@ BOOST_AUTO_TEST_CASE(test_ParseFixedPoint)
|
||||
BOOST_CHECK(!ParseFixedPoint("1.", 8, &amount));
|
||||
}
|
||||
|
||||
template <int F, int T>
|
||||
static void CheckConvertBits(const std::vector<uint8_t> &in, const std::vector<uint8_t> &expected)
|
||||
{
|
||||
std::vector<uint8_t> outpad;
|
||||
bool ret = ConvertBits<F, T, true>(outpad, in.begin(), in.end());
|
||||
BOOST_CHECK(ret);
|
||||
BOOST_CHECK(outpad == expected);
|
||||
|
||||
const bool dopad = (in.size() * F) % T;
|
||||
std::vector<uint8_t> outnopad;
|
||||
ret = ConvertBits<F, T, false>(outnopad, in.begin(), in.end());
|
||||
BOOST_CHECK(ret != dopad);
|
||||
|
||||
if (dopad)
|
||||
{
|
||||
// We should have skipped the last digit.
|
||||
outnopad.push_back(expected.back());
|
||||
}
|
||||
|
||||
BOOST_CHECK(outnopad == expected);
|
||||
|
||||
// Check the other way around.
|
||||
std::vector<uint8_t> orignopad;
|
||||
ret = ConvertBits<T, F, false>(orignopad, expected.begin(), expected.end());
|
||||
BOOST_CHECK(ret == !((expected.size() * T) % F));
|
||||
BOOST_CHECK(orignopad == in);
|
||||
|
||||
// Check with padding. We may get an extra 0 in that case.
|
||||
std::vector<uint8_t> origpad;
|
||||
ret = ConvertBits<T, F, true>(origpad, expected.begin(), expected.end());
|
||||
BOOST_CHECK(ret);
|
||||
|
||||
if (dopad)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(origpad.back(), 0);
|
||||
origpad.pop_back();
|
||||
}
|
||||
|
||||
BOOST_CHECK(origpad == in);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_ConvertBits)
|
||||
{
|
||||
CheckConvertBits<8, 5>({}, {});
|
||||
CheckConvertBits<8, 5>({0xff}, {0x1f, 0x1c});
|
||||
CheckConvertBits<8, 5>({0xff, 0xff}, {0x1f, 0x1f, 0x1f, 0x10});
|
||||
CheckConvertBits<8, 5>({0xff, 0xff, 0xff}, {0x1f, 0x1f, 0x1f, 0x1f, 0x1e});
|
||||
CheckConvertBits<8, 5>({0xff, 0xff, 0xff, 0xff}, {0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x18});
|
||||
CheckConvertBits<8, 5>({0xff, 0xff, 0xff, 0xff, 0xff}, {0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f});
|
||||
CheckConvertBits<8, 5>({0xff, 0xff, 0xff, 0xff, 0xff}, {0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f});
|
||||
CheckConvertBits<8, 5>({0xff, 0xff, 0xff, 0xff, 0xff}, {0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f});
|
||||
CheckConvertBits<8, 5>({0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef},
|
||||
{0x00, 0x04, 0x11, 0x14, 0x0a, 0x19, 0x1c, 0x09, 0x15, 0x0f, 0x06, 0x1e, 0x1e});
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
Reference in New Issue
Block a user