Changeset View
Changeset View
Standalone View
Standalone View
src/test/cashaddrenc_tests.cpp
Show First 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | const std::array<std::pair<uint8_t, uint32_t>, 8> valid_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}}}; | ||||
} // namespace | } // namespace | ||||
BOOST_FIXTURE_TEST_SUITE(cashaddrenc_tests, BasicTestingSetup) | BOOST_FIXTURE_TEST_SUITE(cashaddrenc_tests, BasicTestingSetup) | ||||
BOOST_AUTO_TEST_CASE(encode_decode_all_sizes) { | BOOST_AUTO_TEST_CASE(encode_decode_all_sizes) { | ||||
FastRandomContext rand(true); | FastRandomContext rand(true); | ||||
const std::string prefix = "bitcoincash"; | const std::string prefix = "abc"; | ||||
jasonbcox: Use CASHADDR_PREFIX | |||||
for (auto ps : valid_sizes) { | for (auto ps : valid_sizes) { | ||||
std::vector<uint8_t> data = | std::vector<uint8_t> data = | ||||
insecure_GetRandomByteArray(rand, ps.second); | insecure_GetRandomByteArray(rand, ps.second); | ||||
CashAddrContent content = {PUBKEY_TYPE, data}; | CashAddrContent content = {PUBKEY_TYPE, data}; | ||||
std::vector<uint8_t> packed_data = PackCashAddrContent(content); | std::vector<uint8_t> packed_data = PackCashAddrContent(content); | ||||
// Check that the packed size is correct | // Check that the packed size is correct | ||||
▲ Show 20 Lines • Show All 187 Lines • ▼ Show 20 Lines | std::vector<std::vector<uint8_t>> hash{ | ||||
{118, 160, 64, 83, 189, 160, 168, 139, 218, 81, | {118, 160, 64, 83, 189, 160, 168, 139, 218, 81, | ||||
119, 184, 106, 21, 195, 178, 159, 85, 152, 115}, | 119, 184, 106, 21, 195, 178, 159, 85, 152, 115}, | ||||
{203, 72, 18, 50, 41, 156, 213, 116, 49, 81, | {203, 72, 18, 50, 41, 156, 213, 116, 49, 81, | ||||
172, 75, 45, 99, 174, 25, 142, 123, 176, 169}, | 172, 75, 45, 99, 174, 25, 142, 123, 176, 169}, | ||||
{1, 31, 40, 228, 115, 201, 95, 64, 19, 215, | {1, 31, 40, 228, 115, 201, 95, 64, 19, 215, | ||||
213, 62, 197, 251, 195, 180, 45, 248, 237, 16}}; | 213, 62, 197, 251, 195, 180, 45, 248, 237, 16}}; | ||||
std::vector<std::string> pubkey = { | std::vector<std::string> pubkey = { | ||||
"bitcoincash:qpm2qsznhks23z7629mms6s4cwef74vcwvy22gdx6a", | "abc:qpm2qsznhks23z7629mms6s4cwef74vcwvjr9zzhs3", | ||||
"bitcoincash:qr95sy3j9xwd2ap32xkykttr4cvcu7as4y0qverfuy", | "abc:qr95sy3j9xwd2ap32xkykttr4cvcu7as4yefrnvckg", | ||||
"bitcoincash:qqq3728yw0y47sqn6l2na30mcw6zm78dzqre909m2r"}; | "abc:qqq3728yw0y47sqn6l2na30mcw6zm78dzq4s2922q0"}; | ||||
std::vector<std::string> script = { | std::vector<std::string> script = { | ||||
"bitcoincash:ppm2qsznhks23z7629mms6s4cwef74vcwvn0h829pq", | "abc:ppm2qsznhks23z7629mms6s4cwef74vcwv9xcd95tv", | ||||
"bitcoincash:pr95sy3j9xwd2ap32xkykttr4cvcu7as4yc93ky28e", | "abc:pr95sy3j9xwd2ap32xkykttr4cvcu7as4ywv7utmd4", | ||||
"bitcoincash:pqq3728yw0y47sqn6l2na30mcw6zm78dzq5ucqzc37"}; | "abc:pqq3728yw0y47sqn6l2na30mcw6zm78dzqz4h2dfmj"}; | ||||
for (size_t i = 0; i < hash.size(); ++i) { | for (size_t i = 0; i < hash.size(); ++i) { | ||||
const CTxDestination dstKey = PKHash(uint160(hash[i])); | const CTxDestination dstKey = PKHash(uint160(hash[i])); | ||||
BOOST_CHECK_EQUAL(pubkey[i], EncodeCashAddr(dstKey, *params)); | BOOST_CHECK_EQUAL(pubkey[i], EncodeCashAddr(dstKey, *params)); | ||||
CashAddrContent keyContent{PUBKEY_TYPE, hash[i]}; | CashAddrContent keyContent{PUBKEY_TYPE, hash[i]}; | ||||
BOOST_CHECK_EQUAL(pubkey[i], EncodeCashAddr("bitcoincash", keyContent)); | BOOST_CHECK_EQUAL(pubkey[i], EncodeCashAddr("abc", keyContent)); | ||||
const CTxDestination dstScript = ScriptHash(uint160(hash[i])); | const CTxDestination dstScript = ScriptHash(uint160(hash[i])); | ||||
BOOST_CHECK_EQUAL(script[i], EncodeCashAddr(dstScript, *params)); | BOOST_CHECK_EQUAL(script[i], EncodeCashAddr(dstScript, *params)); | ||||
CashAddrContent scriptContent{SCRIPT_TYPE, hash[i]}; | CashAddrContent scriptContent{SCRIPT_TYPE, hash[i]}; | ||||
BOOST_CHECK_EQUAL(script[i], | BOOST_CHECK_EQUAL(script[i], EncodeCashAddr("abc", scriptContent)); | ||||
EncodeCashAddr("bitcoincash", scriptContent)); | |||||
} | } | ||||
} | } | ||||
struct CashAddrTestVector { | struct CashAddrTestVector { | ||||
std::string prefix; | std::string prefix; | ||||
CashAddrType type; | CashAddrType type; | ||||
std::vector<uint8_t> hash; | std::vector<uint8_t> hash; | ||||
std::string addr; | std::string addr; | ||||
▲ Show 20 Lines • Show All 151 Lines • Show Last 20 Lines |
Use CASHADDR_PREFIX