fix tests
This commit is contained in:
parent
501495d995
commit
62f621c00a
11 changed files with 96 additions and 168 deletions
|
|
@ -59,23 +59,24 @@ namespace graphene { namespace chain {
|
|||
ordered_unique< tag<by_sidechain_and_deposit_public_key_and_expires>,
|
||||
composite_key<sidechain_address_object,
|
||||
member<sidechain_address_object, sidechain_type, &sidechain_address_object::sidechain>,
|
||||
member<sidechain_address_object, std::string, &sidechain_address_object::deposit_public_key>,
|
||||
member<sidechain_address_object, string, &sidechain_address_object::deposit_public_key>,
|
||||
member<sidechain_address_object, time_point_sec, &sidechain_address_object::expires>
|
||||
>
|
||||
>,
|
||||
ordered_non_unique< tag<by_withdraw_public_key>,
|
||||
member<sidechain_address_object, std::string, &sidechain_address_object::withdraw_public_key>
|
||||
member<sidechain_address_object, string, &sidechain_address_object::withdraw_public_key>
|
||||
>,
|
||||
ordered_unique< tag<by_account_and_sidechain_and_expires>,
|
||||
ordered_non_unique< tag<by_account_and_sidechain_and_expires>,
|
||||
composite_key<sidechain_address_object,
|
||||
member<sidechain_address_object, account_id_type, &sidechain_address_object::sidechain_address_account>,
|
||||
member<sidechain_address_object, sidechain_type, &sidechain_address_object::sidechain>,
|
||||
member<sidechain_address_object, time_point_sec, &sidechain_address_object::expires>
|
||||
>
|
||||
>,
|
||||
ordered_unique< tag<by_sidechain_and_deposit_address_and_expires>,
|
||||
ordered_non_unique< tag<by_sidechain_and_deposit_address_and_expires>,
|
||||
composite_key<sidechain_address_object,
|
||||
member<sidechain_address_object, sidechain_type, &sidechain_address_object::sidechain>,
|
||||
member<sidechain_address_object, std::string, &sidechain_address_object::deposit_address>,
|
||||
member<sidechain_address_object, string, &sidechain_address_object::deposit_address>,
|
||||
member<sidechain_address_object, time_point_sec, &sidechain_address_object::expires>
|
||||
>
|
||||
>
|
||||
|
|
@ -88,4 +89,4 @@ namespace graphene { namespace chain {
|
|||
FC_REFLECT_DERIVED( graphene::chain::sidechain_address_object, (graphene::db::object),
|
||||
(sidechain_address_account) (sidechain)
|
||||
(deposit_public_key) (deposit_address) (deposit_address_data)
|
||||
(withdraw_public_key) (withdraw_address) )
|
||||
(withdraw_public_key) (withdraw_address) (valid_from) (expires) )
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#include <graphene/chain/sidechain_address_evaluator.hpp>
|
||||
|
||||
#include <graphene/chain/database.hpp>
|
||||
#include <graphene/chain/son_object.hpp>
|
||||
#include <graphene/chain/sidechain_address_object.hpp>
|
||||
#include <graphene/chain/hardfork.hpp>
|
||||
|
||||
|
|
@ -16,11 +17,12 @@ void_result add_sidechain_address_evaluator::do_evaluate(const sidechain_address
|
|||
|
||||
object_id_type add_sidechain_address_evaluator::do_apply(const sidechain_address_add_operation& op)
|
||||
{ try {
|
||||
const auto &sidechain_addresses_idx = database.get_index_type<sidechain_address_index>().indices().get<by_account_and_sidechain_and_expires>();
|
||||
const auto &addr_itr = sidechain_addresses_idx.find(std::make_tuple(sed.peerplays_from, op.sidechain, time_point_sec::maximum()));
|
||||
const auto &sidechain_addresses_idx = db().get_index_type<sidechain_address_index>().indices().get<by_account_and_sidechain_and_expires>();
|
||||
const auto &addr_itr = sidechain_addresses_idx.find(std::make_tuple(op.sidechain_address_account, op.sidechain, time_point_sec::maximum()));
|
||||
|
||||
if (addr_itr != sidechain_addresses_idx.end())
|
||||
{
|
||||
db().modify(*addr_itr, [&op](sidechain_address_object &sao) {
|
||||
db().modify(*addr_itr, [&](sidechain_address_object &sao) {
|
||||
sao.expires = db().head_block_time();
|
||||
});
|
||||
}
|
||||
|
|
@ -41,13 +43,13 @@ object_id_type add_sidechain_address_evaluator::do_apply(const sidechain_address
|
|||
|
||||
void_result update_sidechain_address_evaluator::do_evaluate(const sidechain_address_update_operation& op)
|
||||
{ try {
|
||||
const auto& sidx = _db.get_index_type<son_index>().indices().get<by_account>();
|
||||
const auto& sidx = db().get_index_type<son_index>().indices().get<by_account>();
|
||||
const auto& son_obj = sidx.find(op.payer);
|
||||
FC_ASSERT( son_obj != sidx.end() && db().is_son_active(son_obj->id), "Non active SON trying to update deposit address object" );
|
||||
const auto& sdpke_idx = db().get_index_type<sidechain_address_index>().indices().get<by_sidechain_and_deposit_public_key_and_expires>();
|
||||
FC_ASSERT( op.deposit_address.valid() && op.deposit_public_key.valid() && op.deposit_address_data.valid(), "Update operation by SON is not valid");
|
||||
FC_ASSERT( op->deposit_address.length() > 0 && op->deposit_public_key.length() > 0 && op->deposit_address_data.length() > 0, "SON should create a valid deposit address with valid deposit public key");
|
||||
FC_ASSERT( sdpke_idx.find(boost::make_tuple(op.sidechain, op.deposit_public_key, time_point_sec::maximum())) != sdpke_idx.end(), "Invalid update operation by SON" );
|
||||
FC_ASSERT( (*op.deposit_address).length() > 0 && (*op.deposit_public_key).length() > 0 && (*op.deposit_address_data).length() > 0, "SON should create a valid deposit address with valid deposit public key");
|
||||
FC_ASSERT( sdpke_idx.find(boost::make_tuple(op.sidechain, *op.deposit_public_key, time_point_sec::maximum())) != sdpke_idx.end(), "Invalid update operation by SON" );
|
||||
FC_ASSERT( db().get(op.sidechain_address_id).sidechain_address_account == op.sidechain_address_account, "Invalid sidechain address account" );
|
||||
const auto& idx = db().get_index_type<sidechain_address_index>().indices().get<by_id>();
|
||||
FC_ASSERT( idx.find(op.sidechain_address_id) != idx.end(), "Invalid sidechain address ID" );
|
||||
|
|
@ -65,15 +67,15 @@ object_id_type update_sidechain_address_evaluator::do_apply(const sidechain_addr
|
|||
const auto& new_sidechain_address_object = db().create<sidechain_address_object>( [&]( sidechain_address_object& obj ) {
|
||||
obj.sidechain_address_account = op.sidechain_address_account;
|
||||
obj.sidechain = op.sidechain;
|
||||
obj.deposit_public_key = op.deposit_public_key;
|
||||
obj.deposit_public_key = *op.deposit_public_key;
|
||||
obj.deposit_address = itr->deposit_address;
|
||||
obj.deposit_address_data = itr->deposit_address_data;
|
||||
obj.withdraw_public_key = op.withdraw_public_key;
|
||||
obj.withdraw_address = op.withdraw_address;
|
||||
obj.withdraw_public_key = *op.withdraw_public_key;
|
||||
obj.withdraw_address = *op.withdraw_address;
|
||||
obj.valid_from = itr->valid_from;
|
||||
obj.expires = db().head_block_time();
|
||||
});
|
||||
db().modify(*itr, [&op](sidechain_address_object &sao) {
|
||||
db().modify(*itr, [&](sidechain_address_object &sao) {
|
||||
if(op.deposit_address.valid()) sao.deposit_address = *op.deposit_address;
|
||||
if(op.deposit_address_data.valid()) sao.deposit_address_data = *op.deposit_address_data;
|
||||
sao.valid_from = db().head_block_time();
|
||||
|
|
@ -102,7 +104,7 @@ 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) {
|
||||
db().modify(*sidechain_address, [&](sidechain_address_object &sao) {
|
||||
sao.expires = db().head_block_time();
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,6 @@ public:
|
|||
virtual bool process_proposal(const proposal_object &po) = 0;
|
||||
virtual void process_primary_wallet() = 0;
|
||||
virtual void process_sidechain_addresses() = 0;
|
||||
virtual bool create_deposit_address(const sidechain_address_object &sao) = 0;
|
||||
virtual bool process_deposit(const son_wallet_deposit_object &swdo) = 0;
|
||||
virtual bool process_withdrawal(const son_wallet_withdraw_object &swwo) = 0;
|
||||
virtual std::string process_sidechain_transaction(const sidechain_transaction_object &sto) = 0;
|
||||
|
|
|
|||
|
|
@ -91,7 +91,6 @@ public:
|
|||
bool process_proposal(const proposal_object &po);
|
||||
void process_primary_wallet();
|
||||
void process_sidechain_addresses();
|
||||
bool create_deposit_address(const sidechain_address_object &sao);
|
||||
bool process_deposit(const son_wallet_deposit_object &swdo);
|
||||
bool process_withdrawal(const son_wallet_withdraw_object &swwo);
|
||||
std::string process_sidechain_transaction(const sidechain_transaction_object &sto);
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ public:
|
|||
bool process_proposal(const proposal_object &po);
|
||||
void process_primary_wallet();
|
||||
void process_sidechain_addresses();
|
||||
bool create_deposit_address(const sidechain_address_object &sao);
|
||||
bool process_deposit(const son_wallet_deposit_object &swdo);
|
||||
bool process_withdrawal(const son_wallet_withdraw_object &swwo);
|
||||
std::string process_sidechain_transaction(const sidechain_transaction_object &sto);
|
||||
|
|
|
|||
|
|
@ -356,31 +356,13 @@ void sidechain_net_handler::process_proposals() {
|
|||
|
||||
void sidechain_net_handler::process_active_sons_change() {
|
||||
process_primary_wallet();
|
||||
process_sidechain_addresses();
|
||||
}
|
||||
|
||||
void sidechain_net_handler::create_deposit_addresses() {
|
||||
if (database.get_global_properties().active_sons.size() < database.get_chain_properties().immutable_parameters.min_son_count) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto &idx = database.get_index_type<sidechain_address_index>().indices().get<by_sidechain_and_deposit_address_and_expires>();
|
||||
const auto &idx_range = idx.equal_range(std::make_tuple(sidechain, "", time_point_sec::maximum()));
|
||||
|
||||
std::for_each(idx_range.first, idx_range.second, [&](const sidechain_address_object &sao) {
|
||||
if (sao.id == object_id_type(0, 0, 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ilog("sidechain deposit address to create: ${sao}", ("sao", sao));
|
||||
|
||||
bool create_address_result = create_deposit_address(sao);
|
||||
|
||||
if (!create_address_result) {
|
||||
wlog("Deposit address not created: ${sao}", ("sao", sao));
|
||||
return;
|
||||
}
|
||||
});
|
||||
process_sidechain_addresses();
|
||||
}
|
||||
|
||||
void sidechain_net_handler::process_deposits() {
|
||||
|
|
|
|||
|
|
@ -1384,49 +1384,6 @@ void sidechain_net_handler_bitcoin::process_sidechain_addresses() {
|
|||
});
|
||||
}
|
||||
|
||||
bool sidechain_net_handler_bitcoin::create_deposit_address(const sidechain_address_object &sao) {
|
||||
using namespace bitcoin;
|
||||
|
||||
const chain::global_property_object &gpo = database.get_global_properties();
|
||||
std::vector<std::pair<fc::ecc::public_key, uint16_t>> pubkeys;
|
||||
for (auto &son : gpo.active_sons) {
|
||||
std::string pub_key_str = son.sidechain_public_keys.at(sidechain_type::bitcoin);
|
||||
auto pubkey = fc::ecc::public_key(create_public_key_data(parse_hex(pub_key_str)));
|
||||
pubkeys.push_back(std::make_pair(pubkey, son.weight));
|
||||
}
|
||||
|
||||
auto usr_pubkey = fc::ecc::public_key(create_public_key_data(parse_hex(sao.deposit_public_key)));
|
||||
|
||||
btc_one_or_weighted_multisig_address addr(usr_pubkey, pubkeys, network_type);
|
||||
std::string address_data = "{ \"redeemScript\": \"" + fc::to_hex(addr.get_redeem_script()) +
|
||||
"\", \"witnessScript\": \"" + fc::to_hex(addr.get_witness_script()) + "\" }";
|
||||
|
||||
if (addr.get_address() != sao.deposit_address) {
|
||||
sidechain_address_update_operation op;
|
||||
op.payer = plugin.get_current_son_object().son_account;
|
||||
op.sidechain_address_id = sao.id;
|
||||
op.sidechain_address_account = sao.sidechain_address_account;
|
||||
op.sidechain = sao.sidechain;
|
||||
op.deposit_public_key = sao.deposit_public_key;
|
||||
op.deposit_address = addr.get_address();
|
||||
op.deposit_address_data = address_data;
|
||||
op.withdraw_public_key = sao.withdraw_public_key;
|
||||
op.withdraw_address = sao.withdraw_address;
|
||||
|
||||
signed_transaction trx = database.create_signed_transaction(plugin.get_private_key(plugin.get_current_son_id()), op);
|
||||
try {
|
||||
trx.validate();
|
||||
database.push_transaction(trx, database::validation_steps::skip_block_size_check);
|
||||
if (plugin.app().p2p_node())
|
||||
plugin.app().p2p_node()->broadcast(net::trx_message(trx));
|
||||
return true;
|
||||
} catch (fc::exception e) {
|
||||
elog("Sending transaction for update deposit address operation failed with exception ${e}", ("e", e.what()));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool sidechain_net_handler_bitcoin::process_deposit(const son_wallet_deposit_object &swdo) {
|
||||
|
||||
if (proposal_exists(chain::operation::tag<chain::son_wallet_deposit_process_operation>::value, swdo.id)) {
|
||||
|
|
|
|||
|
|
@ -124,11 +124,39 @@ void sidechain_net_handler_peerplays::process_primary_wallet() {
|
|||
}
|
||||
|
||||
void sidechain_net_handler_peerplays::process_sidechain_addresses() {
|
||||
return;
|
||||
}
|
||||
const auto &sidechain_addresses_idx = database.get_index_type<sidechain_address_index>();
|
||||
const auto &sidechain_addresses_by_sidechain_idx = sidechain_addresses_idx.indices().get<by_sidechain>();
|
||||
const auto &sidechain_addresses_by_sidechain_range = sidechain_addresses_by_sidechain_idx.equal_range(sidechain);
|
||||
std::for_each(sidechain_addresses_by_sidechain_range.first, sidechain_addresses_by_sidechain_range.second,
|
||||
[&](const sidechain_address_object &sao) {
|
||||
if (sao.expires == time_point_sec::maximum()) {
|
||||
if (sao.deposit_address == "") {
|
||||
sidechain_address_update_operation op;
|
||||
op.payer = plugin.get_current_son_object().son_account;
|
||||
op.sidechain_address_id = sao.id;
|
||||
op.sidechain_address_account = sao.sidechain_address_account;
|
||||
op.sidechain = sao.sidechain;
|
||||
op.deposit_public_key = sao.deposit_public_key;
|
||||
op.deposit_address = sao.withdraw_address;
|
||||
op.deposit_address_data = sao.withdraw_address;
|
||||
op.withdraw_public_key = sao.withdraw_public_key;
|
||||
op.withdraw_address = sao.withdraw_address;
|
||||
|
||||
bool sidechain_net_handler_peerplays::create_deposit_address(const sidechain_address_object &sao) {
|
||||
return true;
|
||||
signed_transaction trx = database.create_signed_transaction(plugin.get_private_key(plugin.get_current_son_id()), op);
|
||||
try {
|
||||
trx.validate();
|
||||
database.push_transaction(trx, database::validation_steps::skip_block_size_check);
|
||||
if (plugin.app().p2p_node())
|
||||
plugin.app().p2p_node()->broadcast(net::trx_message(trx));
|
||||
return true;
|
||||
} catch (fc::exception e) {
|
||||
elog("Sending transaction for update deposit address operation failed with exception ${e}", ("e", e.what()));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
bool sidechain_net_handler_peerplays::process_deposit(const son_wallet_deposit_object &swdo) {
|
||||
|
|
|
|||
|
|
@ -1452,25 +1452,6 @@ class wallet_api
|
|||
string withdraw_address,
|
||||
bool broadcast = false);
|
||||
|
||||
/** Updates existing sidechain address owned by the given account for a given sidechain.
|
||||
*
|
||||
* Only address, private key and public key might be updated.
|
||||
*
|
||||
* @param account the name or id of the account who owns the address
|
||||
* @param sidechain a sidechain to whom address belongs
|
||||
* @param deposit_public_key sidechain public key used for deposit address
|
||||
* @param withdraw_public_key sidechain public key used for withdraw address
|
||||
* @param withdraw_address sidechain address for withdrawals
|
||||
* @param broadcast true to broadcast the transaction on the network
|
||||
* @returns the signed transaction updating sidechain address
|
||||
*/
|
||||
signed_transaction update_sidechain_address(string account,
|
||||
sidechain_type sidechain,
|
||||
string deposit_public_key,
|
||||
string withdraw_public_key,
|
||||
string withdraw_address,
|
||||
bool broadcast = false);
|
||||
|
||||
/** Deletes existing sidechain address owned by the given account for a given sidechain.
|
||||
*
|
||||
* @param account the name or id of the account who owns the address
|
||||
|
|
@ -2319,7 +2300,6 @@ FC_API( graphene::wallet::wallet_api,
|
|||
(get_son_wallet_by_time_point)
|
||||
(get_son_wallets)
|
||||
(add_sidechain_address)
|
||||
(update_sidechain_address)
|
||||
(delete_sidechain_address)
|
||||
(get_sidechain_addresses_by_account)
|
||||
(get_sidechain_addresses_by_sidechain)
|
||||
|
|
|
|||
|
|
@ -2102,35 +2102,6 @@ public:
|
|||
return sign_transaction( tx, broadcast );
|
||||
} FC_CAPTURE_AND_RETHROW() }
|
||||
|
||||
signed_transaction update_sidechain_address(string account,
|
||||
sidechain_type sidechain,
|
||||
string deposit_public_key,
|
||||
string withdraw_public_key,
|
||||
string withdraw_address,
|
||||
bool broadcast /* = false */)
|
||||
{ try {
|
||||
account_id_type sidechain_address_account_id = get_account_id(account);
|
||||
fc::optional<sidechain_address_object> sao = _remote_db->get_sidechain_address_by_account_and_sidechain(sidechain_address_account_id, sidechain);
|
||||
if (!sao)
|
||||
FC_THROW("No sidechain address for account ${account} and sidechain ${sidechain}", ("account", sidechain_address_account_id)("sidechain", sidechain));
|
||||
|
||||
sidechain_address_update_operation op;
|
||||
op.payer = sidechain_address_account_id;
|
||||
op.sidechain_address_id = sao->id;
|
||||
op.sidechain_address_account = sidechain_address_account_id;
|
||||
op.sidechain = sidechain;
|
||||
op.deposit_public_key = deposit_public_key;
|
||||
op.withdraw_public_key = withdraw_public_key;
|
||||
op.withdraw_address = withdraw_address;
|
||||
|
||||
signed_transaction tx;
|
||||
tx.operations.push_back( op );
|
||||
set_operation_fees( tx, _remote_db->get_global_properties().parameters.current_fees);
|
||||
tx.validate();
|
||||
|
||||
return sign_transaction( tx, broadcast );
|
||||
} FC_CAPTURE_AND_RETHROW() }
|
||||
|
||||
signed_transaction delete_sidechain_address(string account,
|
||||
sidechain_type sidechain,
|
||||
bool broadcast /* = false */)
|
||||
|
|
@ -4807,16 +4778,6 @@ signed_transaction wallet_api::add_sidechain_address(string account,
|
|||
return my->add_sidechain_address(account, sidechain, deposit_public_key, withdraw_public_key, withdraw_address, broadcast);
|
||||
}
|
||||
|
||||
signed_transaction wallet_api::update_sidechain_address(string account,
|
||||
sidechain_type sidechain,
|
||||
string deposit_public_key,
|
||||
string withdraw_public_key,
|
||||
string withdraw_address,
|
||||
bool broadcast /* = false */)
|
||||
{
|
||||
return my->update_sidechain_address(account, sidechain, deposit_public_key, withdraw_public_key, withdraw_address, broadcast);
|
||||
}
|
||||
|
||||
signed_transaction wallet_api::delete_sidechain_address(string account,
|
||||
sidechain_type sidechain,
|
||||
bool broadcast /* = false */)
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
#include "../common/database_fixture.hpp"
|
||||
|
||||
#include <graphene/chain/hardfork.hpp>
|
||||
#include <graphene/chain/son_object.hpp>
|
||||
#include <graphene/chain/sidechain_address_object.hpp>
|
||||
#include <graphene/chain/sidechain_defs.hpp>
|
||||
|
||||
|
|
@ -31,7 +32,6 @@ BOOST_AUTO_TEST_CASE( sidechain_address_add_test ) {
|
|||
op.sidechain_address_account = alice_id;
|
||||
op.sidechain = sidechain_type::bitcoin;
|
||||
op.deposit_public_key = "deposit_public_key";
|
||||
op.deposit_address = "deposit_address";
|
||||
op.withdraw_public_key = "withdraw_public_key";
|
||||
op.withdraw_address = "withdraw_address";
|
||||
|
||||
|
|
@ -43,66 +43,83 @@ BOOST_AUTO_TEST_CASE( sidechain_address_add_test ) {
|
|||
|
||||
BOOST_TEST_MESSAGE("Check sidechain_address_add_operation results");
|
||||
|
||||
const auto& idx = db.get_index_type<sidechain_address_index>().indices().get<by_account_and_sidechain>();
|
||||
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 ) );
|
||||
auto obj = idx.find( boost::make_tuple( alice_id, sidechain_type::bitcoin, time_point_sec::maximum() ) );
|
||||
BOOST_REQUIRE( obj != idx.end() );
|
||||
BOOST_CHECK( obj->sidechain_address_account == alice_id );
|
||||
BOOST_CHECK( obj->sidechain == sidechain_type::bitcoin );
|
||||
BOOST_CHECK( obj->deposit_public_key == "deposit_public_key" );
|
||||
BOOST_CHECK( obj->deposit_address == "deposit_address" );
|
||||
BOOST_CHECK( obj->deposit_address == "" );
|
||||
BOOST_CHECK( obj->deposit_address_data == "" );
|
||||
BOOST_CHECK( obj->withdraw_public_key == "withdraw_public_key" );
|
||||
BOOST_CHECK( obj->withdraw_address == "withdraw_address" );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( sidechain_address_update_test ) {
|
||||
|
||||
BOOST_TEST_MESSAGE("sidechain_address_update_test");
|
||||
generate_blocks(HARDFORK_SON_TIME);
|
||||
generate_block();
|
||||
|
||||
INVOKE(sidechain_address_add_test);
|
||||
|
||||
GET_ACTOR(alice);
|
||||
ACTORS((bob));
|
||||
|
||||
const auto& idx = db.get_index_type<sidechain_address_index>().indices().get<by_account_and_sidechain>();
|
||||
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 ) );
|
||||
auto obj = idx.find( boost::make_tuple( alice_id, sidechain_type::bitcoin, time_point_sec::maximum() ) );
|
||||
BOOST_REQUIRE( obj != idx.end() );
|
||||
|
||||
std::string new_deposit_public_key = "new_deposit_public_key";
|
||||
std::string new_deposit_public_key = "deposit_public_key";
|
||||
std::string new_deposit_address = "new_deposit_address";
|
||||
std::string new_withdraw_public_key = "new_withdraw_public_key";
|
||||
std::string new_withdraw_address = "new_withdraw_address";
|
||||
std::string new_deposit_address_data = "new_deposit_address_data";
|
||||
std::string new_withdraw_public_key = "withdraw_public_key";
|
||||
std::string new_withdraw_address = "withdraw_address";
|
||||
|
||||
generate_block();
|
||||
auto& son = db.create<son_object>( [&]( son_object& sobj )
|
||||
{
|
||||
sobj.son_account = bob_id;
|
||||
sobj.statistics = db.create<son_statistics_object>([&](son_statistics_object& s){s.owner = sobj.id;}).id;
|
||||
});
|
||||
generate_block();
|
||||
db.modify( db.get_global_properties(), [&]( global_property_object& _gpo )
|
||||
{
|
||||
son_info sinfo;
|
||||
sinfo.son_id = son.id;
|
||||
_gpo.active_sons.push_back(sinfo);
|
||||
});
|
||||
generate_block();
|
||||
{
|
||||
BOOST_TEST_MESSAGE("Send sidechain_address_update_operation");
|
||||
|
||||
trx.clear();
|
||||
sidechain_address_update_operation op;
|
||||
op.payer = alice_id;
|
||||
op.payer = bob_id;
|
||||
op.sidechain_address_id = sidechain_address_id_type(0);
|
||||
op.sidechain_address_account = obj->sidechain_address_account;
|
||||
op.sidechain = obj->sidechain;
|
||||
op.deposit_public_key = new_deposit_public_key;
|
||||
op.deposit_address = new_deposit_address;
|
||||
op.deposit_address_data = new_deposit_address_data;
|
||||
op.withdraw_public_key = new_withdraw_public_key;
|
||||
op.withdraw_address = new_withdraw_address;
|
||||
|
||||
trx.operations.push_back(op);
|
||||
sign(trx, alice_private_key);
|
||||
sign(trx, bob_private_key);
|
||||
PUSH_TX(db, trx, ~0);
|
||||
}
|
||||
generate_block();
|
||||
|
||||
{
|
||||
BOOST_TEST_MESSAGE("Check sidechain_address_update_operation results");
|
||||
|
||||
const auto& idx = db.get_index_type<sidechain_address_index>().indices().get<by_account_and_sidechain>();
|
||||
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 ) );
|
||||
auto obj = idx.find( boost::make_tuple( alice_id, sidechain_type::bitcoin, time_point_sec::maximum() ) );
|
||||
BOOST_REQUIRE( obj != idx.end() );
|
||||
BOOST_CHECK( obj->sidechain_address_account == obj->sidechain_address_account );
|
||||
BOOST_CHECK( obj->sidechain == obj->sidechain );
|
||||
BOOST_CHECK( obj->deposit_public_key == new_deposit_public_key );
|
||||
BOOST_CHECK( obj->deposit_address == new_deposit_address );
|
||||
BOOST_CHECK( obj->deposit_address_data == new_deposit_address_data );
|
||||
BOOST_CHECK( obj->withdraw_public_key == new_withdraw_public_key );
|
||||
BOOST_CHECK( obj->withdraw_address == new_withdraw_address );
|
||||
}
|
||||
|
|
@ -116,9 +133,9 @@ BOOST_AUTO_TEST_CASE( sidechain_address_delete_test ) {
|
|||
|
||||
GET_ACTOR(alice);
|
||||
|
||||
const auto& idx = db.get_index_type<sidechain_address_index>().indices().get<by_account_and_sidechain>();
|
||||
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 ) );
|
||||
auto obj = idx.find( boost::make_tuple( alice_id, sidechain_type::bitcoin, time_point_sec::maximum() ) );
|
||||
BOOST_REQUIRE( obj != idx.end() );
|
||||
|
||||
{
|
||||
|
|
@ -134,15 +151,18 @@ 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();
|
||||
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>();
|
||||
BOOST_REQUIRE( idx.size() == 0 );
|
||||
auto obj = idx.find( boost::make_tuple( alice_id, sidechain_type::bitcoin ) );
|
||||
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() );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue