Skip to content

Commit

Permalink
Merge pull request #687 from eosnetworkfoundation/yarkin/silkworm_for…
Browse files Browse the repository at this point in the history
…_test

Remove silkworm copy in tests
  • Loading branch information
yarkinwho committed Mar 19, 2024
2 parents c5541b3 + b50e42f commit 3cc42ee
Show file tree
Hide file tree
Showing 348 changed files with 185 additions and 118,321 deletions.
43 changes: 23 additions & 20 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ configure_file(${CMAKE_SOURCE_DIR}/contracts.hpp.in ${CMAKE_BINARY_DIR}/contract

include_directories(
${CMAKE_BINARY_DIR}
${CMAKE_SOURCE_DIR}/silkworm/node
${CMAKE_SOURCE_DIR}/silkworm/core
${CMAKE_SOURCE_DIR}/../silkworm/
${CMAKE_SOURCE_DIR}/../silkworm/third_party/evmone/lib
${CMAKE_SOURCE_DIR}/../silkworm/third_party/evmone/evmc/include
${CMAKE_SOURCE_DIR}/../silkworm/third_party/intx/include
${CMAKE_SOURCE_DIR}/../silkworm/third_party/ethash/include
${CMAKE_SOURCE_DIR}/../silkworm/third_party/secp256k1/include
${CMAKE_SOURCE_DIR}/../external/expected/include
${CMAKE_SOURCE_DIR}/external
${CMAKE_SOURCE_DIR}/external/evmone/lib
${CMAKE_SOURCE_DIR}/external/evmone/evmc/include
${CMAKE_SOURCE_DIR}/external/magic_enum/include
${CMAKE_SOURCE_DIR}/external/abseil
${CMAKE_SOURCE_DIR}/external/intx/include
${CMAKE_SOURCE_DIR}/external/ethash/include
${CMAKE_SOURCE_DIR}/external/secp256k1/include
)

add_eosio_test_executable( unit_test
Expand All @@ -38,19 +38,22 @@ add_eosio_test_executable( unit_test
${CMAKE_SOURCE_DIR}/bridge_message_tests.cpp
${CMAKE_SOURCE_DIR}/admin_actions_tests.cpp
${CMAKE_SOURCE_DIR}/main.cpp
${CMAKE_SOURCE_DIR}/silkworm/core/silkworm/rlp/encode.cpp
${CMAKE_SOURCE_DIR}/silkworm/core/silkworm/rlp/decode.cpp
${CMAKE_SOURCE_DIR}/silkworm/core/silkworm/types/block.cpp
${CMAKE_SOURCE_DIR}/silkworm/core/silkworm/types/transaction.cpp
${CMAKE_SOURCE_DIR}/silkworm/core/silkworm/types/account.cpp
${CMAKE_SOURCE_DIR}/silkworm/node/silkworm/common/stopwatch.cpp
${CMAKE_SOURCE_DIR}/silkworm/core/silkworm/common/util.cpp
${CMAKE_SOURCE_DIR}/silkworm/core/silkworm/common/endian.cpp
${CMAKE_SOURCE_DIR}/silkworm/core/silkworm/execution/address.cpp
${CMAKE_SOURCE_DIR}/silkworm/core/silkworm/crypto/ecdsa.cpp
${CMAKE_SOURCE_DIR}/external/ethash/lib/keccak/keccak.c
${CMAKE_SOURCE_DIR}/external/ethash/lib/ethash/ethash.cpp
${CMAKE_SOURCE_DIR}/external/ethash/lib/ethash/primes.c
${CMAKE_SOURCE_DIR}/../silkworm/silkworm/core/rlp/encode.cpp
${CMAKE_SOURCE_DIR}/../silkworm/silkworm/core/rlp/decode.cpp
${CMAKE_SOURCE_DIR}/../silkworm/silkworm/core/types/block.cpp
${CMAKE_SOURCE_DIR}/../silkworm/silkworm/core/types/withdrawal.cpp
${CMAKE_SOURCE_DIR}/../silkworm/silkworm/core/types/transaction.cpp
${CMAKE_SOURCE_DIR}/../silkworm/silkworm/core/types/account.cpp
${CMAKE_SOURCE_DIR}/../silkworm/silkworm/core/types/y_parity_and_chain_id.cpp
${CMAKE_SOURCE_DIR}/../silkworm/silkworm/core/common/util.cpp
${CMAKE_SOURCE_DIR}/../silkworm/silkworm/core/common/endian.cpp
${CMAKE_SOURCE_DIR}/../silkworm/silkworm/core/common/assert.cpp
${CMAKE_SOURCE_DIR}/../silkworm/silkworm/core/execution/address.cpp
${CMAKE_SOURCE_DIR}/../silkworm/silkworm/core/crypto/ecdsa.c
${CMAKE_SOURCE_DIR}/../silkworm/silkworm/infra/common/stopwatch.cpp
${CMAKE_SOURCE_DIR}/../silkworm/third_party/ethash/lib/keccak/keccak.c
${CMAKE_SOURCE_DIR}/../silkworm/third_party/ethash/lib/ethash/ethash.cpp
${CMAKE_SOURCE_DIR}/../silkworm/third_party/ethash/lib/ethash/primes.c
)

add_test(NAME consensus_tests COMMAND unit_test --report_level=detailed --color_output --run_test=evm_runtime_tests -- --eos-vm-oc)
Expand Down
2 changes: 1 addition & 1 deletion tests/account_id_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "basic_evm_tester.hpp"
#include <silkworm/execution/address.hpp>
#include <silkworm/core/execution/address.hpp>

using namespace evm_test;
struct account_id_tester : basic_evm_tester {
Expand Down
2 changes: 1 addition & 1 deletion tests/admin_actions_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <boost/test/unit_test.hpp>

#include "basic_evm_tester.hpp"
#include <silkworm/execution/address.hpp>
#include <silkworm/core/execution/address.hpp>
#include "utils.hpp"

using namespace evm_test;
Expand Down
42 changes: 29 additions & 13 deletions tests/basic_evm_tester.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "basic_evm_tester.hpp"
#include <fc/io/raw.hpp>
#include <secp256k1_recovery.h>

namespace fc {

Expand Down Expand Up @@ -97,6 +98,16 @@ FC_REFLECT(evm_test::storage_table_row, (id)(key)(value))

namespace evm_test {

// Copied from old silkworm code as new silkworm code do not expose this function
std::optional<evmc::address> public_key_to_address(const std::basic_string<uint8_t>& public_key) noexcept {
if (public_key.length() != 65 || public_key[0] != 4u) {
return std::nullopt;
}
// Ignore first byte of public key
const auto key_hash{ethash::keccak256(public_key.data() + 1, 64)};
return evmc::address(*reinterpret_cast<const evmc_address*>(&key_hash.bytes[12]));
}

evm_eoa::evm_eoa(std::basic_string<uint8_t> optional_private_key)
{
if (optional_private_key.size() == 0) {
Expand All @@ -117,7 +128,8 @@ evm_eoa::evm_eoa(std::basic_string<uint8_t> optional_private_key)
size_t serialized_result_sz = public_key.size();
secp256k1_ec_pubkey_serialize(ctx, public_key.data(), &serialized_result_sz, &pubkey, SECP256K1_EC_UNCOMPRESSED);

std::optional<evmc::address> addr = silkworm::ecdsa::public_key_to_address(public_key);
std::optional<evmc::address> addr = public_key_to_address(public_key);

BOOST_REQUIRE(!!addr);
address = *addr;
}
Expand All @@ -141,7 +153,7 @@ void evm_eoa::sign(silkworm::Transaction& trx, std::optional<uint64_t> evm_chain
if(evm_chain_id.has_value())
trx.chain_id = evm_chain_id.value();
trx.nonce = next_nonce++;
silkworm::rlp::encode(rlp, trx, true, false);
trx.encode_for_signing(rlp);
ethash::hash256 hash{silkworm::keccak256(rlp)};

secp256k1_ecdsa_recoverable_signature sig;
Expand Down Expand Up @@ -333,12 +345,14 @@ basic_evm_tester::generate_tx(const evmc::address& to, const intx::uint256& valu
const auto gas_price = get_config().gas_price;

return silkworm::Transaction{
.type = silkworm::Transaction::Type::kLegacy,
.max_priority_fee_per_gas = gas_price,
.max_fee_per_gas = gas_price,
.gas_limit = gas_limit,
.to = to,
.value = value,
silkworm::UnsignedTransaction {
.type = silkworm::TransactionType::kLegacy,
.max_priority_fee_per_gas = gas_price,
.max_fee_per_gas = gas_price,
.gas_limit = gas_limit,
.to = to,
.value = value,
}
};
}
transaction_trace_ptr basic_evm_tester::exec(const exec_input& input, const std::optional<exec_callback>& callback) {
Expand Down Expand Up @@ -476,11 +490,13 @@ evmc::address basic_evm_tester::deploy_contract(evm_eoa& eoa, evmc::bytes byteco
const auto gas_price = get_config().gas_price;

silkworm::Transaction tx{
.type = silkworm::Transaction::Type::kLegacy,
.max_priority_fee_per_gas = gas_price,
.max_fee_per_gas = gas_price,
.gas_limit = 10'000'000,
.data = std::move(bytecode),
silkworm::UnsignedTransaction {
.type = silkworm::TransactionType::kLegacy,
.max_priority_fee_per_gas = gas_price,
.max_fee_per_gas = gas_price,
.gas_limit = 10'000'000,
.data = std::move(bytecode),
}
};

eoa.sign(tx);
Expand Down
12 changes: 6 additions & 6 deletions tests/basic_evm_tester.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
#include <fc/crypto/rand.hpp>
#include <fc/crypto/hex.hpp>

#include <silkworm/crypto/ecdsa.hpp>
#include <silkworm/types/transaction.hpp>
#include <silkworm/rlp/encode.hpp>
#include <silkworm/common/util.hpp>
#include <silkworm/execution/address.hpp>
#include <silkworm/core/crypto/ecdsa.h>
#include <silkworm/core/types/transaction.hpp>
#include <silkworm/core/rlp/encode.hpp>
#include <silkworm/core/common/util.hpp>
#include <silkworm/core/execution/address.hpp>

#include <secp256k1.h>

#include <silkworm/common/util.hpp>
#include <silkworm/core/common/util.hpp>

#include <contracts.hpp>

Expand Down
2 changes: 1 addition & 1 deletion tests/blockhash_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "basic_evm_tester.hpp"
#include <silkworm/execution/address.hpp>
#include <silkworm/core/execution/address.hpp>

using namespace evm_test;
struct blockhash_evm_tester : basic_evm_tester {
Expand Down
2 changes: 1 addition & 1 deletion tests/bridge_message_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "basic_evm_tester.hpp"
#include <silkworm/execution/address.hpp>
#include <silkworm/core/execution/address.hpp>

#include "utils.hpp"

Expand Down
2 changes: 1 addition & 1 deletion tests/call_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "basic_evm_tester.hpp"
#include <silkworm/execution/address.hpp>
#include <silkworm/core/execution/address.hpp>

using intx::operator""_u256;

Expand Down
2 changes: 1 addition & 1 deletion tests/chainid_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "basic_evm_tester.hpp"
#include <silkworm/execution/address.hpp>
#include <silkworm/core/execution/address.hpp>

using namespace evm_test;
struct chain_id_tester : basic_evm_tester {
Expand Down
29 changes: 15 additions & 14 deletions tests/evm_runtime_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,23 @@

#include "eosio.system_tester.hpp"

#include <silkworm/common/as_range.hpp>
#include <silkworm/common/cast.hpp>
#include <silkworm/common/endian.hpp>
#include <silkworm/common/rlp_err.hpp>
#include <silkworm/common/stopwatch.hpp>
#include <silkworm/common/terminal.hpp>
#include <silkworm/common/test_util.hpp>
#include <silkworm/types/block.hpp>
#include <silkworm/types/transaction.hpp>
#include <silkworm/rlp/encode.hpp>

#include <silkworm/state/state.hpp>
#include <silkworm/consensus/blockchain.hpp>
#include <silkworm/core/common/as_range.hpp>
#include <silkworm/core/common/cast.hpp>
#include <silkworm/core/common/endian.hpp>
#include <silkworm/core/common/decoding_result.hpp>
#include <silkworm/infra/common/stopwatch.hpp>
#include <silkworm/infra/common/terminal.hpp>
#include <silkworm/core/common/test_util.hpp>
#include <silkworm/core/types/block.hpp>
#include <silkworm/core/types/transaction.hpp>
#include <silkworm/core/rlp/encode.hpp>

#include <silkworm/core/state/state.hpp>
#include <silkworm/core/protocol/blockchain.hpp>

#include <nlohmann/json.hpp>
#include <ethash/keccak.hpp>
#include <magic_enum.hpp>

using namespace eosio_system;
using namespace eosio;
Expand Down Expand Up @@ -883,7 +884,7 @@ struct evm_runtime_tester : eosio_system_tester, silkworm::State {

Block block;
ByteView view{*rlp};
if (rlp::decode(view, block) != DecodingResult::kOk || !view.empty()) {
if (!rlp::decode(view, block) || !view.empty()) {
if (invalid) {
dlog("invalid=kPassed 2");
return Status::kPassed;
Expand Down
2 changes: 1 addition & 1 deletion tests/exec_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "basic_evm_tester.hpp"
#include <silkworm/execution/address.hpp>
#include <silkworm/core/execution/address.hpp>

using intx::operator""_u256;

Expand Down
42 changes: 24 additions & 18 deletions tests/gas_fee_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,14 @@ try {
auto restore_nonce = faucet_eoa.next_nonce;

silkworm::Transaction tx{
.type = silkworm::Transaction::Type::kLegacy,
.max_priority_fee_per_gas = suggested_gas_price - 1,
.max_fee_per_gas = suggested_gas_price - 1,
.gas_limit = 21000,
.to = recipient.address,
.value = 1,
silkworm::UnsignedTransaction {
.type = silkworm::TransactionType::kLegacy,
.max_priority_fee_per_gas = suggested_gas_price - 1,
.max_fee_per_gas = suggested_gas_price - 1,
.gas_limit = 21000,
.to = recipient.address,
.value = 1,
}
};
faucet_eoa.sign(tx);

Expand All @@ -162,12 +164,14 @@ try {
// Exactly matching gas price is accepted

silkworm::Transaction tx{
.type = silkworm::Transaction::Type::kLegacy,
.max_priority_fee_per_gas = suggested_gas_price,
.max_fee_per_gas = suggested_gas_price,
.gas_limit = 21000,
.to = recipient.address,
.value = 1,
silkworm::UnsignedTransaction {
.type = silkworm::TransactionType::kLegacy,
.max_priority_fee_per_gas = suggested_gas_price,
.max_fee_per_gas = suggested_gas_price,
.gas_limit = 21000,
.to = recipient.address,
.value = 1,
}
};
faucet_eoa.sign(tx);
pushtx(tx);
Expand All @@ -177,12 +181,14 @@ try {
// Higher gas price is also okay

silkworm::Transaction tx{
.type = silkworm::Transaction::Type::kLegacy,
.max_priority_fee_per_gas = suggested_gas_price + 1,
.max_fee_per_gas = suggested_gas_price + 1,
.gas_limit = 21000,
.to = recipient.address,
.value = 1,
silkworm::UnsignedTransaction {
.type = silkworm::TransactionType::kLegacy,
.max_priority_fee_per_gas = suggested_gas_price + 1,
.max_fee_per_gas = suggested_gas_price + 1,
.gas_limit = 21000,
.to = recipient.address,
.value = 1,
}
};
faucet_eoa.sign(tx);
pushtx(tx);
Expand Down
Loading

0 comments on commit 3cc42ee

Please sign in to comment.