diff --git a/libraries/utilities/CMakeLists.txt b/libraries/utilities/CMakeLists.txt index f018afff..124ed673 100644 --- a/libraries/utilities/CMakeLists.txt +++ b/libraries/utilities/CMakeLists.txt @@ -9,9 +9,12 @@ endif(NOT GRAPHENE_GIT_REVISION_DESCRIPTION) file(GLOB headers "include/graphene/utilities/*.hpp") -set(sources key_conversion.cpp string_escape.cpp - words.cpp - ${headers}) +set(sources + key_conversion.cpp + string_escape.cpp + tempdir.cpp + words.cpp + ${headers}) configure_file("${CMAKE_CURRENT_SOURCE_DIR}/git_revision.cpp.in" "${CMAKE_CURRENT_BINARY_DIR}/git_revision.cpp" @ONLY) list(APPEND sources "${CMAKE_CURRENT_BINARY_DIR}/git_revision.cpp") diff --git a/libraries/utilities/include/graphene/utilities/tempdir.hpp b/libraries/utilities/include/graphene/utilities/tempdir.hpp new file mode 100644 index 00000000..600f6fa9 --- /dev/null +++ b/libraries/utilities/include/graphene/utilities/tempdir.hpp @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2015, Cryptonomex, Inc. + * All rights reserved. + * + * This source code is provided for evaluation in private test networks only, until September 8, 2015. After this date, this license expires and + * the code may not be used, modified or distributed for any purpose. Redistribution and use in source and binary forms, with or without modification, + * are permitted until September 8, 2015, provided that the following conditions are met: + * + * 1. The code and/or derivative works are used only for private test networks consisting of no more than 10 P2P nodes. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#pragma once + +#include + +#include + +namespace graphene { namespace utilities { + +fc::path temp_directory_path(); + +} } // graphene::utilities diff --git a/libraries/utilities/tempdir.cpp b/libraries/utilities/tempdir.cpp new file mode 100644 index 00000000..2076151d --- /dev/null +++ b/libraries/utilities/tempdir.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2015, Cryptonomex, Inc. + * All rights reserved. + * + * This source code is provided for evaluation in private test networks only, until September 8, 2015. After this date, this license expires and + * the code may not be used, modified or distributed for any purpose. Redistribution and use in source and binary forms, with or without modification, + * are permitted until September 8, 2015, provided that the following conditions are met: + * + * 1. The code and/or derivative works are used only for private test networks consisting of no more than 10 P2P nodes. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +#include + +namespace graphene { namespace utilities { + +fc::path temp_directory_path() +{ + const char* graphene_tempdir = getenv("GRAPHENE_TEMPDIR"); + if( graphene_tempdir != nullptr ) + return fc::path( graphene_tempdir ); + return fc::temp_directory_path() / "graphene-tmp"; +} + +} } // graphene::utilities diff --git a/tests/app/main.cpp b/tests/app/main.cpp index 6febbfd7..c4d05708 100644 --- a/tests/app/main.cpp +++ b/tests/app/main.cpp @@ -20,6 +20,8 @@ #include +#include + #include #include @@ -36,8 +38,8 @@ BOOST_AUTO_TEST_CASE( two_node_network ) using namespace graphene::chain; using namespace graphene::app; try { - fc::temp_directory app_dir; - fc::temp_directory app2_dir; + fc::temp_directory app_dir( graphene::utilities::temp_directory_path() ); + fc::temp_directory app2_dir( graphene::utilities::temp_directory_path() ); fc::temp_file genesis_json; // TODO: Time should be read from the blockchain diff --git a/tests/benchmarks/genesis_allocation.cpp b/tests/benchmarks/genesis_allocation.cpp index fc842719..3e2b4882 100644 --- a/tests/benchmarks/genesis_allocation.cpp +++ b/tests/benchmarks/genesis_allocation.cpp @@ -17,6 +17,7 @@ */ #include #include +#include #include @@ -58,7 +59,7 @@ BOOST_AUTO_TEST_CASE( genesis_and_persistence_bench ) genesis_state.initial_accounts.emplace_back("target"+fc::to_string(i), public_key_type(fc::ecc::private_key::regenerate(fc::digest(i)).get_public_key())); - fc::temp_directory data_dir(fc::current_path()); + fc::temp_directory data_dir( graphene::utilities::temp_directory_path() ); { database db; diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index 62700820..c748af9c 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -30,6 +30,8 @@ #include #include +#include + #include #include @@ -285,7 +287,7 @@ void database_fixture::verify_account_history_plugin_index( )const void database_fixture::open_database() { if( !data_dir ) { - data_dir = fc::temp_directory(); + data_dir = fc::temp_directory( graphene::utilities::temp_directory_path() ); db.open(data_dir->path(), [this]{return genesis_state;}); } } diff --git a/tests/tests/block_tests.cpp b/tests/tests/block_tests.cpp index 03b243e2..3a70d28c 100644 --- a/tests/tests/block_tests.cpp +++ b/tests/tests/block_tests.cpp @@ -26,6 +26,8 @@ #include #include +#include + #include #include "../common/database_fixture.hpp" @@ -58,7 +60,7 @@ BOOST_AUTO_TEST_SUITE(block_tests) BOOST_AUTO_TEST_CASE( block_database_test ) { try { - fc::temp_directory data_dir; + fc::temp_directory data_dir( graphene::utilities::temp_directory_path() ); block_database bdb; bdb.open( data_dir.path() ); @@ -119,7 +121,7 @@ BOOST_AUTO_TEST_CASE( generate_empty_blocks ) { try { fc::time_point_sec now( GRAPHENE_TESTING_GENESIS_TIMESTAMP ); - fc::temp_directory data_dir; + fc::temp_directory data_dir( graphene::utilities::temp_directory_path() ); signed_block b; now += GRAPHENE_DEFAULT_BLOCK_INTERVAL; @@ -166,7 +168,7 @@ BOOST_AUTO_TEST_CASE( generate_empty_blocks ) BOOST_AUTO_TEST_CASE( undo_block ) { try { - fc::temp_directory data_dir; + fc::temp_directory data_dir( graphene::utilities::temp_directory_path() ); { database db; db.open(data_dir.path(), make_genesis); @@ -204,8 +206,8 @@ BOOST_AUTO_TEST_CASE( undo_block ) BOOST_AUTO_TEST_CASE( fork_blocks ) { try { - fc::temp_directory data_dir1; - fc::temp_directory data_dir2; + fc::temp_directory data_dir1( graphene::utilities::temp_directory_path() ); + fc::temp_directory data_dir2( graphene::utilities::temp_directory_path() ); fc::time_point_sec now( GRAPHENE_TESTING_GENESIS_TIMESTAMP ); database db1; @@ -271,7 +273,7 @@ BOOST_AUTO_TEST_CASE( undo_pending ) { try { fc::time_point_sec now(GRAPHENE_TESTING_GENESIS_TIMESTAMP); - fc::temp_directory data_dir; + fc::temp_directory data_dir( graphene::utilities::temp_directory_path() ); { database db; db.open(data_dir.path(), make_genesis); @@ -335,8 +337,8 @@ BOOST_AUTO_TEST_CASE( undo_pending ) BOOST_AUTO_TEST_CASE( switch_forks_undo_create ) { try { - fc::temp_directory dir1, - dir2; + fc::temp_directory dir1( graphene::utilities::temp_directory_path() ), + dir2( graphene::utilities::temp_directory_path() ); database db1, db2; db1.open(dir1.path(), make_genesis); @@ -393,8 +395,8 @@ BOOST_AUTO_TEST_CASE( duplicate_transactions ) { try { fc::time_point_sec now( GRAPHENE_TESTING_GENESIS_TIMESTAMP ); - fc::temp_directory dir1, - dir2; + fc::temp_directory dir1( graphene::utilities::temp_directory_path() ), + dir2( graphene::utilities::temp_directory_path() ); database db1, db2; db1.open(dir1.path(), make_genesis); @@ -445,8 +447,8 @@ BOOST_AUTO_TEST_CASE( tapos ) { try { fc::time_point_sec now( GRAPHENE_TESTING_GENESIS_TIMESTAMP ); - fc::temp_directory dir1, - dir2; + fc::temp_directory dir1( graphene::utilities::temp_directory_path() ), + dir2( graphene::utilities::temp_directory_path() ); database db1, db2; db1.open(dir1.path(), make_genesis); diff --git a/tests/tests/operation_tests2.cpp b/tests/tests/operation_tests2.cpp index 82cb5675..f5561ffb 100644 --- a/tests/tests/operation_tests2.cpp +++ b/tests/tests/operation_tests2.cpp @@ -19,6 +19,8 @@ #include #include +#include + #include #include #include @@ -28,7 +30,8 @@ #include #include #include -#include + +#include #include @@ -970,7 +973,7 @@ BOOST_AUTO_TEST_CASE( balance_object_test ) { try { // Intentionally overriding the fixture's db; I need to control genesis on this one. database db; - fc::temp_directory td; + fc::temp_directory td( graphene::utilities::temp_directory_path() ); genesis_state.initial_balances.push_back({generate_private_key("n").get_public_key(), GRAPHENE_SYMBOL, 1}); genesis_state.initial_balances.push_back({generate_private_key("x").get_public_key(), GRAPHENE_SYMBOL, 1}); auto starting_time = time_point_sec((time_point::now().sec_since_epoch() / GRAPHENE_DEFAULT_BLOCK_INTERVAL + 1) *