Changeset View
Changeset View
Standalone View
Standalone View
src/test/cashaddrenc_tests.cpp
Show First 20 Lines • Show All 182 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(check_size) { | ||||
// hash in bytes. | // hash in bytes. | ||||
std::vector<std::pair<uint8_t, uint32_t>> sizes = { | std::vector<std::pair<uint8_t, uint32_t>> sizes = { | ||||
{0, 20}, {1, 24}, {2, 28}, {3, 32}, {4, 40}, {5, 48}, {6, 56}, {7, 64}, | {0, 20}, {1, 24}, {2, 28}, {3, 32}, {4, 40}, {5, 48}, {6, 56}, {7, 64}, | ||||
}; | }; | ||||
std::vector<uint8_t> data; | std::vector<uint8_t> data; | ||||
for (auto ps : sizes) { | for (auto ps : sizes) { | ||||
size_t expectedSize = (12 + ps.second * 8) / 5; | // Number of bytes required for a 5-bit packed version of a hash, with | ||||
// version byte. Add half a byte(4) so integer math provides the next | |||||
// multiple-of-5 that would fit all the data. | |||||
size_t expectedSize = (8 * (1 + ps.second) + 4) / 5; | |||||
data.resize(expectedSize); | data.resize(expectedSize); | ||||
std::fill(begin(data), end(data), 0); | std::fill(begin(data), end(data), 0); | ||||
// After conversion from 8 bit packing to 5 bit packing, the size will | |||||
// be in the second 5-bit group, shifted left twice. | |||||
data[1] = ps.first << 2; | data[1] = ps.first << 2; | ||||
auto content = DecodeCashAddrContent( | auto content = DecodeCashAddrContent( | ||||
cashaddr::Encode(params.CashAddrPrefix(), data), params); | cashaddr::Encode(params.CashAddrPrefix(), data), params); | ||||
BOOST_CHECK_EQUAL(content.type, 0); | BOOST_CHECK_EQUAL(content.type, 0); | ||||
BOOST_CHECK_EQUAL(content.hash.size(), ps.second); | BOOST_CHECK_EQUAL(content.hash.size(), ps.second); | ||||
▲ Show 20 Lines • Show All 47 Lines • Show Last 20 Lines |