Fix for undo crash
This commit is contained in:
parent
06bc65cc79
commit
c3b2a598b4
2 changed files with 62 additions and 12 deletions
|
|
@ -24,9 +24,10 @@ object_id_type add_sidechain_address_evaluator::do_apply(const sidechain_address
|
|||
|
||||
if (addr_itr != sidechain_addresses_idx.end())
|
||||
{
|
||||
db().modify(*addr_itr, [&](sidechain_address_object &sao) {
|
||||
sao.expires = db().head_block_time();
|
||||
});
|
||||
//db().modify(*addr_itr, [&](sidechain_address_object &sao) {
|
||||
// sao.expires = db().head_block_time();
|
||||
//});
|
||||
db().remove(*addr_itr);
|
||||
}
|
||||
|
||||
const auto& new_sidechain_address_object = db().create<sidechain_address_object>( [&]( sidechain_address_object& obj ){
|
||||
|
|
@ -106,9 +107,10 @@ void_result delete_sidechain_address_evaluator::do_apply(const sidechain_address
|
|||
const auto& idx = db().get_index_type<sidechain_address_index>().indices().get<by_id>();
|
||||
auto sidechain_address = idx.find(op.sidechain_address_id);
|
||||
if(sidechain_address != idx.end()) {
|
||||
db().modify(*sidechain_address, [&](sidechain_address_object &sao) {
|
||||
sao.expires = db().head_block_time();
|
||||
});
|
||||
//db().modify(*sidechain_address, [&](sidechain_address_object &sao) {
|
||||
// sao.expires = db().head_block_time();
|
||||
//});
|
||||
db().remove(*sidechain_address);
|
||||
}
|
||||
return void_result();
|
||||
} FC_CAPTURE_AND_RETHROW( (op) ) }
|
||||
|
|
|
|||
|
|
@ -266,18 +266,66 @@ BOOST_AUTO_TEST_CASE( sidechain_address_delete_test ) {
|
|||
sign(trx, alice_private_key);
|
||||
PUSH_TX(db, trx, ~0);
|
||||
}
|
||||
time_point_sec now = db.head_block_time();
|
||||
//time_point_sec now = db.head_block_time();
|
||||
generate_block();
|
||||
|
||||
{
|
||||
BOOST_TEST_MESSAGE("Check sidechain_address_delete_operation results");
|
||||
|
||||
const auto& idx = db.get_index_type<sidechain_address_index>().indices().get<by_account_and_sidechain_and_expires>();
|
||||
BOOST_REQUIRE( idx.size() == 1 );
|
||||
auto obj = idx.find( boost::make_tuple( alice_id, sidechain_type::bitcoin, time_point_sec::maximum() ) );
|
||||
BOOST_REQUIRE( obj == idx.end() );
|
||||
auto expired_obj = idx.find( boost::make_tuple( alice_id, sidechain_type::bitcoin, now ) );
|
||||
BOOST_REQUIRE( expired_obj != idx.end() );
|
||||
//BOOST_REQUIRE( idx.size() == 1 );
|
||||
//auto obj = idx.find( boost::make_tuple( alice_id, sidechain_type::bitcoin, time_point_sec::maximum() ) );
|
||||
//BOOST_REQUIRE( obj == idx.end() );
|
||||
//auto expired_obj = idx.find( boost::make_tuple( alice_id, sidechain_type::bitcoin, now ) );
|
||||
//BOOST_REQUIRE( expired_obj != idx.end() );
|
||||
BOOST_REQUIRE( idx.size() == 0 );
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(sidechain_address_delete_create_test) {
|
||||
|
||||
BOOST_TEST_MESSAGE("sidechain_address_delete_create_test");
|
||||
|
||||
INVOKE(sidechain_address_add_test);
|
||||
|
||||
GET_ACTOR(alice);
|
||||
|
||||
const auto &idx = db.get_index_type<sidechain_address_index>().indices().get<by_account_and_sidechain_and_expires>();
|
||||
BOOST_REQUIRE(idx.size() == 1);
|
||||
auto obj = idx.find(boost::make_tuple(alice_id, sidechain_type::bitcoin, time_point_sec::maximum()));
|
||||
BOOST_REQUIRE(obj != idx.end());
|
||||
|
||||
{
|
||||
BOOST_TEST_MESSAGE("Delete and create sidechain address");
|
||||
sidechain_address_delete_operation op_del;
|
||||
op_del.payer = alice_id;
|
||||
op_del.sidechain_address_id = sidechain_address_id_type(0);
|
||||
op_del.sidechain_address_account = alice_id;
|
||||
op_del.sidechain = obj->sidechain;
|
||||
|
||||
sidechain_address_add_operation op_create;
|
||||
op_create.payer = alice_id;
|
||||
op_create.sidechain_address_account = alice_id;
|
||||
op_create.sidechain = sidechain_type::bitcoin;
|
||||
op_create.deposit_public_key = "deposit_public_key";
|
||||
op_create.withdraw_public_key = "withdraw_public_key";
|
||||
op_create.withdraw_address = "withdraw_address";
|
||||
|
||||
trx.operations.push_back(op_del);
|
||||
trx.operations.push_back(op_create);
|
||||
sign(trx, alice_private_key);
|
||||
PUSH_TX(db, trx, ~0);
|
||||
}
|
||||
|
||||
// both transactions should goes in one block (delete + create)
|
||||
generate_block();
|
||||
|
||||
{
|
||||
BOOST_TEST_MESSAGE("Check sidechain_address_delete_add_operation results");
|
||||
const auto &idx = db.get_index_type<sidechain_address_index>().indices().get<by_account_and_sidechain_and_expires>();
|
||||
BOOST_REQUIRE(idx.size() == 1);
|
||||
auto obj = idx.find(boost::make_tuple(alice_id, sidechain_type::bitcoin, time_point_sec::maximum()));
|
||||
BOOST_REQUIRE(obj != idx.end());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue