Added cli tests from bitshares
This commit is contained in:
parent
c35a88bd51
commit
e3e405a7e7
6 changed files with 1270 additions and 0 deletions
|
|
@ -52,6 +52,7 @@ fc::variant_object get_config()
|
|||
result[ "GRAPHENE_DEFAULT_MAINTENANCE_SKIP_SLOTS" ] = GRAPHENE_DEFAULT_MAINTENANCE_SKIP_SLOTS;
|
||||
result[ "GRAPHENE_MIN_UNDO_HISTORY" ] = GRAPHENE_MIN_UNDO_HISTORY;
|
||||
result[ "GRAPHENE_MAX_UNDO_HISTORY" ] = GRAPHENE_MAX_UNDO_HISTORY;
|
||||
result[ "GRAPHENE_MAX_NESTED_OBJECTS" ] = GRAPHENE_MAX_NESTED_OBJECTS;
|
||||
result[ "GRAPHENE_MIN_BLOCK_SIZE_LIMIT" ] = GRAPHENE_MIN_BLOCK_SIZE_LIMIT;
|
||||
result[ "GRAPHENE_MIN_TRANSACTION_EXPIRATION_LIMIT" ] = GRAPHENE_MIN_TRANSACTION_EXPIRATION_LIMIT;
|
||||
result[ "GRAPHENE_BLOCKCHAIN_PRECISION" ] = GRAPHENE_BLOCKCHAIN_PRECISION;
|
||||
|
|
|
|||
|
|
@ -53,6 +53,8 @@
|
|||
#define GRAPHENE_MIN_UNDO_HISTORY 10
|
||||
#define GRAPHENE_MAX_UNDO_HISTORY 10000
|
||||
|
||||
#define GRAPHENE_MAX_NESTED_OBJECTS (200)
|
||||
|
||||
#define GRAPHENE_MIN_BLOCK_SIZE_LIMIT (GRAPHENE_MIN_TRANSACTION_SIZE_LIMIT*5) // 5 transactions per block
|
||||
#define GRAPHENE_MIN_TRANSACTION_EXPIRATION_LIMIT (GRAPHENE_MAX_BLOCK_INTERVAL * 5) // 5 transactions per block
|
||||
#define GRAPHENE_BLOCKCHAIN_PRECISION uint64_t( 100000 )
|
||||
|
|
|
|||
|
|
@ -481,6 +481,11 @@ class wallet_api
|
|||
* @ingroup Transaction Builder API
|
||||
*/
|
||||
signed_transaction sign_builder_transaction(transaction_handle_type transaction_handle, bool broadcast = true);
|
||||
/** Broadcast signed transaction
|
||||
* @param tx signed transaction
|
||||
* @returns the transaction ID along with the signed transaction.
|
||||
*/
|
||||
pair<transaction_id_type,signed_transaction> broadcast_transaction(signed_transaction tx);
|
||||
/**
|
||||
* @ingroup Transaction Builder API
|
||||
*/
|
||||
|
|
@ -580,6 +585,12 @@ class wallet_api
|
|||
*/
|
||||
bool load_wallet_file(string wallet_filename = "");
|
||||
|
||||
/** Quitting from BitShares wallet.
|
||||
*
|
||||
* The current wallet will be closed.
|
||||
*/
|
||||
void quit();
|
||||
|
||||
/** Saves the current wallet to the given filename.
|
||||
*
|
||||
* @warning This does not change the wallet filename that will be used for future
|
||||
|
|
@ -1489,6 +1500,37 @@ class wallet_api
|
|||
*/
|
||||
signed_transaction sign_transaction(signed_transaction tx, bool broadcast = false);
|
||||
|
||||
/** Get transaction signers.
|
||||
*
|
||||
* Returns information about who signed the transaction, specifically,
|
||||
* the corresponding public keys of the private keys used to sign the transaction.
|
||||
* @param tx the signed transaction
|
||||
* @return the set of public_keys
|
||||
*/
|
||||
flat_set<public_key_type> get_transaction_signers(const signed_transaction &tx) const;
|
||||
|
||||
/** Get key references.
|
||||
*
|
||||
* Returns accounts related to given public keys.
|
||||
* @param keys public keys to search for related accounts
|
||||
* @return the set of related accounts
|
||||
*/
|
||||
vector<vector<account_id_type>> get_key_references(const vector<public_key_type> &keys) const;
|
||||
|
||||
/** Signs a transaction.
|
||||
*
|
||||
* Given a fully-formed transaction with or without signatures, signs
|
||||
* the transaction with the owned keys and optionally broadcasts the
|
||||
* transaction.
|
||||
*
|
||||
* @param tx the unsigned transaction
|
||||
* @param broadcast true if you wish to broadcast the transaction
|
||||
*
|
||||
* @return the signed transaction
|
||||
*/
|
||||
signed_transaction add_transaction_signature( signed_transaction tx,
|
||||
bool broadcast = false );
|
||||
|
||||
/** Returns an uninitialized object representing a given blockchain operation.
|
||||
*
|
||||
* This returns a default-initialized object of the given type; it can be used
|
||||
|
|
@ -1910,6 +1952,7 @@ FC_API( graphene::wallet::wallet_api,
|
|||
(set_fees_on_builder_transaction)
|
||||
(preview_builder_transaction)
|
||||
(sign_builder_transaction)
|
||||
(broadcast_transaction)
|
||||
(propose_builder_transaction)
|
||||
(propose_builder_transaction2)
|
||||
(remove_builder_transaction)
|
||||
|
|
@ -1990,6 +2033,9 @@ FC_API( graphene::wallet::wallet_api,
|
|||
(save_wallet_file)
|
||||
(serialize_transaction)
|
||||
(sign_transaction)
|
||||
(get_transaction_signers)
|
||||
(get_key_references)
|
||||
(add_transaction_signature)
|
||||
(get_prototype_operation)
|
||||
(propose_parameter_change)
|
||||
(propose_fee_change)
|
||||
|
|
|
|||
|
|
@ -598,6 +598,13 @@ public:
|
|||
fc::async([this, object]{subscribed_object_changed(object);}, "Object changed");
|
||||
}
|
||||
|
||||
void quit()
|
||||
{
|
||||
ilog( "Quitting Cli Wallet ..." );
|
||||
|
||||
throw fc::canceled_exception();
|
||||
}
|
||||
|
||||
bool copy_wallet_file( string destination_filename )
|
||||
{
|
||||
fc::path src_path = get_wallet_filename();
|
||||
|
|
@ -1161,6 +1168,20 @@ public:
|
|||
|
||||
return _builder_transactions[transaction_handle] = sign_transaction(_builder_transactions[transaction_handle], broadcast);
|
||||
}
|
||||
|
||||
pair<transaction_id_type,signed_transaction> broadcast_transaction(signed_transaction tx)
|
||||
{
|
||||
try {
|
||||
_remote_net_broadcast->broadcast_transaction(tx);
|
||||
}
|
||||
catch (const fc::exception& e) {
|
||||
elog("Caught exception while broadcasting tx ${id}: ${e}",
|
||||
("id", tx.id().str())("e", e.to_detail_string()));
|
||||
throw;
|
||||
}
|
||||
return std::make_pair(tx.id(),tx);
|
||||
}
|
||||
|
||||
signed_transaction propose_builder_transaction(
|
||||
transaction_handle_type handle,
|
||||
time_point_sec expiration = time_point::now() + fc::minutes(1),
|
||||
|
|
@ -2292,6 +2313,84 @@ public:
|
|||
return tx;
|
||||
}
|
||||
|
||||
flat_set<public_key_type> get_transaction_signers(const signed_transaction &tx) const
|
||||
{
|
||||
return tx.get_signature_keys(_chain_id);
|
||||
}
|
||||
|
||||
vector<vector<account_id_type>> get_key_references(const vector<public_key_type> &keys) const
|
||||
{
|
||||
return _remote_db->get_key_references(keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the required public keys to sign the transaction which had been
|
||||
* owned by us
|
||||
*
|
||||
* NOTE, if `erase_existing_sigs` set to true, the original trasaction's
|
||||
* signatures will be erased
|
||||
*
|
||||
* @param tx The transaction to be signed
|
||||
* @param erase_existing_sigs
|
||||
* The transaction could have been partially signed already,
|
||||
* if set to false, the corresponding public key of existing
|
||||
* signatures won't be returned.
|
||||
* If set to true, the existing signatures will be erased and
|
||||
* all required keys returned.
|
||||
*/
|
||||
set<public_key_type> get_owned_required_keys( signed_transaction &tx,
|
||||
bool erase_existing_sigs = true)
|
||||
{
|
||||
set<public_key_type> pks = _remote_db->get_potential_signatures( tx );
|
||||
flat_set<public_key_type> owned_keys;
|
||||
owned_keys.reserve( pks.size() );
|
||||
std::copy_if( pks.begin(), pks.end(),
|
||||
std::inserter( owned_keys, owned_keys.end() ),
|
||||
[this]( const public_key_type &pk ) {
|
||||
return _keys.find( pk ) != _keys.end();
|
||||
} );
|
||||
|
||||
if ( erase_existing_sigs )
|
||||
tx.signatures.clear();
|
||||
|
||||
return _remote_db->get_required_signatures( tx, owned_keys );
|
||||
}
|
||||
|
||||
signed_transaction add_transaction_signature( signed_transaction tx,
|
||||
bool broadcast )
|
||||
{
|
||||
set<public_key_type> approving_key_set = get_owned_required_keys(tx, false);
|
||||
|
||||
if ( ( ( tx.ref_block_num == 0 && tx.ref_block_prefix == 0 ) ||
|
||||
tx.expiration == fc::time_point_sec() ) &&
|
||||
tx.signatures.empty() )
|
||||
{
|
||||
auto dyn_props = get_dynamic_global_properties();
|
||||
auto parameters = get_global_properties().parameters;
|
||||
fc::time_point_sec now = dyn_props.time;
|
||||
tx.set_reference_block( dyn_props.head_block_id );
|
||||
tx.set_expiration( now + parameters.maximum_time_until_expiration );
|
||||
}
|
||||
for ( const public_key_type &key : approving_key_set )
|
||||
tx.sign( get_private_key( key ), _chain_id );
|
||||
|
||||
if ( broadcast )
|
||||
{
|
||||
try
|
||||
{
|
||||
_remote_net_broadcast->broadcast_transaction( tx );
|
||||
}
|
||||
catch ( const fc::exception &e )
|
||||
{
|
||||
elog( "Caught exception while broadcasting tx ${id}: ${e}",
|
||||
( "id", tx.id().str() )( "e", e.to_detail_string() ) );
|
||||
FC_THROW( "Caught exception while broadcasting tx" );
|
||||
}
|
||||
}
|
||||
|
||||
return tx;
|
||||
}
|
||||
|
||||
signed_transaction sell_asset(string seller_account,
|
||||
string amount_to_sell,
|
||||
string symbol_to_sell,
|
||||
|
|
@ -3631,6 +3730,11 @@ signed_transaction wallet_api::sign_builder_transaction(transaction_handle_type
|
|||
return my->sign_builder_transaction(transaction_handle, broadcast);
|
||||
}
|
||||
|
||||
pair<transaction_id_type,signed_transaction> wallet_api::broadcast_transaction(signed_transaction tx)
|
||||
{
|
||||
return my->broadcast_transaction(tx);
|
||||
}
|
||||
|
||||
signed_transaction wallet_api::propose_builder_transaction(
|
||||
transaction_handle_type handle,
|
||||
time_point_sec expiration,
|
||||
|
|
@ -4087,6 +4191,22 @@ signed_transaction wallet_api::sign_transaction(signed_transaction tx, bool broa
|
|||
return my->sign_transaction( tx, broadcast);
|
||||
} FC_CAPTURE_AND_RETHROW( (tx) ) }
|
||||
|
||||
signed_transaction wallet_api::add_transaction_signature( signed_transaction tx,
|
||||
bool broadcast )
|
||||
{
|
||||
return my->add_transaction_signature( tx, broadcast );
|
||||
}
|
||||
|
||||
flat_set<public_key_type> wallet_api::get_transaction_signers(const signed_transaction &tx) const
|
||||
{ try {
|
||||
return my->get_transaction_signers(tx);
|
||||
} FC_CAPTURE_AND_RETHROW( (tx) ) }
|
||||
|
||||
vector<vector<account_id_type>> wallet_api::get_key_references(const vector<public_key_type> &keys) const
|
||||
{ try {
|
||||
return my->get_key_references(keys);
|
||||
} FC_CAPTURE_AND_RETHROW( (keys) ) }
|
||||
|
||||
operation wallet_api::get_prototype_operation(string operation_name)
|
||||
{
|
||||
return my->get_prototype_operation( operation_name );
|
||||
|
|
@ -4274,6 +4394,11 @@ bool wallet_api::load_wallet_file( string wallet_filename )
|
|||
return my->load_wallet_file( wallet_filename );
|
||||
}
|
||||
|
||||
void wallet_api::quit()
|
||||
{
|
||||
my->quit();
|
||||
}
|
||||
|
||||
void wallet_api::save_wallet_file( string wallet_filename )
|
||||
{
|
||||
my->save_wallet_file( wallet_filename );
|
||||
|
|
|
|||
|
|
@ -25,6 +25,16 @@ file(GLOB APP_SOURCES "app/*.cpp")
|
|||
add_executable( app_test ${APP_SOURCES} )
|
||||
target_link_libraries( app_test graphene_app graphene_account_history graphene_bookie graphene_net graphene_chain graphene_egenesis_none fc ${PLATFORM_SPECIFIC_LIBS} )
|
||||
|
||||
file(GLOB CLI_SOURCES "cli/*.cpp")
|
||||
add_executable( cli_test ${CLI_SOURCES} )
|
||||
if(WIN32)
|
||||
list(APPEND PLATFORM_SPECIFIC_LIBS ws2_32)
|
||||
endif()
|
||||
target_link_libraries( cli_test graphene_app graphene_wallet graphene_witness graphene_account_history graphene_net graphene_chain graphene_egenesis_none fc ${PLATFORM_SPECIFIC_LIBS} )
|
||||
if(MSVC)
|
||||
set_source_files_properties( cli/main.cpp PROPERTIES COMPILE_FLAGS "/bigobj" )
|
||||
endif(MSVC)
|
||||
|
||||
file(GLOB INTENSE_SOURCES "intense/*.cpp")
|
||||
add_executable( intense_test ${INTENSE_SOURCES} ${COMMON_SOURCES} )
|
||||
target_link_libraries( intense_test graphene_chain graphene_app graphene_account_history graphene_bookie graphene_egenesis_none fc ${PLATFORM_SPECIFIC_LIBS} )
|
||||
|
|
|
|||
1086
tests/cli/main.cpp
Normal file
1086
tests/cli/main.cpp
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue