From bd85f1631289b2401581335ddb70dca3183f5ee3 Mon Sep 17 00:00:00 2001 From: Timothy Banks Date: Fri, 27 Nov 2020 21:25:56 -0500 Subject: [PATCH 1/2] Remove warnings in test_kv_rocksdb.cpp --- .../backing_store/tests/test_kv_rocksdb.cpp | 46 +++++++++++++------ 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/libraries/chain/backing_store/tests/test_kv_rocksdb.cpp b/libraries/chain/backing_store/tests/test_kv_rocksdb.cpp index 8ebd4802299..5e5a5e92764 100644 --- a/libraries/chain/backing_store/tests/test_kv_rocksdb.cpp +++ b/libraries/chain/backing_store/tests/test_kv_rocksdb.cpp @@ -164,11 +164,22 @@ struct kv_rocksdb_fixture { } void check_test_kv_it_status(it_state state, it_pos pos, kv_it_stat expected_status) { - mock_is_end = [pos]() -> bool { return pos == it_pos::END; }; + mock_get_kv = []() -> std::pair> { + auto expected_key = prefix + std::string{"key"}; + auto key = eosio::chain::make_prefix_key(contract, expected_key.c_str(), expected_key.size()); + return std::pair{ key, eosio::session::shared_bytes{"payernamValue", 13} }; + }; + mock_get_key_prefix = [&]() { return eosio::chain::make_prefix_key(contract, prefix.c_str(), prefix.size()); }; + mock_is_erased = []() -> bool { return false; }; + mock_is_end = []() -> bool { return false; }; + std::unique_ptr it = my_kv_context->kv_it_create(contract, prefix.c_str(), prefix.size()); + if (pos != it_pos::END) { + uint32_t found_key_size = 0; + uint32_t found_value_size = 0; + it->kv_it_next(&found_key_size, &found_value_size); + } mock_is_erased = [state]() -> bool { return state == it_state::ERASED; }; - mock_get_key_prefix = [&]() { return eosio::chain::make_prefix_key(contract, prefix.c_str(), it_key_size); }; - - std::unique_ptr it = my_kv_context->kv_it_create(contract, prefix.c_str(), it_key_size); + mock_is_end = [pos]() -> bool { return pos == it_pos::END; }; BOOST_CHECK(it->kv_it_status() == expected_status); } @@ -317,13 +328,18 @@ struct kv_rocksdb_fixture { mock_is_erased = [state]() -> bool { return state == it_state::ERASED; }; mock_get_kv = []() -> std::pair> { - return std::pair{ eosio::session::shared_bytes("key", 3), std::optional{} }; + auto expected_key = prefix + std::string{"key"}; + auto key = eosio::chain::make_prefix_key(contract, expected_key.c_str(), expected_key.size()); + return std::pair{ key, eosio::session::shared_bytes{"payernamValue", 13} }; }; - mock_get_key_prefix = [&]() { return eosio::chain::make_prefix_key(contract, prefix.c_str(), it_key_size); }; - std::unique_ptr it = my_kv_context->kv_it_create(contract, prefix.c_str(), it_key_size); + mock_get_key_prefix = [&]() { return eosio::chain::make_prefix_key(contract, prefix.c_str(), prefix.size()); }; + std::unique_ptr it = my_kv_context->kv_it_create(contract, prefix.c_str(), prefix.size()); if (state == it_state::ERASED) { BOOST_CHECK_THROW(it->kv_it_key_compare(mykey.c_str(), mykey.size()), kv_bad_iter); } else { + uint32_t found_key_size = 0; + uint32_t found_value_size = 0; + it->kv_it_next(&found_key_size, &found_value_size); if (keys_equal == it_keys_equal::YES) { BOOST_CHECK(it->kv_it_key_compare(mykey.c_str(), mykey.size()) == 0); } else { @@ -581,16 +597,18 @@ BOOST_FIXTURE_TEST_CASE(test_kv_it_compare_erased, kv_rocksdb_fixture) { } BOOST_FIXTURE_TEST_CASE(test_kv_it_key_compare_equal, kv_rocksdb_fixture) { -#warning Re-enable after merge -// check_kv_it_key_compare(it_state::NOT_ERASED, it_keys_equal::YES, "key"); + auto key = prefix + std::string{"key"}; + check_kv_it_key_compare(it_state::NOT_ERASED, it_keys_equal::YES, key.c_str()); } BOOST_FIXTURE_TEST_CASE(test_kv_it_key_compare_non_equal, kv_rocksdb_fixture) { - check_kv_it_key_compare(it_state::NOT_ERASED, it_keys_equal::NO, "randomkey"); + auto key = prefix + std::string{"randomkey"}; + check_kv_it_key_compare(it_state::NOT_ERASED, it_keys_equal::NO, key.c_str()); } BOOST_FIXTURE_TEST_CASE(test_kv_it_key_compare_erased, kv_rocksdb_fixture) { - check_kv_it_key_compare(it_state::ERASED, it_keys_equal::YES, "key"); + auto key = prefix + std::string{"key"}; + check_kv_it_key_compare(it_state::ERASED, it_keys_equal::YES, key.c_str()); } BOOST_FIXTURE_TEST_CASE(test_kv_it_status_end, kv_rocksdb_fixture) { @@ -599,13 +617,11 @@ BOOST_FIXTURE_TEST_CASE(test_kv_it_status_end, kv_rocksdb_fixture) { } BOOST_FIXTURE_TEST_CASE(test_kv_it_status_erased, kv_rocksdb_fixture) { -#warning Re-enable after merge -// check_test_kv_it_status(it_state::ERASED, it_pos::NOT_END, kv_it_stat::iterator_erased); + check_test_kv_it_status(it_state::ERASED, it_pos::NOT_END, kv_it_stat::iterator_erased); } BOOST_FIXTURE_TEST_CASE(test_kv_it_status_ok, kv_rocksdb_fixture) { -#warning Re-enable after merge -// check_test_kv_it_status(it_state::NOT_ERASED, it_pos::NOT_END, kv_it_stat::iterator_ok); + check_test_kv_it_status(it_state::NOT_ERASED, it_pos::NOT_END, kv_it_stat::iterator_ok); } BOOST_FIXTURE_TEST_CASE(test_kv_it_move_to_end, kv_rocksdb_fixture) { From c6106a1c33a4bba3f73dc54763288d807799cee7 Mon Sep 17 00:00:00 2001 From: Timothy Banks Date: Sat, 28 Nov 2020 10:59:50 -0500 Subject: [PATCH 2/2] Make variables const static --- .../chain/backing_store/tests/test_kv_rocksdb.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/libraries/chain/backing_store/tests/test_kv_rocksdb.cpp b/libraries/chain/backing_store/tests/test_kv_rocksdb.cpp index 5e5a5e92764..0f959a9fde6 100644 --- a/libraries/chain/backing_store/tests/test_kv_rocksdb.cpp +++ b/libraries/chain/backing_store/tests/test_kv_rocksdb.cpp @@ -165,8 +165,8 @@ struct kv_rocksdb_fixture { void check_test_kv_it_status(it_state state, it_pos pos, kv_it_stat expected_status) { mock_get_kv = []() -> std::pair> { - auto expected_key = prefix + std::string{"key"}; - auto key = eosio::chain::make_prefix_key(contract, expected_key.c_str(), expected_key.size()); + static const auto expected_key = prefix + std::string{"key"}; + static const auto key = eosio::chain::make_prefix_key(contract, expected_key.c_str(), expected_key.size()); return std::pair{ key, eosio::session::shared_bytes{"payernamValue", 13} }; }; mock_get_key_prefix = [&]() { return eosio::chain::make_prefix_key(contract, prefix.c_str(), prefix.size()); }; @@ -328,8 +328,8 @@ struct kv_rocksdb_fixture { mock_is_erased = [state]() -> bool { return state == it_state::ERASED; }; mock_get_kv = []() -> std::pair> { - auto expected_key = prefix + std::string{"key"}; - auto key = eosio::chain::make_prefix_key(contract, expected_key.c_str(), expected_key.size()); + static const auto expected_key = prefix + std::string{"key"}; + static const auto key = eosio::chain::make_prefix_key(contract, expected_key.c_str(), expected_key.size()); return std::pair{ key, eosio::session::shared_bytes{"payernamValue", 13} }; }; mock_get_key_prefix = [&]() { return eosio::chain::make_prefix_key(contract, prefix.c_str(), prefix.size()); }; @@ -597,17 +597,17 @@ BOOST_FIXTURE_TEST_CASE(test_kv_it_compare_erased, kv_rocksdb_fixture) { } BOOST_FIXTURE_TEST_CASE(test_kv_it_key_compare_equal, kv_rocksdb_fixture) { - auto key = prefix + std::string{"key"}; + static const auto key = prefix + std::string{"key"}; check_kv_it_key_compare(it_state::NOT_ERASED, it_keys_equal::YES, key.c_str()); } BOOST_FIXTURE_TEST_CASE(test_kv_it_key_compare_non_equal, kv_rocksdb_fixture) { - auto key = prefix + std::string{"randomkey"}; + static const auto key = prefix + std::string{"randomkey"}; check_kv_it_key_compare(it_state::NOT_ERASED, it_keys_equal::NO, key.c_str()); } BOOST_FIXTURE_TEST_CASE(test_kv_it_key_compare_erased, kv_rocksdb_fixture) { - auto key = prefix + std::string{"key"}; + static const auto key = prefix + std::string{"key"}; check_kv_it_key_compare(it_state::ERASED, it_keys_equal::YES, key.c_str()); }