diff --git a/libraries/app/api.cpp b/libraries/app/api.cpp index 0910cc83..e92b602d 100644 --- a/libraries/app/api.cpp +++ b/libraries/app/api.cpp @@ -140,6 +140,11 @@ namespace graphene { namespace app { return _db.get(global_property_id_type()); } + chain_id_type database_api::get_chain_id()const + { + return _db.get_chain_id(); + } + dynamic_global_property_object database_api::get_dynamic_global_properties()const { return _db.get(dynamic_global_property_id_type()); @@ -1118,15 +1123,17 @@ namespace graphene { namespace app { set database_api::get_required_signatures( const signed_transaction& trx, const flat_set& available_keys )const { - return trx.get_required_signatures( available_keys, + return trx.get_required_signatures( _db.get_chain_id(), + available_keys, [&]( account_id_type id ){ return &id(_db).active; }, [&]( account_id_type id ){ return &id(_db).owner; }, _db.get_global_properties().parameters.max_authority_depth ); } - bool database_api::verify_authority( const signed_transaction& trx )const + bool database_api::verify_authority( const signed_transaction& trx )const { - trx.verify_authority( [&]( account_id_type id ){ return &id(_db).active; }, + trx.verify_authority( _db.get_chain_id(), + [&]( account_id_type id ){ return &id(_db).active; }, [&]( account_id_type id ){ return &id(_db).owner; }, _db.get_global_properties().parameters.max_authority_depth ); return true; diff --git a/libraries/app/application.cpp b/libraries/app/application.cpp index 22fee5e4..fb4a1546 100644 --- a/libraries/app/application.cpp +++ b/libraries/app/application.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -425,7 +426,7 @@ namespace detail { return trx_message( _chain_db->get_recent_transaction( id.item_hash ) ); } FC_CAPTURE_AND_RETHROW( (id) ) } - virtual fc::sha256 get_chain_id()const override + virtual chain_id_type get_chain_id()const override { return _chain_db->get_global_properties().chain_id; } diff --git a/libraries/app/include/graphene/app/api.hpp b/libraries/app/include/graphene/app/api.hpp index 1da694de..cbbd267a 100644 --- a/libraries/app/include/graphene/app/api.hpp +++ b/libraries/app/include/graphene/app/api.hpp @@ -16,6 +16,7 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #pragma once +#include #include #include #include @@ -82,6 +83,12 @@ namespace graphene { namespace app { * @brief Retrieve the current @ref global_property_object */ global_property_object get_global_properties()const; + + /** + * @brief Get the chain ID + */ + chain_id_type get_chain_id()const; + /** * @brief Retrieve the current @ref dynamic_global_property_object */ @@ -513,6 +520,7 @@ FC_API(graphene::app::database_api, (get_block) (get_transaction) (get_global_properties) + (get_chain_id) (get_dynamic_global_properties) (get_accounts) (get_assets) diff --git a/libraries/chain/db_block.cpp b/libraries/chain/db_block.cpp index c16d7fd4..a91ba696 100644 --- a/libraries/chain/db_block.cpp +++ b/libraries/chain/db_block.cpp @@ -478,6 +478,7 @@ processed_transaction database::_apply_transaction(const signed_transaction& trx uint32_t skip = get_node_properties().skip_flags; trx.validate(); auto& trx_idx = get_mutable_index_type(); + const chain_id_type& chain_id = get_chain_id(); auto trx_id = trx.id(); FC_ASSERT( (skip & skip_transaction_dupe_check) || trx_idx.indices().get().find(trx_id) == trx_idx.indices().get().end() ); @@ -489,7 +490,7 @@ processed_transaction database::_apply_transaction(const signed_transaction& trx { auto get_active = [&]( account_id_type id ) { return &id(*this).active; }; auto get_owner = [&]( account_id_type id ) { return &id(*this).owner; }; - trx.verify_authority( get_active, get_owner, get_global_properties().parameters.max_authority_depth ); + trx.verify_authority( chain_id, get_active, get_owner, get_global_properties().parameters.max_authority_depth ); } //Skip all manner of expiration and TaPoS checking if we're on block 1; It's impossible that the transaction is diff --git a/libraries/chain/db_getter.cpp b/libraries/chain/db_getter.cpp index 28e15602..b10c702d 100644 --- a/libraries/chain/db_getter.cpp +++ b/libraries/chain/db_getter.cpp @@ -63,6 +63,11 @@ decltype( chain_parameters::block_interval ) database::block_interval( )const return get_global_properties().parameters.block_interval; } +const chain_id_type& database::get_chain_id( )const +{ + return get_global_properties().chain_id; +} + const node_property_object& database::get_node_properties()const { return _node_property_object; diff --git a/libraries/chain/include/graphene/chain/database.hpp b/libraries/chain/include/graphene/chain/database.hpp index c2c7cd23..a26addc5 100644 --- a/libraries/chain/include/graphene/chain/database.hpp +++ b/libraries/chain/include/graphene/chain/database.hpp @@ -252,6 +252,7 @@ namespace graphene { namespace chain { //////////////////// db_getter.cpp //////////////////// + const chain_id_type& get_chain_id()const; const asset_object& get_core_asset()const; const global_property_object& get_global_properties()const; const dynamic_global_property_object& get_dynamic_global_properties()const; diff --git a/libraries/chain/include/graphene/chain/global_property_object.hpp b/libraries/chain/include/graphene/chain/global_property_object.hpp index 7ad166f2..f64d8527 100644 --- a/libraries/chain/include/graphene/chain/global_property_object.hpp +++ b/libraries/chain/include/graphene/chain/global_property_object.hpp @@ -18,8 +18,8 @@ #pragma once #include -#include #include +#include #include #include @@ -48,7 +48,7 @@ namespace graphene { namespace chain { // n.b. witness scheduling is done by witness_schedule object flat_set witness_accounts; // updated once per maintenance interval - fc::sha256 chain_id; + chain_id_type chain_id; }; /** diff --git a/libraries/chain/include/graphene/chain/protocol/transaction.hpp b/libraries/chain/include/graphene/chain/protocol/transaction.hpp index dd353b43..5580ad6b 100644 --- a/libraries/chain/include/graphene/chain/protocol/transaction.hpp +++ b/libraries/chain/include/graphene/chain/protocol/transaction.hpp @@ -16,6 +16,7 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #pragma once +#include #include #include @@ -77,10 +78,12 @@ namespace graphene { namespace chain { vector operations; extensions_type extensions; - /// Calculate the digest for a transaction with an absolute expiration time + /// Calculate the digest for a transaction digest_type digest()const; transaction_id_type id()const; void validate() const; + /// Calculate the digest used for signature validation + digest_type sig_digest( const chain_id_type& chain_id )const; void set_expiration( fc::time_point_sec expiration_time ); void set_reference_block( const block_id_type& reference_block ); @@ -115,10 +118,10 @@ namespace graphene { namespace chain { : transaction(trx){} /** signs and appends to signatures */ - const signature_type& sign( const private_key_type& key ); + const signature_type& sign( const private_key_type& key, const chain_id_type& chain_id ); /** returns signature but does not append */ - signature_type sign( const private_key_type& key )const; + signature_type sign( const private_key_type& key, const chain_id_type& chain_id )const; /** * The purpose of this method is to identify some subset of @@ -128,15 +131,18 @@ namespace graphene { namespace chain { * validation. */ set get_required_signatures( + const chain_id_type& chain_id, const flat_set& available_keys, const std::function& get_active, const std::function& get_owner, uint32_t max_recursion = GRAPHENE_MAX_SIG_CHECK_DEPTH )const; - void verify_authority( const std::function& get_active, - const std::function& get_owner, - uint32_t max_recursion = GRAPHENE_MAX_SIG_CHECK_DEPTH )const; + void verify_authority( + const chain_id_type& chain_id, + const std::function& get_active, + const std::function& get_owner, + uint32_t max_recursion = GRAPHENE_MAX_SIG_CHECK_DEPTH )const; /** * This is a slower replacement for get_required_signatures() @@ -146,13 +152,14 @@ namespace graphene { namespace chain { */ set minimize_required_signatures( + const chain_id_type& chain_id, const flat_set& available_keys, const std::function& get_active, const std::function& get_owner, uint32_t max_recursion = GRAPHENE_MAX_SIG_CHECK_DEPTH ) const; - flat_set get_signature_keys()const; + flat_set get_signature_keys( const chain_id_type& chain_id )const; vector signatures; diff --git a/libraries/chain/protocol/transaction.cpp b/libraries/chain/protocol/transaction.cpp index e9a16be3..86c8a210 100644 --- a/libraries/chain/protocol/transaction.cpp +++ b/libraries/chain/protocol/transaction.cpp @@ -24,10 +24,11 @@ namespace graphene { namespace chain { - digest_type processed_transaction::merkle_digest()const { - return digest_type::hash(*this); + digest_type::encoder enc; + fc::raw::pack( enc, *this ); + return enc.result(); } digest_type transaction::digest()const @@ -36,6 +37,15 @@ digest_type transaction::digest()const fc::raw::pack( enc, *this ); return enc.result(); } + +digest_type transaction::sig_digest( const chain_id_type& chain_id )const +{ + digest_type::encoder enc; + fc::raw::pack( enc, chain_id ); + fc::raw::pack( enc, *this ); + return enc.result(); +} + void transaction::validate() const { FC_ASSERT( operations.size() > 0, "A transaction must have at least one operation", ("trx",*this) ); @@ -45,22 +55,25 @@ void transaction::validate() const graphene::chain::transaction_id_type graphene::chain::transaction::id() const { - digest_type::encoder enc; - fc::raw::pack(enc, *this); - auto hash = enc.result(); + auto h = digest(); transaction_id_type result; - memcpy(result._hash, hash._hash, std::min(sizeof(result), sizeof(hash))); + memcpy(result._hash, h._hash, std::min(sizeof(result), sizeof(h))); return result; } -const signature_type& graphene::chain::signed_transaction::sign(const private_key_type& key) +const signature_type& graphene::chain::signed_transaction::sign(const private_key_type& key, const chain_id_type& chain_id) { - signatures.push_back(key.sign_compact(digest())); + digest_type h = sig_digest( chain_id ); + signatures.push_back(key.sign_compact(h)); return signatures.back(); } -signature_type graphene::chain::signed_transaction::sign(const private_key_type& key)const + +signature_type graphene::chain::signed_transaction::sign(const private_key_type& key, const chain_id_type& chain_id)const { - return key.sign_compact(digest()); + digest_type::encoder enc; + fc::raw::pack( enc, chain_id ); + fc::raw::pack( enc, *this ); + return key.sign_compact(enc.result()); } void transaction::set_expiration( fc::time_point_sec expiration_time ) @@ -234,9 +247,9 @@ void verify_authority( const vector& ops, const flat_set signed_transaction::get_signature_keys()const +flat_set signed_transaction::get_signature_keys( const chain_id_type& chain_id )const { try { - auto d = digest(); + auto d = sig_digest( chain_id ); flat_set result; for( const auto& sig : signatures ) { @@ -250,10 +263,12 @@ flat_set signed_transaction::get_signature_keys()const -set signed_transaction::get_required_signatures( const flat_set& available_keys, - const std::function& get_active, - const std::function& get_owner, - uint32_t max_recursion_depth )const +set signed_transaction::get_required_signatures( + const chain_id_type& chain_id, + const flat_set& available_keys, + const std::function& get_active, + const std::function& get_owner, + uint32_t max_recursion_depth )const { flat_set required_active; flat_set required_owner; @@ -261,7 +276,7 @@ set signed_transaction::get_required_signatures( const flat_set get_required_authorities( required_active, required_owner, other ); - sign_state s(get_signature_keys(),get_active,available_keys); + sign_state s(get_signature_keys( chain_id ),get_active,available_keys); s.max_recursion = max_recursion_depth; for( const auto& auth : other ) @@ -283,13 +298,14 @@ set signed_transaction::get_required_signatures( const flat_set } set signed_transaction::minimize_required_signatures( + const chain_id_type& chain_id, const flat_set& available_keys, const std::function& get_active, const std::function& get_owner, uint32_t max_recursion ) const { - set< public_key_type > s = get_required_signatures( available_keys, get_active, get_owner, max_recursion ); + set< public_key_type > s = get_required_signatures( chain_id, available_keys, get_active, get_owner, max_recursion ); flat_set< public_key_type > result( s.begin(), s.end() ); for( const public_key_type& k : s ) @@ -308,11 +324,13 @@ set signed_transaction::minimize_required_signatures( return set( result.begin(), result.end() ); } -void signed_transaction::verify_authority( const std::function& get_active, - const std::function& get_owner, - uint32_t max_recursion )const +void signed_transaction::verify_authority( + const chain_id_type& chain_id, + const std::function& get_active, + const std::function& get_owner, + uint32_t max_recursion )const { try { - graphene::chain::verify_authority( operations, get_signature_keys(), get_active, get_owner, max_recursion ); + graphene::chain::verify_authority( operations, get_signature_keys( chain_id ), get_active, get_owner, max_recursion ); } FC_CAPTURE_AND_RETHROW( (*this) ) } } } // graphene::chain diff --git a/libraries/egenesis/egenesis_brief.cpp.tmpl b/libraries/egenesis/egenesis_brief.cpp.tmpl index 03d00a9b..f7d295e8 100644 --- a/libraries/egenesis/egenesis_brief.cpp.tmpl +++ b/libraries/egenesis/egenesis_brief.cpp.tmpl @@ -20,7 +20,7 @@ ${generated_file_banner} #include #include -namespace graphene { namespace chain { +namespace graphene { namespace egenesis { using namespace graphene::chain; diff --git a/libraries/net/include/graphene/net/node.hpp b/libraries/net/include/graphene/net/node.hpp index 22ef496e..544a59ae 100644 --- a/libraries/net/include/graphene/net/node.hpp +++ b/libraries/net/include/graphene/net/node.hpp @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -28,6 +29,7 @@ namespace graphene { namespace net { using fc::variant_object; + using graphene::chain::chain_id_type; namespace detail { @@ -108,7 +110,7 @@ namespace graphene { namespace net { */ virtual message get_item( const item_id& id ) = 0; - virtual fc::sha256 get_chain_id()const = 0; + virtual chain_id_type get_chain_id()const = 0; /** * Returns a synopsis of the blockchain used for syncing. diff --git a/libraries/net/node.cpp b/libraries/net/node.cpp index 93bb5759..08137457 100644 --- a/libraries/net/node.cpp +++ b/libraries/net/node.cpp @@ -378,7 +378,7 @@ namespace graphene { namespace net { namespace detail { uint32_t& remaining_item_count, uint32_t limit = 2000) override; message get_item( const item_id& id ) override; - fc::sha256 get_chain_id() const override; + chain_id_type get_chain_id() const override; std::vector get_blockchain_synopsis(uint32_t item_type, const graphene::net::item_hash_t& reference_point = graphene::net::item_hash_t(), uint32_t number_of_blocks_after_reference_point = 0) override; @@ -5163,7 +5163,7 @@ namespace graphene { namespace net { namespace detail { INVOKE_AND_COLLECT_STATISTICS(get_item, id); } - fc::sha256 statistics_gathering_node_delegate_wrapper::get_chain_id() const + chain_id_type statistics_gathering_node_delegate_wrapper::get_chain_id() const { INVOKE_AND_COLLECT_STATISTICS(get_chain_id); } diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index 566c6f23..311617ae 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -143,6 +143,8 @@ typedef multi_index_container< struct wallet_data { + /** Chain ID this wallet is used with */ + chain_id_type chain_id; account_multi_index_type my_accounts; /// @return IDs of all accounts in @ref my_accounts vector my_account_ids()const @@ -211,7 +213,7 @@ class wallet_api_impl; class wallet_api { public: - wallet_api(fc::api rapi); + wallet_api( const chain_id_type& chain_id, fc::api rapi ); virtual ~wallet_api(); bool copy_wallet_file( string destination_filename ); @@ -1191,7 +1193,6 @@ class wallet_api std::map> get_result_formatters() const; - fc::signal lock_changed; std::shared_ptr my; void encrypt_keys(); @@ -1207,6 +1208,7 @@ FC_REFLECT( graphene::wallet::blind_confirmation, (trx)(outputs) ) FC_REFLECT( graphene::wallet::plain_keys, (keys)(checksum) ) FC_REFLECT( graphene::wallet::wallet_data, + (chain_id) (my_accounts) (cipher_keys) (extra_keys) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 832729cf..85fe7192 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -359,13 +359,21 @@ private: public: wallet_api& self; - wallet_api_impl( wallet_api& s, fc::api rapi ) + wallet_api_impl( wallet_api& s, const chain_id_type& chain_id, fc::api rapi ) : self(s), + _chain_id(chain_id), _remote_api(rapi), _remote_db(rapi->database()), _remote_net_broadcast(rapi->network_broadcast()), _remote_hist(rapi->history()) { + chain_id_type remote_chain_id = _remote_db->get_chain_id(); + if( remote_chain_id != _chain_id ) + { + FC_THROW( "Remote server gave us an unexpected chain_id", + ("remote_chain_id", remote_chain_id) + ("chain_id", chain_id) ); + } init_prototype_ops(); _remote_db->subscribe_to_objects( [=]( const fc::variant& obj ) { @@ -636,6 +644,10 @@ public: if( !_wallet.my_accounts.empty() ) _remote_db->unsubscribe_from_objects(_wallet.my_account_ids()); _wallet = fc::json::from_file( wallet_filename ).as< wallet_data >(); + if( _wallet.chain_id != _chain_id ) + FC_THROW( "Wallet chain ID does not match", + ("wallet.chain_id", _wallet.chain_id) + ("chain_id", _chain_id) ); if( !_wallet.my_accounts.empty() ) _remote_db->subscribe_to_objects([this](const fc::variant& v) { _wallet.update_account(v.as()); @@ -815,7 +827,7 @@ public: { FC_ASSERT( false, "Malformed private key in _keys" ); } - tx.sign( *privkey ); + tx.sign( *privkey, _chain_id ); } } @@ -938,7 +950,7 @@ public: { fc::optional< fc::ecc::private_key > privkey = wif_to_key( it->second ); FC_ASSERT( privkey.valid(), "Malformed private key in _keys" ); - tx.sign( *privkey ); + tx.sign( *privkey, _chain_id ); } } @@ -1537,7 +1549,7 @@ public: { fc::optional privkey = wif_to_key( it->second ); FC_ASSERT( privkey.valid(), "Malformed private key in _keys" ); - tx.sign( *privkey ); + tx.sign( *privkey, _chain_id ); } /// TODO: if transaction has enough signatures to be "valid" don't add any more, /// there are cases where the wallet may have more keys than strictly necessary and @@ -1901,6 +1913,7 @@ public: map _keys; fc::sha512 _checksum; + chain_id_type _chain_id; fc::api _remote_api; fc::api _remote_db; fc::api _remote_net_broadcast; @@ -2007,8 +2020,8 @@ void operation_printer::operator()(const asset_create_operation& op) const namespace graphene { namespace wallet { -wallet_api::wallet_api(fc::api rapi) - : my(new detail::wallet_api_impl(*this, rapi)) +wallet_api::wallet_api(const chain_id_type& chain_id, fc::api rapi) + : my(new detail::wallet_api_impl(*this, chain_id, rapi)) { } @@ -2628,7 +2641,7 @@ signed_transaction wallet_api::import_balance( string name_or_id, const vector_chain_id ); // if the key for a balance object was the same as a key for the account we're importing it into, // we may end up with duplicate signatures, so remove those diff --git a/programs/cli_wallet/main.cpp b/programs/cli_wallet/main.cpp index 2c2ebbc9..8ba9e548 100644 --- a/programs/cli_wallet/main.cpp +++ b/programs/cli_wallet/main.cpp @@ -32,6 +32,7 @@ #include #include +#include #include #include @@ -68,7 +69,8 @@ int main( int argc, char** argv ) ("rpc-tls-certificate,c", bpo::value()->implicit_value("server.pem"), "PEM certificate for wallet websocket TLS RPC") ("rpc-http-endpoint,H", bpo::value()->implicit_value("127.0.0.1:8093"), "Endpoint for wallet HTTP RPC to listen on") ("daemon,d", "Run the wallet in daemon mode" ) - ("wallet-file,w", bpo::value()->implicit_value("wallet.json"), "wallet to load"); + ("wallet-file,w", bpo::value()->implicit_value("wallet.json"), "wallet to load") + ("chain-id", bpo::value(), "chain ID to connect to"); bpo::variables_map options; @@ -123,8 +125,33 @@ int main( int argc, char** argv ) fc::path wallet_file( options.count("wallet-file") ? options.at("wallet-file").as() : "wallet.json"); if( fc::exists( wallet_file ) ) - wdata = fc::json::from_file( wallet_file ).as(); + { + wdata = fc::json::from_file( wallet_file ).as(); + if( options.count("chain-id") ) + { + // the --chain-id on the CLI must match the chain ID embedded in the wallet file + if( chain_id_type(options.at("chain-id").as()) != wdata.chain_id ) + { + std::cout << "Chain ID in wallet file does not match specified chain ID\n"; + return 1; + } + } + } + else + { + if( options.count("chain-id") ) + { + wdata.chain_id = chain_id_type(options.at("chain-id").as()); + std::cout << "Starting a new wallet with chain ID " << wdata.chain_id << " (from CLI)\n"; + } + else + { + wdata.chain_id = graphene::egenesis::get_egenesis_chain_id(); + std::cout << "Starting a new wallet with chain ID " << wdata.chain_id << " (from egenesis)\n"; + } + } + // but allow CLI to override if( options.count("server-rpc-endpoint") ) wdata.ws_server = options.at("server-rpc-endpoint").as(); if( options.count("server-rpc-user") ) @@ -139,9 +166,10 @@ int main( int argc, char** argv ) auto remote_api = apic->get_remote_api< login_api >(1); edump((wdata.ws_user)(wdata.ws_password) ); + // TODO: Error message here FC_ASSERT( remote_api->login( wdata.ws_user, wdata.ws_password ) ); - auto wapiptr = std::make_shared(remote_api); + auto wapiptr = std::make_shared( wdata.chain_id, remote_api ); wapiptr->set_wallet_filename( wallet_file.generic_string() ); wapiptr->load_wallet_file(); diff --git a/tests/app/main.cpp b/tests/app/main.cpp index 1de4dc3e..1e7bfcad 100644 --- a/tests/app/main.cpp +++ b/tests/app/main.cpp @@ -105,7 +105,7 @@ BOOST_AUTO_TEST_CASE( two_node_network ) db1->current_fee_schedule().set_fee( trx.operations.back() ); trx.set_expiration( db1->get_slot_time( 10 ) ); - trx.sign( nathan_key ); + trx.sign( nathan_key, db1->get_chain_id() ); trx.validate(); } diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index bfc46f62..0f7b4f14 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -612,7 +612,12 @@ uint64_t database_fixture::fund( void database_fixture::sign(signed_transaction& trx, const fc::ecc::private_key& key) { - trx.sign( key ); + trx.sign( key, db.get_chain_id() ); +} + +digest_type database_fixture::digest( const transaction& tx ) +{ + return tx.digest(); } const limit_order_object*database_fixture::create_sell_order(account_id_type user, const asset& amount, const asset& recv) diff --git a/tests/common/database_fixture.hpp b/tests/common/database_fixture.hpp index 65772d4c..5b00ec8f 100644 --- a/tests/common/database_fixture.hpp +++ b/tests/common/database_fixture.hpp @@ -251,6 +251,7 @@ struct database_fixture { const witness_object& create_witness(const account_object& owner, const fc::ecc::private_key& signing_private_key = generate_private_key("null_key")); uint64_t fund( const account_object& account, const asset& amount = asset(500000) ); + digest_type digest( const transaction& tx ); void sign( signed_transaction& trx, const fc::ecc::private_key& key ); const limit_order_object* create_sell_order( account_id_type user, const asset& amount, const asset& recv ); const limit_order_object* create_sell_order( const account_object& user, const asset& amount, const asset& recv ); diff --git a/tests/intense/block_tests.cpp b/tests/intense/block_tests.cpp index 37e61672..e9f1196e 100644 --- a/tests/intense/block_tests.cpp +++ b/tests/intense/block_tests.cpp @@ -204,7 +204,7 @@ BOOST_FIXTURE_TEST_CASE( update_account_keys, database_fixture ) trx.operations.push_back( update_op ); for( int i=0; i(PUSH_TX( db, trx ).operation_results.front().get()); BOOST_CHECK_EQUAL(proposal.required_active_approvals.size(), 1); @@ -356,13 +356,13 @@ BOOST_AUTO_TEST_CASE( proposed_single_account ) pup.active_approvals_to_add.insert(nathan.id); trx.operations = {pup}; - trx.sign( committee_key ); + sign( trx, committee_key ); //committee may not add nathan's approval. GRAPHENE_CHECK_THROW(PUSH_TX( db, trx ), fc::exception); pup.active_approvals_to_add.clear(); pup.active_approvals_to_add.insert(account_id_type()); trx.operations = {pup}; - trx.sign( committee_key ); + sign( trx, committee_key ); //committee has no stake in the transaction. GRAPHENE_CHECK_THROW(PUSH_TX( db, trx ), fc::exception); @@ -371,8 +371,8 @@ BOOST_AUTO_TEST_CASE( proposed_single_account ) pup.active_approvals_to_add.insert(nathan.id); trx.operations = {pup}; - trx.sign( nathan_key3 ); - trx.sign( nathan_key2 ); + sign( trx, nathan_key3 ); + sign( trx, nathan_key2 ); BOOST_CHECK_EQUAL(get_balance(nathan, core), nathan_start_balance.amount.value); PUSH_TX( db, trx ); @@ -407,25 +407,25 @@ BOOST_AUTO_TEST_CASE( committee_authority ) sign(trx, committee_key); GRAPHENE_CHECK_THROW(PUSH_TX( db, trx ), graphene::chain::invalid_committee_approval ); - auto sign = [&] { trx.signatures.clear(); trx.sign(nathan_key); }; + auto _sign = [&] { trx.signatures.clear(); sign( trx, nathan_key ); }; proposal_create_operation pop; pop.proposed_ops.push_back({trx.operations.front()}); pop.expiration_time = db.head_block_time() + global_params.committee_proposal_review_period*2; pop.fee_paying_account = nathan.id; trx.operations = {pop}; - sign(); + _sign(); // The review period isn't set yet. Make sure it throws. GRAPHENE_REQUIRE_THROW( PUSH_TX( db, trx ), proposal_create_review_period_required ); pop.review_period_seconds = global_params.committee_proposal_review_period / 2; trx.operations.back() = pop; - sign(); + _sign(); // The review period is too short. Make sure it throws. GRAPHENE_REQUIRE_THROW( PUSH_TX( db, trx ), proposal_create_review_period_insufficient ); pop.review_period_seconds = global_params.committee_proposal_review_period; trx.operations.back() = pop; - sign(); + _sign(); proposal_object prop = db.get(PUSH_TX( db, trx ).operation_results.front().get()); BOOST_REQUIRE(db.find_object(prop.id)); @@ -457,7 +457,7 @@ BOOST_AUTO_TEST_CASE( committee_authority ) uop.key_approvals_to_add.emplace(6); */ trx.operations.push_back(uop); - trx.sign(committee_key); + sign( trx, committee_key ); db.push_transaction(trx); BOOST_CHECK_EQUAL(get_balance(nathan, asset_id_type()(db)), 0); BOOST_CHECK(db.get(prop.id).is_authorized_to_execute(db)); @@ -467,7 +467,7 @@ BOOST_AUTO_TEST_CASE( committee_authority ) uop.key_approvals_to_add.clear(); uop.key_approvals_to_add.insert(committee_key.get_public_key()); // was 7 trx.operations.back() = uop; - trx.sign( committee_key); + sign( trx, committee_key ); // Should throw because the transaction is now in review. GRAPHENE_CHECK_THROW(PUSH_TX( db, trx ), fc::exception); @@ -530,7 +530,7 @@ BOOST_FIXTURE_TEST_CASE( fired_committee_members, database_fixture ) uop.key_approvals_to_add.emplace(9); */ trx.operations.back() = uop; - trx.sign(committee_key); + sign( trx, committee_key ); PUSH_TX( db, trx ); BOOST_CHECK(pid(db).is_authorized_to_execute(db)); @@ -601,7 +601,7 @@ BOOST_FIXTURE_TEST_CASE( proposal_two_accounts, database_fixture ) pop.fee_paying_account = nathan.get_id(); pop.expiration_time = db.head_block_time() + fc::days(1); trx.operations.push_back(pop); - trx.sign(nathan_key); + sign( trx, nathan_key ); PUSH_TX( db, trx ); trx.clear(); } @@ -618,7 +618,7 @@ BOOST_FIXTURE_TEST_CASE( proposal_two_accounts, database_fixture ) uop.active_approvals_to_add.insert(nathan.get_id()); uop.fee_paying_account = nathan.get_id(); trx.operations.push_back(uop); - trx.sign(nathan_key); + sign( trx, nathan_key ); PUSH_TX( db, trx ); trx.clear(); @@ -627,9 +627,9 @@ BOOST_FIXTURE_TEST_CASE( proposal_two_accounts, database_fixture ) uop.active_approvals_to_add = {dan.get_id()}; trx.operations.push_back(uop); - trx.sign(nathan_key); + sign( trx, nathan_key ); GRAPHENE_REQUIRE_THROW(PUSH_TX( db, trx ), fc::exception); - trx.sign(dan_key); + sign( trx, dan_key ); PUSH_TX( db, trx ); BOOST_CHECK(db.find_object(pid) == nullptr); @@ -663,7 +663,7 @@ BOOST_FIXTURE_TEST_CASE( proposal_delete, database_fixture ) pop.fee_paying_account = nathan.get_id(); pop.expiration_time = db.head_block_time() + fc::days(1); trx.operations.push_back(pop); - trx.sign(nathan_key); + sign( trx, nathan_key ); PUSH_TX( db, trx ); trx.clear(); } @@ -679,7 +679,7 @@ BOOST_FIXTURE_TEST_CASE( proposal_delete, database_fixture ) uop.proposal = prop.id; uop.active_approvals_to_add.insert(nathan.get_id()); trx.operations.push_back(uop); - trx.sign(nathan_key); + sign( trx, nathan_key ); PUSH_TX( db, trx ); trx.clear(); BOOST_CHECK(!prop.is_authorized_to_execute(db)); @@ -687,7 +687,7 @@ BOOST_FIXTURE_TEST_CASE( proposal_delete, database_fixture ) std::swap(uop.active_approvals_to_add, uop.active_approvals_to_remove); trx.operations.push_back(uop); - trx.sign(nathan_key); + sign( trx, nathan_key ); PUSH_TX( db, trx ); trx.clear(); BOOST_CHECK(!prop.is_authorized_to_execute(db)); @@ -700,7 +700,7 @@ BOOST_FIXTURE_TEST_CASE( proposal_delete, database_fixture ) dop.fee_paying_account = nathan.get_id(); dop.proposal = pid; trx.operations.push_back(dop); - trx.sign(nathan_key); + sign( trx, nathan_key ); PUSH_TX( db, trx ); BOOST_CHECK(db.find_object(pid) == nullptr); BOOST_CHECK_EQUAL(get_balance(nathan, asset_id_type()(db)), 100000); @@ -739,7 +739,7 @@ BOOST_FIXTURE_TEST_CASE( proposal_owner_authority_delete, database_fixture ) pop.fee_paying_account = nathan.get_id(); pop.expiration_time = db.head_block_time() + fc::days(1); trx.operations.push_back(pop); - trx.sign(nathan_key); + sign( trx, nathan_key ); PUSH_TX( db, trx ); trx.clear(); } @@ -755,7 +755,7 @@ BOOST_FIXTURE_TEST_CASE( proposal_owner_authority_delete, database_fixture ) uop.proposal = prop.id; uop.owner_approvals_to_add.insert(nathan.get_id()); trx.operations.push_back(uop); - trx.sign(nathan_key); + sign( trx, nathan_key ); PUSH_TX( db, trx ); trx.clear(); BOOST_CHECK(!prop.is_authorized_to_execute(db)); @@ -763,7 +763,7 @@ BOOST_FIXTURE_TEST_CASE( proposal_owner_authority_delete, database_fixture ) std::swap(uop.owner_approvals_to_add, uop.owner_approvals_to_remove); trx.operations.push_back(uop); - trx.sign(nathan_key); + sign( trx, nathan_key ); PUSH_TX( db, trx ); trx.clear(); BOOST_CHECK(!prop.is_authorized_to_execute(db)); @@ -777,7 +777,7 @@ BOOST_FIXTURE_TEST_CASE( proposal_owner_authority_delete, database_fixture ) dop.proposal = pid; dop.using_owner_authority = true; trx.operations.push_back(dop); - trx.sign(nathan_key); + sign( trx, nathan_key ); PUSH_TX( db, trx ); BOOST_CHECK(db.find_object(pid) == nullptr); BOOST_CHECK_EQUAL(get_balance(nathan, asset_id_type()(db)), 100000); @@ -816,7 +816,7 @@ BOOST_FIXTURE_TEST_CASE( proposal_owner_authority_complete, database_fixture ) pop.fee_paying_account = nathan.get_id(); pop.expiration_time = db.head_block_time() + fc::days(1); trx.operations.push_back(pop); - trx.sign(nathan_key); + sign( trx, nathan_key ); PUSH_TX( db, trx ); trx.clear(); } @@ -834,8 +834,8 @@ BOOST_FIXTURE_TEST_CASE( proposal_owner_authority_complete, database_fixture ) uop.key_approvals_to_add.insert(dan.active.key_auths.begin()->first); trx.operations.push_back(uop); set_expiration( db, trx ); - trx.sign(nathan_key); - trx.sign(dan_key); + sign( trx, nathan_key ); + sign( trx, dan_key ); PUSH_TX( db, trx ); trx.clear(); BOOST_CHECK(!prop.is_authorized_to_execute(db)); @@ -844,8 +844,8 @@ BOOST_FIXTURE_TEST_CASE( proposal_owner_authority_complete, database_fixture ) std::swap(uop.key_approvals_to_add, uop.key_approvals_to_remove); trx.operations.push_back(uop); trx.expiration += fc::seconds(1); // Survive trx dupe check - trx.sign(nathan_key); - trx.sign(dan_key); + sign( trx, nathan_key ); + sign( trx, dan_key ); PUSH_TX( db, trx ); trx.clear(); BOOST_CHECK(!prop.is_authorized_to_execute(db)); @@ -854,8 +854,8 @@ BOOST_FIXTURE_TEST_CASE( proposal_owner_authority_complete, database_fixture ) std::swap(uop.key_approvals_to_add, uop.key_approvals_to_remove); trx.operations.push_back(uop); trx.expiration += fc::seconds(1); // Survive trx dupe check - trx.sign(nathan_key); - trx.sign(dan_key); + sign( trx, nathan_key ); + sign( trx, dan_key ); PUSH_TX( db, trx ); trx.clear(); BOOST_CHECK(!prop.is_authorized_to_execute(db)); @@ -865,7 +865,7 @@ BOOST_FIXTURE_TEST_CASE( proposal_owner_authority_complete, database_fixture ) uop.owner_approvals_to_add.insert(nathan.get_id()); trx.operations.push_back(uop); trx.expiration += fc::seconds(1); // Survive trx dupe check - trx.sign(nathan_key); + sign( trx, nathan_key ); PUSH_TX( db, trx ); trx.clear(); BOOST_CHECK(db.find_object(pid) == nullptr); @@ -1003,7 +1003,7 @@ BOOST_FIXTURE_TEST_CASE( bogus_signature, database_fixture ) trx.operations.push_back( xfer_op ); BOOST_TEST_MESSAGE( "Transfer signed by alice" ); - trx.sign(alice_key ); + sign( trx, alice_key ); flat_set active_set, owner_set; vector others; @@ -1018,13 +1018,13 @@ BOOST_FIXTURE_TEST_CASE( bogus_signature, database_fixture ) // Re-sign, now OK (sig is replaced) BOOST_TEST_MESSAGE( "Resign with Alice's Signature" ); trx.signatures.clear(); - trx.sign( alice_key ); + sign( trx, alice_key ); PUSH_TX( db, trx, skip ); trx.signatures.clear(); trx.operations.pop_back(); - trx.sign( alice_key ); - trx.sign( charlie_key ); + sign( trx, alice_key ); + sign( trx, charlie_key ); // Signed by third-party Charlie (irrelevant key, not in authority) GRAPHENE_REQUIRE_THROW( PUSH_TX( db, trx, skip ), tx_irrelevant_sig ); } @@ -1054,7 +1054,7 @@ BOOST_FIXTURE_TEST_CASE( voting_account, database_fixture ) op.new_options->votes = flat_set{nathan_committee_member(db).vote_id}; op.new_options->num_committee = 1; trx.operations.push_back(op); - trx.sign(nathan_private_key); + sign( trx, nathan_private_key ); PUSH_TX( db, trx ); trx.clear(); } @@ -1065,13 +1065,13 @@ BOOST_FIXTURE_TEST_CASE( voting_account, database_fixture ) op.new_options->votes.insert(vikram_committee_member(db).vote_id); op.new_options->num_committee = 11; trx.operations.push_back(op); - trx.sign(vikram_private_key); + sign( trx, vikram_private_key ); // Fails because num_committee is larger than the cardinality of committee members being voted for GRAPHENE_CHECK_THROW(PUSH_TX( db, trx ), fc::exception); op.new_options->num_committee = 3; trx.operations = {op}; trx.signatures.clear(); - trx.sign(vikram_private_key); + sign( trx, vikram_private_key ); PUSH_TX( db, trx ); trx.clear(); } @@ -1147,7 +1147,7 @@ BOOST_FIXTURE_TEST_CASE( get_required_signatures_test, database_fixture ) ) -> bool { //wdump( (tx)(available_keys) ); - set result_set = tx.get_required_signatures( available_keys, get_active, get_owner ); + set result_set = tx.get_required_signatures( db.get_chain_id(), available_keys, get_active, get_owner ); //wdump( (result_set)(ref_set) ); return result_set == ref_set; } ; @@ -1261,7 +1261,7 @@ BOOST_FIXTURE_TEST_CASE( nonminimal_sig_test, database_fixture ) ) -> bool { //wdump( (tx)(available_keys) ); - set result_set = tx.get_required_signatures( available_keys, get_active, get_owner ); + set result_set = tx.get_required_signatures( db.get_chain_id(), available_keys, get_active, get_owner ); //wdump( (result_set)(ref_set) ); return result_set == ref_set; } ; @@ -1273,7 +1273,7 @@ BOOST_FIXTURE_TEST_CASE( nonminimal_sig_test, database_fixture ) ) -> bool { //wdump( (tx)(available_keys) ); - set result_set = tx.minimize_required_signatures( available_keys, get_active, get_owner ); + set result_set = tx.minimize_required_signatures( db.get_chain_id(), available_keys, get_active, get_owner ); //wdump( (result_set)(ref_set) ); return result_set == ref_set; } ; @@ -1292,9 +1292,9 @@ BOOST_FIXTURE_TEST_CASE( nonminimal_sig_test, database_fixture ) BOOST_CHECK( chk( tx, { alice_public_key, bob_public_key }, { alice_public_key, bob_public_key } ) ); BOOST_CHECK( chk_min( tx, { alice_public_key, bob_public_key }, { alice_public_key } ) ); - GRAPHENE_REQUIRE_THROW( tx.verify_authority( get_active, get_owner ), fc::exception ); - tx.sign( alice_private_key ); - tx.verify_authority( get_active, get_owner ); + GRAPHENE_REQUIRE_THROW( tx.verify_authority( db.get_chain_id(), get_active, get_owner ), fc::exception ); + sign( tx, alice_private_key ); + tx.verify_authority( db.get_chain_id(), get_active, get_owner ); } catch(fc::exception& e) { diff --git a/tests/tests/block_tests.cpp b/tests/tests/block_tests.cpp index 59c90265..129a2085 100644 --- a/tests/tests/block_tests.cpp +++ b/tests/tests/block_tests.cpp @@ -222,6 +222,7 @@ BOOST_AUTO_TEST_CASE( fork_blocks ) db1.open(data_dir1.path(), make_genesis); database db2; db2.open(data_dir2.path(), make_genesis); + BOOST_CHECK( db1.get_chain_id() == db2.get_chain_id() ); auto init_account_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key")) ); for( uint32_t i = 0; i < 10; ++i ) @@ -258,7 +259,7 @@ BOOST_AUTO_TEST_CASE( fork_blocks ) good_block = b; b.transactions.emplace_back(signed_transaction()); b.transactions.back().operations.emplace_back(transfer_operation()); - b.sign(init_account_priv_key); + b.sign( init_account_priv_key ); BOOST_CHECK_EQUAL(b.block_num(), 14); GRAPHENE_CHECK_THROW(PUSH_BLOCK( db1, b ), fc::exception); } @@ -309,7 +310,7 @@ BOOST_AUTO_TEST_CASE( undo_pending ) cop.owner = authority(1, init_account_pub_key, 1); cop.active = cop.owner; trx.operations.push_back(cop); - //trx.sign( init_account_priv_key ); + //sign( trx, init_account_priv_key ); PUSH_TX( db, trx ); auto b = db.generate_block(db.get_slot_time(1), db.get_scheduled_witness(1).first, init_account_priv_key, database::skip_nothing); @@ -348,6 +349,7 @@ BOOST_AUTO_TEST_CASE( switch_forks_undo_create ) db2; db1.open(dir1.path(), make_genesis); db2.open(dir2.path(), make_genesis); + BOOST_CHECK( db1.get_chain_id() == db2.get_chain_id() ); auto init_account_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key")) ); public_key_type init_account_pub_key = init_account_priv_key.get_public_key(); @@ -404,6 +406,7 @@ BOOST_AUTO_TEST_CASE( duplicate_transactions ) db2; db1.open(dir1.path(), make_genesis); db2.open(dir2.path(), make_genesis); + BOOST_CHECK( db1.get_chain_id() == db2.get_chain_id() ); auto skip_sigs = database::skip_transaction_signatures | database::skip_authority_check; @@ -419,7 +422,7 @@ BOOST_AUTO_TEST_CASE( duplicate_transactions ) cop.owner = authority(1, init_account_pub_key, 1); cop.active = cop.owner; trx.operations.push_back(cop); - trx.sign( init_account_priv_key ); + trx.sign( init_account_priv_key, db1.get_chain_id() ); PUSH_TX( db1, trx, skip_sigs ); trx = decltype(trx)(); @@ -428,7 +431,7 @@ BOOST_AUTO_TEST_CASE( duplicate_transactions ) t.to = nathan_id; t.amount = asset(500); trx.operations.push_back(t); - trx.sign( init_account_priv_key ); + trx.sign( init_account_priv_key, db1.get_chain_id() ); PUSH_TX( db1, trx, skip_sigs ); GRAPHENE_CHECK_THROW(PUSH_TX( db1, trx, skip_sigs ), fc::exception); @@ -473,7 +476,7 @@ BOOST_AUTO_TEST_CASE( tapos ) cop.owner = authority(1, init_account_pub_key, 1); cop.active = cop.owner; trx.operations.push_back(cop); - trx.sign(init_account_priv_key); + trx.sign( init_account_priv_key, db1.get_chain_id() ); db1.push_transaction(trx); b = db1.generate_block(db1.get_slot_time(1), db1.get_scheduled_witness(1).first, init_account_priv_key, database::skip_nothing); trx.clear(); @@ -482,12 +485,12 @@ BOOST_AUTO_TEST_CASE( tapos ) t.to = nathan_id; t.amount = asset(50); trx.operations.push_back(t); - trx.sign(init_account_priv_key); + trx.sign( init_account_priv_key, db1.get_chain_id() ); //relative_expiration is 1, but ref block is 2 blocks old, so this should fail. GRAPHENE_REQUIRE_THROW(PUSH_TX( db1, trx, database::skip_transaction_signatures | database::skip_authority_check ), fc::exception); set_expiration( db1, trx ); trx.signatures.clear(); - trx.sign(init_account_priv_key); + trx.sign( init_account_priv_key, db1.get_chain_id() ); db1.push_transaction(trx, database::skip_transaction_signatures | database::skip_authority_check); } catch (fc::exception& e) { edump((e.to_detail_string())); @@ -619,19 +622,19 @@ BOOST_FIXTURE_TEST_CASE( double_sign_check, database_fixture ) GRAPHENE_REQUIRE_THROW( db.push_transaction(trx, 0), fc::exception ); BOOST_TEST_MESSAGE( "Verify that double-signing causes an exception" ); - trx.sign(bob_private_key); - trx.sign(bob_private_key); + sign( trx, bob_private_key ); + sign( trx, bob_private_key ); GRAPHENE_REQUIRE_THROW( db.push_transaction(trx, 0), tx_duplicate_sig ); BOOST_TEST_MESSAGE( "Verify that signing with an extra, unused key fails" ); trx.signatures.pop_back(); - trx.sign(generate_private_key("bogus")); + sign( trx, generate_private_key("bogus" )); GRAPHENE_REQUIRE_THROW( db.push_transaction(trx, 0), tx_irrelevant_sig ); BOOST_TEST_MESSAGE( "Verify that signing once with the proper key passes" ); trx.signatures.pop_back(); db.push_transaction(trx, 0); - trx.sign(bob_private_key); + sign( trx, bob_private_key ); } FC_LOG_AND_RETHROW() } @@ -663,15 +666,15 @@ BOOST_FIXTURE_TEST_CASE( change_block_interval, database_fixture ) get_account("init4").get_id(), get_account("init5").get_id(), get_account("init6").get_id(), get_account("init7").get_id()}; trx.operations.push_back(uop); - trx.sign(init_account_priv_key); + sign( trx, init_account_priv_key ); /* - trx.sign(get_account("init1").active.get_keys().front(),init_account_priv_key); - trx.sign(get_account("init2").active.get_keys().front(),init_account_priv_key); - trx.sign(get_account("init3").active.get_keys().front(),init_account_priv_key); - trx.sign(get_account("init4").active.get_keys().front(),init_account_priv_key); - trx.sign(get_account("init5").active.get_keys().front(),init_account_priv_key); - trx.sign(get_account("init6").active.get_keys().front(),init_account_priv_key); - trx.sign(get_account("init7").active.get_keys().front(),init_account_priv_key); + sign( trx, get_account("init1" ).active.get_keys().front(),init_account_priv_key); + sign( trx, get_account("init2" ).active.get_keys().front(),init_account_priv_key); + sign( trx, get_account("init3" ).active.get_keys().front(),init_account_priv_key); + sign( trx, get_account("init4" ).active.get_keys().front(),init_account_priv_key); + sign( trx, get_account("init5" ).active.get_keys().front(),init_account_priv_key); + sign( trx, get_account("init6" ).active.get_keys().front(),init_account_priv_key); + sign( trx, get_account("init7" ).active.get_keys().front(),init_account_priv_key); */ db.push_transaction(trx); BOOST_CHECK(proposal_id_type()(db).is_authorized_to_execute(db)); diff --git a/tests/tests/confidential_tests.cpp b/tests/tests/confidential_tests.cpp index dba74eda..729b25c3 100644 --- a/tests/tests/confidential_tests.cpp +++ b/tests/tests/confidential_tests.cpp @@ -72,7 +72,7 @@ BOOST_AUTO_TEST_CASE( confidential_test ) to_blind.outputs = {out2,out1}; trx.operations = {to_blind}; - trx.sign( dan_private_key ); + sign( trx, dan_private_key ); db.push_transaction(trx); trx.signatures.clear(); @@ -92,7 +92,7 @@ BOOST_AUTO_TEST_CASE( confidential_test ) blind_tr.outputs = {out3,out4}; blind_tr.validate(); trx.operations = {blind_tr}; - trx.sign( owner2_key ); + sign( trx, owner2_key ); db.push_transaction(trx); BOOST_TEST_MESSAGE( "Attempting to double spend the same commitments" ); diff --git a/tests/tests/fee_tests.cpp b/tests/tests/fee_tests.cpp index ed9b6eb4..f2efc353 100644 --- a/tests/tests/fee_tests.cpp +++ b/tests/tests/fee_tests.cpp @@ -155,7 +155,7 @@ BOOST_AUTO_TEST_CASE( cashback_test ) op.owner = op.active; \ op.fee = fees->calculate_fee(op); \ trx.operations = {op}; \ - trx.sign( registrar_name ## _private_key); \ + sign( trx, registrar_name ## _private_key ); \ actor_name ## _id = PUSH_TX( db, trx ).operation_results.front().get(); \ trx.clear(); \ } diff --git a/tests/tests/operation_tests.cpp b/tests/tests/operation_tests.cpp index 1d31cffd..fb7ac93e 100644 --- a/tests/tests/operation_tests.cpp +++ b/tests/tests/operation_tests.cpp @@ -332,7 +332,7 @@ BOOST_AUTO_TEST_CASE( create_account_test ) op.owner = auth_bak; trx.operations.back() = op; - trx.sign( init_account_priv_key); + sign( trx, init_account_priv_key ); trx.validate(); PUSH_TX( db, trx, ~0 ); @@ -1180,7 +1180,7 @@ BOOST_AUTO_TEST_CASE( witness_pay_test ) trx.operations.push_back(uop); for( auto& op : trx.operations ) db.current_fee_schedule().set_fee(op); trx.validate(); - trx.sign(init_account_priv_key); + sign( trx, init_account_priv_key ); PUSH_TX( db, trx ); auto pay_fee_time = db.head_block_time().sec_since_epoch(); trx.clear(); diff --git a/tests/tests/operation_tests2.cpp b/tests/tests/operation_tests2.cpp index ae0e6f32..393f08ee 100644 --- a/tests/tests/operation_tests2.cpp +++ b/tests/tests/operation_tests2.cpp @@ -72,7 +72,7 @@ BOOST_AUTO_TEST_CASE( withdraw_permission_create ) REQUIRE_THROW_WITH_VALUE(op, withdrawal_period_sec, 1); trx.operations.back() = op; } - trx.sign(nathan_private_key); + sign( trx, nathan_private_key ); db.push_transaction( trx ); trx.clear(); } FC_LOG_AND_RETHROW() } @@ -126,7 +126,7 @@ BOOST_AUTO_TEST_CASE( withdraw_permission_test ) set_expiration( db, trx ); trx.clear(); trx.operations.push_back(op); - trx.sign(dan_private_key); + sign( trx, dan_private_key ); PUSH_TX( db, trx ); // would be legal on its own, but doesn't work because trx already withdrew @@ -138,7 +138,7 @@ BOOST_AUTO_TEST_CASE( withdraw_permission_test ) trx.operations = {op}; // make it different from previous trx so it's non-duplicate trx.expiration += fc::seconds(1); - trx.sign(dan_private_key); + sign( trx, dan_private_key ); PUSH_TX( db, trx ); trx.clear(); } @@ -169,14 +169,14 @@ BOOST_AUTO_TEST_CASE( withdraw_permission_test ) op.amount_to_withdraw = asset(5); trx.operations.push_back(op); set_expiration( db, trx ); - trx.sign(dan_private_key); + sign( trx, dan_private_key ); //Throws because nathan doesn't have the money GRAPHENE_CHECK_THROW(PUSH_TX( db, trx ), fc::exception); op.amount_to_withdraw = asset(1); trx.clear(); trx.operations = {op}; set_expiration( db, trx ); - trx.sign(dan_private_key); + sign( trx, dan_private_key ); PUSH_TX( db, trx ); } @@ -206,7 +206,7 @@ BOOST_AUTO_TEST_CASE( withdraw_permission_test ) op.amount_to_withdraw = asset(5); trx.operations.push_back(op); set_expiration( db, trx ); - trx.sign(dan_private_key); + sign( trx, dan_private_key ); //Throws because the permission has expired GRAPHENE_CHECK_THROW(PUSH_TX( db, trx ), fc::exception); } @@ -233,7 +233,7 @@ BOOST_AUTO_TEST_CASE( withdraw_permission_nominal_case ) op.amount_to_withdraw = asset(5); trx.operations.push_back(op); set_expiration( db, trx ); - trx.sign(dan_private_key); + sign( trx, dan_private_key ); PUSH_TX( db, trx ); // tx's involving withdraw_permissions can't delete it even // if no further withdrawals are possible @@ -279,7 +279,7 @@ BOOST_AUTO_TEST_CASE( withdraw_permission_update ) REQUIRE_THROW_WITH_VALUE(op, authorized_account, account_id_type(0)); REQUIRE_THROW_WITH_VALUE(op, period_start_time, db.head_block_time() - 50); trx.operations.back() = op; - trx.sign(nathan_private_key); + sign( trx, nathan_private_key ); PUSH_TX( db, trx ); } @@ -303,7 +303,7 @@ BOOST_AUTO_TEST_CASE( withdraw_permission_delete ) op.withdraw_from_account = get_account("nathan").id; set_expiration( db, trx ); trx.operations.push_back(op); - trx.sign(generate_private_key("nathan")); + sign( trx, generate_private_key("nathan" )); PUSH_TX( db, trx ); } FC_LOG_AND_RETHROW() } @@ -330,7 +330,7 @@ BOOST_AUTO_TEST_CASE( mia_feeds ) op.issuer = nathan_id; op.new_feed_producers = {dan_id, ben_id, vikram_id}; trx.operations.push_back(op); - trx.sign(nathan_private_key); + sign( trx, nathan_private_key ); PUSH_TX( db, trx ); generate_block(database::skip_nothing); } @@ -393,7 +393,7 @@ BOOST_AUTO_TEST_CASE( feed_limit_test ) op.asset_to_update = bit_usd.get_id(); op.issuer = bit_usd.issuer; trx.operations = {op}; - trx.sign(nathan_private_key); + sign( trx, nathan_private_key ); db.push_transaction(trx); BOOST_TEST_MESSAGE("Checking current_feed is null"); @@ -403,7 +403,7 @@ BOOST_AUTO_TEST_CASE( feed_limit_test ) op.new_options.minimum_feeds = 3; trx.clear(); trx.operations = {op}; - trx.sign(nathan_private_key); + sign( trx, nathan_private_key ); db.push_transaction(trx); BOOST_TEST_MESSAGE("Checking current_feed is not null"); @@ -431,7 +431,7 @@ BOOST_AUTO_TEST_CASE( witness_create ) op.new_options->num_committee = std::count_if(op.new_options->votes.begin(), op.new_options->votes.end(), [](vote_id_type id) { return id.type() == vote_id_type::committee; }); trx.operations.push_back(op); - trx.sign(nathan_private_key); + sign( trx, nathan_private_key ); PUSH_TX( db, trx ); trx.clear(); } @@ -541,7 +541,7 @@ BOOST_AUTO_TEST_CASE( global_settle_test ) REQUIRE_THROW_WITH_VALUE(op, asset_to_settle, asset_id_type(100)); REQUIRE_THROW_WITH_VALUE(op, issuer, account_id_type(2)); trx.operations.back() = op; - trx.sign(nathan_private_key); + sign( trx, nathan_private_key ); PUSH_TX( db, trx ); } @@ -578,7 +578,7 @@ BOOST_AUTO_TEST_CASE( worker_create_test ) REQUIRE_THROW_WITH_VALUE(op, work_begin_date, db.head_block_time() - 10); REQUIRE_THROW_WITH_VALUE(op, work_end_date, op.work_begin_date); trx.operations.back() = op; - trx.sign(nathan_private_key); + sign( trx, nathan_private_key ); PUSH_TX( db, trx ); } @@ -633,7 +633,7 @@ BOOST_AUTO_TEST_CASE( worker_pay_test ) op.owner = nathan_id; set_expiration( db, trx ); trx.operations.push_back(op); - trx.sign( nathan_private_key); + sign( trx, nathan_private_key ); PUSH_TX( db, trx ); trx.signatures.clear(); REQUIRE_THROW_WITH_VALUE(op, amount, asset(1)); @@ -668,7 +668,7 @@ BOOST_AUTO_TEST_CASE( worker_pay_test ) set_expiration( db, trx ); REQUIRE_THROW_WITH_VALUE(op, amount, asset(501)); trx.operations.back() = op; - trx.sign( nathan_private_key); + sign( trx, nathan_private_key ); PUSH_TX( db, trx ); trx.signatures.clear(); trx.clear(); @@ -701,7 +701,7 @@ BOOST_AUTO_TEST_CASE( refund_worker_test ) REQUIRE_THROW_WITH_VALUE(op, work_begin_date, db.head_block_time() - 10); REQUIRE_THROW_WITH_VALUE(op, work_end_date, op.work_begin_date); trx.operations.back() = op; - trx.sign( nathan_private_key); + sign( trx, nathan_private_key ); PUSH_TX( db, trx ); trx.clear(); } @@ -774,7 +774,7 @@ BOOST_AUTO_TEST_CASE( burn_worker_test ) REQUIRE_THROW_WITH_VALUE(op, work_begin_date, db.head_block_time() - 10); REQUIRE_THROW_WITH_VALUE(op, work_end_date, op.work_begin_date); trx.operations.back() = op; - trx.sign( nathan_private_key); + sign( trx, nathan_private_key ); PUSH_TX( db, trx ); trx.clear(); } @@ -1025,14 +1025,14 @@ BOOST_AUTO_TEST_CASE( assert_op_test ) op.fee_paying_account = nathan_id; op.predicates.emplace_back(account_name_eq_lit_predicate{ nathan_id, "nathan" }); trx.operations.push_back(op); - trx.sign(nathan_private_key); + sign( trx, nathan_private_key ); PUSH_TX( db, trx ); // nathan checks that his public key is not equal to the given value (fail) trx.clear(); op.predicates.emplace_back(account_name_eq_lit_predicate{ nathan_id, "dan" }); trx.operations.push_back(op); - trx.sign(nathan_private_key); + sign( trx, nathan_private_key ); GRAPHENE_CHECK_THROW( PUSH_TX( db, trx ), fc::exception ); } FC_LOG_AND_RETHROW() } @@ -1068,6 +1068,9 @@ BOOST_AUTO_TEST_CASE( balance_object_test ) genesis_state.initial_accounts.emplace_back("n", n_key.get_public_key()); + auto _sign = [&]( signed_transaction& tx, const private_key_type& key ) + { tx.sign( key, db.get_chain_id() ); }; + db.open(td.path(), [this]{return genesis_state;}); const balance_object& balance = balance_id_type()(db); BOOST_CHECK_EQUAL(balance.balance.amount.value, 1); @@ -1079,14 +1082,14 @@ BOOST_AUTO_TEST_CASE( balance_object_test ) op.balance_to_claim = balance_id_type(1); op.balance_owner_key = x_key.get_public_key(); trx.operations = {op}; - trx.sign(n_key); + _sign( trx, n_key ); // Fail because I'm claiming from an address which hasn't signed - GRAPHENE_CHECK_THROW(db.push_transaction(trx), fc::exception); + GRAPHENE_CHECK_THROW(db.push_transaction(trx), tx_missing_other_auth); trx.clear(); op.balance_to_claim = balance_id_type(); op.balance_owner_key = n_key.get_public_key(); trx.operations = {op}; - trx.sign(n_key); + _sign( trx, n_key ); db.push_transaction(trx); // Not using fixture's get_balance() here because it uses fixture's db, not my override @@ -1112,8 +1115,8 @@ BOOST_AUTO_TEST_CASE( balance_object_test ) op.balance_owner_key = v1_key.get_public_key(); trx.clear(); trx.operations = {op}; - trx.sign(n_key); - trx.sign(v1_key); + _sign( trx, n_key ); + _sign( trx, v1_key ); // Attempting to claim 1 from a balance with 0 available GRAPHENE_CHECK_THROW(db.push_transaction(trx), balance_claim_invalid_claim_amount); @@ -1122,8 +1125,8 @@ BOOST_AUTO_TEST_CASE( balance_object_test ) op.balance_owner_key = v2_key.get_public_key(); trx.operations = {op}; trx.signatures.clear(); - trx.sign(n_key); - trx.sign(v2_key); + _sign( trx, n_key ); + _sign( trx, v2_key ); // Attempting to claim 151 from a balance with 150 available GRAPHENE_CHECK_THROW(db.push_transaction(trx), balance_claim_invalid_claim_amount); @@ -1132,8 +1135,8 @@ BOOST_AUTO_TEST_CASE( balance_object_test ) op.balance_owner_key = v2_key.get_public_key(); trx.operations = {op}; trx.signatures.clear(); - trx.sign(n_key); - trx.sign(v2_key); + _sign( trx, n_key ); + _sign( trx, v2_key ); db.push_transaction(trx); BOOST_CHECK_EQUAL(db.get_balance(op.deposit_to_account, asset_id_type()).amount.value, 101); BOOST_CHECK_EQUAL(vesting_balance_2.balance.amount.value, 300); @@ -1141,8 +1144,8 @@ BOOST_AUTO_TEST_CASE( balance_object_test ) op.total_claimed.amount = 10; trx.operations = {op}; trx.signatures.clear(); - trx.sign(n_key); - trx.sign(v2_key); + _sign( trx, n_key ); + _sign( trx, v2_key ); // Attempting to claim twice within a day GRAPHENE_CHECK_THROW(db.push_transaction(trx), balance_claim_claimed_too_often); @@ -1156,8 +1159,8 @@ BOOST_AUTO_TEST_CASE( balance_object_test ) op.balance_owner_key = v1_key.get_public_key(); trx.operations = {op}; trx.signatures.clear(); - trx.sign(n_key); - trx.sign(v1_key); + _sign( trx, n_key ); + _sign( trx, v1_key ); db.push_transaction(trx); BOOST_CHECK(db.find_object(op.balance_to_claim) == nullptr); BOOST_CHECK_EQUAL(db.get_balance(op.deposit_to_account, asset_id_type()).amount.value, 601); @@ -1167,8 +1170,8 @@ BOOST_AUTO_TEST_CASE( balance_object_test ) op.total_claimed.amount = 10; trx.operations = {op}; trx.signatures.clear(); - trx.sign(n_key); - trx.sign(v2_key); + _sign( trx, n_key ); + _sign( trx, v2_key ); // Attempting to claim twice within a day GRAPHENE_CHECK_THROW(db.push_transaction(trx), balance_claim_claimed_too_often); @@ -1180,8 +1183,8 @@ BOOST_AUTO_TEST_CASE( balance_object_test ) op.total_claimed = vesting_balance_2.balance; trx.operations = {op}; trx.signatures.clear(); - trx.sign(n_key); - trx.sign(v2_key); + _sign( trx, n_key ); + _sign( trx, v2_key ); db.push_transaction(trx); BOOST_CHECK(db.find_object(op.balance_to_claim) == nullptr); BOOST_CHECK_EQUAL(db.get_balance(op.deposit_to_account, asset_id_type()).amount.value, 901); diff --git a/tests/tests/serialization_tests.cpp b/tests/tests/serialization_tests.cpp index a1714e66..5067f20b 100644 --- a/tests/tests/serialization_tests.cpp +++ b/tests/tests/serialization_tests.cpp @@ -42,7 +42,7 @@ BOOST_AUTO_TEST_CASE( serialization_raw_test ) auto packed = fc::raw::pack( trx ); signed_transaction unpacked = fc::raw::unpack(packed); unpacked.validate(); - BOOST_CHECK( trx.digest() == unpacked.digest() ); + BOOST_CHECK( digest(trx) == digest(unpacked) ); } catch (fc::exception& e) { edump((e.to_detail_string())); throw; @@ -60,7 +60,7 @@ BOOST_AUTO_TEST_CASE( serialization_json_test ) fc::variant packed(trx); signed_transaction unpacked = packed.as(); unpacked.validate(); - BOOST_CHECK( trx.digest() == unpacked.digest() ); + BOOST_CHECK( digest(trx) == digest(unpacked) ); } catch (fc::exception& e) { edump((e.to_detail_string())); throw; @@ -79,6 +79,4 @@ BOOST_AUTO_TEST_CASE( json_tests ) } } - - BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/tests/uia_tests.cpp b/tests/tests/uia_tests.cpp index c3f0280a..435810ea 100644 --- a/tests/tests/uia_tests.cpp +++ b/tests/tests/uia_tests.cpp @@ -88,11 +88,11 @@ BOOST_AUTO_TEST_CASE( override_transfer_test ) BOOST_TEST_MESSAGE( "Require throwing without signature" ); GRAPHENE_REQUIRE_THROW( PUSH_TX( db, trx, 0 ), tx_missing_active_auth ); BOOST_TEST_MESSAGE( "Require throwing with dan's signature" ); - trx.sign( dan_private_key ); + sign( trx, dan_private_key ); GRAPHENE_REQUIRE_THROW( PUSH_TX( db, trx, 0 ), tx_missing_active_auth ); BOOST_TEST_MESSAGE( "Pass with issuer's signature" ); trx.signatures.clear(); - trx.sign( sam_private_key ); + sign( trx, sam_private_key ); PUSH_TX( db, trx, 0 ); BOOST_REQUIRE_EQUAL( get_balance( dan, advanced ), 900 ); @@ -117,11 +117,11 @@ BOOST_AUTO_TEST_CASE( override_transfer_test2 ) BOOST_TEST_MESSAGE( "Require throwing without signature" ); GRAPHENE_REQUIRE_THROW( PUSH_TX( db, trx, 0 ), fc::exception); BOOST_TEST_MESSAGE( "Require throwing with dan's signature" ); - trx.sign( dan_private_key ); + sign( trx, dan_private_key ); GRAPHENE_REQUIRE_THROW( PUSH_TX( db, trx, 0 ), fc::exception); BOOST_TEST_MESSAGE( "Fail because overide_authority flag is not set" ); trx.signatures.clear(); - trx.sign( sam_private_key ); + sign( trx, sam_private_key ); GRAPHENE_REQUIRE_THROW( PUSH_TX( db, trx, 0 ), fc::exception ); BOOST_REQUIRE_EQUAL( get_balance( dan, advanced ), 1000 );