From fca0c8df0a3e227e62b40d7355ca0eddfef73920 Mon Sep 17 00:00:00 2001 From: lupin012 <58134934+lupin012@users.noreply.github.com> Date: Wed, 8 May 2024 07:24:45 +0200 Subject: [PATCH] add unit tests --- silkworm/rpc/types/call.hpp | 5 ++-- silkworm/rpc/types/call_test.cpp | 40 ++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/silkworm/rpc/types/call.hpp b/silkworm/rpc/types/call.hpp index 893579357f..7708ac09e4 100644 --- a/silkworm/rpc/types/call.hpp +++ b/silkworm/rpc/types/call.hpp @@ -45,7 +45,7 @@ struct Call { std::optional nonce; AccessList access_list; - [[nodiscard]] silkworm::Transaction to_transaction(const std::optional& override_gas_price = std::nullopt, + [[nodiscard]] silkworm::Transaction to_transaction(const std::optional& override_gas_price = std::nullopt, const std::optional& override_access_list = std::nullopt, const std::optional override_nonce = std::nullopt) const { silkworm::Transaction txn{}; @@ -55,8 +55,7 @@ struct Call { txn.to = to; if (override_nonce) { txn.nonce = *override_nonce; - } - else if (nonce) { + } else if (nonce) { txn.nonce = *nonce; } diff --git a/silkworm/rpc/types/call_test.cpp b/silkworm/rpc/types/call_test.cpp index 868f3ed787..92e3cfca97 100644 --- a/silkworm/rpc/types/call_test.cpp +++ b/silkworm/rpc/types/call_test.cpp @@ -222,4 +222,44 @@ TEST_CASE("create call with AccessList", "[rpc][types][call]") { CHECK(txn.access_list == access_list); } +TEST_CASE("create call with no AccessList and pass it to_transaction", "[rpc][types][call]") { + Call call{ + std::nullopt, + std::nullopt, + 235, // gas + 21000, // gas_price + std::nullopt, // max_priority_fee_per_gas + std::nullopt, // max_fee_per_gas + 31337, // value + {}, // data + 1}; // nonce + silkworm::Transaction txn = call.to_transaction(std::nullopt, access_list); + CHECK(txn.gas_limit == 235); + CHECK(txn.max_fee_per_gas == 21000); + CHECK(txn.max_priority_fee_per_gas == 21000); + CHECK(txn.nonce == 1); + CHECK(!txn.access_list.empty()); + CHECK(txn.access_list == access_list); +} + +TEST_CASE("create call with no nonce and pass it to_transaction", "[rpc][types][call]") { + uint64_t nonce = 5; + Call call{ + std::nullopt, + std::nullopt, + 235, // gas + 21000, // gas_price + std::nullopt, // max_priority_fee_per_gas + std::nullopt, // max_fee_per_gas + 31337, // value + {}, // data + std::nullopt}; // nonce + silkworm::Transaction txn = call.to_transaction(std::nullopt, std::nullopt, nonce); + CHECK(txn.gas_limit == 235); + CHECK(txn.max_fee_per_gas == 21000); + CHECK(txn.max_priority_fee_per_gas == 21000); + CHECK(txn.nonce == nonce); + CHECK(txn.access_list.empty()); +} + } // namespace silkworm::rpc