-
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
Fix tests #1126
Fix tests #1126
Changes from all commits
7f17d17
00c9188
7dd4ce0
025bd61
1561981
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright (c) 2015 Cryptonomex, Inc., and contributors. | ||
* | ||
* The MIT License | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
#include <cstdlib> | ||
#include <iostream> | ||
#include <boost/test/included/unit_test.hpp> | ||
|
||
extern uint32_t GRAPHENE_TESTING_GENESIS_TIMESTAMP; | ||
|
||
boost::unit_test::test_suite* init_unit_test_suite(int argc, char* argv[]) { | ||
std::srand(time(NULL)); | ||
std::cout << "Random number generator seeded to " << time(NULL) << std::endl; | ||
const char* genesis_timestamp_str = getenv("GRAPHENE_TESTING_GENESIS_TIMESTAMP"); | ||
if( genesis_timestamp_str != nullptr ) | ||
{ | ||
GRAPHENE_TESTING_GENESIS_TIMESTAMP = std::stoul( genesis_timestamp_str ); | ||
} | ||
std::cout << "GRAPHENE_TESTING_GENESIS_TIMESTAMP is " << GRAPHENE_TESTING_GENESIS_TIMESTAMP << std::endl; | ||
return nullptr; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -145,6 +145,7 @@ BOOST_AUTO_TEST_CASE( call_order_update_test ) | |
GRAPHENE_REQUIRE_THROW( borrow( dan, bitusd.amount(80000), asset(0)), fc::exception ); | ||
BOOST_TEST_MESSAGE( "attempting to claim all collateral without paying off debt" ); | ||
GRAPHENE_REQUIRE_THROW( cover( dan, bitusd.amount(0), asset(20000)), fc::exception ); | ||
GRAPHENE_REQUIRE_THROW( cover( dan, bitusd.amount(0), asset(20000-1)), fc::exception ); | ||
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. What is this new test for? Actually it will throw an exception due to triggering a blackswan which is not allowed when updating a call position. It worth testing, but better add a message above it. 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. The underlying implementation now explicitly checks for zero collateral. This test was added to probe the edge case that collateral is not zero, but still too low to sustain the debt. I feel it is sufficiently described by the message, "attempting to claim all collateral without paying off debt"; even though it leaves one unit of collateral unclaimed, the spirit is the same. 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. 0 and 1 are absolutely different. |
||
|
||
borrow( sam, bitusd.amount(1000), asset(10000)); | ||
transfer( sam, dan, bitusd.amount(1000) ); | ||
|
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.
"zero collateral with nonzero debt" is covered by this test case:
bitshares-core/tests/tests/operation_tests.cpp
Lines 146 to 147 in c6b28b2
price::call_price()
will generate a division-by-zero exception, then the exception will be captured and converted tofc::exception
, then be caught by callers. So I think this change is more an optimization rather than a fix. No?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.
Incorrect. The test fails, because boost captures the division by zero exception, as it occurs inside the modify functor (line 257), triggering the object to be deleted. As per boost docs, this is expected behavior: