Skip to content

Commit

Permalink
Merge pull request #1493 from oxarbitrage/1270_existing_testcases
Browse files Browse the repository at this point in the history
add support for existing tests after hf1270
  • Loading branch information
abitmore authored Jan 30, 2019
2 parents 8c0152c + ca1e045 commit 6b22b91
Show file tree
Hide file tree
Showing 4 changed files with 214 additions and 39 deletions.
1 change: 1 addition & 0 deletions tests/common/database_fixture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ struct database_fixture {
optional<fc::temp_directory> data_dir;
bool skip_key_index_test = false;
uint32_t anon_acct_count;
bool hf1270 = false;

database_fixture();
~database_fixture();
Expand Down
67 changes: 51 additions & 16 deletions tests/tests/bitasset_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,14 +453,18 @@ BOOST_AUTO_TEST_CASE( hf_890_test )
generate_blocks(HARDFORK_615_TIME, true, skip); // get around Graphene issue #615 feed expiration bug
generate_blocks(db.get_dynamic_global_properties().next_maintenance_time, true, skip);

auto hf_time = HARDFORK_CORE_868_890_TIME;
if(hf1270)
hf_time = HARDFORK_CORE_1270_TIME;

for( int i=0; i<2; ++i )
{
int blocks = 0;
auto mi = db.get_global_properties().parameters.maintenance_interval;

if( i == 1 ) // go beyond hard fork
{
blocks += generate_blocks(HARDFORK_CORE_868_890_TIME - mi, true, skip);
blocks += generate_blocks(hf_time - mi, true, skip);
blocks += generate_blocks(db.get_dynamic_global_properties().next_maintenance_time, true, skip);
}
set_expiration( db, trx );
Expand Down Expand Up @@ -526,7 +530,7 @@ BOOST_AUTO_TEST_CASE( hf_890_test )
ba_op.asset_to_update = usd_id;
ba_op.issuer = asset_to_update.issuer;
ba_op.new_options = asset_to_update.bitasset_data(db).options;
ba_op.new_options.feed_lifetime_sec = HARDFORK_CORE_868_890_TIME.sec_since_epoch()
ba_op.new_options.feed_lifetime_sec = hf_time.sec_since_epoch()
- db.head_block_time().sec_since_epoch()
+ mi
+ 1800;
Expand All @@ -542,7 +546,7 @@ BOOST_AUTO_TEST_CASE( hf_890_test )
BOOST_CHECK( db.find<limit_order_object>( sell_id ) );

// go beyond hard fork
blocks += generate_blocks(HARDFORK_CORE_868_890_TIME - mi, true, skip);
blocks += generate_blocks(hf_time - mi, true, skip);
blocks += generate_blocks(db.get_dynamic_global_properties().next_maintenance_time, true, skip);
}

Expand Down Expand Up @@ -924,7 +928,10 @@ BOOST_AUTO_TEST_CASE( hf_935_test )
generate_blocks( db.get_dynamic_global_properties().next_maintenance_time, true, skip );
generate_block( skip );

for( int i = 0; i < 6; ++i )
// need additional block to avoid prev: popping block would leave head block null error
generate_block( skip );

for( int i = 0; i < 8; ++i )
{
idump( (i) );
int blocks = 0;
Expand All @@ -940,6 +947,11 @@ BOOST_AUTO_TEST_CASE( hf_935_test )
generate_blocks( HARDFORK_CORE_935_TIME - mi, true, skip );
generate_blocks( db.get_dynamic_global_properties().next_maintenance_time, true, skip );
}
else if( i == 6 ) // go beyond hard fork 1270
{
generate_blocks( HARDFORK_CORE_1270_TIME - mi, true, skip );
generate_blocks( db.get_dynamic_global_properties().next_maintenance_time, true, skip );
}
set_expiration( db, trx );

ACTORS( (seller)(borrower)(feedproducer)(feedproducer2)(feedproducer3) );
Expand Down Expand Up @@ -1050,7 +1062,7 @@ BOOST_AUTO_TEST_CASE( hf_935_test )
ba_op.asset_to_update = usd_id;
ba_op.issuer = asset_to_update.issuer;
ba_op.new_options = asset_to_update.bitasset_data(db).options;
ba_op.new_options.feed_lifetime_sec = HARDFORK_CORE_935_TIME.sec_since_epoch()
ba_op.new_options.feed_lifetime_sec = HARDFORK_CORE_1270_TIME.sec_since_epoch()
+ mi * 3 + 86400 * 2
- db.head_block_time().sec_since_epoch();
trx.operations.push_back(ba_op);
Expand Down Expand Up @@ -1103,22 +1115,39 @@ BOOST_AUTO_TEST_CASE( hf_935_test )
blocks += generate_blocks(db.get_dynamic_global_properties().next_maintenance_time, true, skip);
}

// after hard fork 935, the limit order should be filled
// after hard fork 935, the limit order is filled only for the MSSR test
if( db.get_dynamic_global_properties().next_maintenance_time > HARDFORK_CORE_935_TIME &&
db.get_dynamic_global_properties().next_maintenance_time <= HARDFORK_CORE_1270_TIME)
{
// check median
BOOST_CHECK( usd_id(db).bitasset_data(db).current_feed.settlement_price == current_feed.settlement_price );
if( i % 2 == 0 ) // MCR test, median MCR should be 350%
BOOST_CHECK_EQUAL( usd_id(db).bitasset_data(db).current_feed.maintenance_collateral_ratio, 3500 );
else // MSSR test, MSSR should be 125%
BOOST_CHECK_EQUAL( usd_id(db).bitasset_data(db).current_feed.maximum_short_squeeze_ratio, 1250 );
// the limit order should have been filled
// TODO FIXME this test case is failing for MCR test,
// because call_order's call_price didn't get updated after MCR changed
// BOOST_CHECK( !db.find<limit_order_object>( sell_id ) );
if( i % 2 == 1 ) // MSSR test
BOOST_CHECK( !db.find<limit_order_object>( sell_id ) );
if( i % 2 == 0) { // MCR test, median MCR should be 350% and order will not be filled except when i = 0
BOOST_CHECK_EQUAL(usd_id(db).bitasset_data(db).current_feed.maintenance_collateral_ratio, 3500);
if( affected_by_hf_343 )
BOOST_CHECK(!db.find<limit_order_object>(sell_id));
else
BOOST_CHECK(db.find<limit_order_object>(sell_id)); // MCR bug, order still there
}
else { // MSSR test, MSSR should be 125% and order is filled
BOOST_CHECK_EQUAL(usd_id(db).bitasset_data(db).current_feed.maximum_short_squeeze_ratio, 1250);
BOOST_CHECK(!db.find<limit_order_object>(sell_id)); // order filled
}

// go beyond hard fork 1270
blocks += generate_blocks(HARDFORK_CORE_1270_TIME - mi, true, skip);
blocks += generate_blocks(db.get_dynamic_global_properties().next_maintenance_time, true, skip);
}

// after hard fork 1270, the limit order should be filled for MCR test
if( db.get_dynamic_global_properties().next_maintenance_time > HARDFORK_CORE_1270_TIME)
{
// check median
BOOST_CHECK( usd_id(db).bitasset_data(db).current_feed.settlement_price == current_feed.settlement_price );
if( i % 2 == 0 ) { // MCR test, order filled
BOOST_CHECK_EQUAL(usd_id(db).bitasset_data(db).current_feed.maintenance_collateral_ratio, 3500);
BOOST_CHECK(!db.find<limit_order_object>(sell_id));
}
}

// undo above tx's and reset
generate_block( skip );
Expand Down Expand Up @@ -1376,5 +1405,11 @@ BOOST_AUTO_TEST_CASE( reset_backing_asset_switching_to_witness_fed )
}
}
*/
BOOST_AUTO_TEST_CASE(hf_890_test_hf1270)
{ try {
hf1270 = true;
INVOKE(hf_890_test);

} FC_LOG_AND_RETHROW() }

