Emit "nano_" prefixed addresses (#1771)

* Emit "nano_" prefixed addresses

* Ensure tests pass with both "nano_" and "xrb_" prefixed accounts

* Update buffer

* Simplify wallet test logic
This commit is contained in:
Wesley Shillingford 2019-04-17 18:24:58 +01:00 committed by GitHub
commit 50ffa31643
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 48 additions and 11 deletions

View file

@ -26,9 +26,16 @@ TEST (interface, xrb_uint256_to_string)
TEST (interface, xrb_uint256_to_address)
{
nano::uint256_union zero (0);
char text[65] = { 0 };
char text[66] = { 0 };
xrb_uint256_to_address (zero.bytes.data (), text);
ASSERT_STREQ ("xrb_1111111111111111111111111111111111111111111111111111hifc8npp", text);
/*
* Handle both "xrb_" and "nano_" results, since it is not
* specified which is returned
*/
auto account_alpha = "1111111111111111111111111111111111111111111111111111hifc8npp";
auto prefix = text[0] == 'x' ? "xrb" : "nano";
ASSERT_STREQ (boost::str (boost::format ("%1%_%2%") % prefix % account_alpha).c_str (), text);
}
TEST (interface, xrb_uint512_to_string)
@ -68,6 +75,9 @@ TEST (interface, xrb_valid_address)
ASSERT_EQ (0, xrb_valid_address ("xrb_1111111111111111111111111111111111111111111111111111hifc8npp"));
ASSERT_EQ (1, xrb_valid_address ("xrb_1111111111111111111111111111111111111111111111111111hifc8nppp"));
ASSERT_EQ (1, xrb_valid_address ("xrb_1111111211111111111111111111111111111111111111111111hifc8npp"));
ASSERT_EQ (0, xrb_valid_address ("nano_1111111111111111111111111111111111111111111111111111hifc8npp"));
ASSERT_EQ (1, xrb_valid_address ("nano_1111111111111111111111111111111111111111111111111111hifc8nppp"));
ASSERT_EQ (1, xrb_valid_address ("nano_1111111211111111111111111111111111111111111111111111hifc8npp"));
}
TEST (interface, xrb_seed_create)

View file

@ -386,11 +386,17 @@ TEST (uint256_union, decode_account_variations)
char account[66] = { 0 };
xrb_uint256_to_address (pub.bytes.data (), account);
/*
* Handle different offsets for the underscore separator
* for "xrb_" prefixed and "nano_" prefixed accounts
*/
unsigned offset = (account[0] == 'x') ? 4 : 5;
// Replace first digit after xrb_ with '0'..'9', make sure only one of them is valid
int errors = 0;
for (int variation = 0; variation < 10; variation++)
{
account[4] = static_cast<char> (variation + 48);
account[offset] = static_cast<char> (variation + 48);
errors += xrb_valid_address (account);
}
@ -404,8 +410,14 @@ TEST (uint256_union, account_transcode)
auto text (nano::test_genesis_key.pub.to_account ());
ASSERT_FALSE (value.decode_account (text));
ASSERT_EQ (nano::test_genesis_key.pub, value);
ASSERT_EQ ('_', text[3]);
text[3] = '-';
/*
* Handle different offsets for the underscore separator
* for "xrb_" prefixed and "nano_" prefixed accounts
*/
unsigned offset = (text.front () == 'x') ? 3 : 4;
ASSERT_EQ ('_', text[offset]);
text[offset] = '-';
nano::uint256_union value2;
ASSERT_FALSE (value2.decode_account (text));
ASSERT_EQ (value, value2);
@ -416,9 +428,15 @@ TEST (uint256_union, account_encode_lex)
nano::uint256_union min ("0000000000000000000000000000000000000000000000000000000000000000");
nano::uint256_union max ("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
auto min_text (min.to_account ());
ASSERT_EQ (64, min_text.size ());
auto max_text (max.to_account ());
ASSERT_EQ (64, max_text.size ());
/*
* Handle different lengths for "xrb_" prefixed and "nano_" prefixed accounts
*/
unsigned length = (min_text.front () == 'x') ? 64 : 65;
ASSERT_EQ (length, min_text.size ());
ASSERT_EQ (length, max_text.size ());
auto previous (min_text);
for (auto i (1); i != 1000; ++i)
{

View file

@ -315,7 +315,12 @@ TEST (account, encode_zero)
nano::uint256_union number0 (0);
std::string str0;
number0.encode_account (str0);
ASSERT_EQ (64, str0.size ());
/*
* Handle different lengths for "xrb_" prefixed and "nano_" prefixed accounts
*/
ASSERT_EQ ((str0.front () == 'x') ? 64 : 65, str0.size ());
ASSERT_EQ (65, str0.size ());
nano::uint256_union number1;
ASSERT_FALSE (number1.decode_account (str0));
ASSERT_EQ (number0, number1);
@ -327,7 +332,11 @@ TEST (account, encode_all)
number0.decode_hex ("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
std::string str0;
number0.encode_account (str0);
ASSERT_EQ (64, str0.size ());
/*
* Handle different lengths for "xrb_" prefixed and "nano_" prefixed accounts
*/
ASSERT_EQ ((str0.front () == 'x') ? 64 : 65, str0.size ());
nano::uint256_union number1;
ASSERT_FALSE (number1.decode_account (str0));
ASSERT_EQ (number0, number1);

View file

@ -43,7 +43,7 @@ uint8_t account_decode (char value)
void nano::uint256_union::encode_account (std::string & destination_a) const
{
assert (destination_a.empty ());
destination_a.reserve (64);
destination_a.reserve (65);
uint64_t check (0);
blake2b_state hash;
blake2b_init (&hash, 5);
@ -58,7 +58,7 @@ void nano::uint256_union::encode_account (std::string & destination_a) const
number_l >>= 5;
destination_a.push_back (account_encode (r));
}
destination_a.append ("_brx"); // xrb_
destination_a.append ("_onan"); // nano_
std::reverse (destination_a.begin (), destination_a.end ());
}