diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/core_tests/chaingen.h | 5 | ||||
-rw-r--r-- | tests/data/fuzz/tx-extra/TXEXTRA1 | bin | 0 -> 44 bytes | |||
-rw-r--r-- | tests/data/fuzz/tx-extra/TXEXTRA2 | bin | 0 -> 547 bytes | |||
-rwxr-xr-x | tests/functional_tests/address_book.py | 10 | ||||
-rwxr-xr-x | tests/functional_tests/speed.py | 4 | ||||
-rwxr-xr-x | tests/functional_tests/validate_address.py | 4 | ||||
-rw-r--r-- | tests/fuzz/CMakeLists.txt | 54 | ||||
-rw-r--r-- | tests/fuzz/base58.cpp | 49 | ||||
-rw-r--r-- | tests/fuzz/block.cpp | 36 | ||||
-rw-r--r-- | tests/fuzz/bulletproof.cpp | 39 | ||||
-rw-r--r-- | tests/fuzz/cold-outputs.cpp | 80 | ||||
-rw-r--r-- | tests/fuzz/cold-transaction.cpp | 82 | ||||
-rw-r--r-- | tests/fuzz/fuzzer.cpp | 4 | ||||
-rw-r--r-- | tests/fuzz/fuzzer.h | 108 | ||||
-rw-r--r-- | tests/fuzz/http-client.cpp | 49 | ||||
-rw-r--r-- | tests/fuzz/levin.cpp | 49 | ||||
-rw-r--r-- | tests/fuzz/load_from_binary.cpp | 48 | ||||
-rw-r--r-- | tests/fuzz/load_from_json.cpp | 48 | ||||
-rw-r--r-- | tests/fuzz/parse_url.cpp | 48 | ||||
-rw-r--r-- | tests/fuzz/signature.cpp | 67 | ||||
-rw-r--r-- | tests/fuzz/transaction.cpp | 36 | ||||
-rw-r--r-- | tests/fuzz/tx-extra.cpp | 40 | ||||
-rw-r--r-- | tests/unit_tests/epee_utils.cpp | 31 |
23 files changed, 343 insertions, 548 deletions
diff --git a/tests/core_tests/chaingen.h b/tests/core_tests/chaingen.h index 453ee923d..e94bf6be1 100644 --- a/tests/core_tests/chaingen.h +++ b/tests/core_tests/chaingen.h @@ -30,6 +30,7 @@ #pragma once +#include <functional> #include <vector> #include <iostream> #include <stdint.h> @@ -856,10 +857,10 @@ inline bool do_replay_file(const std::string& filename) } #define REGISTER_CALLBACK(CB_NAME, CLBACK) \ - register_callback(CB_NAME, boost::bind(&CLBACK, this, _1, _2, _3)); + register_callback(CB_NAME, std::bind(&CLBACK, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); #define REGISTER_CALLBACK_METHOD(CLASS, METHOD) \ - register_callback(#METHOD, boost::bind(&CLASS::METHOD, this, _1, _2, _3)); + register_callback(#METHOD, std::bind(&CLASS::METHOD, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); #define MAKE_GENESIS_BLOCK(VEC_EVENTS, BLK_NAME, MINER_ACC, TS) \ test_generator generator; \ diff --git a/tests/data/fuzz/tx-extra/TXEXTRA1 b/tests/data/fuzz/tx-extra/TXEXTRA1 Binary files differnew file mode 100644 index 000000000..08852abe3 --- /dev/null +++ b/tests/data/fuzz/tx-extra/TXEXTRA1 diff --git a/tests/data/fuzz/tx-extra/TXEXTRA2 b/tests/data/fuzz/tx-extra/TXEXTRA2 Binary files differnew file mode 100644 index 000000000..170301145 --- /dev/null +++ b/tests/data/fuzz/tx-extra/TXEXTRA2 diff --git a/tests/functional_tests/address_book.py b/tests/functional_tests/address_book.py index f9ec217af..99140847c 100755 --- a/tests/functional_tests/address_book.py +++ b/tests/functional_tests/address_book.py @@ -145,7 +145,7 @@ class AddressBookTest(): res = wallet.get_address_book() assert len(res.entries) == 1 e = res.entries[0] - assert e.address == '44AFFq5kSiGBoZ4NMDwYtN18obc8AemS33DBLWs3H7otXft3XjrpDtQGv7SqSsaBYBb98uNbr2VBBEt7f2wfn3RVGQBEP3A' + assert e.address == '888tNkZrPN6JsEgekjMnABU4TBzc2Dt29EPAvkRxbANsAnjyPbb3iQ1YBRk1UXcdRsiKc9dhwMVgN5S9cQUiyoogDavup3H' assert e.description == 'dev fund' # UTF-8 @@ -173,7 +173,7 @@ class AddressBookTest(): # get them back res = wallet.get_address_book([0]) assert len(res.entries) == 1 - assert res.entries[0].address == '44AFFq5kSiGBoZ4NMDwYtN18obc8AemS33DBLWs3H7otXft3XjrpDtQGv7SqSsaBYBb98uNbr2VBBEt7f2wfn3RVGQBEP3A' + assert res.entries[0].address == '888tNkZrPN6JsEgekjMnABU4TBzc2Dt29EPAvkRxbANsAnjyPbb3iQ1YBRk1UXcdRsiKc9dhwMVgN5S9cQUiyoogDavup3H' assert res.entries[0].description == 'dev fund' res = wallet.get_address_book([1]) assert len(res.entries) == 1 @@ -213,12 +213,12 @@ class AddressBookTest(): assert e.index == 1 assert e.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm' assert e.description == u'えんしゅう' - res = wallet.edit_address_book(1, address = '44AFFq5kSiGBoZ4NMDwYtN18obc8AemS33DBLWs3H7otXft3XjrpDtQGv7SqSsaBYBb98uNbr2VBBEt7f2wfn3RVGQBEP3A') + res = wallet.edit_address_book(1, address = '888tNkZrPN6JsEgekjMnABU4TBzc2Dt29EPAvkRxbANsAnjyPbb3iQ1YBRk1UXcdRsiKc9dhwMVgN5S9cQUiyoogDavup3H') res = wallet.get_address_book([1]) assert len(res.entries) == 1 e = res.entries[0] assert e.index == 1 - assert e.address == '44AFFq5kSiGBoZ4NMDwYtN18obc8AemS33DBLWs3H7otXft3XjrpDtQGv7SqSsaBYBb98uNbr2VBBEt7f2wfn3RVGQBEP3A' + assert e.address == '888tNkZrPN6JsEgekjMnABU4TBzc2Dt29EPAvkRxbANsAnjyPbb3iQ1YBRk1UXcdRsiKc9dhwMVgN5S9cQUiyoogDavup3H' assert e.description == u'えんしゅう' ok = False try: res = wallet.edit_address_book(1, address = '') @@ -237,7 +237,7 @@ class AddressBookTest(): wallet.delete_address_book(0) res = wallet.get_address_book([0]) # entries above the deleted one collapse one slot up assert len(res.entries) == 1 - assert res.entries[0].address == '44AFFq5kSiGBoZ4NMDwYtN18obc8AemS33DBLWs3H7otXft3XjrpDtQGv7SqSsaBYBb98uNbr2VBBEt7f2wfn3RVGQBEP3A' + assert res.entries[0].address == '888tNkZrPN6JsEgekjMnABU4TBzc2Dt29EPAvkRxbANsAnjyPbb3iQ1YBRk1UXcdRsiKc9dhwMVgN5S9cQUiyoogDavup3H' assert res.entries[0].description == u'えんしゅう' wallet.delete_address_book(2) wallet.delete_address_book(0) diff --git a/tests/functional_tests/speed.py b/tests/functional_tests/speed.py index 71be785b8..c0c1d23c2 100755 --- a/tests/functional_tests/speed.py +++ b/tests/functional_tests/speed.py @@ -67,7 +67,7 @@ class SpeedTest(): destinations = [] for i in range(3): - destinations.append({"amount":1,"address":'44AFFq5kSiGBoZ4NMDwYtN18obc8AemS33DBLWs3H7otXft3XjrpDtQGv7SqSsaBYBb98uNbr2VBBEt7f2wfn3RVGQBEP3A'}) + destinations.append({"amount":1,"address":'888tNkZrPN6JsEgekjMnABU4TBzc2Dt29EPAvkRxbANsAnjyPbb3iQ1YBRk1UXcdRsiKc9dhwMVgN5S9cQUiyoogDavup3H'}) self._test_speed_generateblocks(daemon=daemon, blocks=70) for i in range(1, 10): @@ -89,7 +89,7 @@ class SpeedTest(): print('Test speed of transfer') start = time.time() - destinations = [{"amount":1,"address":'44AFFq5kSiGBoZ4NMDwYtN18obc8AemS33DBLWs3H7otXft3XjrpDtQGv7SqSsaBYBb98uNbr2VBBEt7f2wfn3RVGQBEP3A'}] + destinations = [{"amount":1,"address":'888tNkZrPN6JsEgekjMnABU4TBzc2Dt29EPAvkRxbANsAnjyPbb3iQ1YBRk1UXcdRsiKc9dhwMVgN5S9cQUiyoogDavup3H'}] res = wallet.transfer_split(destinations) print('generating tx took: ', time.time() - start, 'seconds') diff --git a/tests/functional_tests/validate_address.py b/tests/functional_tests/validate_address.py index 7c3d8abfa..af0de87e5 100755 --- a/tests/functional_tests/validate_address.py +++ b/tests/functional_tests/validate_address.py @@ -94,7 +94,7 @@ class AddressValidationTest(): def check_openalias_addresses(self): print('Validating openalias addresses') addresses = [ - ['donate@getmonero.org', '44AFFq5kSiGBoZ4NMDwYtN18obc8AemS33DBLWs3H7otXft3XjrpDtQGv7SqSsaBYBb98uNbr2VBBEt7f2wfn3RVGQBEP3A'] + ['donate@getmonero.org', '888tNkZrPN6JsEgekjMnABU4TBzc2Dt29EPAvkRxbANsAnjyPbb3iQ1YBRk1UXcdRsiKc9dhwMVgN5S9cQUiyoogDavup3H'] ] for address in addresses: res = self.wallet.validate_address(address[0]) @@ -102,7 +102,7 @@ class AddressValidationTest(): res = self.wallet.validate_address(address[0], allow_openalias = True) assert res.valid assert not res.integrated - assert not res.subaddress + assert res.subaddress assert res.nettype == 'mainnet' assert res.openalias_address == address[1] diff --git a/tests/fuzz/CMakeLists.txt b/tests/fuzz/CMakeLists.txt index a6ef139f5..606fec465 100644 --- a/tests/fuzz/CMakeLists.txt +++ b/tests/fuzz/CMakeLists.txt @@ -34,7 +34,8 @@ target_link_libraries(block_fuzz_tests epee device ${CMAKE_THREAD_LIBS_INIT} - ${EXTRA_LIBRARIES}) + ${EXTRA_LIBRARIES} + $ENV{LIB_FUZZING_ENGINE}) set_property(TARGET block_fuzz_tests PROPERTY FOLDER "tests") @@ -47,7 +48,8 @@ target_link_libraries(transaction_fuzz_tests epee device ${CMAKE_THREAD_LIBS_INIT} - ${EXTRA_LIBRARIES}) + ${EXTRA_LIBRARIES} + $ENV{LIB_FUZZING_ENGINE}) set_property(TARGET transaction_fuzz_tests PROPERTY FOLDER "tests") @@ -61,7 +63,8 @@ target_link_libraries(signature_fuzz_tests epee device ${CMAKE_THREAD_LIBS_INIT} - ${EXTRA_LIBRARIES}) + ${EXTRA_LIBRARIES} + $ENV{LIB_FUZZING_ENGINE}) set_property(TARGET signature_fuzz_tests PROPERTY FOLDER "tests") @@ -75,7 +78,8 @@ target_link_libraries(cold-outputs_fuzz_tests epee device ${CMAKE_THREAD_LIBS_INIT} - ${EXTRA_LIBRARIES}) + ${EXTRA_LIBRARIES} + $ENV{LIB_FUZZING_ENGINE}) set_property(TARGET cold-outputs_fuzz_tests PROPERTY FOLDER "tests") @@ -89,7 +93,8 @@ target_link_libraries(cold-transaction_fuzz_tests epee device ${CMAKE_THREAD_LIBS_INIT} - ${EXTRA_LIBRARIES}) + ${EXTRA_LIBRARIES} + $ENV{LIB_FUZZING_ENGINE}) set_property(TARGET cold-transaction_fuzz_tests PROPERTY FOLDER "tests") @@ -101,7 +106,8 @@ target_link_libraries(load-from-binary_fuzz_tests epee ${Boost_PROGRAM_OPTIONS_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} - ${EXTRA_LIBRARIES}) + ${EXTRA_LIBRARIES} + $ENV{LIB_FUZZING_ENGINE}) set_property(TARGET load-from-binary_fuzz_tests PROPERTY FOLDER "tests") @@ -113,7 +119,8 @@ target_link_libraries(load-from-json_fuzz_tests epee ${Boost_PROGRAM_OPTIONS_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} - ${EXTRA_LIBRARIES}) + ${EXTRA_LIBRARIES} + $ENV{LIB_FUZZING_ENGINE}) set_property(TARGET load-from-json_fuzz_tests PROPERTY FOLDER "tests") @@ -125,7 +132,8 @@ target_link_libraries(base58_fuzz_tests epee ${Boost_PROGRAM_OPTIONS_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} - ${EXTRA_LIBRARIES}) + ${EXTRA_LIBRARIES} + $ENV{LIB_FUZZING_ENGINE}) set_property(TARGET base58_fuzz_tests PROPERTY FOLDER "tests") @@ -138,7 +146,8 @@ target_link_libraries(parse-url_fuzz_tests ${Boost_PROGRAM_OPTIONS_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} - ${EXTRA_LIBRARIES}) + ${EXTRA_LIBRARIES} + $ENV{LIB_FUZZING_ENGINE}) set_property(TARGET parse-url_fuzz_tests PROPERTY FOLDER "tests") @@ -153,7 +162,8 @@ target_link_libraries(http-client_fuzz_tests ${Boost_PROGRAM_OPTIONS_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} - ${EXTRA_LIBRARIES}) + ${EXTRA_LIBRARIES} + $ENV{LIB_FUZZING_ENGINE}) set_property(TARGET http-client_fuzz_tests PROPERTY FOLDER "tests") @@ -168,7 +178,8 @@ target_link_libraries(levin_fuzz_tests ${Boost_REGEX_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} - ${EXTRA_LIBRARIES}) + ${EXTRA_LIBRARIES} + $ENV{LIB_FUZZING_ENGINE}) set_property(TARGET levin_fuzz_tests PROPERTY FOLDER "tests") @@ -183,8 +194,27 @@ target_link_libraries(bulletproof_fuzz_tests ${Boost_REGEX_LIBRARY} ${Boost_PROGRAM_OPTIONS_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} - ${EXTRA_LIBRARIES}) + ${EXTRA_LIBRARIES} + $ENV{LIB_FUZZING_ENGINE}) set_property(TARGET bulletproof_fuzz_tests PROPERTY FOLDER "tests") +add_executable(tx-extra_fuzz_tests tx-extra.cpp fuzzer.cpp) +target_link_libraries(tx-extra_fuzz_tests + PRIVATE + cryptonote_basic + common + epee + ${Boost_THREAD_LIBRARY} + ${Boost_CHRONO_LIBRARY} + ${Boost_REGEX_LIBRARY} + ${Boost_PROGRAM_OPTIONS_LIBRARY} + ${Boost_SYSTEM_LIBRARY} + ${CMAKE_THREAD_LIBS_INIT} + ${EXTRA_LIBRARIES} + $ENV{LIB_FUZZING_ENGINE}) +set_property(TARGET tx-extra_fuzz_tests + PROPERTY + FOLDER "tests") + diff --git a/tests/fuzz/base58.cpp b/tests/fuzz/base58.cpp index 5f909a5d9..08fa402dd 100644 --- a/tests/fuzz/base58.cpp +++ b/tests/fuzz/base58.cpp @@ -27,50 +27,13 @@ // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "include_base_utils.h" -#include "file_io_utils.h" #include "common/base58.h" #include "fuzzer.h" -class Base58Fuzzer: public Fuzzer -{ -public: - Base58Fuzzer() {} - virtual int init(); - virtual int run(const std::string &filename); -}; - -int Base58Fuzzer::init() -{ - return 0; -} - -int Base58Fuzzer::run(const std::string &filename) -{ - std::string s; - - if (!epee::file_io_utils::load_file_to_string(filename, s)) - { - std::cout << "Error: failed to load file " << filename << std::endl; - return 1; - } - try - { - std::string data; - tools::base58::decode(s, data); - } - catch (const std::exception &e) - { - std::cerr << "Failed to load from binary: " << e.what() << std::endl; - return 1; - } - return 0; -} - -int main(int argc, const char **argv) -{ - TRY_ENTRY(); - Base58Fuzzer fuzzer; - return run_fuzzer(argc, argv, fuzzer); - CATCH_ENTRY_L0("main", 1); -} +BEGIN_INIT_SIMPLE_FUZZER() +END_INIT_SIMPLE_FUZZER() +BEGIN_SIMPLE_FUZZER() + std::string data; + tools::base58::decode(std::string((const char*)buf, len), data); +END_SIMPLE_FUZZER() diff --git a/tests/fuzz/block.cpp b/tests/fuzz/block.cpp index 850c58890..44818f8cd 100644 --- a/tests/fuzz/block.cpp +++ b/tests/fuzz/block.cpp @@ -33,36 +33,10 @@ #include "cryptonote_basic/cryptonote_format_utils.h" #include "fuzzer.h" -class BlockFuzzer: public Fuzzer -{ -public: - virtual int run(const std::string &filename); +BEGIN_INIT_SIMPLE_FUZZER() +END_INIT_SIMPLE_FUZZER() -private: -}; - -int BlockFuzzer::run(const std::string &filename) -{ - std::string s; - - if (!epee::file_io_utils::load_file_to_string(filename, s)) - { - std::cout << "Error: failed to load file " << filename << std::endl; - return 1; - } +BEGIN_SIMPLE_FUZZER() cryptonote::block b = AUTO_VAL_INIT(b); - if(!parse_and_validate_block_from_blob(s, b)) - { - std::cout << "Error: failed to parse block from file " << filename << std::endl; - return 1; - } - return 0; -} - -int main(int argc, const char **argv) -{ - TRY_ENTRY(); - BlockFuzzer fuzzer; - return run_fuzzer(argc, argv, fuzzer); - CATCH_ENTRY_L0("main", 1); -} + parse_and_validate_block_from_blob(std::string((const char*)buf, len), b); +END_SIMPLE_FUZZER() diff --git a/tests/fuzz/bulletproof.cpp b/tests/fuzz/bulletproof.cpp index e9a6ded7d..7e58770ca 100644 --- a/tests/fuzz/bulletproof.cpp +++ b/tests/fuzz/bulletproof.cpp @@ -33,40 +33,13 @@ #include "cryptonote_basic/cryptonote_format_utils.h" #include "fuzzer.h" -class BulletproofFuzzer: public Fuzzer -{ -public: - virtual int run(const std::string &filename); +BEGIN_INIT_SIMPLE_FUZZER() +END_INIT_SIMPLE_FUZZER() -private: -}; - -int BulletproofFuzzer::run(const std::string &filename) -{ - std::string s; - - if (!epee::file_io_utils::load_file_to_string(filename, s)) - { - std::cout << "Error: failed to load file " << filename << std::endl; - return 1; - } +BEGIN_SIMPLE_FUZZER() std::stringstream ss; - ss << s; + ss << std::string((const char*)buf, len); binary_archive<false> ba(ss); rct::Bulletproof proof = AUTO_VAL_INIT(proof); - bool r = ::serialization::serialize(ba, proof); - if(!r) - { - std::cout << "Error: failed to parse bulletproof from file " << filename << std::endl; - return 1; - } - return 0; -} - -int main(int argc, const char **argv) -{ - TRY_ENTRY(); - BulletproofFuzzer fuzzer; - return run_fuzzer(argc, argv, fuzzer); - CATCH_ENTRY_L0("main", 1); -} + ::serialization::serialize(ba, proof); +END_SIMPLE_FUZZER() diff --git a/tests/fuzz/cold-outputs.cpp b/tests/fuzz/cold-outputs.cpp index f4050c948..ce6d6640c 100644 --- a/tests/fuzz/cold-outputs.cpp +++ b/tests/fuzz/cold-outputs.cpp @@ -34,70 +34,28 @@ #include "wallet/wallet2.h" #include "fuzzer.h" -class ColdOutputsFuzzer: public Fuzzer -{ -public: - ColdOutputsFuzzer(): wallet(cryptonote::TESTNET) {} - virtual int init(); - virtual int run(const std::string &filename); +static tools::wallet2 *wallet = NULL; -private: - tools::wallet2 wallet; -}; +BEGIN_INIT_SIMPLE_FUZZER() + static tools::wallet2 local_wallet; + wallet = &local_wallet; -int ColdOutputsFuzzer::init() -{ static const char * const spendkey_hex = "0b4f47697ec99c3de6579304e5f25c68b07afbe55b71d99620bf6cbf4e45a80f"; crypto::secret_key spendkey; epee::string_tools::hex_to_pod(spendkey_hex, spendkey); - try - { - wallet.init("", boost::none, boost::asio::ip::tcp::endpoint{}, 0, true, epee::net_utils::ssl_support_t::e_ssl_support_disabled); - wallet.set_subaddress_lookahead(1, 1); - wallet.generate("", "", spendkey, true, false); - } - catch (const std::exception &e) - { - std::cerr << "Error on ColdOutputsFuzzer::init: " << e.what() << std::endl; - return 1; - } - return 0; -} - -int ColdOutputsFuzzer::run(const std::string &filename) -{ - std::string s; - - if (!epee::file_io_utils::load_file_to_string(filename, s)) - { - std::cout << "Error: failed to load file " << filename << std::endl; - return 1; - } - s = std::string("\x01\x16serialization::archive") + s; - try - { - std::pair<size_t, std::vector<tools::wallet2::transfer_details>> outputs; - std::stringstream iss; - iss << s; - boost::archive::portable_binary_iarchive ar(iss); - ar >> outputs; - size_t n_outputs = wallet.import_outputs(outputs); - std::cout << boost::lexical_cast<std::string>(n_outputs) << " outputs imported" << std::endl; - } - catch (const std::exception &e) - { - std::cerr << "Failed to import outputs: " << e.what() << std::endl; - return 1; - } - return 0; -} - -int main(int argc, const char **argv) -{ - TRY_ENTRY(); - ColdOutputsFuzzer fuzzer; - return run_fuzzer(argc, argv, fuzzer); - CATCH_ENTRY_L0("main", 1); -} - + wallet->init("", boost::none, boost::asio::ip::tcp::endpoint{}, 0, true, epee::net_utils::ssl_support_t::e_ssl_support_disabled); + wallet->set_subaddress_lookahead(1, 1); + wallet->generate("", "", spendkey, true, false); +END_INIT_SIMPLE_FUZZER() + +BEGIN_SIMPLE_FUZZER() + std::string s = std::string("\x01\x16serialization::archive") + std::string((const char*)buf, len); + std::pair<size_t, std::vector<tools::wallet2::transfer_details>> outputs; + std::stringstream iss; + iss << s; + boost::archive::portable_binary_iarchive ar(iss); + ar >> outputs; + size_t n_outputs = wallet->import_outputs(outputs); + std::cout << boost::lexical_cast<std::string>(n_outputs) << " outputs imported" << std::endl; +END_SIMPLE_FUZZER() diff --git a/tests/fuzz/cold-transaction.cpp b/tests/fuzz/cold-transaction.cpp index 08117281b..ebbbc283f 100644 --- a/tests/fuzz/cold-transaction.cpp +++ b/tests/fuzz/cold-transaction.cpp @@ -34,71 +34,29 @@ #include "wallet/wallet2.h" #include "fuzzer.h" -class ColdTransactionFuzzer: public Fuzzer -{ -public: - ColdTransactionFuzzer(): wallet(cryptonote::TESTNET) {} - virtual int init(); - virtual int run(const std::string &filename); +static tools::wallet2 *wallet = NULL; -private: - tools::wallet2 wallet; -}; +BEGIN_INIT_SIMPLE_FUZZER() + static tools::wallet2 local_wallet; + wallet = &local_wallet; - -int ColdTransactionFuzzer::init() -{ static const char * const spendkey_hex = "0b4f47697ec99c3de6579304e5f25c68b07afbe55b71d99620bf6cbf4e45a80f"; crypto::secret_key spendkey; epee::string_tools::hex_to_pod(spendkey_hex, spendkey); - try - { - wallet.init("", boost::none, boost::asio::ip::tcp::endpoint{}, 0, true, epee::net_utils::ssl_support_t::e_ssl_support_disabled); - wallet.set_subaddress_lookahead(1, 1); - wallet.generate("", "", spendkey, true, false); - } - catch (const std::exception &e) - { - std::cerr << "Error on ColdTransactionFuzzer::init: " << e.what() << std::endl; - return 1; - } - return 0; -} - -int ColdTransactionFuzzer::run(const std::string &filename) -{ - std::string s; - - if (!epee::file_io_utils::load_file_to_string(filename, s)) - { - std::cout << "Error: failed to load file " << filename << std::endl; - return 1; - } - s = std::string("\x01\x16serialization::archive") + s; - try - { - tools::wallet2::unsigned_tx_set exported_txs; - std::stringstream iss; - iss << s; - boost::archive::portable_binary_iarchive ar(iss); - ar >> exported_txs; - std::vector<tools::wallet2::pending_tx> ptx; - bool success = wallet.sign_tx(exported_txs, "/tmp/cold-transaction-test-signed", ptx); - std::cout << (success ? "signed" : "error") << std::endl; - } - catch (const std::exception &e) - { - std::cerr << "Failed to sign transaction: " << e.what() << std::endl; - return 1; - } - return 0; -} - -int main(int argc, const char **argv) -{ - TRY_ENTRY(); - ColdTransactionFuzzer fuzzer; - return run_fuzzer(argc, argv, fuzzer); - CATCH_ENTRY_L0("main", 1); -} + wallet->init("", boost::none, boost::asio::ip::tcp::endpoint{}, 0, true, epee::net_utils::ssl_support_t::e_ssl_support_disabled); + wallet->set_subaddress_lookahead(1, 1); + wallet->generate("", "", spendkey, true, false); +END_INIT_SIMPLE_FUZZER() + +BEGIN_SIMPLE_FUZZER() + std::string s = std::string("\x01\x16serialization::archive") + std::string((const char*)buf, len); + tools::wallet2::unsigned_tx_set exported_txs; + std::stringstream iss; + iss << s; + boost::archive::portable_binary_iarchive ar(iss); + ar >> exported_txs; + std::vector<tools::wallet2::pending_tx> ptx; + bool success = wallet->sign_tx(exported_txs, "/tmp/cold-transaction-test-signed", ptx); + std::cout << (success ? "signed" : "error") << std::endl; +END_SIMPLE_FUZZER() diff --git a/tests/fuzz/fuzzer.cpp b/tests/fuzz/fuzzer.cpp index 24db5ee05..0d2366263 100644 --- a/tests/fuzz/fuzzer.cpp +++ b/tests/fuzz/fuzzer.cpp @@ -33,6 +33,8 @@ #include "common/util.h" #include "fuzzer.h" +#ifndef OSSFUZZ + #if (!defined(__clang__) || (__clang__ < 5)) static int __AFL_LOOP(int) { @@ -74,3 +76,5 @@ int run_fuzzer(int argc, const char **argv, Fuzzer &fuzzer) CATCH_ENTRY_L0("run_fuzzer", 1); } + +#endif diff --git a/tests/fuzz/fuzzer.h b/tests/fuzz/fuzzer.h index 5cbd1abc2..ce230fb66 100644 --- a/tests/fuzz/fuzzer.h +++ b/tests/fuzz/fuzzer.h @@ -27,6 +27,56 @@ // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <string> +#include "file_io_utils.h" + +#ifdef OSSFUZZ + +#define BEGIN_INIT_SIMPLE_FUZZER() \ + static int init() \ + { \ + try \ + { + +#define END_INIT_SIMPLE_FUZZER() \ + } \ + catch (const std::exception &e) \ + { \ + fprintf(stderr, "Exception: %s\n", e.what()); \ + return 1; \ + } \ + return 0; \ + } + +#define BEGIN_SIMPLE_FUZZER() \ +extern "C" { \ + int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) \ + { \ + try \ + { \ + static bool first = true; \ + if (first) \ + { \ + if (init()) \ + return 1; \ + first = false; \ + } \ + +#define END_SIMPLE_FUZZER() \ + } \ + catch (const std::exception &e) \ + { \ + fprintf(stderr, "Exception: %s\n", e.what()); \ + delete el::base::elStorage; \ + el::base::elStorage = NULL; \ + return 0; \ + } \ + delete el::base::elStorage; \ + el::base::elStorage = NULL; \ + return 0; \ + } \ +} + +#else class Fuzzer { @@ -36,3 +86,61 @@ public: }; int run_fuzzer(int argc, const char **argv, Fuzzer &fuzzer); + +#define BEGIN_INIT_SIMPLE_FUZZER() \ + class SimpleFuzzer: public Fuzzer \ + { \ + virtual int init() \ + { \ + try \ + { + +#define END_INIT_SIMPLE_FUZZER() \ + } \ + catch (const std::exception &e) \ + { \ + fprintf(stderr, "Exception: %s\n", e.what()); \ + return 1; \ + } \ + return 0; \ + } + +#define BEGIN_SIMPLE_FUZZER() \ + virtual int run(const std::string &filename) \ + { \ + try \ + { \ + std::string s; \ + if (!epee::file_io_utils::load_file_to_string(filename, s)) \ + { \ + std::cout << "Error: failed to load file " << filename << std::endl; \ + return 1; \ + } \ + const uint8_t *buf = (const uint8_t*)s.data(); \ + const size_t len = s.size(); \ + { + +#define END_SIMPLE_FUZZER() \ + } \ + } \ + catch (const std::exception &e) \ + { \ + fprintf(stderr, "Exception: %s\n", e.what()); \ + delete el::base::elStorage; \ + el::base::elStorage = NULL; \ + return 0; \ + } \ + delete el::base::elStorage; \ + el::base::elStorage = NULL; \ + return 0; \ + } \ + }; \ + int main(int argc, const char **argv) \ + { \ + TRY_ENTRY(); \ + SimpleFuzzer fuzzer; \ + return run_fuzzer(argc, argv, fuzzer); \ + CATCH_ENTRY_L0("main", 1); \ + } + +#endif diff --git a/tests/fuzz/http-client.cpp b/tests/fuzz/http-client.cpp index ea6d5a2ad..1801affee 100644 --- a/tests/fuzz/http-client.cpp +++ b/tests/fuzz/http-client.cpp @@ -58,48 +58,11 @@ private: std::string data; }; -class HTTPClientFuzzer: public Fuzzer -{ -public: - HTTPClientFuzzer() {} - virtual int init(); - virtual int run(const std::string &filename); - -private: - epee::net_utils::http::http_simple_client_template<dummy_client> client; -}; - -int HTTPClientFuzzer::init() -{ - return 0; -} - -int HTTPClientFuzzer::run(const std::string &filename) -{ - std::string s; +static epee::net_utils::http::http_simple_client_template<dummy_client> client; - if (!epee::file_io_utils::load_file_to_string(filename, s)) - { - std::cout << "Error: failed to load file " << filename << std::endl; - return 1; - } - try - { - client.test(s, std::chrono::milliseconds(1000)); - } - catch (const std::exception &e) - { - std::cerr << "Failed to test http client: " << e.what() << std::endl; - return 1; - } - return 0; -} - -int main(int argc, const char **argv) -{ - TRY_ENTRY(); - HTTPClientFuzzer fuzzer; - return run_fuzzer(argc, argv, fuzzer); - CATCH_ENTRY_L0("main", 1); -} +BEGIN_INIT_SIMPLE_FUZZER() +END_INIT_SIMPLE_FUZZER() +BEGIN_SIMPLE_FUZZER() + client.test(std::string((const char*)buf, len), std::chrono::milliseconds(1000)); +END_SIMPLE_FUZZER() diff --git a/tests/fuzz/levin.cpp b/tests/fuzz/levin.cpp index 6c16a0a85..ab7bbb6da 100644 --- a/tests/fuzz/levin.cpp +++ b/tests/fuzz/levin.cpp @@ -279,26 +279,10 @@ namespace #endif } -class LevinFuzzer: public Fuzzer -{ -public: - LevinFuzzer() {} //: handler(endpoint, config, context) {} - virtual int init(); - virtual int run(const std::string &filename); - -private: - //epee::net_utils::connection_context_base context; - //epee::levin::async_protocol_handler<> handler; -}; +BEGIN_INIT_SIMPLE_FUZZER() +END_INIT_SIMPLE_FUZZER() -int LevinFuzzer::init() -{ - return 0; -} - -int LevinFuzzer::run(const std::string &filename) -{ - std::string s; +BEGIN_SIMPLE_FUZZER() #if 0 epee::levin::bucket_head2 req_head; @@ -313,13 +297,6 @@ int LevinFuzzer::run(const std::string &filename) fwrite(&req_head,sizeof(req_head),1, f); fclose(f); #endif - if (!epee::file_io_utils::load_file_to_string(filename, s)) - { - std::cout << "Error: failed to load file " << filename << std::endl; - return 1; - } - try - { //std::unique_ptr<test_connection> conn = new test(); boost::asio::io_service io_service; test_levin_protocol_handler_config m_handler_config; @@ -329,21 +306,5 @@ int LevinFuzzer::run(const std::string &filename) conn->start(); //m_commands_handler.invoke_out_buf(expected_out_data); //m_commands_handler.return_code(expected_return_code); - conn->m_protocol_handler.handle_recv(s.data(), s.size()); - } - catch (const std::exception &e) - { - std::cerr << "Failed to test http client: " << e.what() << std::endl; - return 1; - } - return 0; -} - -int main(int argc, const char **argv) -{ - TRY_ENTRY(); - LevinFuzzer fuzzer; - return run_fuzzer(argc, argv, fuzzer); - CATCH_ENTRY_L0("main", 1); -} - + conn->m_protocol_handler.handle_recv(buf, len); +END_SIMPLE_FUZZER() diff --git a/tests/fuzz/load_from_binary.cpp b/tests/fuzz/load_from_binary.cpp index 85b7361e5..b185df522 100644 --- a/tests/fuzz/load_from_binary.cpp +++ b/tests/fuzz/load_from_binary.cpp @@ -33,46 +33,10 @@ #include "storages/portable_storage_base.h" #include "fuzzer.h" -class PortableStorageFuzzer: public Fuzzer -{ -public: - PortableStorageFuzzer() {} - virtual int init(); - virtual int run(const std::string &filename); -}; - -int PortableStorageFuzzer::init() -{ - return 0; -} - -int PortableStorageFuzzer::run(const std::string &filename) -{ - std::string s; - - if (!epee::file_io_utils::load_file_to_string(filename, s)) - { - std::cout << "Error: failed to load file " << filename << std::endl; - return 1; - } - try - { - epee::serialization::portable_storage ps; - ps.load_from_binary(s); - } - catch (const std::exception &e) - { - std::cerr << "Failed to load from binary: " << e.what() << std::endl; - return 1; - } - return 0; -} - -int main(int argc, const char **argv) -{ - TRY_ENTRY(); - PortableStorageFuzzer fuzzer; - return run_fuzzer(argc, argv, fuzzer); - CATCH_ENTRY_L0("main", 1); -} +BEGIN_INIT_SIMPLE_FUZZER() +END_INIT_SIMPLE_FUZZER() +BEGIN_SIMPLE_FUZZER() + epee::serialization::portable_storage ps; + ps.load_from_binary(std::string((const char*)buf, len)); +END_SIMPLE_FUZZER() diff --git a/tests/fuzz/load_from_json.cpp b/tests/fuzz/load_from_json.cpp index 3ba98050b..0252360ba 100644 --- a/tests/fuzz/load_from_json.cpp +++ b/tests/fuzz/load_from_json.cpp @@ -33,46 +33,10 @@ #include "storages/portable_storage_base.h" #include "fuzzer.h" -class PortableStorageFuzzer: public Fuzzer -{ -public: - PortableStorageFuzzer() {} - virtual int init(); - virtual int run(const std::string &filename); -}; - -int PortableStorageFuzzer::init() -{ - return 0; -} - -int PortableStorageFuzzer::run(const std::string &filename) -{ - std::string s; - - if (!epee::file_io_utils::load_file_to_string(filename, s)) - { - std::cout << "Error: failed to load file " << filename << std::endl; - return 1; - } - try - { - epee::serialization::portable_storage ps; - ps.load_from_json(s); - } - catch (const std::exception &e) - { - std::cerr << "Failed to load from binary: " << e.what() << std::endl; - return 1; - } - return 0; -} - -int main(int argc, const char **argv) -{ - TRY_ENTRY(); - PortableStorageFuzzer fuzzer; - return run_fuzzer(argc, argv, fuzzer); - CATCH_ENTRY_L0("main", 1); -} +BEGIN_INIT_SIMPLE_FUZZER() +END_INIT_SIMPLE_FUZZER() +BEGIN_SIMPLE_FUZZER() + epee::serialization::portable_storage ps; + ps.load_from_json(std::string((const char*)buf, len)); +END_SIMPLE_FUZZER() diff --git a/tests/fuzz/parse_url.cpp b/tests/fuzz/parse_url.cpp index 3db78f9d9..41f4319a6 100644 --- a/tests/fuzz/parse_url.cpp +++ b/tests/fuzz/parse_url.cpp @@ -31,46 +31,10 @@ #include "net/net_parse_helpers.h" #include "fuzzer.h" -class ParseURLFuzzer: public Fuzzer -{ -public: - ParseURLFuzzer() {} - virtual int init(); - virtual int run(const std::string &filename); -}; - -int ParseURLFuzzer::init() -{ - return 0; -} - -int ParseURLFuzzer::run(const std::string &filename) -{ - std::string s; - - if (!epee::file_io_utils::load_file_to_string(filename, s)) - { - std::cout << "Error: failed to load file " << filename << std::endl; - return 1; - } - try - { - epee::net_utils::http::url_content url; - epee::net_utils::parse_url(s, url); - } - catch (const std::exception &e) - { - std::cerr << "Failed to load from binary: " << e.what() << std::endl; - return 1; - } - return 0; -} - -int main(int argc, const char **argv) -{ - TRY_ENTRY(); - ParseURLFuzzer fuzzer; - return run_fuzzer(argc, argv, fuzzer); - CATCH_ENTRY_L0("main", 1); -} +BEGIN_INIT_SIMPLE_FUZZER() +END_INIT_SIMPLE_FUZZER() +BEGIN_SIMPLE_FUZZER() + epee::net_utils::http::url_content url; + epee::net_utils::parse_url(std::string((const char*)buf, len), url); +END_SIMPLE_FUZZER() diff --git a/tests/fuzz/signature.cpp b/tests/fuzz/signature.cpp index 038378ae2..3743cfdd0 100644 --- a/tests/fuzz/signature.cpp +++ b/tests/fuzz/signature.cpp @@ -34,66 +34,31 @@ #include "wallet/wallet2.h" #include "fuzzer.h" -class SignatureFuzzer: public Fuzzer -{ -public: - SignatureFuzzer(): Fuzzer(), wallet(cryptonote::TESTNET) {} - virtual int init(); - virtual int run(const std::string &filename); +static tools::wallet2 *wallet = NULL; +static cryptonote::account_public_address address; -private: - tools::wallet2 wallet; - cryptonote::account_public_address address; -}; +BEGIN_INIT_SIMPLE_FUZZER() + static tools::wallet2 local_wallet(cryptonote::TESTNET); + wallet = &local_wallet; -int SignatureFuzzer::init() -{ static const char * const spendkey_hex = "0b4f47697ec99c3de6579304e5f25c68b07afbe55b71d99620bf6cbf4e45a80f"; crypto::secret_key spendkey; epee::string_tools::hex_to_pod(spendkey_hex, spendkey); - try - { - wallet.init("", boost::none, boost::asio::ip::tcp::endpoint{}, 0, true, epee::net_utils::ssl_support_t::e_ssl_support_disabled); - wallet.set_subaddress_lookahead(1, 1); - wallet.generate("", "", spendkey, true, false); + wallet->init("", boost::none, boost::asio::ip::tcp::endpoint{}, 0, true, epee::net_utils::ssl_support_t::e_ssl_support_disabled); + wallet->set_subaddress_lookahead(1, 1); + wallet->generate("", "", spendkey, true, false); - cryptonote::address_parse_info info; - if (!cryptonote::get_account_address_from_str_or_url(info, cryptonote::TESTNET, "9uVsvEryzpN8WH2t1WWhFFCG5tS8cBNdmJYNRuckLENFimfauV5pZKeS1P2CbxGkSDTUPHXWwiYE5ZGSXDAGbaZgDxobqDN")) - { - std::cerr << "failed to parse address" << std::endl; - return 1; - } - address = info.address; - } - catch (const std::exception &e) + cryptonote::address_parse_info info; + if (!cryptonote::get_account_address_from_str_or_url(info, cryptonote::TESTNET, "9uVsvEryzpN8WH2t1WWhFFCG5tS8cBNdmJYNRuckLENFimfauV5pZKeS1P2CbxGkSDTUPHXWwiYE5ZGSXDAGbaZgDxobqDN")) { - std::cerr << "Error on SignatureFuzzer::init: " << e.what() << std::endl; + std::cerr << "failed to parse address" << std::endl; return 1; } - return 0; -} - -int SignatureFuzzer::run(const std::string &filename) -{ - std::string s; + address = info.address; +END_INIT_SIMPLE_FUZZER() - if (!epee::file_io_utils::load_file_to_string(filename, s)) - { - std::cout << "Error: failed to load file " << filename << std::endl; - return 1; - } - - bool valid = wallet.verify("test", address, s); +BEGIN_SIMPLE_FUZZER() + bool valid = wallet->verify("test", address, std::string((const char*)buf, len)); std::cout << "Signature " << (valid ? "valid" : "invalid") << std::endl; - - return 0; -} - -int main(int argc, const char **argv) -{ - TRY_ENTRY(); - SignatureFuzzer fuzzer; - return run_fuzzer(argc, argv, fuzzer); - CATCH_ENTRY_L0("main", 1); -} +END_SIMPLE_FUZZER() diff --git a/tests/fuzz/transaction.cpp b/tests/fuzz/transaction.cpp index 0f62888a1..1e4a61a78 100644 --- a/tests/fuzz/transaction.cpp +++ b/tests/fuzz/transaction.cpp @@ -33,36 +33,10 @@ #include "cryptonote_basic/cryptonote_format_utils.h" #include "fuzzer.h" -class TransactionFuzzer: public Fuzzer -{ -public: - virtual int run(const std::string &filename); +BEGIN_INIT_SIMPLE_FUZZER() +END_INIT_SIMPLE_FUZZER() -private: -}; - -int TransactionFuzzer::run(const std::string &filename) -{ - std::string s; - - if (!epee::file_io_utils::load_file_to_string(filename, s)) - { - std::cout << "Error: failed to load file " << filename << std::endl; - return 1; - } +BEGIN_SIMPLE_FUZZER() cryptonote::transaction tx = AUTO_VAL_INIT(tx); - if(!parse_and_validate_tx_from_blob(s, tx)) - { - std::cout << "Error: failed to parse transaction from file " << filename << std::endl; - return 1; - } - return 0; -} - -int main(int argc, const char **argv) -{ - TRY_ENTRY(); - TransactionFuzzer fuzzer; - return run_fuzzer(argc, argv, fuzzer); - CATCH_ENTRY_L0("main", 1); -} + parse_and_validate_tx_from_blob(std::string((const char*)buf, len), tx); +END_SIMPLE_FUZZER() diff --git a/tests/fuzz/tx-extra.cpp b/tests/fuzz/tx-extra.cpp new file mode 100644 index 000000000..35b14b802 --- /dev/null +++ b/tests/fuzz/tx-extra.cpp @@ -0,0 +1,40 @@ +// Copyright (c) 2020, The Monero Project +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are +// permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list +// of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its contributors may be +// used to endorse or promote products derived from this software without specific +// prior written permission. +// +// 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_base_utils.h" +#include "cryptonote_basic/cryptonote_format_utils.h" +#include "fuzzer.h" + +BEGIN_INIT_SIMPLE_FUZZER() +END_INIT_SIMPLE_FUZZER() + +BEGIN_SIMPLE_FUZZER() + std::vector<cryptonote::tx_extra_field> tx_extra_fields; + cryptonote::parse_tx_extra(std::vector<uint8_t>(buf, buf + len), tx_extra_fields); +END_SIMPLE_FUZZER() + diff --git a/tests/unit_tests/epee_utils.cpp b/tests/unit_tests/epee_utils.cpp index 8af8f360b..0f91671a7 100644 --- a/tests/unit_tests/epee_utils.cpp +++ b/tests/unit_tests/epee_utils.cpp @@ -690,6 +690,23 @@ TEST(ByteSlice, TakeSlice) EXPECT_TRUE(boost::range::equal(base_string, slice)); const epee::span<const std::uint8_t> original = epee::to_span(slice); + const epee::byte_slice empty_slice = slice.take_slice(0); + EXPECT_EQ(original.begin(), slice.begin()); + EXPECT_EQ(slice.begin(), slice.cbegin()); + EXPECT_EQ(original.end(), slice.end()); + EXPECT_EQ(slice.end(), slice.cend()); + + EXPECT_EQ(nullptr, empty_slice.begin()); + EXPECT_EQ(nullptr, empty_slice.cbegin()); + EXPECT_EQ(nullptr, empty_slice.end()); + EXPECT_EQ(nullptr, empty_slice.cend()); + EXPECT_EQ(nullptr, empty_slice.data()); + EXPECT_TRUE(empty_slice.empty()); + EXPECT_EQ(0u, empty_slice.size()); + + EXPECT_FALSE(slice.empty()); + EXPECT_EQ(slice.cbegin(), slice.data()); + const epee::byte_slice slice2 = slice.take_slice(remove_size); EXPECT_EQ(original.begin() + remove_size, slice.begin()); @@ -1084,6 +1101,20 @@ TEST(ByteStream, ToByteSlice) EXPECT_EQ(nullptr, stream.data()); EXPECT_EQ(nullptr, stream.tellp()); EXPECT_TRUE(equal(source, slice)); + + stream = epee::byte_stream{}; + stream.reserve(1); + EXPECT_NE(nullptr, stream.data()); + EXPECT_NE(nullptr, stream.tellp()); + + const epee::byte_slice empty_slice{std::move(stream)}; + EXPECT_TRUE(empty_slice.empty()); + EXPECT_EQ(0u, empty_slice.size()); + EXPECT_EQ(nullptr, empty_slice.begin()); + EXPECT_EQ(nullptr, empty_slice.cbegin()); + EXPECT_EQ(nullptr, empty_slice.end()); + EXPECT_EQ(nullptr, empty_slice.cend()); + EXPECT_EQ(nullptr, empty_slice.data()); } TEST(ToHex, String) |