diff --git a/external/unbound b/external/unbound index 7f2396795..0f6c0579d 160000 --- a/external/unbound +++ b/external/unbound @@ -1 +1 @@ -Subproject commit 7f23967954736dcaa366806b9eaba7e2bdfede11 +Subproject commit 0f6c0579d66b65f86066e30e7876105ba2775ef4 diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp index fd68901dd..bd8229d92 100644 --- a/src/blockchain_db/lmdb/db_lmdb.cpp +++ b/src/blockchain_db/lmdb/db_lmdb.cpp @@ -1251,7 +1251,11 @@ uint64_t BlockchainLMDB::add_advanced_output(const tx_out& tx_output, const uint okadv.unlock_time = unlock_time; okadv.output_id = output_id; okadv.pubkey = txout.key; //todo if there are multiple keys, rest will go to data - okadv.data = blobdata(txout.data.begin(),txout.data.end()); //no need to serialize vector to blob. Just copy it. + + if(out_type == tx_out_type::out_staked_token) + okadv.data = std::to_string(tx_output.token_amount); + else + okadv.data = blobdata(txout.data.begin(),txout.data.end()); //no need to serialize vector to blob. Just copy it. MDB_val_copy adv_value(okadv); diff --git a/src/safex/command.cpp b/src/safex/command.cpp index c0dfcd932..87458d826 100644 --- a/src/safex/command.cpp +++ b/src/safex/command.cpp @@ -77,26 +77,28 @@ namespace safex return execution_status::error_unstake_token_offset_not_one; uint64_t staked_token_index = txin.key_offsets[0]; - const cryptonote::output_advanced_data_t od = blokchainDB.get_output_advanced_data(cryptonote::tx_out_type::out_staked_token, staked_token_index); + try + { + const cryptonote::output_advanced_data_t od = blokchainDB.get_output_advanced_data(cryptonote::tx_out_type::out_staked_token, staked_token_index); + uint64_t token_amount = 0; + epee::string_tools::get_xtype_from_string(token_amount, od.data); - auto toi = blokchainDB.get_output_tx_and_index_from_global(od.output_id); - auto tx = blokchainDB.get_tx(toi.first); - bool output_found = false; - for(auto out: tx.vout) - if(out.target.type() == typeid(cryptonote::txout_to_script) && get_tx_out_type(out.target) == cryptonote::tx_out_type::out_staked_token) - if(out.token_amount == txin.token_amount) - output_found = true; + if(token_amount != txin.token_amount) + return execution_status::error_unstake_token_output_not_found; - uint64_t expected_interest = blokchainDB.calculate_staked_token_interest_for_output(txin, blokchainDB.height()); + uint64_t expected_interest = blokchainDB.calculate_staked_token_interest_for_output(txin, blokchainDB.height()); - if(txin.amount > expected_interest) - return execution_status::error_unstake_token_network_fee_not_matching; + if(txin.amount > expected_interest) + return execution_status::error_unstake_token_network_fee_not_matching; - if(!output_found) - return execution_status::error_unstake_token_output_not_found; - if(od.height + get_safex_minumum_token_lock_period(blokchainDB.get_net_type()) > blokchainDB.height()) - return execution_status::error_unstake_token_minimum_period; + if(od.height + get_safex_minumum_token_lock_period(blokchainDB.get_net_type()) > blokchainDB.height()) + return execution_status::error_unstake_token_minimum_period; + } + catch (...) + { + return execution_status::error_unstake_token_output_not_found; + } return execution_status::ok; } @@ -287,17 +289,39 @@ namespace safex std::unique_ptr cmd = safex::safex_command_serializer::parse_safex_command(txin.script); - for (auto ch: cmd->get_username()) { - if (!(std::islower(ch) || std::isdigit(ch)) && ch!='_' && ch!='-') { - return execution_status::error_invalid_account_name; - } - } + if(txin.key_offsets.size() != 1) + return execution_status::error_account_offset_not_one; + + uint64_t safex_account_index = txin.key_offsets[0]; std::vector dummy{}; if (!blokchainDB.get_account_data(cmd->get_username(), dummy)) { return execution_status::error_account_non_existant; } + try + { + const cryptonote::output_advanced_data_t od = blokchainDB.get_output_advanced_data(cryptonote::tx_out_type::out_safex_account, safex_account_index); + + safex::create_account_data account; + const cryptonote::blobdata accblob(std::begin(od.data), std::end(od.data)); + cryptonote::parse_and_validate_from_blob(accblob, account); + std::string accusername(begin(account.username), end(account.username)); + + if(accusername != cmd->get_username()) + return execution_status::error_invalid_account_name; + } + catch (...) + { + return execution_status::error_account_non_existant; + } + + for (auto ch: cmd->get_username()) { + if (!(std::islower(ch) || std::isdigit(ch)) && ch!='_' && ch!='-') { + return execution_status::error_invalid_account_name; + } + } + if (cmd->get_username().length() > SAFEX_ACCOUNT_USERNAME_MAX_SIZE) { return execution_status::error_account_data_too_big; @@ -330,20 +354,38 @@ namespace safex std::unique_ptr cmd = safex::safex_command_serializer::parse_safex_command(txin.script); + if(txin.key_offsets.size() != 1) + return execution_status::error_offer_offset_not_one; + + uint64_t safex_account_index = txin.key_offsets[0]; + std::vector dummy{}; if (!blokchainDB.get_account_data(cmd->get_seller(), dummy)) { return execution_status::error_account_non_existant; } + try + { + const cryptonote::output_advanced_data_t od = blokchainDB.get_output_advanced_data(cryptonote::tx_out_type::out_safex_account, safex_account_index); + + safex::create_account_data account; + const cryptonote::blobdata accblob(std::begin(od.data), std::end(od.data)); + cryptonote::parse_and_validate_from_blob(accblob, account); + + if(account.username != cmd->get_seller()) + return execution_status::error_invalid_account_name; + } + catch (...) + { + return execution_status::error_account_non_existant; + } + + safex::safex_offer sfx_offer{}; if (blokchainDB.get_offer(cmd->get_offerid(),sfx_offer)) { return execution_status::error_offer_already_exists; } - if(cmd->get_active() == false || cmd->get_quantity() == 0) { - return execution_status::error_wrong_input_params; - } - if(cmd->get_min_sfx_price() < SAFEX_OFFER_MINIMUM_PRICE){ return execution_status::error_offer_price_too_small; } @@ -393,11 +435,37 @@ namespace safex std::unique_ptr cmd = safex::safex_command_serializer::parse_safex_command(txin.script); + if(txin.key_offsets.size() != 1) + return execution_status::error_offer_offset_not_one; + + uint64_t safex_offer_index = txin.key_offsets[0]; + std::vector dummy{}; if (!blokchainDB.get_account_data(cmd->get_seller(), dummy)) { return execution_status::error_account_non_existant; } + safex::safex_offer sfx_dummy{}; + if (!blokchainDB.get_offer(cmd->get_offerid(), sfx_dummy)) { + return execution_status::error_offer_non_existant; + } + + try + { + const cryptonote::output_advanced_data_t od = blokchainDB.get_output_advanced_data(cryptonote::tx_out_type::out_safex_offer, safex_offer_index); + + safex::create_offer_data offer; + const cryptonote::blobdata offerblob(std::begin(od.data), std::end(od.data)); + cryptonote::parse_and_validate_from_blob(offerblob, offer); + + if(offer.offer_id != cmd->get_offerid()) + return execution_status::error_offer_invalid_offer_id; + } + catch (...) + { + return execution_status::error_account_non_existant; + } + if(cmd->get_min_sfx_price() < SAFEX_OFFER_MINIMUM_PRICE){ return execution_status::error_offer_price_too_small; } @@ -427,10 +495,6 @@ namespace safex return execution_status::error_offer_price_peg_not_existant; } - safex::safex_offer sfx_dummy{}; - if (!blokchainDB.get_offer(cmd->get_offerid(), sfx_dummy)) { - return execution_status::error_offer_non_existant; - } return execution_status::ok; }; @@ -451,6 +515,22 @@ namespace safex std::unique_ptr cmd = safex::safex_command_serializer::parse_safex_command(txin.script); + if(txin.key_offsets.size() != 1) + return execution_status::error_feedback_offset_not_one; + + uint64_t safex_feedback_token_index = txin.key_offsets[0]; + + try + { + const cryptonote::output_advanced_data_t od = blokchainDB.get_output_advanced_data(cryptonote::tx_out_type::out_safex_feedback_token, safex_feedback_token_index); + + } + catch (...) + { + return execution_status::error_feedback_token_non_existant; + } + + safex::safex_offer sfx_dummy{}; if (!blokchainDB.get_offer(cmd->get_offerid(), sfx_dummy)) { return execution_status::error_offer_non_existant; @@ -490,6 +570,27 @@ namespace safex return execution_status::error_account_non_existant; } + if(txin.key_offsets.size() != 1) + return execution_status::error_price_peg_offset_not_one; + + uint64_t safex_account_index = txin.key_offsets[0]; + + try + { + const cryptonote::output_advanced_data_t od = blokchainDB.get_output_advanced_data(cryptonote::tx_out_type::out_safex_account, safex_account_index); + + safex::create_account_data account; + const cryptonote::blobdata accblob(std::begin(od.data), std::end(od.data)); + cryptonote::parse_and_validate_from_blob(accblob, account); + + if(account.username != cmd->get_creator()) + return execution_status::error_invalid_account_name; + } + catch (...) + { + return execution_status::error_account_non_existant; + } + safex::safex_price_peg dummy_price_peg{}; if(blokchainDB.get_safex_price_peg(cmd->get_price_peg_id(),dummy_price_peg)) { @@ -544,6 +645,26 @@ namespace safex std::unique_ptr cmd = safex::safex_command_serializer::parse_safex_command(txin.script); + if(txin.key_offsets.size() != 1) + return execution_status::error_price_peg_offset_not_one; + + uint64_t safex_price_peg_index = txin.key_offsets[0]; + + try + { + const cryptonote::output_advanced_data_t od = blokchainDB.get_output_advanced_data(cryptonote::tx_out_type::out_safex_price_peg, safex_price_peg_index); + + safex::create_price_peg_data price_peg; + const cryptonote::blobdata price_pegblob(std::begin(od.data), std::end(od.data)); + cryptonote::parse_and_validate_from_blob(price_pegblob, price_peg); + + if(price_peg.price_peg_id != cmd->get_price_peg_id()) + return execution_status::error_price_peg_invalid_price_peg_id; + } + catch (...) + { + return execution_status::error_account_non_existant; + } if(cmd->get_rate() == 0) { diff --git a/src/safex/command.h b/src/safex/command.h index 2edde29b6..2c5b1421e 100644 --- a/src/safex/command.h +++ b/src/safex/command.h @@ -49,6 +49,7 @@ namespace safex error_invalid_account_name = 12, error_account_non_existant = 13, error_account_no_tokens = 14, + error_account_offset_not_one = 15, // Safex purchase error_offer_non_existant = 20, error_purchase_out_of_stock = 21, @@ -62,15 +63,21 @@ namespace safex error_offer_price_peg_not_existant = 33, error_offer_price_mismatch = 34, error_offer_already_exists = 35, + error_offer_invalid_offer_id = 36, + error_offer_offset_not_one = 37, // Safex feedback error_feedback_invalid_rating = 40, error_feedback_data_too_big = 41, + error_feedback_offset_not_one = 42, + error_feedback_token_non_existant = 43, // Safex price peg error_price_peg_bad_currency_format = 51, error_price_peg_data_too_big = 52, error_price_peg_not_existant = 53, error_price_peg_rate_zero = 54, error_price_peg_already_exists = 55, + error_price_peg_offset_not_one = 56, + error_price_peg_invalid_price_peg_id = 57, // Safex unstake token error_unstake_token_output_not_found = 60, error_unstake_token_minimum_period = 61, diff --git a/tests/unit_tests/safex_db/safex_account.cpp b/tests/unit_tests/safex_db/safex_account.cpp index 7fde5d276..6c30a64df 100644 --- a/tests/unit_tests/safex_db/safex_account.cpp +++ b/tests/unit_tests/safex_db/safex_account.cpp @@ -810,6 +810,7 @@ namespace cryptonote::txin_to_script txinput = AUTO_VAL_INIT(txinput); txinput.command_type = safex::command_t::edit_account; txinput.token_amount = 100*SAFEX_TOKEN; + txinput.key_offsets.push_back(0); std::string username = this->m_safex_account1.username; std::string description = "Some test data inserted"; safex::edit_account command1{SAFEX_COMMAND_PROTOCOL_VERSION, username, description}; @@ -861,6 +862,7 @@ namespace cryptonote::txin_to_script txinput = AUTO_VAL_INIT(txinput); txinput.command_type = safex::command_t::edit_account; txinput.token_amount = 100*SAFEX_TOKEN; + txinput.key_offsets.push_back(0); std::string username = "not_here"; std::string description = "Some test data inserted"; safex::edit_account command1{SAFEX_COMMAND_PROTOCOL_VERSION, username, description}; @@ -894,6 +896,7 @@ namespace cryptonote::txin_to_script txinput = AUTO_VAL_INIT(txinput); txinput.command_type = safex::command_t::edit_account; txinput.token_amount = 100*SAFEX_TOKEN; + txinput.key_offsets.push_back(0); std::string username = this->m_safex_account1.username; std::string description = ""; for(int i=0; i < SAFEX_ACCOUNT_DATA_MAX_SIZE + 1; i++) diff --git a/tests/unit_tests/safex_db/safex_offer.cpp b/tests/unit_tests/safex_db/safex_offer.cpp index 36b96b4d8..6881ec979 100644 --- a/tests/unit_tests/safex_db/safex_offer.cpp +++ b/tests/unit_tests/safex_db/safex_offer.cpp @@ -570,6 +570,7 @@ namespace { cryptonote::txin_to_script txinput = AUTO_VAL_INIT(txinput); txinput.command_type = safex::command_t::create_offer; + txinput.key_offsets.push_back(0); safex::safex_offer sfx_offer = safex::safex_offer("Apple",10,100*COIN,"This is an apple", "usernamenothere",this->m_users_acc[0].get_keys().m_view_secret_key, this->m_users_acc[0].get_keys().m_account_address); @@ -608,6 +609,7 @@ namespace { cryptonote::txin_to_script txinput = AUTO_VAL_INIT(txinput); txinput.command_type = safex::command_t::create_offer; + txinput.key_offsets.push_back(0); safex::safex_offer sfx_offer = safex::safex_offer("Apple",10,100*COIN,"This is an apple", this->m_safex_account1.username,this->m_users_acc[0].get_keys().m_view_secret_key, this->m_users_acc[0].get_keys().m_account_address); @@ -647,6 +649,7 @@ namespace { cryptonote::txin_to_script txinput = AUTO_VAL_INIT(txinput); txinput.command_type = safex::command_t::create_offer; + txinput.key_offsets.push_back(0); safex::safex_offer sfx_offer = safex::safex_offer("Apple",10,100*COIN,"This is an apple", this->m_safex_account1.username,this->m_users_acc[0].get_keys().m_view_secret_key, this->m_users_acc[0].get_keys().m_account_address); @@ -687,6 +690,7 @@ namespace { cryptonote::txin_to_script txinput = AUTO_VAL_INIT(txinput); txinput.command_type = safex::command_t::create_offer; + txinput.key_offsets.push_back(0); safex::safex_offer sfx_offer = safex::safex_offer("Apple",10,100*COIN,"This is an apple", this->m_safex_account1.username,this->m_users_acc[0].get_keys().m_view_secret_key, this->m_users_acc[0].get_keys().m_account_address); @@ -726,6 +730,7 @@ namespace { cryptonote::txin_to_script txinput = AUTO_VAL_INIT(txinput); txinput.command_type = safex::command_t::create_offer; + txinput.key_offsets.push_back(0); safex::safex_offer sfx_offer = safex::safex_offer("Apple",10,100*COIN,"This is an apple", this->m_safex_account1.username,this->m_users_acc[0].get_keys().m_view_secret_key, this->m_users_acc[0].get_keys().m_account_address); @@ -767,6 +772,7 @@ namespace { cryptonote::txin_to_script txinput = AUTO_VAL_INIT(txinput); txinput.command_type = safex::command_t::create_offer; + txinput.key_offsets.push_back(0); safex::safex_offer sfx_offer = safex::safex_offer("Apple",10,100*COIN,"This is an apple", this->m_safex_account1.username,this->m_users_acc[0].get_keys().m_view_secret_key, this->m_users_acc[0].get_keys().m_account_address); @@ -808,6 +814,7 @@ namespace { cryptonote::txin_to_script txinput = AUTO_VAL_INIT(txinput); txinput.command_type = safex::command_t::create_offer; + txinput.key_offsets.push_back(0); safex::safex_offer sfx_offer = safex::safex_offer("Apple",10,100*COIN,"This is an apple", this->m_safex_account1.username,this->m_users_acc[0].get_keys().m_view_secret_key, this->m_users_acc[0].get_keys().m_account_address); @@ -848,6 +855,7 @@ namespace { cryptonote::txin_to_script txinput = AUTO_VAL_INIT(txinput); txinput.command_type = safex::command_t::create_offer; + txinput.key_offsets.push_back(0); safex::create_offer_data offer_data{this->m_safex_offer[0]}; @@ -878,85 +886,6 @@ namespace FAIL() << "Unexpected exception"; } - // Safex offer quantity zero - try - { - cryptonote::txin_to_script txinput = AUTO_VAL_INIT(txinput); - txinput.command_type = safex::command_t::create_offer; - safex::safex_offer sfx_offer = safex::safex_offer("Apple",10,100*COIN,"This is an apple", - this->m_safex_account1.username,this->m_users_acc[0].get_keys().m_view_secret_key, - this->m_users_acc[0].get_keys().m_account_address); - - sfx_offer.quantity = 0; - - safex::create_offer_data offer_data{sfx_offer}; - - safex::create_offer command1{SAFEX_COMMAND_PROTOCOL_VERSION , offer_data}; - - - safex::safex_command_serializer::serialize_safex_object(command1, txinput.script); - - std::unique_ptr command2 = safex::safex_command_serializer::parse_safex_object(txinput.script, safex::command_t::create_offer); - - safex::execution_status status = command2->validate(*(this->m_db), txinput); - ASSERT_EQ(status, safex::execution_status::error_wrong_input_params); - - std::unique_ptr result{command2->execute(*(this->m_db), txinput)}; - FAIL() << "Should throw exception with Safex offer price peg doesn't exist"; - - } - catch (safex::command_exception &exception) - { - - } - catch (std::exception &exception) - { - FAIL() << "Exception happened " << exception.what(); - } - catch (...) - { - FAIL() << "Unexpected exception"; - } - - // Safex offer inactive - try - { - cryptonote::txin_to_script txinput = AUTO_VAL_INIT(txinput); - txinput.command_type = safex::command_t::create_offer; - safex::safex_offer sfx_offer = safex::safex_offer("Apple",10,100*COIN,"This is an apple", - this->m_safex_account1.username,this->m_users_acc[0].get_keys().m_view_secret_key, - this->m_users_acc[0].get_keys().m_account_address); - - sfx_offer.active = false; - - safex::create_offer_data offer_data{sfx_offer}; - - safex::create_offer command1{SAFEX_COMMAND_PROTOCOL_VERSION , offer_data}; - - - safex::safex_command_serializer::serialize_safex_object(command1, txinput.script); - - std::unique_ptr command2 = safex::safex_command_serializer::parse_safex_object(txinput.script, safex::command_t::create_offer); - - safex::execution_status status = command2->validate(*(this->m_db), txinput); - ASSERT_EQ(status, safex::execution_status::error_wrong_input_params); - - std::unique_ptr result{command2->execute(*(this->m_db), txinput)}; - FAIL() << "Should throw exception with Safex offer price peg doesn't exist"; - - } - catch (safex::command_exception &exception) - { - - } - catch (std::exception &exception) - { - FAIL() << "Exception happened " << exception.what(); - } - catch (...) - { - FAIL() << "Unexpected exception"; - } ASSERT_NO_THROW(this->m_db->close()); } @@ -982,6 +911,7 @@ namespace { cryptonote::txin_to_script txinput = AUTO_VAL_INIT(txinput); txinput.command_type = safex::command_t::edit_offer; + txinput.key_offsets.push_back(0); safex::safex_offer sfx_offer = safex::safex_offer("Apple",10,100*COIN,"This is an apple", "usernamenothere",this->m_users_acc[0].get_keys().m_view_secret_key, this->m_users_acc[0].get_keys().m_account_address); @@ -1020,9 +950,8 @@ namespace { cryptonote::txin_to_script txinput = AUTO_VAL_INIT(txinput); txinput.command_type = safex::command_t::edit_offer; - safex::safex_offer sfx_offer = safex::safex_offer("Apple",10,100*COIN,"This is an apple", - this->m_safex_account1.username,this->m_users_acc[0].get_keys().m_view_secret_key, - this->m_users_acc[0].get_keys().m_account_address); + txinput.key_offsets.push_back(0); + safex::safex_offer sfx_offer = this->m_safex_offer[0]; sfx_offer.min_sfx_price = SAFEX_OFFER_MINIMUM_PRICE - 1; safex::edit_offer_data offer_data{sfx_offer}; @@ -1059,9 +988,8 @@ namespace { cryptonote::txin_to_script txinput = AUTO_VAL_INIT(txinput); txinput.command_type = safex::command_t::edit_offer; - safex::safex_offer sfx_offer = safex::safex_offer("Apple",10,100*COIN,"This is an apple", - this->m_safex_account1.username,this->m_users_acc[0].get_keys().m_view_secret_key, - this->m_users_acc[0].get_keys().m_account_address); + txinput.key_offsets.push_back(0); + safex::safex_offer sfx_offer = this->m_safex_offer[0]; sfx_offer.min_sfx_price = MONEY_SUPPLY + 1; sfx_offer.price = sfx_offer.min_sfx_price; @@ -1099,9 +1027,8 @@ namespace { cryptonote::txin_to_script txinput = AUTO_VAL_INIT(txinput); txinput.command_type = safex::command_t::edit_offer; - safex::safex_offer sfx_offer = safex::safex_offer("Apple",10,100*COIN,"This is an apple", - this->m_safex_account1.username,this->m_users_acc[0].get_keys().m_view_secret_key, - this->m_users_acc[0].get_keys().m_account_address); + txinput.key_offsets.push_back(0); + safex::safex_offer sfx_offer = this->m_safex_offer[0]; sfx_offer.min_sfx_price = sfx_offer.price + 1; safex::edit_offer_data offer_data{sfx_offer}; @@ -1138,9 +1065,8 @@ namespace { cryptonote::txin_to_script txinput = AUTO_VAL_INIT(txinput); txinput.command_type = safex::command_t::edit_offer; - safex::safex_offer sfx_offer = safex::safex_offer("Apple",10,100*COIN,"This is an apple", - this->m_safex_account1.username,this->m_users_acc[0].get_keys().m_view_secret_key, - this->m_users_acc[0].get_keys().m_account_address); + txinput.key_offsets.push_back(0); + safex::safex_offer sfx_offer = this->m_safex_offer[0]; sfx_offer.title = ""; for(int i = 0; i<=SAFEX_OFFER_NAME_MAX_SIZE+1; i++) @@ -1179,9 +1105,8 @@ namespace { cryptonote::txin_to_script txinput = AUTO_VAL_INIT(txinput); txinput.command_type = safex::command_t::edit_offer; - safex::safex_offer sfx_offer = safex::safex_offer("Apple",10,100*COIN,"This is an apple", - this->m_safex_account1.username,this->m_users_acc[0].get_keys().m_view_secret_key, - this->m_users_acc[0].get_keys().m_account_address); + txinput.key_offsets.push_back(0); + safex::safex_offer sfx_offer = this->m_safex_offer[0]; sfx_offer.description.clear(); for(int i = 0; i<=SAFEX_OFFER_DATA_MAX_SIZE+1; i++) @@ -1220,9 +1145,8 @@ namespace { cryptonote::txin_to_script txinput = AUTO_VAL_INIT(txinput); txinput.command_type = safex::command_t::edit_offer; - safex::safex_offer sfx_offer = safex::safex_offer("Apple",10,100*COIN,"This is an apple", - this->m_safex_account1.username,this->m_users_acc[0].get_keys().m_view_secret_key, - this->m_users_acc[0].get_keys().m_account_address); + txinput.key_offsets.push_back(0); + safex::safex_offer sfx_offer = this->m_safex_offer[0]; sfx_offer.set_price_peg(sfx_offer.offer_id,100,100*COIN); @@ -1260,6 +1184,7 @@ namespace { cryptonote::txin_to_script txinput = AUTO_VAL_INIT(txinput); txinput.command_type = safex::command_t::edit_offer; + txinput.key_offsets.push_back(0); safex::edit_offer_data offer_data{this->m_safex_offer[0]}; offer_data.offer_id.data[0] +=1; @@ -1290,85 +1215,7 @@ namespace FAIL() << "Unexpected exception"; } - // Safex offer quantity zero - try - { - cryptonote::txin_to_script txinput = AUTO_VAL_INIT(txinput); - txinput.command_type = safex::command_t::create_offer; - safex::safex_offer sfx_offer = safex::safex_offer("Apple",10,100*COIN,"This is an apple", - this->m_safex_account1.username,this->m_users_acc[0].get_keys().m_view_secret_key, - this->m_users_acc[0].get_keys().m_account_address); - - sfx_offer.quantity = 0; - - safex::create_offer_data offer_data{sfx_offer}; - - safex::create_offer command1{SAFEX_COMMAND_PROTOCOL_VERSION , offer_data}; - - safex::safex_command_serializer::serialize_safex_object(command1, txinput.script); - - std::unique_ptr command2 = safex::safex_command_serializer::parse_safex_object(txinput.script, safex::command_t::create_offer); - - safex::execution_status status = command2->validate(*(this->m_db), txinput); - ASSERT_EQ(status, safex::execution_status::error_wrong_input_params); - - std::unique_ptr result{command2->execute(*(this->m_db), txinput)}; - FAIL() << "Should throw exception with Safex offer price peg doesn't exist"; - - } - catch (safex::command_exception &exception) - { - - } - catch (std::exception &exception) - { - FAIL() << "Exception happened " << exception.what(); - } - catch (...) - { - FAIL() << "Unexpected exception"; - } - - // Safex offer inactive - try - { - cryptonote::txin_to_script txinput = AUTO_VAL_INIT(txinput); - txinput.command_type = safex::command_t::create_offer; - safex::safex_offer sfx_offer = safex::safex_offer("Apple",10,100*COIN,"This is an apple", - this->m_safex_account1.username,this->m_users_acc[0].get_keys().m_view_secret_key, - this->m_users_acc[0].get_keys().m_account_address); - - sfx_offer.active = false; - - safex::create_offer_data offer_data{sfx_offer}; - - safex::create_offer command1{SAFEX_COMMAND_PROTOCOL_VERSION , offer_data}; - - - safex::safex_command_serializer::serialize_safex_object(command1, txinput.script); - - std::unique_ptr command2 = safex::safex_command_serializer::parse_safex_object(txinput.script, safex::command_t::create_offer); - - safex::execution_status status = command2->validate(*(this->m_db), txinput); - ASSERT_EQ(status, safex::execution_status::error_wrong_input_params); - - std::unique_ptr result{command2->execute(*(this->m_db), txinput)}; - FAIL() << "Should throw exception with Safex offer price peg doesn't exist"; - - } - catch (safex::command_exception &exception) - { - - } - catch (std::exception &exception) - { - FAIL() << "Exception happened " << exception.what(); - } - catch (...) - { - FAIL() << "Unexpected exception"; - } ASSERT_NO_THROW(this->m_db->close()); } diff --git a/tests/unit_tests/safex_db/safex_price_peg.cpp b/tests/unit_tests/safex_db/safex_price_peg.cpp index 98683e109..197a9ba92 100644 --- a/tests/unit_tests/safex_db/safex_price_peg.cpp +++ b/tests/unit_tests/safex_db/safex_price_peg.cpp @@ -190,14 +190,14 @@ namespace { tx_list.resize(tx_list.size() + 1); cryptonote::transaction &tx = tx_list.back(); \ - construct_create_price_peg_transaction(m_txmap, m_blocks, tx, m_users_acc[0], default_miner_fee, 0, m_safex_account1.pkey, m_safex_price_pegs[1], m_safex_account1_keys.get_keys()); + construct_create_price_peg_transaction(m_txmap, m_blocks, tx, m_users_acc[1], default_miner_fee, 0, m_safex_account2.pkey, m_safex_price_pegs[1], m_safex_account2_keys.get_keys()); m_txmap[get_transaction_hash(tx)] = tx; } else if (i == 15) { tx_list.resize(tx_list.size() + 1); cryptonote::transaction &tx = tx_list.back(); \ - construct_update_price_peg_transaction(m_txmap, m_blocks, tx, m_users_acc[0], default_miner_fee, 0, m_safex_account1.pkey, m_edited_safex_price_peg, m_safex_account1_keys.get_keys()); + construct_update_price_peg_transaction(m_txmap, m_blocks, tx, m_users_acc[1], default_miner_fee, 0, m_safex_account2.pkey, m_edited_safex_price_peg, m_safex_account2_keys.get_keys()); m_txmap[get_transaction_hash(tx)] = tx; } @@ -485,6 +485,7 @@ namespace { cryptonote::txin_to_script txinput = AUTO_VAL_INIT(txinput); txinput.command_type = safex::command_t::create_price_peg; + txinput.key_offsets.push_back(0); safex::safex_price_peg sfx_price_peg = safex::safex_price_peg("Apple", "username","USD","Some description", 1828); safex::create_price_peg_data price_peg_data{sfx_price_peg}; @@ -521,6 +522,7 @@ namespace { cryptonote::txin_to_script txinput = AUTO_VAL_INIT(txinput); txinput.command_type = safex::command_t::create_price_peg; + txinput.key_offsets.push_back(0); safex::create_price_peg_data price_peg_data{this->m_safex_price_pegs[0]}; @@ -556,6 +558,8 @@ namespace { cryptonote::txin_to_script txinput = AUTO_VAL_INIT(txinput); txinput.command_type = safex::command_t::create_price_peg; + txinput.key_offsets.push_back(0); + safex::safex_price_peg sfx_price_peg = safex::safex_price_peg("Apple", this->m_safex_account1.username,"USD","Some description", 1828); sfx_price_peg.title = ""; @@ -597,6 +601,8 @@ namespace { cryptonote::txin_to_script txinput = AUTO_VAL_INIT(txinput); txinput.command_type = safex::command_t::create_price_peg; + txinput.key_offsets.push_back(0); + safex::safex_price_peg sfx_price_peg = safex::safex_price_peg("Apple", this->m_safex_account1.username,"USD","Some description", 1828); sfx_price_peg.currency = ""; @@ -638,6 +644,8 @@ namespace { cryptonote::txin_to_script txinput = AUTO_VAL_INIT(txinput); txinput.command_type = safex::command_t::create_price_peg; + txinput.key_offsets.push_back(0); + safex::safex_price_peg sfx_price_peg = safex::safex_price_peg("Apple", this->m_safex_account1.username,"USD","Some description", 1828); sfx_price_peg.description.clear(); @@ -679,6 +687,8 @@ namespace { cryptonote::txin_to_script txinput = AUTO_VAL_INIT(txinput); txinput.command_type = safex::command_t::create_price_peg; + txinput.key_offsets.push_back(0); + safex::safex_price_peg sfx_price_peg = safex::safex_price_peg("Apple", this->m_safex_account1.username,"US-D","Some description", 1828); safex::create_price_peg_data price_peg_data{sfx_price_peg}; @@ -715,6 +725,8 @@ namespace { cryptonote::txin_to_script txinput = AUTO_VAL_INIT(txinput); txinput.command_type = safex::command_t::create_price_peg; + txinput.key_offsets.push_back(0); + safex::safex_price_peg sfx_price_peg = safex::safex_price_peg("Apple", this->m_safex_account1.username,"USD","Some description", 1828); sfx_price_peg.rate = 0; @@ -773,6 +785,8 @@ namespace { cryptonote::txin_to_script txinput = AUTO_VAL_INIT(txinput); txinput.command_type = safex::command_t::update_price_peg; + txinput.key_offsets.push_back(0); + safex::safex_price_peg sfx_price_peg = safex::safex_price_peg("Apple", "username","USD","Some description", 1828); safex::create_price_peg_data price_peg_data{sfx_price_peg}; @@ -809,6 +823,8 @@ namespace { cryptonote::txin_to_script txinput = AUTO_VAL_INIT(txinput); txinput.command_type = safex::command_t::update_price_peg; + txinput.key_offsets.push_back(0); + safex::safex_price_peg sfx_price_peg = safex::safex_price_peg("Apple", this->m_safex_account1.username,"USD","Some description", 1828); sfx_price_peg.rate = 0; diff --git a/tests/unit_tests/safex_db/simple_purchase.cpp b/tests/unit_tests/safex_db/simple_purchase.cpp index f28cfd65f..e70e4d47b 100644 --- a/tests/unit_tests/safex_db/simple_purchase.cpp +++ b/tests/unit_tests/safex_db/simple_purchase.cpp @@ -738,6 +738,7 @@ namespace { cryptonote::txin_to_script txinput = AUTO_VAL_INIT(txinput); txinput.command_type = safex::command_t::create_feedback; + txinput.key_offsets.push_back(0); crypto::hash offer_id{}; @@ -777,6 +778,7 @@ namespace { cryptonote::txin_to_script txinput = AUTO_VAL_INIT(txinput); txinput.command_type = safex::command_t::create_feedback; + txinput.key_offsets.push_back(0); safex::safex_feedback sfx_feedback = safex::safex_feedback(4, "100", this->m_edited_safex_offer.offer_id); @@ -814,6 +816,7 @@ namespace { cryptonote::txin_to_script txinput = AUTO_VAL_INIT(txinput); txinput.command_type = safex::command_t::create_feedback; + txinput.key_offsets.push_back(0); safex::safex_feedback sfx_feedback = safex::safex_feedback(3, "100", this->m_edited_safex_offer.offer_id);