[SON-113] Unit test for cli update_son_votes (#179)
* refactor cli tests * update_son_votes tests * list_sons test * test changes in get_global_properties() result * fix generate_block failure * fix update_son_votes test * improve update_son cli test * fix linking errors * refactor select_top_fifteen_sons test * refactor other son cli tests to use son_test_helper * create_vesting call in wallet_api * test fix * fix create_son in wallet_api and cli tests
This commit is contained in:
parent
e0242bcf86
commit
f9f95cd242
7 changed files with 954 additions and 1319 deletions
|
|
@ -1310,11 +1310,15 @@ class wallet_api
|
|||
* @param owner_account the name or id of the account which is creating the SON
|
||||
* @param url a URL to include in the SON record in the blockchain. Clients may
|
||||
* display this when showing a list of SONs. May be blank.
|
||||
* @param deposit_id vesting balance id for SON deposit
|
||||
* @param pay_vb_id vesting balance id for SON pay_vb
|
||||
* @param broadcast true to broadcast the transaction on the network
|
||||
* @returns the signed transaction registering a SON
|
||||
*/
|
||||
signed_transaction create_son(string owner_account,
|
||||
string url,
|
||||
vesting_balance_id_type deposit_id,
|
||||
vesting_balance_id_type pay_vb_id,
|
||||
bool broadcast = false);
|
||||
|
||||
/**
|
||||
|
|
@ -1423,6 +1427,19 @@ class wallet_api
|
|||
bool broadcast = false
|
||||
);
|
||||
|
||||
/** Creates a vesting deposit owned by the given account.
|
||||
*
|
||||
* @param owner_account the name or id of the account
|
||||
* @param amount the amount to deposit
|
||||
* @param vesting_type "normal", "gpos" or "son"
|
||||
* @param broadcast true to broadcast the transaction on the network
|
||||
* @returns the signed transaction registering a vesting object
|
||||
*/
|
||||
signed_transaction create_vesting(string owner_account,
|
||||
string amount,
|
||||
string vesting_type,
|
||||
bool broadcast = false);
|
||||
|
||||
/**
|
||||
* Get information about a vesting balance object.
|
||||
*
|
||||
|
|
@ -2101,6 +2118,7 @@ FC_API( graphene::wallet::wallet_api,
|
|||
(update_witness)
|
||||
(create_worker)
|
||||
(update_worker_votes)
|
||||
(create_vesting)
|
||||
(get_vesting_balances)
|
||||
(withdraw_vesting)
|
||||
(vote_for_committee_member)
|
||||
|
|
|
|||
|
|
@ -1860,6 +1860,8 @@ public:
|
|||
|
||||
signed_transaction create_son(string owner_account,
|
||||
string url,
|
||||
vesting_balance_id_type deposit_id,
|
||||
vesting_balance_id_type pay_vb_id,
|
||||
bool broadcast /* = false */)
|
||||
{ try {
|
||||
account_object son_account = get_account(owner_account);
|
||||
|
|
@ -1872,6 +1874,8 @@ public:
|
|||
son_create_op.owner_account = son_account.id;
|
||||
son_create_op.signing_key = son_public_key;
|
||||
son_create_op.url = url;
|
||||
son_create_op.deposit = deposit_id;
|
||||
son_create_op.pay_vb = pay_vb_id;
|
||||
|
||||
if (_remote_db->get_son_by_account(son_create_op.owner_account))
|
||||
FC_THROW("Account ${owner_account} is already a SON", ("owner_account", owner_account));
|
||||
|
|
@ -2102,6 +2106,38 @@ public:
|
|||
return sign_transaction( tx, broadcast );
|
||||
}
|
||||
|
||||
signed_transaction create_vesting(string owner_account,
|
||||
string amount,
|
||||
string vesting_type,
|
||||
bool broadcast /* = false */)
|
||||
{ try {
|
||||
account_object son_account = get_account(owner_account);
|
||||
|
||||
vesting_balance_create_operation op;
|
||||
op.creator = son_account.get_id();
|
||||
op.owner = son_account.get_id();
|
||||
op.amount = asset_object().amount_from_string(amount);
|
||||
if (vesting_type == "normal")
|
||||
op.balance_type = vesting_balance_type::normal;
|
||||
else if (vesting_type == "gpos")
|
||||
op.balance_type = vesting_balance_type::gpos;
|
||||
else if (vesting_type == "son")
|
||||
op.balance_type = vesting_balance_type::son;
|
||||
else
|
||||
{
|
||||
FC_ASSERT( false, "unknown vesting type value ${vt}", ("vt", vesting_type) );
|
||||
}
|
||||
if (op.balance_type == vesting_balance_type::son)
|
||||
op.policy = dormant_vesting_policy_initializer {};
|
||||
|
||||
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( (owner_account)(broadcast) ) }
|
||||
|
||||
vector< vesting_balance_object_with_info > get_vesting_balances( string account_name )
|
||||
{ try {
|
||||
fc::optional<vesting_balance_id_type> vbid = maybe_id<vesting_balance_id_type>( account_name );
|
||||
|
|
@ -4234,11 +4270,21 @@ committee_member_object wallet_api::get_committee_member(string owner_account)
|
|||
return my->get_committee_member(owner_account);
|
||||
}
|
||||
|
||||
signed_transaction wallet_api::create_vesting(string owner_account,
|
||||
string amount,
|
||||
string vesting_type,
|
||||
bool broadcast /* = false */)
|
||||
{
|
||||
return my->create_vesting(owner_account, amount, vesting_type, broadcast);
|
||||
}
|
||||
|
||||
signed_transaction wallet_api::create_son(string owner_account,
|
||||
string url,
|
||||
vesting_balance_id_type deposit_id,
|
||||
vesting_balance_id_type pay_vb_id,
|
||||
bool broadcast /* = false */)
|
||||
{
|
||||
return my->create_son(owner_account, url, broadcast);
|
||||
return my->create_son(owner_account, url, deposit_id, pay_vb_id, broadcast);
|
||||
}
|
||||
|
||||
signed_transaction wallet_api::update_son(string owner_account,
|
||||
|
|
|
|||
Binary file not shown.
277
tests/cli/cli_fixture.cpp
Normal file
277
tests/cli/cli_fixture.cpp
Normal file
|
|
@ -0,0 +1,277 @@
|
|||
#include <graphene/app/plugin.hpp>
|
||||
#include <graphene/app/api.hpp>
|
||||
|
||||
#include <graphene/utilities/tempdir.hpp>
|
||||
#include <graphene/bookie/bookie_plugin.hpp>
|
||||
#include <graphene/witness/witness.hpp>
|
||||
#include <graphene/account_history/account_history_plugin.hpp>
|
||||
#include <graphene/egenesis/egenesis.hpp>
|
||||
#include <graphene/chain/config.hpp>
|
||||
#include <graphene/chain/database.hpp>
|
||||
|
||||
#include <fc/crypto/base58.hpp>
|
||||
|
||||
#include <fc/crypto/aes.hpp>
|
||||
#include <fc/smart_ref_impl.hpp>
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifndef _WIN32_WINNT
|
||||
#define _WIN32_WINNT 0x0501
|
||||
#endif
|
||||
#include <winsock2.h>
|
||||
#include <WS2tcpip.h>
|
||||
#else
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
#include <thread>
|
||||
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include "cli_fixture.hpp"
|
||||
|
||||
/*****
|
||||
* Global Initialization for Windows
|
||||
* ( sets up Winsock stuf )
|
||||
*/
|
||||
#ifdef _WIN32
|
||||
int sockInit(void)
|
||||
{
|
||||
WSADATA wsa_data;
|
||||
return WSAStartup(MAKEWORD(1,1), &wsa_data);
|
||||
}
|
||||
int sockQuit(void)
|
||||
{
|
||||
return WSACleanup();
|
||||
}
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* Helper Methods
|
||||
*********************/
|
||||
|
||||
#include "../common/genesis_file_util.hpp"
|
||||
|
||||
//////
|
||||
/// @brief attempt to find an available port on localhost
|
||||
/// @returns an available port number, or -1 on error
|
||||
/////
|
||||
int get_available_port()
|
||||
{
|
||||
struct sockaddr_in sin;
|
||||
int socket_fd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (socket_fd == -1)
|
||||
return -1;
|
||||
sin.sin_family = AF_INET;
|
||||
sin.sin_port = 0;
|
||||
sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
|
||||
if (::bind(socket_fd, (struct sockaddr*)&sin, sizeof(struct sockaddr_in)) == -1)
|
||||
return -1;
|
||||
socklen_t len = sizeof(sin);
|
||||
if (getsockname(socket_fd, (struct sockaddr *)&sin, &len) == -1)
|
||||
return -1;
|
||||
#ifdef _WIN32
|
||||
closesocket(socket_fd);
|
||||
#else
|
||||
close(socket_fd);
|
||||
#endif
|
||||
return ntohs(sin.sin_port);
|
||||
}
|
||||
|
||||
///////////
|
||||
/// @brief Start the application
|
||||
/// @param app_dir the temporary directory to use
|
||||
/// @param server_port_number to be filled with the rpc endpoint port number
|
||||
/// @returns the application object
|
||||
//////////
|
||||
std::shared_ptr<graphene::app::application> start_application(fc::temp_directory& app_dir, int& server_port_number) {
|
||||
std::shared_ptr<graphene::app::application> app1(new graphene::app::application{});
|
||||
|
||||
app1->register_plugin<graphene::bookie::bookie_plugin>();
|
||||
app1->register_plugin<graphene::account_history::account_history_plugin>();
|
||||
app1->register_plugin<graphene::market_history::market_history_plugin>();
|
||||
app1->register_plugin<graphene::witness_plugin::witness_plugin>();
|
||||
app1->startup_plugins();
|
||||
boost::program_options::variables_map cfg;
|
||||
#ifdef _WIN32
|
||||
sockInit();
|
||||
#endif
|
||||
server_port_number = get_available_port();
|
||||
cfg.emplace(
|
||||
"rpc-endpoint",
|
||||
boost::program_options::variable_value(string("127.0.0.1:" + std::to_string(server_port_number)), false)
|
||||
);
|
||||
cfg.emplace("genesis-json", boost::program_options::variable_value(create_genesis_file(app_dir), false));
|
||||
cfg.emplace("seed-nodes", boost::program_options::variable_value(string("[]"), false));
|
||||
cfg.emplace("plugins", boost::program_options::variable_value(string("bookie account_history market_history"), false));
|
||||
|
||||
app1->initialize(app_dir.path(), cfg);
|
||||
|
||||
app1->initialize_plugins(cfg);
|
||||
app1->startup_plugins();
|
||||
|
||||
app1->startup();
|
||||
fc::usleep(fc::milliseconds(500));
|
||||
return app1;
|
||||
}
|
||||
|
||||
client_connection::client_connection(
|
||||
std::shared_ptr<graphene::app::application> app,
|
||||
const fc::temp_directory& data_dir,
|
||||
const int server_port_number
|
||||
)
|
||||
{
|
||||
wallet_data.chain_id = app->chain_database()->get_chain_id();
|
||||
wallet_data.ws_server = "ws://127.0.0.1:" + std::to_string(server_port_number);
|
||||
wallet_data.ws_user = "";
|
||||
wallet_data.ws_password = "";
|
||||
websocket_connection = websocket_client.connect( wallet_data.ws_server );
|
||||
|
||||
api_connection = std::make_shared<fc::rpc::websocket_api_connection>(websocket_connection, GRAPHENE_MAX_NESTED_OBJECTS);
|
||||
|
||||
remote_login_api = api_connection->get_remote_api< graphene::app::login_api >(1);
|
||||
BOOST_CHECK(remote_login_api->login( wallet_data.ws_user, wallet_data.ws_password ) );
|
||||
|
||||
wallet_api_ptr = std::make_shared<graphene::wallet::wallet_api>(wallet_data, remote_login_api);
|
||||
wallet_filename = data_dir.path().generic_string() + "/wallet.json";
|
||||
wallet_api_ptr->set_wallet_filename(wallet_filename);
|
||||
|
||||
wallet_api = fc::api<graphene::wallet::wallet_api>(wallet_api_ptr);
|
||||
|
||||
wallet_cli = std::make_shared<fc::rpc::cli>(GRAPHENE_MAX_NESTED_OBJECTS);
|
||||
for( auto& name_formatter : wallet_api_ptr->get_result_formatters() )
|
||||
wallet_cli->format_result( name_formatter.first, name_formatter.second );
|
||||
|
||||
boost::signals2::scoped_connection closed_connection(websocket_connection->closed.connect([=]{
|
||||
cerr << "Server has disconnected us.\n";
|
||||
wallet_cli->stop();
|
||||
}));
|
||||
(void)(closed_connection);
|
||||
}
|
||||
|
||||
client_connection::~client_connection()
|
||||
{
|
||||
// wait for everything to finish up
|
||||
fc::usleep(fc::milliseconds(500));
|
||||
}
|
||||
|
||||
///////////////////////////////
|
||||
// Cli Wallet Fixture
|
||||
///////////////////////////////
|
||||
|
||||
cli_fixture::cli_fixture() :
|
||||
server_port_number(0),
|
||||
app_dir( graphene::utilities::temp_directory_path() ),
|
||||
app1( start_application(app_dir, server_port_number) ),
|
||||
con( app1, app_dir, server_port_number ),
|
||||
nathan_keys( {"5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"} )
|
||||
{
|
||||
BOOST_TEST_MESSAGE("Setup cli_wallet::boost_fixture_test_case");
|
||||
|
||||
using namespace graphene::chain;
|
||||
using namespace graphene::app;
|
||||
|
||||
try
|
||||
{
|
||||
BOOST_TEST_MESSAGE("Setting wallet password");
|
||||
con.wallet_api_ptr->set_password("supersecret");
|
||||
con.wallet_api_ptr->unlock("supersecret");
|
||||
|
||||
// import Nathan account
|
||||
BOOST_TEST_MESSAGE("Importing nathan key");
|
||||
BOOST_CHECK_EQUAL(nathan_keys[0], "5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3");
|
||||
BOOST_CHECK(con.wallet_api_ptr->import_key("nathan", nathan_keys[0]));
|
||||
} catch( fc::exception& e ) {
|
||||
edump((e.to_detail_string()));
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
cli_fixture::~cli_fixture()
|
||||
{
|
||||
BOOST_TEST_MESSAGE("Cleanup cli_wallet::boost_fixture_test_case");
|
||||
|
||||
// wait for everything to finish up
|
||||
fc::usleep(fc::seconds(1));
|
||||
|
||||
app1->shutdown();
|
||||
#ifdef _WIN32
|
||||
sockQuit();
|
||||
#endif
|
||||
}
|
||||
|
||||
bool cli_fixture::generate_maintenance_block() {
|
||||
try {
|
||||
fc::ecc::private_key committee_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("nathan")));
|
||||
uint32_t skip = ~database::skip_fork_db;
|
||||
auto db = app1->chain_database();
|
||||
auto maint_time = db->get_dynamic_global_properties().next_maintenance_time;
|
||||
auto slots_to_miss = db->get_slot_at_time(maint_time);
|
||||
db->generate_block(db->get_slot_time(slots_to_miss),
|
||||
db->get_scheduled_witness(slots_to_miss),
|
||||
committee_key,
|
||||
skip);
|
||||
return true;
|
||||
} catch (exception& e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool cli_fixture::generate_block()
|
||||
{
|
||||
graphene::chain::signed_block returned_block;
|
||||
return generate_block(returned_block);
|
||||
}
|
||||
|
||||
bool cli_fixture::generate_block(graphene::chain::signed_block& returned_block)
|
||||
{
|
||||
try {
|
||||
fc::ecc::private_key committee_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("nathan")));
|
||||
auto db = app1->chain_database();
|
||||
returned_block = db->generate_block( db->get_slot_time(1),
|
||||
db->get_scheduled_witness(1),
|
||||
committee_key,
|
||||
database::skip_nothing );
|
||||
return true;
|
||||
} catch (exception &e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void cli_fixture::init_nathan()
|
||||
{
|
||||
try
|
||||
{
|
||||
BOOST_TEST_MESSAGE("Upgrade Nathan's account");
|
||||
|
||||
account_object nathan_acct_before_upgrade, nathan_acct_after_upgrade;
|
||||
std::vector<signed_transaction> import_txs;
|
||||
signed_transaction upgrade_tx;
|
||||
|
||||
BOOST_TEST_MESSAGE("Importing nathan's balance");
|
||||
import_txs = con.wallet_api_ptr->import_balance("nathan", nathan_keys, true);
|
||||
nathan_acct_before_upgrade = con.wallet_api_ptr->get_account("nathan");
|
||||
|
||||
BOOST_CHECK(generate_block());
|
||||
|
||||
// upgrade nathan
|
||||
BOOST_TEST_MESSAGE("Upgrading Nathan to LTM");
|
||||
upgrade_tx = con.wallet_api_ptr->upgrade_account("nathan", true);
|
||||
|
||||
nathan_acct_after_upgrade = con.wallet_api_ptr->get_account("nathan");
|
||||
|
||||
// verify that the upgrade was successful
|
||||
BOOST_CHECK_PREDICATE(
|
||||
std::not_equal_to<uint32_t>(),
|
||||
(nathan_acct_before_upgrade.membership_expiration_date.sec_since_epoch())
|
||||
(nathan_acct_after_upgrade.membership_expiration_date.sec_since_epoch())
|
||||
);
|
||||
BOOST_CHECK(nathan_acct_after_upgrade.is_lifetime_member());
|
||||
} catch( fc::exception& e ) {
|
||||
edump((e.to_detail_string()));
|
||||
throw;
|
||||
}
|
||||
}
|
||||
77
tests/cli/cli_fixture.hpp
Normal file
77
tests/cli/cli_fixture.hpp
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
#include <graphene/app/application.hpp>
|
||||
#include <graphene/wallet/wallet.hpp>
|
||||
|
||||
#include <fc/network/http/websocket.hpp>
|
||||
#include <fc/rpc/cli.hpp>
|
||||
#include <fc/rpc/websocket_api.hpp>
|
||||
#include <fc/thread/thread.hpp>
|
||||
|
||||
#define INVOKE(test) ((struct test*)this)->test_method();
|
||||
|
||||
///////////
|
||||
/// @brief a class to make connecting to the application server easier
|
||||
///////////
|
||||
class client_connection
|
||||
{
|
||||
public:
|
||||
client_connection(
|
||||
std::shared_ptr<graphene::app::application> app,
|
||||
const fc::temp_directory& data_dir,
|
||||
const int server_port_number
|
||||
);
|
||||
~client_connection();
|
||||
public:
|
||||
fc::http::websocket_client websocket_client;
|
||||
graphene::wallet::wallet_data wallet_data;
|
||||
fc::http::websocket_connection_ptr websocket_connection;
|
||||
std::shared_ptr<fc::rpc::websocket_api_connection> api_connection;
|
||||
fc::api<login_api> remote_login_api;
|
||||
std::shared_ptr<graphene::wallet::wallet_api> wallet_api_ptr;
|
||||
fc::api<graphene::wallet::wallet_api> wallet_api;
|
||||
std::shared_ptr<fc::rpc::cli> wallet_cli;
|
||||
std::string wallet_filename;
|
||||
};
|
||||
|
||||
///////////////////////////////
|
||||
// Cli Wallet Fixture
|
||||
///////////////////////////////
|
||||
struct cli_fixture
|
||||
{
|
||||
class dummy
|
||||
{
|
||||
public:
|
||||
~dummy()
|
||||
{
|
||||
// wait for everything to finish up
|
||||
fc::usleep(fc::milliseconds(500));
|
||||
}
|
||||
};
|
||||
dummy dmy;
|
||||
int server_port_number;
|
||||
fc::temp_directory app_dir;
|
||||
std::shared_ptr<graphene::app::application> app1;
|
||||
client_connection con;
|
||||
std::vector<std::string> nathan_keys;
|
||||
|
||||
cli_fixture();
|
||||
~cli_fixture();
|
||||
|
||||
///////////
|
||||
/// Send a block to the db
|
||||
/// @param returned_block the signed block
|
||||
/// @returns true on success
|
||||
///////////
|
||||
bool generate_block(graphene::chain::signed_block& returned_block);
|
||||
bool generate_block();
|
||||
///////////
|
||||
/// @brief Skip intermediate blocks, and generate a maintenance block
|
||||
/// @returns true on success
|
||||
///////////
|
||||
bool generate_maintenance_block();
|
||||
|
||||
///////////
|
||||
// @brief init "nathan" account and make it LTM to use in tests
|
||||
//////////
|
||||
void init_nathan();
|
||||
};
|
||||
|
||||
1334
tests/cli/main.cpp
1334
tests/cli/main.cpp
File diff suppressed because it is too large
Load diff
519
tests/cli/son.cpp
Normal file
519
tests/cli/son.cpp
Normal file
|
|
@ -0,0 +1,519 @@
|
|||
/*
|
||||
* Copyright (c) 2019 PBSA, 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 "cli_fixture.hpp"
|
||||
|
||||
#include <fc/smart_ref_impl.hpp>
|
||||
#include <fc/string.hpp>
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
class son_test_helper
|
||||
{
|
||||
cli_fixture& fixture_;
|
||||
|
||||
public:
|
||||
son_test_helper(cli_fixture& fixture):
|
||||
fixture_(fixture)
|
||||
{
|
||||
fixture_.init_nathan();
|
||||
}
|
||||
|
||||
void create_son(const std::string& account_name, const std::string& son_url,
|
||||
bool generate_maintenance = true)
|
||||
{
|
||||
graphene::wallet::brain_key_info bki;
|
||||
signed_transaction create_tx;
|
||||
signed_transaction transfer_tx;
|
||||
signed_transaction upgrade_tx;
|
||||
account_object son_account;
|
||||
son_object son_obj;
|
||||
|
||||
// create son account
|
||||
bki = fixture_.con.wallet_api_ptr->suggest_brain_key();
|
||||
BOOST_CHECK(!bki.brain_priv_key.empty());
|
||||
create_tx = fixture_.con.wallet_api_ptr->create_account_with_brain_key(
|
||||
bki.brain_priv_key, account_name, "nathan", "nathan", true
|
||||
);
|
||||
// save the private key for this new account in the wallet file
|
||||
BOOST_CHECK(fixture_.con.wallet_api_ptr->import_key(account_name, bki.wif_priv_key));
|
||||
fixture_.con.wallet_api_ptr->save_wallet_file(fixture_.con.wallet_filename);
|
||||
|
||||
// attempt to give son account some CORE tokens
|
||||
BOOST_TEST_MESSAGE("Transferring CORE tokens from Nathan to son account");
|
||||
transfer_tx = fixture_.con.wallet_api_ptr->transfer(
|
||||
"nathan", account_name, "65000", "1.3.0", "Here are some CORE token for your new account", true
|
||||
);
|
||||
|
||||
BOOST_CHECK(fixture_.generate_block());
|
||||
|
||||
// upgrade son account
|
||||
BOOST_TEST_MESSAGE("Upgrading son account to LTM");
|
||||
upgrade_tx = fixture_.con.wallet_api_ptr->upgrade_account(account_name, true);
|
||||
son_account = fixture_.con.wallet_api_ptr->get_account(account_name);
|
||||
|
||||
// verify that the upgrade was successful
|
||||
BOOST_CHECK(son_account.is_lifetime_member());
|
||||
|
||||
BOOST_CHECK(fixture_.generate_block());
|
||||
|
||||
// create deposit vesting
|
||||
fixture_.con.wallet_api_ptr->create_vesting(account_name, "50000000", "son", true);
|
||||
BOOST_CHECK(fixture_.generate_block());
|
||||
|
||||
// create pay_vb vesting
|
||||
fixture_.con.wallet_api_ptr->create_vesting(account_name, "1000000", "normal", true);
|
||||
BOOST_CHECK(fixture_.generate_block());
|
||||
|
||||
// check deposits are here
|
||||
auto deposits = fixture_.con.wallet_api_ptr->get_vesting_balances(account_name);
|
||||
BOOST_CHECK(deposits.size() == 2);
|
||||
|
||||
create_tx = fixture_.con.wallet_api_ptr->create_son(account_name, son_url,
|
||||
deposits[0].id, deposits[1].id,
|
||||
true);
|
||||
|
||||
if (generate_maintenance)
|
||||
BOOST_CHECK(fixture_.generate_maintenance_block());
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
///////////////////////
|
||||
// SON CLI
|
||||
///////////////////////
|
||||
BOOST_FIXTURE_TEST_SUITE(son_cli, cli_fixture)
|
||||
|
||||
BOOST_AUTO_TEST_CASE( create_sons )
|
||||
{
|
||||
BOOST_TEST_MESSAGE("SON cli wallet tests begin");
|
||||
try
|
||||
{
|
||||
son_test_helper sth(*this);
|
||||
sth.create_son("son1account", "http://son1");
|
||||
sth.create_son("son2account", "http://son2");
|
||||
|
||||
auto son1_obj = con.wallet_api_ptr->get_son("son1account");
|
||||
BOOST_CHECK(son1_obj.son_account == con.wallet_api_ptr->get_account_id("son1account"));
|
||||
BOOST_CHECK_EQUAL(son1_obj.url, "http://son1");
|
||||
|
||||
auto son2_obj = con.wallet_api_ptr->get_son("son2account");
|
||||
BOOST_CHECK(son2_obj.son_account == con.wallet_api_ptr->get_account_id("son2account"));
|
||||
BOOST_CHECK_EQUAL(son2_obj.url, "http://son2");
|
||||
|
||||
} catch( fc::exception& e ) {
|
||||
BOOST_TEST_MESSAGE("SON cli wallet tests exception");
|
||||
edump((e.to_detail_string()));
|
||||
throw;
|
||||
}
|
||||
BOOST_TEST_MESSAGE("SON cli wallet tests end");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( cli_update_son )
|
||||
{
|
||||
try
|
||||
{
|
||||
BOOST_TEST_MESSAGE("Cli get_son and update_son Test");
|
||||
|
||||
son_test_helper sth(*this);
|
||||
sth.create_son("sonmember", "http://sonmember");
|
||||
|
||||
auto sonmember_acct = con.wallet_api_ptr->get_account("sonmember");
|
||||
|
||||
// get_son
|
||||
auto son_data = con.wallet_api_ptr->get_son("sonmember");
|
||||
BOOST_CHECK(son_data.url == "http://sonmember");
|
||||
BOOST_CHECK(son_data.son_account == sonmember_acct.get_id());
|
||||
|
||||
// update SON
|
||||
con.wallet_api_ptr->update_son("sonmember", "http://sonmember_updated", "", true);
|
||||
son_data = con.wallet_api_ptr->get_son("sonmember");
|
||||
BOOST_CHECK(son_data.url == "http://sonmember_updated");
|
||||
|
||||
// update SON signing key
|
||||
con.wallet_api_ptr->update_son("sonmember", "http://sonmember_updated2", "TEST6Yaq5ZNTTkMM2kBBzV5jktr8ETsniCC3bnVD7eFmegRrLXfGGG", true);
|
||||
son_data = con.wallet_api_ptr->get_son("sonmember");
|
||||
BOOST_CHECK(son_data.url == "http://sonmember_updated2");
|
||||
BOOST_CHECK(std::string(son_data.signing_key) == "TEST6Yaq5ZNTTkMM2kBBzV5jktr8ETsniCC3bnVD7eFmegRrLXfGGG");
|
||||
|
||||
} catch( fc::exception& e ) {
|
||||
edump((e.to_detail_string()));
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( son_voting )
|
||||
{
|
||||
BOOST_TEST_MESSAGE("SON Vote cli wallet tests begin");
|
||||
try
|
||||
{
|
||||
son_test_helper sth(*this);
|
||||
sth.create_son("son1account", "http://son1");
|
||||
sth.create_son("son2account", "http://son2");
|
||||
|
||||
BOOST_TEST_MESSAGE("Voting for SONs");
|
||||
|
||||
son_object son1_obj;
|
||||
son_object son2_obj;
|
||||
signed_transaction vote_son1_tx;
|
||||
signed_transaction vote_son2_tx;
|
||||
int son1_start_votes, son1_end_votes;
|
||||
int son2_start_votes, son2_end_votes;
|
||||
|
||||
son1_obj = con.wallet_api_ptr->get_son("son1account");
|
||||
son1_start_votes = son1_obj.total_votes;
|
||||
son2_obj = con.wallet_api_ptr->get_son("son2account");
|
||||
son2_start_votes = son2_obj.total_votes;
|
||||
|
||||
// Vote for a son1account
|
||||
BOOST_TEST_MESSAGE("Voting for son1account");
|
||||
vote_son1_tx = con.wallet_api_ptr->vote_for_son("nathan", "son1account", true, true);
|
||||
BOOST_CHECK(generate_maintenance_block());
|
||||
|
||||
// Verify that the vote is there
|
||||
son1_obj = con.wallet_api_ptr->get_son("son1account");
|
||||
son1_end_votes = son1_obj.total_votes;
|
||||
BOOST_CHECK(son1_end_votes > son1_start_votes);
|
||||
|
||||
// Vote for a son2account
|
||||
BOOST_TEST_MESSAGE("Voting for son2account");
|
||||
vote_son2_tx = con.wallet_api_ptr->vote_for_son("nathan", "son2account", true, true);
|
||||
BOOST_CHECK(generate_maintenance_block());
|
||||
|
||||
// Verify that the vote is there
|
||||
son2_obj = con.wallet_api_ptr->get_son("son2account");
|
||||
son2_end_votes = son2_obj.total_votes;
|
||||
BOOST_CHECK(son2_end_votes > son2_start_votes);
|
||||
|
||||
// Withdraw vote for a son1account
|
||||
BOOST_TEST_MESSAGE("Withdraw vote for a son1account");
|
||||
vote_son1_tx = con.wallet_api_ptr->vote_for_son("nathan", "son1account", false, true);
|
||||
BOOST_CHECK(generate_maintenance_block());
|
||||
|
||||
// Verify that the vote is removed
|
||||
son1_obj = con.wallet_api_ptr->get_son("son1account");
|
||||
son1_end_votes = son1_obj.total_votes;
|
||||
BOOST_CHECK(son1_end_votes == son1_start_votes);
|
||||
|
||||
// Withdraw vote for a son2account
|
||||
BOOST_TEST_MESSAGE("Withdraw vote for a son2account");
|
||||
vote_son2_tx = con.wallet_api_ptr->vote_for_son("nathan", "son2account", false, true);
|
||||
BOOST_CHECK(generate_maintenance_block());
|
||||
|
||||
// Verify that the vote is removed
|
||||
son2_obj = con.wallet_api_ptr->get_son("son2account");
|
||||
son2_end_votes = son2_obj.total_votes;
|
||||
BOOST_CHECK(son2_end_votes == son2_start_votes);
|
||||
|
||||
} catch( fc::exception& e ) {
|
||||
BOOST_TEST_MESSAGE("SON cli wallet tests exception");
|
||||
edump((e.to_detail_string()));
|
||||
throw;
|
||||
}
|
||||
BOOST_TEST_MESSAGE("SON Vote cli wallet tests end");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( delete_son )
|
||||
{
|
||||
BOOST_TEST_MESSAGE("SON delete cli wallet tests begin");
|
||||
try
|
||||
{
|
||||
son_test_helper sth(*this);
|
||||
sth.create_son("son1account", "http://son1");
|
||||
sth.create_son("son2account", "http://son2");
|
||||
|
||||
BOOST_TEST_MESSAGE("Deleting SONs");
|
||||
signed_transaction delete_tx;
|
||||
auto _db = app1->chain_database();
|
||||
BOOST_CHECK(_db->get_index_type<son_index>().indices().size() == 2);
|
||||
delete_tx = con.wallet_api_ptr->delete_son("son1account", "true");
|
||||
delete_tx = con.wallet_api_ptr->delete_son("son2account", "true");
|
||||
BOOST_CHECK(generate_maintenance_block());
|
||||
BOOST_CHECK(_db->get_index_type<son_index>().indices().size() == 0);
|
||||
} catch( fc::exception& e ) {
|
||||
BOOST_TEST_MESSAGE("SON cli wallet tests exception");
|
||||
edump((e.to_detail_string()));
|
||||
throw;
|
||||
}
|
||||
BOOST_TEST_MESSAGE("SON delete cli wallet tests end");
|
||||
}
|
||||
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE( select_top_fifteen_sons, cli_fixture )
|
||||
{
|
||||
BOOST_TEST_MESSAGE("SON cli wallet tests begin");
|
||||
try
|
||||
{
|
||||
son_test_helper sth(*this);
|
||||
|
||||
graphene::wallet::brain_key_info bki;
|
||||
signed_transaction create_tx;
|
||||
signed_transaction transfer_tx;
|
||||
signed_transaction upgrade_tx;
|
||||
signed_transaction vote_tx;
|
||||
account_object acc_before_upgrade, acc_after_upgrade;
|
||||
son_object son_obj;
|
||||
global_property_object gpo;
|
||||
|
||||
gpo = con.wallet_api_ptr->get_global_properties();
|
||||
unsigned int son_number = gpo.parameters.maximum_son_count;
|
||||
|
||||
// create son accounts
|
||||
for(unsigned int i = 0; i < son_number + 1; i++)
|
||||
{
|
||||
sth.create_son("sonaccount" + fc::to_pretty_string(i),
|
||||
"http://son" + fc::to_pretty_string(i), false);
|
||||
}
|
||||
BOOST_CHECK(generate_maintenance_block());
|
||||
|
||||
BOOST_TEST_MESSAGE("Voting for SONs");
|
||||
for(unsigned int i = 0; i < son_number + 1; i++)
|
||||
{
|
||||
std::string name = "sonaccount" + fc::to_pretty_string(i);
|
||||
vote_tx = con.wallet_api_ptr->vote_for_son(name, name, true, true);
|
||||
}
|
||||
BOOST_CHECK(generate_maintenance_block());
|
||||
|
||||
for(unsigned int i = 0; i < son_number; i++)
|
||||
{
|
||||
std::string name1 = "sonaccount" + fc::to_pretty_string(i);
|
||||
std::string name2 = "sonaccount" + fc::to_pretty_string(i + 1);
|
||||
vote_tx = con.wallet_api_ptr->vote_for_son(name1, name2, true, true);
|
||||
}
|
||||
gpo = con.wallet_api_ptr->get_global_properties();
|
||||
BOOST_TEST_MESSAGE("gpo: " << gpo.active_sons.size());
|
||||
BOOST_CHECK(generate_maintenance_block());
|
||||
gpo = con.wallet_api_ptr->get_global_properties();
|
||||
BOOST_TEST_MESSAGE("gpo: " << gpo.active_sons.size());
|
||||
|
||||
for(unsigned int i = 0; i < son_number - 1; i++)
|
||||
{
|
||||
std::string name1 = "sonaccount" + fc::to_pretty_string(i + 2);
|
||||
std::string name2 = "sonaccount" + fc::to_pretty_string(i);
|
||||
vote_tx = con.wallet_api_ptr->vote_for_son(name1, name2, true, true);
|
||||
}
|
||||
gpo = con.wallet_api_ptr->get_global_properties();
|
||||
BOOST_TEST_MESSAGE("gpo: " << gpo.active_sons.size());
|
||||
BOOST_CHECK(generate_maintenance_block());
|
||||
gpo = con.wallet_api_ptr->get_global_properties();
|
||||
BOOST_TEST_MESSAGE("gpo: " << gpo.active_sons.size());
|
||||
|
||||
for(unsigned int i = 0; i < son_number - 2; i++)
|
||||
{
|
||||
std::string name1 = "sonaccount" + fc::to_pretty_string(i + 3);
|
||||
std::string name2 = "sonaccount" + fc::to_pretty_string(i);
|
||||
vote_tx = con.wallet_api_ptr->vote_for_son(name1, name2, true, true);
|
||||
}
|
||||
gpo = con.wallet_api_ptr->get_global_properties();
|
||||
BOOST_TEST_MESSAGE("gpo: " << gpo.active_sons.size());
|
||||
BOOST_CHECK(generate_maintenance_block());
|
||||
|
||||
BOOST_CHECK(gpo.active_sons.size() == 15);
|
||||
|
||||
} catch( fc::exception& e ) {
|
||||
BOOST_TEST_MESSAGE("SON cli wallet tests exception");
|
||||
edump((e.to_detail_string()));
|
||||
throw;
|
||||
}
|
||||
BOOST_TEST_MESSAGE("SON cli wallet tests end");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( list_son )
|
||||
{
|
||||
BOOST_TEST_MESSAGE("List SONs cli wallet tests begin");
|
||||
try
|
||||
{
|
||||
son_test_helper sth(*this);
|
||||
sth.create_son("son1account", "http://son1");
|
||||
sth.create_son("son2account", "http://son2");
|
||||
|
||||
auto res = con.wallet_api_ptr->list_sons("", 100);
|
||||
BOOST_REQUIRE(res.size() == 2);
|
||||
BOOST_CHECK(res.find("son1account") != res.end());
|
||||
BOOST_CHECK(res.find("son2account") != res.end());
|
||||
|
||||
} catch( fc::exception& e ) {
|
||||
BOOST_TEST_MESSAGE("SON cli wallet tests exception");
|
||||
edump((e.to_detail_string()));
|
||||
throw;
|
||||
}
|
||||
BOOST_TEST_MESSAGE("List SONs cli wallet tests end");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( update_son_votes_test )
|
||||
{
|
||||
BOOST_TEST_MESSAGE("SON update_son_votes cli wallet tests begin");
|
||||
try
|
||||
{
|
||||
son_test_helper sth(*this);
|
||||
sth.create_son("son1account", "http://son1");
|
||||
sth.create_son("son2account", "http://son2");
|
||||
|
||||
BOOST_TEST_MESSAGE("Vote for 2 accounts with update_son_votes");
|
||||
|
||||
son_object son1_obj;
|
||||
son_object son2_obj;
|
||||
int son1_start_votes, son1_end_votes;
|
||||
int son2_start_votes, son2_end_votes;
|
||||
|
||||
// Get votes at start
|
||||
son1_obj = con.wallet_api_ptr->get_son("son1account");
|
||||
son1_start_votes = son1_obj.total_votes;
|
||||
son2_obj = con.wallet_api_ptr->get_son("son2account");
|
||||
son2_start_votes = son2_obj.total_votes;
|
||||
|
||||
std::vector<std::string> accepted;
|
||||
std::vector<std::string> rejected;
|
||||
signed_transaction update_votes_tx;
|
||||
|
||||
// Vote for both SONs
|
||||
accepted.clear();
|
||||
rejected.clear();
|
||||
accepted.push_back("son1account");
|
||||
accepted.push_back("son2account");
|
||||
update_votes_tx = con.wallet_api_ptr->update_son_votes("nathan", accepted,
|
||||
rejected, 15, true);
|
||||
BOOST_CHECK(generate_block());
|
||||
BOOST_CHECK(generate_maintenance_block());
|
||||
|
||||
// Verify the votes
|
||||
son1_obj = con.wallet_api_ptr->get_son("son1account");
|
||||
son1_end_votes = son1_obj.total_votes;
|
||||
BOOST_CHECK(son1_end_votes > son1_start_votes);
|
||||
son1_start_votes = son1_end_votes;
|
||||
son2_obj = con.wallet_api_ptr->get_son("son2account");
|
||||
son2_end_votes = son2_obj.total_votes;
|
||||
BOOST_CHECK(son2_end_votes > son2_start_votes);
|
||||
son2_start_votes = son2_end_votes;
|
||||
|
||||
|
||||
// Withdraw vote for SON 1
|
||||
accepted.clear();
|
||||
rejected.clear();
|
||||
rejected.push_back("son1account");
|
||||
update_votes_tx = con.wallet_api_ptr->update_son_votes("nathan", accepted,
|
||||
rejected, 15, true);
|
||||
BOOST_CHECK(generate_maintenance_block());
|
||||
|
||||
// Verify the votes
|
||||
son1_obj = con.wallet_api_ptr->get_son("son1account");
|
||||
son1_end_votes = son1_obj.total_votes;
|
||||
BOOST_CHECK(son1_end_votes < son1_start_votes);
|
||||
son1_start_votes = son1_end_votes;
|
||||
son2_obj = con.wallet_api_ptr->get_son("son2account");
|
||||
// voice distribution changed, SON2 now has all voices
|
||||
son2_end_votes = son2_obj.total_votes;
|
||||
BOOST_CHECK(son2_end_votes > son2_start_votes);
|
||||
son2_start_votes = son2_end_votes;
|
||||
|
||||
// Try to reject incorrect SON
|
||||
accepted.clear();
|
||||
rejected.clear();
|
||||
rejected.push_back("son1accnt");
|
||||
BOOST_CHECK_THROW(update_votes_tx = con.wallet_api_ptr->update_son_votes("nathan", accepted,
|
||||
rejected, 15, true), fc::exception);
|
||||
BOOST_CHECK(generate_block());
|
||||
|
||||
// Verify the votes
|
||||
son1_obj = con.wallet_api_ptr->get_son("son1account");
|
||||
son1_end_votes = son1_obj.total_votes;
|
||||
BOOST_CHECK(son1_end_votes == son1_start_votes);
|
||||
son1_start_votes = son1_end_votes;
|
||||
son2_obj = con.wallet_api_ptr->get_son("son2account");
|
||||
son2_end_votes = son2_obj.total_votes;
|
||||
BOOST_CHECK(son2_end_votes == son2_start_votes);
|
||||
son2_start_votes = son2_end_votes;
|
||||
|
||||
// Reject SON2
|
||||
accepted.clear();
|
||||
rejected.clear();
|
||||
rejected.push_back("son2account");
|
||||
update_votes_tx = con.wallet_api_ptr->update_son_votes("nathan", accepted,
|
||||
rejected, 15, true);
|
||||
BOOST_CHECK(generate_maintenance_block());
|
||||
|
||||
// Verify the votes
|
||||
son1_obj = con.wallet_api_ptr->get_son("son1account");
|
||||
son1_end_votes = son1_obj.total_votes;
|
||||
BOOST_CHECK(son1_end_votes == son1_start_votes);
|
||||
son1_start_votes = son1_end_votes;
|
||||
son2_obj = con.wallet_api_ptr->get_son("son2account");
|
||||
son2_end_votes = son2_obj.total_votes;
|
||||
BOOST_CHECK(son2_end_votes < son2_start_votes);
|
||||
son2_start_votes = son2_end_votes;
|
||||
|
||||
// Try to accept and reject the same SON
|
||||
accepted.clear();
|
||||
rejected.clear();
|
||||
rejected.push_back("son1accnt");
|
||||
accepted.push_back("son1accnt");
|
||||
BOOST_REQUIRE_THROW(update_votes_tx = con.wallet_api_ptr->update_son_votes("nathan", accepted,
|
||||
rejected, 15, true), fc::exception);
|
||||
BOOST_CHECK(generate_maintenance_block());
|
||||
|
||||
// Verify the votes
|
||||
son1_obj = con.wallet_api_ptr->get_son("son1account");
|
||||
son1_end_votes = son1_obj.total_votes;
|
||||
BOOST_CHECK(son1_end_votes == son1_start_votes);
|
||||
son1_start_votes = son1_end_votes;
|
||||
son2_obj = con.wallet_api_ptr->get_son("son2account");
|
||||
son2_end_votes = son2_obj.total_votes;
|
||||
BOOST_CHECK(son2_end_votes == son2_start_votes);
|
||||
son2_start_votes = son2_end_votes;
|
||||
|
||||
} catch( fc::exception& e ) {
|
||||
BOOST_TEST_MESSAGE("SON cli wallet tests exception");
|
||||
edump((e.to_detail_string()));
|
||||
throw;
|
||||
}
|
||||
BOOST_TEST_MESSAGE("SON update_son_votes cli wallet tests end");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( related_functions )
|
||||
{
|
||||
BOOST_TEST_MESSAGE("SON-related functions cli wallet tests begin");
|
||||
try
|
||||
{
|
||||
global_property_object gpo = con.wallet_api_ptr->get_global_properties();
|
||||
BOOST_CHECK(gpo.active_sons.size() == 0);
|
||||
|
||||
son_test_helper sth(*this);
|
||||
sth.create_son("son1account", "http://son1");
|
||||
sth.create_son("son2account", "http://son2");
|
||||
|
||||
gpo = con.wallet_api_ptr->get_global_properties();
|
||||
BOOST_CHECK(gpo.active_sons.size() == 2);
|
||||
|
||||
} catch( fc::exception& e ) {
|
||||
BOOST_TEST_MESSAGE("SON cli wallet tests exception");
|
||||
edump((e.to_detail_string()));
|
||||
throw;
|
||||
}
|
||||
BOOST_TEST_MESSAGE("SON-related functions cli wallet tests end");
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in a new issue