BOOST_AUTO_TEST_SUITE_END()
103 changes: 87 additions & 16 deletions tests/tests/market_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,14 @@ BOOST_AUTO_TEST_CASE(issue_338_etc)
*/
BOOST_AUTO_TEST_CASE(hardfork_core_338_test)
{ try {

auto mi = db.get_global_properties().parameters.maintenance_interval;
generate_blocks(HARDFORK_CORE_343_TIME - mi); // assume all hard forks occur at same time

if(hf1270)
generate_blocks(HARDFORK_CORE_1270_TIME - mi);
else
generate_blocks(HARDFORK_CORE_343_TIME - mi);

generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);

set_expiration( db, trx );
Expand Down Expand Up @@ -325,7 +331,8 @@ BOOST_AUTO_TEST_CASE(hardfork_core_338_test)

// call's call_price will be updated after the match, to 741/31/1.75 CORE/USD = 2964/217
// it's above settlement price (10/1) so won't be margin called again
BOOST_CHECK( price(asset(2964),asset(217,usd_id)) == call.call_price );
if(!hf1270) // can use call price only if we are before hf1270
BOOST_CHECK( price(asset(2964),asset(217,usd_id)) == call.call_price );

// This would match with call before, but would match with call2 after #343 fixed
BOOST_CHECK( !create_sell_order(seller, bitusd.amount(700), core.amount(6000) ) );
Expand All @@ -342,7 +349,8 @@ BOOST_AUTO_TEST_CASE(hardfork_core_338_test)
BOOST_CHECK_EQUAL( 1000, call3.debt.value );
BOOST_CHECK_EQUAL( 16000, call3.collateral.value );
// call2's call_price will be updated after the match, to 78/3/1.75 CORE/USD = 312/21
BOOST_CHECK( price(asset(312),asset(21,usd_id)) == call2.call_price );
if(!hf1270) // can use call price only if we are before hf1270
BOOST_CHECK( price(asset(312),asset(21,usd_id)) == call2.call_price );
// it's above settlement price (10/1) so won't be margin called

// at this moment, collateralization of call is 7410 / 310 = 23.9
Expand Down Expand Up @@ -406,8 +414,14 @@ BOOST_AUTO_TEST_CASE(hardfork_core_338_test)
*/
BOOST_AUTO_TEST_CASE(hardfork_core_453_test)
{ try {

auto mi = db.get_global_properties().parameters.maintenance_interval;
generate_blocks(HARDFORK_CORE_453_TIME - mi); // assume all hard forks occur at same time

if(hf1270)
generate_blocks(HARDFORK_CORE_1270_TIME - mi);
else
generate_blocks(HARDFORK_CORE_343_TIME - mi);

generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);

set_expiration( db, trx );
Expand Down Expand Up @@ -478,16 +492,21 @@ BOOST_AUTO_TEST_CASE(hardfork_core_453_test)
// generate a block
generate_block();


} FC_LOG_AND_RETHROW() }

