-
Notifications
You must be signed in to change notification settings - Fork 648
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove UTF8 test #1346
Merged
Remove UTF8 test #1346
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -428,6 +428,68 @@ BOOST_AUTO_TEST_CASE( transfer_restricted_test ) | |
} | ||
} | ||
|
||
/*** | ||
* Test to see if a asset name is valid | ||
* @param db the database | ||
* @param acct the account that will attempt to create the asset | ||
* @param asset_name the asset_name | ||
* @param allowed whether the creation should be successful | ||
* @returns true if meets expectations | ||
*/ | ||
bool test_asset_name(graphene::chain::database_fixture* db, const graphene::chain::account_object& acct, std::string asset_name, bool allowed) | ||
{ | ||
if (allowed) | ||
{ | ||
try | ||
{ | ||
db->create_user_issued_asset(asset_name, acct, 0); | ||
} catch (...) | ||
{ | ||
return false; | ||
} | ||
} | ||
else | ||
{ | ||
try | ||
{ | ||
db->create_user_issued_asset(asset_name, acct, 0); | ||
return false; | ||
} catch (fc::exception& ex) | ||
{ | ||
return true; | ||
} catch (...) | ||
{ | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
/*** | ||
* Test to see if an ascii character can be used in an asset name | ||
* @param c the ascii character (NOTE: includes extended ascii up to 255) | ||
* @param allowed_beginning true if it should be allowed as the first character of an asset name | ||
* @param allowed_middle true if it should be allowed in the middle of an asset name | ||
* @param allowed_end true if it should be allowed at the end of an asset name | ||
* @returns true if tests met expectations | ||
*/ | ||
bool test_asset_char(graphene::chain::database_fixture* db, const graphene::chain::account_object& acct, const char c, bool allowed_beginning, bool allowed_middle, bool allowed_end) | ||
{ | ||
// beginning | ||
std::string asset_name = std::string("") + c + "CHARLIE"; | ||
if (!test_asset_name(db, acct, asset_name, allowed_beginning)) | ||
return false; | ||
|
||
// middle | ||
asset_name = std::string("CHAR") + c + "LIE"; | ||
if (!test_asset_name(db, acct, asset_name, allowed_middle)) | ||
return false; | ||
|
||
// end | ||
asset_name = std::string("CHARLIE") + c; | ||
return test_asset_name(db, acct, asset_name, allowed_end); | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE( asset_name_test ) | ||
{ | ||
try | ||
|
@@ -502,14 +564,6 @@ BOOST_AUTO_TEST_CASE( asset_name_test ) | |
BOOST_CHECK( has_asset("ALPHA2") ); | ||
BOOST_CHECK( has_asset("ALPHA2.ONE") ); | ||
|
||
// locales issue | ||
std::locale loc1("en_US.UTF8"); | ||
static const std::locale& loc2 = std::locale::classic(); | ||
const wchar_t c = L'\u042f'; | ||
// isalpha will allow non ascii chars if locale is not C | ||
BOOST_CHECK_EQUAL( isalpha(c, loc1), true); | ||
BOOST_CHECK_EQUAL( isalpha(c, loc2), false); | ||
|
||
// proposal to create asset ending in number will now be created successfully as we are in > hf_620 time | ||
prop.expiration_time = db.head_block_time() + fc::days(3); | ||
signed_transaction tx_hf620; | ||
|
@@ -519,6 +573,16 @@ BOOST_AUTO_TEST_CASE( asset_name_test ) | |
sign( tx_hf620, alice_private_key ); | ||
PUSH_TX( db, tx_hf620 ); | ||
|
||
// assets with invalid characters should not be allowed | ||
for (int c = 0; c < 128; ++c) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about chars in the |
||
{ | ||
if ( (c >= 48 && c <= 57) ) // numbers | ||
BOOST_CHECK_MESSAGE( test_asset_char(this, alice_id(db), c, false, true, true), "Failed on good char " + std::to_string(c) ); | ||
else if ( c >= 65 && c <= 90) // letters | ||
BOOST_CHECK_MESSAGE( test_asset_char(this, alice_id(db), c, true, true, true), "Failed on good char " + std::to_string(c) ); | ||
else // everything else | ||
BOOST_CHECK_MESSAGE( test_asset_char(this, alice_id(db), c, false, false, false), "Failed on bad char " + std::to_string(c) ); | ||
} | ||
} | ||
catch(fc::exception& e) | ||
{ | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Putting tests here means only checks after the hard fork. Please make sure it's appropriate.