diff --git a/silkworm/node/db/buffer_test.cpp b/silkworm/node/db/buffer_test.cpp index 28fcd45504..71072920af 100644 --- a/silkworm/node/db/buffer_test.cpp +++ b/silkworm/node/db/buffer_test.cpp @@ -107,7 +107,11 @@ TEST_CASE("Account update") { Buffer buffer{txn, 0}; buffer.begin_block(1); buffer.update_account(address, /*initial=*/std::nullopt, current_account); - REQUIRE(buffer.account_changes().empty() == false); + REQUIRE(!buffer.account_changes().empty()); + // Current state batch: current account address + current account encoding + CHECK(buffer.current_batch_state_size() == kAddressLength + current_account.encoding_length_for_storage()); + // State history batch: current block + initial account address + initial account encoding (empty) + CHECK(buffer.current_batch_history_size() == sizeof(uint64_t) + kAddressLength); REQUIRE_NOTHROW(buffer.write_to_db()); auto account_changeset{db::open_cursor(txn, table::kAccountChangeSet)}; @@ -122,7 +126,7 @@ TEST_CASE("Account update") { auto changeset_address{bytes_to_address(data_value_view)}; REQUIRE(changeset_address == address); data_value_view.remove_prefix(kAddressLength); - REQUIRE(data_value_view.length() == 0); + REQUIRE(data_value_view.empty()); } SECTION("Changed EOA account") { @@ -138,7 +142,11 @@ TEST_CASE("Account update") { Buffer buffer{txn, 0}; buffer.begin_block(1); buffer.update_account(address, /*initial=*/initial_account, current_account); - REQUIRE(buffer.account_changes().empty() == false); + REQUIRE(!buffer.account_changes().empty()); + // Current state batch: current account address + current account encoding + CHECK(buffer.current_batch_state_size() == kAddressLength + current_account.encoding_length_for_storage()); + // State history batch: current block + initial account address + initial account encoding + CHECK(buffer.current_batch_history_size() == sizeof(uint64_t) + kAddressLength + initial_account.encoding_length_for_storage()); REQUIRE_NOTHROW(buffer.write_to_db()); auto account_changeset{db::open_cursor(txn, table::kAccountChangeSet)}; @@ -153,13 +161,13 @@ TEST_CASE("Account update") { auto changeset_address{bytes_to_address(data_value_view)}; REQUIRE(changeset_address == address); data_value_view.remove_prefix(kAddressLength); - REQUIRE(data_value_view.length() != 0); + REQUIRE(!data_value_view.empty()); auto previous_account{Account::from_encoded_storage(data_value_view)}; CHECK(previous_account == initial_account); } - SECTION("Delete Contract account") { + SECTION("Delete contract account") { const auto address{0xbe00000000000000000000000000000000000000_address}; Account account; account.incarnation = kDefaultIncarnation; @@ -167,8 +175,12 @@ TEST_CASE("Account update") { Buffer buffer{txn, 0}; buffer.begin_block(1); - buffer.update_account(address, /*initial=*/account, std::nullopt); - REQUIRE(buffer.account_changes().empty() == false); + buffer.update_account(address, /*initial=*/account, /*current=*/std::nullopt); + REQUIRE(!buffer.account_changes().empty()); + // Current state batch: initial account for delete + (initial account + incarnation) for incarnation + CHECK(buffer.current_batch_state_size() == kAddressLength + (kAddressLength + kIncarnationLength)); + // State history batch: current block + initial account address + initial account encoding + CHECK(buffer.current_batch_history_size() == sizeof(uint64_t) + kAddressLength + account.encoding_length_for_storage()); REQUIRE_NOTHROW(buffer.write_to_db()); auto incarnations{db::open_cursor(txn, table::kIncarnationMap)}; @@ -192,6 +204,8 @@ TEST_CASE("Account update") { buffer.begin_block(1); buffer.update_account(address, /*initial=*/initial_account, current_account); REQUIRE(buffer.account_changes().empty()); + CHECK(buffer.current_batch_state_size() == 0); // No change in current state batch + CHECK(buffer.current_batch_history_size() == 0); // No change in state history batch REQUIRE_NOTHROW(buffer.write_to_db()); auto account_changeset{db::open_cursor(txn, table::kAccountChangeSet)};