/***
* Tests (big) limit order matching logic after #625 got fixed
*/
BOOST_AUTO_TEST_CASE(hardfork_core_625_big_limit_order_test)
{ try {

auto mi = db.get_global_properties().parameters.maintenance_interval;
generate_blocks(HARDFORK_CORE_625_TIME - mi); // assume all hard forks occur at same time

if(hf1270)
generate_blocks(HARDFORK_CORE_1270_TIME - mi);
else
generate_blocks(HARDFORK_CORE_625_TIME - mi);

generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);

set_expiration( db, trx );
Expand Down Expand Up @@ -1195,8 +1214,14 @@ BOOST_AUTO_TEST_CASE(hard_fork_343_cross_test)
*/
BOOST_AUTO_TEST_CASE(target_cr_test_limit_call)
{ try {

auto mi = db.get_global_properties().parameters.maintenance_interval;
generate_blocks(HARDFORK_CORE_834_TIME - mi);

if(hf1270)
generate_blocks(HARDFORK_CORE_1270_TIME - mi);
else
generate_blocks(HARDFORK_CORE_834_TIME - mi);

generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);

set_expiration( db, trx );
Expand Down Expand Up @@ -1373,8 +1398,14 @@ BOOST_AUTO_TEST_CASE(target_cr_test_limit_call)
*/
BOOST_AUTO_TEST_CASE(target_cr_test_call_limit)
{ try {

auto mi = db.get_global_properties().parameters.maintenance_interval;
generate_blocks(HARDFORK_CORE_834_TIME - mi);

if(hf1270)
generate_blocks(HARDFORK_CORE_1270_TIME - mi);
else
generate_blocks(HARDFORK_CORE_834_TIME - mi);

generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);

set_expiration( db, trx );
Expand Down Expand Up @@ -1510,8 +1541,9 @@ BOOST_AUTO_TEST_CASE(target_cr_test_call_limit)
BOOST_AUTO_TEST_CASE(mcr_bug_increase_before1270)
{ try {

generate_blocks(HARDFORK_CORE_453_TIME);

auto mi = db.get_global_properties().parameters.maintenance_interval;
generate_blocks(HARDFORK_CORE_453_TIME - mi);
generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);
generate_block();

set_expiration( db, trx );
Expand Down Expand Up @@ -1574,8 +1606,9 @@ BOOST_AUTO_TEST_CASE(mcr_bug_increase_before1270)
BOOST_AUTO_TEST_CASE(mcr_bug_increase_after1270)
{ try {

generate_blocks(HARDFORK_CORE_1270_TIME);

auto mi = db.get_global_properties().parameters.maintenance_interval;
generate_blocks(HARDFORK_CORE_1270_TIME - mi);
generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);
generate_block();

set_expiration( db, trx );
Expand Down Expand Up @@ -1639,8 +1672,9 @@ BOOST_AUTO_TEST_CASE(mcr_bug_increase_after1270)
BOOST_AUTO_TEST_CASE(mcr_bug_decrease_before1270)
{ try {

generate_blocks(HARDFORK_CORE_453_TIME);

auto mi = db.get_global_properties().parameters.maintenance_interval;
generate_blocks(HARDFORK_CORE_453_TIME - mi);
generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);
generate_block();

set_expiration( db, trx );
Expand Down Expand Up @@ -1708,8 +1742,9 @@ BOOST_AUTO_TEST_CASE(mcr_bug_decrease_before1270)
BOOST_AUTO_TEST_CASE(mcr_bug_decrease_after1270)
{ try {

generate_blocks(HARDFORK_CORE_1270_TIME);

auto mi = db.get_global_properties().parameters.maintenance_interval;
generate_blocks(HARDFORK_CORE_1270_TIME - mi);
generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);
generate_block();

set_expiration( db, trx );
Expand Down Expand Up @@ -1817,4 +1852,40 @@ BOOST_AUTO_TEST_CASE(mcr_bug_cross1270)

} FC_LOG_AND_RETHROW() }

BOOST_AUTO_TEST_CASE(hardfork_core_338_test_after_hf1270)
{ try {
hf1270 = true;
INVOKE(hardfork_core_338_test);

} FC_LOG_AND_RETHROW() }

BOOST_AUTO_TEST_CASE(hardfork_core_453_test_after_hf1270)
{ try {
hf1270 = true;
INVOKE(hardfork_core_453_test);

} FC_LOG_AND_RETHROW() }

BOOST_AUTO_TEST_CASE(hardfork_core_625_big_limit_order_test_after_hf1270)
{ try {
hf1270 = true;
INVOKE(hardfork_core_625_big_limit_order_test);

} FC_LOG_AND_RETHROW() }

BOOST_AUTO_TEST_CASE(target_cr_test_limit_call_after_hf1270)
{ try {
hf1270 = true;
INVOKE(target_cr_test_limit_call);

} FC_LOG_AND_RETHROW() }

BOOST_AUTO_TEST_CASE(target_cr_test_call_limit_after_hf1270)
{ try {
hf1270 = true;
INVOKE(target_cr_test_call_limit);

} FC_LOG_AND_RETHROW() }


BOOST_AUTO_TEST_SUITE_END()
Loading

0 comments on commit 6b22b91

Please sign in to comment.