Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
6.0.0


2 changes: 2 additions & 0 deletions INSTALL.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,5 @@ bazel build @com_github_bazelbuild_buildtools//buildifier:buildifier

sudo apt-get install python3.10-dev -y
sudo apt-get install python3-dev -y


12 changes: 10 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,25 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "hedron_compile_commands",
strip_prefix = "bazel-compile-commands-extractor-4f28899228fb3ad0126897876f147ca15026151e",
#Replace the commit hash (4f28899228fb3ad0126897876f147ca15026151e) with the latest commit hash from the repo
url = "https://github.com/hedronvision/bazel-compile-commands-extractor/archive/4f28899228fb3ad0126897876f147ca15026151e.tar.gz",
strip_prefix = "bazel-compile-commands-extractor-4f28899228fb3ad0126897876f147ca15026151e",
)

load("@hedron_compile_commands//:workspace_setup.bzl", "hedron_compile_commands_setup")

hedron_compile_commands_setup()

load("@hedron_compile_commands//:workspace_setup_transitive.bzl", "hedron_compile_commands_setup_transitive")

hedron_compile_commands_setup_transitive()

load("@hedron_compile_commands//:workspace_setup_transitive_transitive.bzl", "hedron_compile_commands_setup_transitive_transitive")

hedron_compile_commands_setup_transitive_transitive()

load("@hedron_compile_commands//:workspace_setup_transitive_transitive_transitive.bzl", "hedron_compile_commands_setup_transitive_transitive_transitive")

hedron_compile_commands_setup_transitive_transitive_transitive()

load("//:repositories.bzl", "nexres_repositories")
Expand Down Expand Up @@ -210,7 +218,7 @@ http_archive(
http_archive(
name = "pybind11_bazel",
strip_prefix = "pybind11_bazel-2.11.1.bzl.1",
urls = ["https://github.com/pybind/pybind11_bazel/archive/refs/tags/v2.11.1.bzl.1.zip"]
urls = ["https://github.com/pybind/pybind11_bazel/archive/refs/tags/v2.11.1.bzl.1.zip"],
)

http_archive(
Expand Down
1 change: 0 additions & 1 deletion api/ip_address.config

This file was deleted.

12 changes: 6 additions & 6 deletions chain/storage/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,24 @@ cc_library(

cc_test(
name = "kv_storage_test",
size = "small", # Set the size to "small"
timeout = "short", # Set the timeout to "short"
srcs = ["kv_storage_test.cpp"],
deps = [
":leveldb",
":memory_db",
"//common/test:test_main",
],
timeout = "short", # Set the timeout to "short"
size = "small", # Set the size to "small"
)

cc_test(
name = "leveldb_test",
size = "small", # Set the size to "small"
timeout = "short", # Set the timeout to "short"
srcs = ["leveldb_test.cpp"],
deps = [
":leveldb",
"//platform/statistic:stats",
"//common/test:test_main",
"//platform/statistic:stats",
],
timeout = "short", # Set the timeout to "short"
size = "small", # Set the size to "small"
)
)
99 changes: 86 additions & 13 deletions chain/storage/kv_storage_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,37 +103,110 @@ TEST_P(KVStorageTest, SetValueWithVersion) {

TEST_P(KVStorageTest, GetAllValueWithVersion) {
{
std::map<std::string, std::pair<std::string, int> > expected_list{
std::map<std::string, std::pair<std::string, int>> expected_list{
std::make_pair("test_key", std::make_pair("test_value", 1))};

EXPECT_EQ(storage->SetValueWithVersion("test_key", "test_value", 0), 0);
EXPECT_EQ(storage->GetAllItems(), expected_list);
}

{
std::map<std::string, std::pair<std::string, int> > expected_list{
std::map<std::string, std::pair<std::string, int>> expected_list{
std::make_pair("test_key", std::make_pair("test_value_v2", 2))};
EXPECT_EQ(storage->SetValueWithVersion("test_key", "test_value_v2", 1), 0);
EXPECT_EQ(storage->GetAllItems(), expected_list);
}

{
std::map<std::string, std::pair<std::string, int> > expected_list{
std::map<std::string, std::pair<std::string, int>> expected_list{
std::make_pair("test_key_v1", std::make_pair("test_value1", 1)),
std::make_pair("test_key", std::make_pair("test_value_v2", 2))};
EXPECT_EQ(storage->SetValueWithVersion("test_key_v1", "test_value1", 0), 0);
EXPECT_EQ(storage->GetAllItems(), expected_list);
}
}

TEST_P(KVStorageTest, SetValueWithSeq) {
EXPECT_EQ(storage->SetValueWithSeq("test_key", "test_value", 2), 0);

EXPECT_EQ(storage->SetValueWithSeq("test_key", "test_value", 1), -2);

EXPECT_EQ(storage->GetValueWithSeq("test_key", static_cast<uint64_t>(1)),
std::make_pair(std::string(""), static_cast<uint64_t>(0)));
EXPECT_EQ(
storage->GetValueWithSeq("test_key", 2),
std::make_pair(std::string("test_value"), static_cast<uint64_t>(2)));

EXPECT_EQ(storage->SetValueWithSeq("test_key", "test_value_v2", 3), 0);

EXPECT_EQ(storage->GetValueWithSeq("test_key", 1),
std::make_pair(std::string(""), static_cast<uint64_t>(0)));

EXPECT_EQ(
storage->GetValueWithSeq("test_key", 2),
std::make_pair(std::string("test_value"), static_cast<uint64_t>(2)));

EXPECT_EQ(
storage->GetValueWithSeq("test_key", 3),
std::make_pair(std::string("test_value_v2"), static_cast<uint64_t>(3)));

EXPECT_EQ(storage->GetValueWithSeq("test_key", 4),
std::make_pair(std::string(""), static_cast<uint64_t>(0)));
}

TEST_P(KVStorageTest, GetAllValueWithSeq) {
typedef std::vector<std::pair<std::string, uint64_t>> List;
{
std::map<std::string, std::vector<std::pair<std::string, uint64_t>>>
expected_list{
std::make_pair("test_key", List{std::make_pair("test_value", 1)})};

EXPECT_EQ(storage->SetValueWithSeq("test_key", "test_value", 1), 0);
EXPECT_EQ(storage->GetAllItemsWithSeq(), expected_list);
}

{
std::map<std::string, std::vector<std::pair<std::string, uint64_t>>>
expected_list{std::make_pair("test_key",
List{std::make_pair("test_value", 1),
std::make_pair("test_value_v2", 2)})};
EXPECT_EQ(storage->SetValueWithSeq("test_key", "test_value_v2", 2), 0);
EXPECT_EQ(storage->GetAllItemsWithSeq(), expected_list);
}

{
std::map<std::string, std::vector<std::pair<std::string, uint64_t>>>
expected_list{std::make_pair("test_key_v1",
List{std::make_pair("test_value1", 1)}),
std::make_pair("test_key",
List{std::make_pair("test_value", 1),
std::make_pair("test_value_v2", 2)})};
EXPECT_EQ(storage->SetValueWithSeq("test_key_v1", "test_value1", 1), 0);
EXPECT_EQ(storage->GetAllItemsWithSeq(), expected_list);
}

{
storage->SetMaxHistoryNum(2);
std::map<std::string, std::vector<std::pair<std::string, uint64_t>>>
expected_list{
std::make_pair("test_key_v1",
List{std::make_pair("test_value1", 1)}),
std::make_pair("test_key", List{std::make_pair("test_value3", 3),
std::make_pair("test_value4", 4)})};
EXPECT_EQ(storage->SetValueWithSeq("test_key", "test_value3", 3), 0);
EXPECT_EQ(storage->SetValueWithSeq("test_key", "test_value4", 4), 0);
EXPECT_EQ(storage->GetAllItemsWithSeq(), expected_list);
}
}

TEST_P(KVStorageTest, GetKeyRange) {
EXPECT_EQ(storage->SetValueWithVersion("1", "value1", 0), 0);
EXPECT_EQ(storage->SetValueWithVersion("2", "value2", 0), 0);
EXPECT_EQ(storage->SetValueWithVersion("3", "value3", 0), 0);
EXPECT_EQ(storage->SetValueWithVersion("4", "value4", 0), 0);

{
std::map<std::string, std::pair<std::string, int> > expected_list{
std::map<std::string, std::pair<std::string, int>> expected_list{
std::make_pair("1", std::make_pair("value1", 1)),
std::make_pair("2", std::make_pair("value2", 1)),
std::make_pair("3", std::make_pair("value3", 1)),
Expand All @@ -143,38 +216,38 @@ TEST_P(KVStorageTest, GetKeyRange) {

EXPECT_EQ(storage->SetValueWithVersion("3", "value3_1", 1), 0);
{
std::map<std::string, std::pair<std::string, int> > expected_list{
std::map<std::string, std::pair<std::string, int>> expected_list{
std::make_pair("1", std::make_pair("value1", 1)),
std::make_pair("2", std::make_pair("value2", 1)),
std::make_pair("3", std::make_pair("value3_1", 2)),
std::make_pair("4", std::make_pair("value4", 1))};
EXPECT_EQ(storage->GetKeyRange("1", "4"), expected_list);
}
{
std::map<std::string, std::pair<std::string, int> > expected_list{
std::map<std::string, std::pair<std::string, int>> expected_list{
std::make_pair("1", std::make_pair("value1", 1)),
std::make_pair("2", std::make_pair("value2", 1)),
std::make_pair("3", std::make_pair("value3_1", 2)),
};
EXPECT_EQ(storage->GetKeyRange("1", "3"), expected_list);
}
{
std::map<std::string, std::pair<std::string, int> > expected_list{
std::map<std::string, std::pair<std::string, int>> expected_list{
std::make_pair("2", std::make_pair("value2", 1)),
std::make_pair("3", std::make_pair("value3_1", 2)),
std::make_pair("4", std::make_pair("value4", 1))};
EXPECT_EQ(storage->GetKeyRange("2", "4"), expected_list);
}
{
std::map<std::string, std::pair<std::string, int> > expected_list{
std::map<std::string, std::pair<std::string, int>> expected_list{
std::make_pair("1", std::make_pair("value1", 1)),
std::make_pair("2", std::make_pair("value2", 1)),
std::make_pair("3", std::make_pair("value3_1", 2)),
std::make_pair("4", std::make_pair("value4", 1))};
EXPECT_EQ(storage->GetKeyRange("0", "5"), expected_list);
}
{
std::map<std::string, std::pair<std::string, int> > expected_list{
std::map<std::string, std::pair<std::string, int>> expected_list{
std::make_pair("2", std::make_pair("value2", 1)),
std::make_pair("3", std::make_pair("value3_1", 2)),
};
Expand All @@ -184,11 +257,11 @@ TEST_P(KVStorageTest, GetKeyRange) {

TEST_P(KVStorageTest, GetHistory) {
{
std::vector<std::pair<std::string, int> > expected_list{};
std::vector<std::pair<std::string, int>> expected_list{};
EXPECT_EQ(storage->GetHistory("1", 1, 5), expected_list);
}
{
std::vector<std::pair<std::string, int> > expected_list{
std::vector<std::pair<std::string, int>> expected_list{
std::make_pair("value3", 3), std::make_pair("value2", 2),
std::make_pair("value1", 1)};

Expand All @@ -200,7 +273,7 @@ TEST_P(KVStorageTest, GetHistory) {
}

{
std::vector<std::pair<std::string, int> > expected_list{
std::vector<std::pair<std::string, int>> expected_list{
std::make_pair("value5", 5), std::make_pair("value4", 4),
std::make_pair("value3", 3), std::make_pair("value2", 2),
std::make_pair("value1", 1)};
Expand All @@ -214,7 +287,7 @@ TEST_P(KVStorageTest, GetHistory) {
}

{
std::vector<std::pair<std::string, int> > expected_list{
std::vector<std::pair<std::string, int>> expected_list{
std::make_pair("value7", 7), std::make_pair("value6", 6)};

EXPECT_EQ(storage->GetTopHistory("1", 2), expected_list);
Expand Down
Loading