From eb4df8c9f926ee1cad5e1437b8d784ef0d8bfe67 Mon Sep 17 00:00:00 2001 From: "Charles.Liu" Date: Tue, 28 Feb 2023 14:52:14 +0800 Subject: [PATCH 1/4] impl tvm_runtime --- src/xtopcom/CMakeLists.txt | 2 + .../xdata/src/xtop_action_generator.cpp | 5 +- .../xevm_common/xevm_transaction_result.h | 2 + .../xstate_accessor/src/xstate_accessor.cpp | 6 + src/xtopcom/xtvm_runtime/CMakeLists.txt | 13 + src/xtopcom/xtvm_runtime/src/xerror.cpp | 48 ++++ src/xtopcom/xtvm_runtime/src/xtvm.cpp | 48 ++++ .../xtvm_runtime/src/xtvm_action_runner.cpp | 63 +++++ src/xtopcom/xtvm_runtime/src/xtvm_context.cpp | 89 +++++++ src/xtopcom/xtvm_runtime/src/xtvm_logic.cpp | 130 ++++++++++ src/xtopcom/xtvm_runtime/src/xtvm_storage.cpp | 228 ++++++++++++++++++ src/xtopcom/xtvm_runtime/xerror.h | 39 +++ src/xtopcom/xtvm_runtime/xtvm.h | 45 ++++ src/xtopcom/xtvm_runtime/xtvm_action_runner.h | 46 ++++ src/xtopcom/xtvm_runtime/xtvm_context.h | 41 ++++ src/xtopcom/xtvm_runtime/xtvm_logic.h | 51 ++++ src/xtopcom/xtvm_runtime/xtvm_storage.h | 93 +++++++ 17 files changed, 947 insertions(+), 2 deletions(-) create mode 100644 src/xtopcom/xtvm_runtime/CMakeLists.txt create mode 100644 src/xtopcom/xtvm_runtime/src/xerror.cpp create mode 100644 src/xtopcom/xtvm_runtime/src/xtvm.cpp create mode 100644 src/xtopcom/xtvm_runtime/src/xtvm_action_runner.cpp create mode 100644 src/xtopcom/xtvm_runtime/src/xtvm_context.cpp create mode 100644 src/xtopcom/xtvm_runtime/src/xtvm_logic.cpp create mode 100644 src/xtopcom/xtvm_runtime/src/xtvm_storage.cpp create mode 100644 src/xtopcom/xtvm_runtime/xerror.h create mode 100644 src/xtopcom/xtvm_runtime/xtvm.h create mode 100644 src/xtopcom/xtvm_runtime/xtvm_action_runner.h create mode 100644 src/xtopcom/xtvm_runtime/xtvm_context.h create mode 100644 src/xtopcom/xtvm_runtime/xtvm_logic.h create mode 100644 src/xtopcom/xtvm_runtime/xtvm_storage.h diff --git a/src/xtopcom/CMakeLists.txt b/src/xtopcom/CMakeLists.txt index 0a32bc296..0a84d0239 100644 --- a/src/xtopcom/CMakeLists.txt +++ b/src/xtopcom/CMakeLists.txt @@ -85,3 +85,5 @@ if (XBUILD_CONSORTIUM) endif() add_subdirectory(xstatistic) +add_subdirectory(xtvm_engine_rs) +add_subdirectory(xtvm_runtime) \ No newline at end of file diff --git a/src/xtopcom/xdata/src/xtop_action_generator.cpp b/src/xtopcom/xdata/src/xtop_action_generator.cpp index b58f418d3..669589f17 100644 --- a/src/xtopcom/xdata/src/xtop_action_generator.cpp +++ b/src/xtopcom/xdata/src/xtop_action_generator.cpp @@ -38,9 +38,10 @@ std::unique_ptr xtop_action_generator::generate case base::enum_vaccount_addr_type_native_contract: // just for followup transfer tx case base::enum_vaccount_addr_type_secp256k1_user_account: - case base::enum_vaccount_addr_type_secp256k1_eth_user_account: return top::make_unique(tx); - + + // T8 address use for tvm (solidity tx) + case base::enum_vaccount_addr_type_secp256k1_eth_user_account: case base::enum_vaccount_addr_type_secp256k1_evm_user_account: return top::make_unique(tx); diff --git a/src/xtopcom/xevm_common/xevm_transaction_result.h b/src/xtopcom/xevm_common/xevm_transaction_result.h index a5e31e33c..311372afb 100644 --- a/src/xtopcom/xevm_common/xevm_transaction_result.h +++ b/src/xtopcom/xevm_common/xevm_transaction_result.h @@ -42,6 +42,7 @@ class xevm_log_t { using xevm_logs_t = std::vector; /// same as TransactionStatus in `evm_engine_rs/engine/src/parameters.rs` +// 23.02.22 future update to: `xtvm_engine_rs/tvm-engine/src/types.rs` enum xevm_transaction_status_t : uint32_t { Success = 0, Revert = 1, @@ -54,6 +55,7 @@ enum xevm_transaction_status_t : uint32_t { OtherExecuteError = 5, Invalid = 32, + FAILED = UINT32_MAX, }; class xevm_transaction_result_t { diff --git a/src/xtopcom/xstate_accessor/src/xstate_accessor.cpp b/src/xtopcom/xstate_accessor/src/xstate_accessor.cpp index f3b863b23..d2dfcf300 100644 --- a/src/xtopcom/xstate_accessor/src/xstate_accessor.cpp +++ b/src/xtopcom/xstate_accessor/src/xstate_accessor.cpp @@ -357,6 +357,12 @@ void xtop_state_accessor::clear_property(properties::xproperty_identifier_t cons return; } + // should check if property exist, the below code `bstate_->load_xxx` has `xerror()` if not exist. + if (!bstate_->find_property(property_id.full_name())) { + ec = error::xerrc_t::property_not_exist; + return; + } + switch (property_id.type()) { case properties::xproperty_type_t::map: { diff --git a/src/xtopcom/xtvm_runtime/CMakeLists.txt b/src/xtopcom/xtvm_runtime/CMakeLists.txt new file mode 100644 index 000000000..5a58d3de1 --- /dev/null +++ b/src/xtopcom/xtvm_runtime/CMakeLists.txt @@ -0,0 +1,13 @@ +add_compile_options(-Wpedantic) + +aux_source_directory(./src src_dir) +add_library(xtvm_runtime STATIC ${src_dir}) + +add_dependencies(xtvm_runtime tvm_engine) +get_target_property(TVM_ENGINE_DIR tvm_engine LOCATION) +target_link_libraries(xtvm_runtime PRIVATE ${TVM_ENGINE_DIR}/libtvm_engine.a) +target_include_directories(xtvm_runtime PRIVATE ${CMAKE_SOURCE_DIR}/src/xtopcom/xtvm_engine_rs/tvm-c-api) + +add_dependencies(xtvm_runtime xstate_accessor xevm_common xbasic xcommon) + +target_link_libraries(xtvm_runtime PRIVATE tvm-c-api xstate_accessor xevm_common xbasic xcommon protobuf) diff --git a/src/xtopcom/xtvm_runtime/src/xerror.cpp b/src/xtopcom/xtvm_runtime/src/xerror.cpp new file mode 100644 index 000000000..a2df4455c --- /dev/null +++ b/src/xtopcom/xtvm_runtime/src/xerror.cpp @@ -0,0 +1,48 @@ +// Copyright (c) 2017-present Telos Foundation & contributors +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include "xtvm_runtime/xerror.h" + +NS_BEG3(top, tvm, error) + +static char const * const errc_to_string(int code) { + auto const ec = static_cast(code); + + switch (ec) { + case xerrc_t::ok: + return "ok"; + + case xerrc_t::protobuf_serilized_error: + return "protobuf error"; + + default: + return "unknown tvm runtime error"; + } +} + +std::error_code make_error_code(xerrc_t const errc) noexcept { + return std::error_code(static_cast(errc), tvm_category()); +} + +std::error_condition make_error_condition(xerrc_t const errc) noexcept { + return std::error_condition(static_cast(errc), tvm_category()); +} + +class xtop_tvm_category final : public std::error_category { + char const * name() const noexcept override { + return "tvm"; + } + + std::string message(int errc) const override { + return errc_to_string(errc); + } +}; +using xtvm_category_t = xtop_tvm_category; + +std::error_category const & tvm_category() { + static xtvm_category_t category{}; + return category; +} + +NS_END3 diff --git a/src/xtopcom/xtvm_runtime/src/xtvm.cpp b/src/xtopcom/xtvm_runtime/src/xtvm.cpp new file mode 100644 index 000000000..a81a95251 --- /dev/null +++ b/src/xtopcom/xtvm_runtime/src/xtvm.cpp @@ -0,0 +1,48 @@ +// Copyright (c) 2017-present Telos Foundation & contributors +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include "xtvm_runtime/xtvm.h" + +#include "xdata/xtop_action.h" +#include "xdata/xtop_action_generator.h" +#include "xtvm_runtime/xtvm_action_runner.h" +#include "xtvm_runtime/xtvm_context.h" + +NS_BEG2(top, tvm) + +xtop_vm::xtop_vm(statectx::xstatectx_face_ptr_t const statectx) : m_statectx{statectx} { +} + +txexecutor::enum_execute_result_type xtop_vm::execute(txexecutor::xvm_input_t const & input, txexecutor::xvm_output_t & output) { + m_statectx = input.get_statectx(); + auto action = contract_runtime::xaction_generator_t::generate(input.get_tx()); + + evm_common::xevm_transaction_result_t action_result; + + try { + action_result = execute_action(std::move(action), input.get_para()); + } catch (top::error::xtop_error_t & eh) { + // should be implment bug here: + xerror("tvm: caught error: %s %s", eh.category().name(), eh.what()); + } catch (std::exception const & eh) { + xerror("tvm: caught unknown exception: %s", eh.what()); + } + + output.m_tx_result = action_result; + if (action_result.status == evm_common::xevm_transaction_status_t::FAILED) { + return txexecutor::enum_exec_error_vm_execute; + } + return txexecutor::enum_exec_success; +} + +evm_common::xevm_transaction_result_t xtop_vm::execute_action(std::unique_ptr action, txexecutor::xvm_para_t const & vm_para) { + // 1. build action runtime context with action and vm_para + auto vm_context = top::make_unique(std::move(action), vm_para); + + // 2. run action runtime on this context, return `evm_common::xevm_transaction_result_t` + auto vm_runner = xtvm_action_runner_t{m_statectx}; + return vm_runner.execute_action(std::move(vm_context)); +} + +NS_END2 \ No newline at end of file diff --git a/src/xtopcom/xtvm_runtime/src/xtvm_action_runner.cpp b/src/xtopcom/xtvm_runtime/src/xtvm_action_runner.cpp new file mode 100644 index 000000000..ece6b3480 --- /dev/null +++ b/src/xtopcom/xtvm_runtime/src/xtvm_action_runner.cpp @@ -0,0 +1,63 @@ +// Copyright (c) 2017-present Telos Foundation & contributors +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include "xtvm_runtime/xtvm_action_runner.h" + +#include "protobuf_types/pparameters.pb.h" +#include "xcommon/xeth_address.h" +#include "xcontract_runtime/xerror/xerror.h" +#include "xtvm_engine_rs/tvm-c-api/tvm_engine_interface.h" +#include "xtvm_engine_rs/tvm-c-api/tvm_import_instance.h" +#include "xtvm_runtime/xerror.h" +#include "xtvm_runtime/xtvm_logic.h" +#include "xtvm_runtime/xtvm_storage.h" + +NS_BEG2(top, tvm) + +xtop_vm_action_runner::xtop_vm_action_runner(statectx::xstatectx_face_ptr_t const statectx) : m_statectx{statectx} { +} + +evm_common::xevm_transaction_result_t xtop_vm_action_runner::execute_action(std::unique_ptr context) { + evm_common::xevm_transaction_result_t result; + + auto storage = top::make_unique(m_statectx); + std::shared_ptr logic_ptr = std::make_shared(top::make_observer(storage.get()), top::make_observer(context.get())); + + tvm_import_instance::instance()->add_logic(logic_ptr); + + // call vm engine in rust. + bool bool_result = call(); + + // fetch result + auto return_result_bytes = logic_ptr->get_return_value(); + + xdbg("xtop_vm_action_runner::execute_action result %s return_bytes_size: %zu", bool_result ? "success" : "fail", return_result_bytes.size()); + + tvm_import_instance::instance()->remove_logic(); + + tvm_engine::parameters::PReturnResult return_result; + auto ret = return_result.ParseFromString(top::to_string(return_result_bytes)); + + if (!ret) { + top::error::throw_error(top::tvm::error::xerrc_t::protobuf_serilized_error); + } + result.set_status(return_result.status()); + result.extra_msg = top::to_hex_prefixed(return_result.status_data()); + result.used_gas = return_result.gas_used(); + // logs: + for (int i = 0; i < return_result.logs_size(); ++i) { + common::xeth_address_t address = common::xeth_address_t::build_from(top::to_bytes(return_result.logs(i).address().value())); + xbytes_t data = top::to_bytes(return_result.logs(i).data()); + evm_common::xh256s_t topics; + for (int j = 0; j < return_result.logs(i).topics_size(); ++j) { + topics.push_back(evm_common::xh256_t(top::to_bytes(return_result.logs(i).topics(j).data()))); + } + evm_common::xevm_log_t log(address, topics, data); + result.logs.push_back(log); + } + + return result; +} + +NS_END2 \ No newline at end of file diff --git a/src/xtopcom/xtvm_runtime/src/xtvm_context.cpp b/src/xtopcom/xtvm_runtime/src/xtvm_context.cpp new file mode 100644 index 000000000..bc2b41dcb --- /dev/null +++ b/src/xtopcom/xtvm_runtime/src/xtvm_context.cpp @@ -0,0 +1,89 @@ +// Copyright (c) 2017-present Telos Foundation & contributors +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include "xtvm_runtime/xtvm_context.h" + +#include "xbasic/xhex.h" +#include "xdata/xconsensus_action.h" +// xtvm_engine_rs/tvm-c-api/ +#include "protobuf_types/pbasic.pb.h" +#include "protobuf_types/pparameters.pb.h" + +NS_BEG2(top, tvm) + +// static const uint32_t CURRENT_CALL_ARGS_VERSION = 1; + +xtop_vm_context::xtop_vm_context(std::unique_ptr action, txexecutor::xvm_para_t const & vm_para) : m_action{std::move(action)} { + // common usage: + assert(m_action->type() == data::xtop_action_type_t::evm); + + // gas_limit: + auto gas_limit = static_cast(m_action.get())->gas_limit(); + + // action_type: + // we don't really need to sense this, should also be deleted in `action` + // m_action_type = static_cast(m_action.get())->evm_action_type(); + + // todo! gas price + // m_gas_price = 0; + + // sender: + assert(m_action->type() == data::xtop_action_type_t::evm); + m_sender = static_cast(m_action.get())->sender(); + + // recver: + auto m_recver = static_cast(m_action.get())->recver(); + + // block_height: + m_block_height = vm_para.get_block_height(); + + // coinbase: + m_coinbase = vm_para.get_block_coinbase(); + + // block ts: + m_block_timestamp = vm_para.get_timestamp(); + + // chain_id; + m_chain_id = XGET_CONFIG(chain_id); + + // input_data; + top::tvm_engine::parameters::PCallArgs call_args; + call_args.set_gas_limit(gas_limit); + call_args.set_input(top::to_string(static_cast(m_action.get())->data())); + auto sender_address = call_args.mutable_sender_address(); + sender_address->set_value(top::to_string(top::from_hex(m_sender.to_string().substr(6)))); + auto recver_address = call_args.mutable_recver_address(); + recver_address->set_value(top::to_string(top::from_hex(m_recver.to_string().substr(6)))); + evm_common::u256 value_u256 = static_cast(m_action.get())->value(); // utop , should not bigger than U256 + uint64_t value_u64 = value_u256.convert_to(); + call_args.set_value(value_u64); + m_input_data = top::to_bytes(call_args.SerializeAsString()); +} + +// data::xtop_evm_action_type xtop_vm_context::action_type() const{ +// return m_action_type; +// } +xbytes_t const & xtop_vm_context::input_data() const { + return m_input_data; +} +uint64_t xtop_vm_context::gas_price() const { + return m_gas_price; +} +common::xaccount_address_t xtop_vm_context::sender() const { + return m_sender; +} +uint64_t xtop_vm_context::block_height() const { + return m_block_height; +} +common::xaccount_address_t xtop_vm_context::coinbase() const { + return m_coinbase; +} +uint64_t xtop_vm_context::block_timestamp() const { + return m_block_timestamp; +} +uint64_t xtop_vm_context::chain_id() const { + return m_chain_id; +} + +NS_END2 \ No newline at end of file diff --git a/src/xtopcom/xtvm_runtime/src/xtvm_logic.cpp b/src/xtopcom/xtvm_runtime/src/xtvm_logic.cpp new file mode 100644 index 000000000..e4e69981e --- /dev/null +++ b/src/xtopcom/xtvm_runtime/src/xtvm_logic.cpp @@ -0,0 +1,130 @@ +// Copyright (c) 2017-present Telos Foundation & contributors +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include "xtvm_runtime/xtvm_logic.h" + +#include "xbasic/xhex.h" + +#include + +NS_BEG2(top, tvm) + +NS_BEG1(register_tools) + +void read_memory(uint64_t offset, xbytes_t & buffer) { + char * begin_address = (char *)offset; + for (std::size_t i = 0; i < buffer.size(); ++i) { + buffer[i] = *begin_address; + begin_address++; + } +} + +void write_memory(uint64_t offset, xbytes_t const & buffer) { + char * begin_address = (char *)offset; + for (std::size_t i = 0; i < buffer.size(); ++i) { + *begin_address = buffer[i]; + begin_address++; + } +} + +NS_END1 + +xtop_vm_logic::xtop_vm_logic(observer_ptr storage_ptr, observer_ptr context) : m_storage{storage_ptr}, m_context{context} { + xdbg("tvm logic instance %p", static_cast(this)); +} + +xbytes_t xtop_vm_logic::get_return_value() const { + return m_return_data_value; +} + +void xtop_vm_logic::read_register(uint64_t register_id, uint64_t ptr) { + auto data = m_registers.at(register_id); + register_tools::write_memory(ptr, data); +} +uint64_t xtop_vm_logic::register_len(uint64_t register_id) { + return m_registers.at(register_id).size(); +} +void xtop_vm_logic::input(uint64_t register_id) { + m_registers[register_id] = m_context->input_data(); +} +void xtop_vm_logic::result(uint64_t value_len, uint64_t value_ptr) { + m_return_data_value.resize(value_len, 0); + register_tools::read_memory(value_ptr, m_return_data_value); +} +uint64_t xtop_vm_logic::storage_write(uint64_t key_len, uint64_t key_ptr, uint64_t value_len, uint64_t value_ptr, uint64_t register_id) { + auto key = xbytes_t(key_len); + register_tools::read_memory(key_ptr, key); + auto value = xbytes_t(value_len); + register_tools::read_memory(value_ptr, value); + auto old_value = m_storage->storage_get(key); + m_storage->storage_set(key, value); + if (!old_value.empty()) { + m_registers[register_id] = old_value; + return 1; + } + return 0; +} +uint64_t xtop_vm_logic::storage_read(uint64_t key_len, uint64_t key_ptr, uint64_t register_id) { + auto key = xbytes_t(key_len); + register_tools::read_memory(key_ptr, key); + auto value = m_storage->storage_get(key); + if (!value.empty()) { + m_registers[register_id] = value; + return 1; + } + return 0; +} +uint64_t xtop_vm_logic::storage_remove(uint64_t key_len, uint64_t key_ptr, uint64_t register_id) { + auto key = xbytes_t(key_len); + register_tools::read_memory(key_ptr, key); + auto old_value = m_storage->storage_get(key); + m_storage->storage_remove(key); + if (!old_value.empty()) { + m_registers[register_id] = old_value; + return 1; + } + return 0; +} +uint64_t xtop_vm_logic::gas_price() { + return m_context->gas_price(); +} +void xtop_vm_logic::origin_address(uint64_t register_id) { + auto sender = m_context->sender(); + assert(sender.to_string().substr(0, 6) == std::string("T80000")); + std::string sender_str = sender.to_string().substr(6); + assert(sender_str.size() == 40); + std::error_code ec; + auto sender_bytes = top::from_hex(sender_str, ec); + assert(!ec); + assert(sender_bytes.size() == 20); + m_registers[register_id] = sender_bytes; +} +uint64_t xtop_vm_logic::block_height() { + return m_context->block_height(); +} +void xtop_vm_logic::block_coinbase(uint64_t register_id) { + auto coinbase = m_context->coinbase(); + assert(coinbase.to_string().substr(0, 6) == std::string("T80000")); + std::string coinbase_str = coinbase.to_string().substr(6); + assert(coinbase_str.size() == 40); + std::error_code ec; + auto coinbase_bytes = top::from_hex(coinbase_str, ec); + assert(!ec); + assert(coinbase_bytes.size() == 20); + m_registers[register_id] = coinbase_bytes; +} +uint64_t xtop_vm_logic::block_timestamp() { + return m_context->block_timestamp(); +} +uint64_t xtop_vm_logic::chain_id() { + return m_context->chain_id(); +} +void xtop_vm_logic::log_utf8(uint64_t len, uint64_t ptr) { + auto logs_bytes = xbytes_t(len); + register_tools::read_memory(ptr, logs_bytes); + std::string logs_str = top::to_string(logs_bytes); + xinfo("[log_utf8] TVM_LOG: %s", logs_str.c_str()); +} + +NS_END2 \ No newline at end of file diff --git a/src/xtopcom/xtvm_runtime/src/xtvm_storage.cpp b/src/xtopcom/xtvm_runtime/src/xtvm_storage.cpp new file mode 100644 index 000000000..f5f3fbb7c --- /dev/null +++ b/src/xtopcom/xtvm_runtime/src/xtvm_storage.cpp @@ -0,0 +1,228 @@ +// Copyright (c) 2017-present Telos Foundation & contributors +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include "xtvm_runtime/xtvm_storage.h" + +#include "xstate_accessor/xproperties/xproperty_identifier.h" +#include "xstate_accessor/xstate_accessor.h" + +#include + +NS_BEG2(top, tvm) + +const state_accessor::properties::xproperty_type_t tvm_property_type_bytes = state_accessor::properties::xproperty_type_t::bytes; +const state_accessor::properties::xproperty_type_t tvm_property_type_map = state_accessor::properties::xproperty_type_t::map; + +// todo ! should `data::XPROPERTY_EVM_CODE` && `data::XPROPERTY_EVM_STORAGE` use new property name. +xbytes_t xtop_vm_storage::storage_get(xbytes_t const & key) { + assert(m_statectx); + + auto storage_key = decode_storage_key(key); + auto address = common::xaccount_address_t{storage_key.t8_address()}; + + try { + auto account_state = m_statectx->load_account_state(address); + if (nullptr == account_state) { + xassert(false); + return {}; + } + auto unit_state = account_state->get_unitstate(); + auto state_observer = make_observer(unit_state->get_bstate().get()); + auto canvas = unit_state->get_canvas(); + state_accessor::xstate_accessor_t sa{state_observer, canvas}; + std::error_code ec; + + switch (storage_key.key_type()) { + case storage_key_prefix::Nonce: { + uint64_t nonce_u64 = account_state->get_tx_nonce(); + xdbg("tvm_storage get address %s nonce %llu", address.to_string().c_str(), nonce_u64); + xbytes_t nonce_bytes(8); + evm_common::toBigEndian(nonce_u64, nonce_bytes); + return nonce_bytes; + } + case storage_key_prefix::Balance: { + uint64_t balance_u64 = account_state->get_unitstate()->balance(); + xdbg("tvm_storage get address %s balance %llu", address.to_string().c_str(), balance_u64); + xbytes_t balance_bytes(8); + evm_common::toBigEndian(balance_u64, balance_bytes); + return balance_bytes; + } + case storage_key_prefix::Code: { + auto property = state_accessor::properties::xtypeless_property_identifier_t{data::XPROPERTY_EVM_CODE, state_accessor::properties::xproperty_category_t::system}; + auto value = sa.get_property(property, ec); + assert(!ec); + top::error::throw_error(ec); + return value; + } + case storage_key_prefix::Storage: { + if (!storage_key.has_storage_key()) { + // remove all storage, but read first + // just return; + return xbytes_t{}; + } + assert(storage_key.has_storage_key()); + auto property = state_accessor::properties::xtypeless_property_identifier_t{data::XPROPERTY_EVM_STORAGE, state_accessor::properties::xproperty_category_t::system}; + auto value = sa.get_property_cell_value(property, storage_key.storage_key(), ec); + assert(!ec); + xdbg("tvm_storage get address %s storage_key %s", address.to_string().c_str(), top::to_hex(storage_key.storage_key()).c_str()); + top::error::throw_error(ec); + return value; + } + default: { + xassert(false); // NOLINT(clang-diagnostic-disabled-macro-expansion) + __builtin_unreachable(); + } + } + } catch (top::error::xtop_error_t const & eh) { + xwarn("tvm_storage get catch category %s, errc %" PRIi32 " msg %s", eh.category().name(), eh.code().value(), eh.what()); + } catch (std::exception const & eh) { + xwarn("tvm_storage get catch std::exception %s", eh.what()); + } catch (enum_xerror_code ec) { + xwarn("tvm_storage get catch xbase error %d", ec); + } catch (...) { + xwarn("tvm_storage get catch unknonw error"); + } + return xbytes_t{}; +} +void xtop_vm_storage::storage_set(xbytes_t const & key, xbytes_t const & value) { + assert(m_statectx); + + auto storage_key = decode_storage_key(key); + auto address = common::xaccount_address_t{storage_key.t8_address()}; + + try { + auto account_state = m_statectx->load_account_state(address); + if (nullptr == account_state) { + xassert(false); + return; + } + auto unit_state = account_state->get_unitstate(); + auto state_observer = make_observer(unit_state->get_bstate().get()); + auto canvas = unit_state->get_canvas(); + state_accessor::xstate_accessor_t sa{state_observer, canvas}; + std::error_code ec; + + switch (storage_key.key_type()) { + case storage_key_prefix::Nonce: { + uint64_t nonce_u64 = evm_common::fromBigEndian(value); + xdbg("tvm_storage set address %s nonce %llu", address.to_string().c_str(), nonce_u64); + account_state->set_tx_nonce(nonce_u64); + return; + } + case storage_key_prefix::Balance: { + uint64_t balance_u64 = evm_common::fromBigEndian(value); + xdbg("tvm_storage set address %s balance %llu", address.to_string().c_str(), balance_u64); + account_state->get_unitstate()->set_token_balance(data::XPROPERTY_BALANCE_AVAILABLE, base::vtoken_t(balance_u64)); + return; + } + case storage_key_prefix::Code: { + auto property = state_accessor::properties::xtypeless_property_identifier_t{data::XPROPERTY_EVM_CODE, state_accessor::properties::xproperty_category_t::system}; + sa.set_property(property, value, ec); + assert(!ec); + top::error::throw_error(ec); + return; + } + case storage_key_prefix::Storage: { + assert(storage_key.has_storage_key()); + auto property = state_accessor::properties::xtypeless_property_identifier_t{data::XPROPERTY_EVM_STORAGE, state_accessor::properties::xproperty_category_t::system}; + sa.set_property_cell_value(property, storage_key.storage_key(), value, ec); + assert(!ec); + xdbg("tvm_storage set address %s storage_key %s", address.to_string().c_str(), top::to_hex(storage_key.storage_key()).c_str()); + top::error::throw_error(ec); + return; + } + default: { + xassert(false); // NOLINT(clang-diagnostic-disabled-macro-expansion) + __builtin_unreachable(); + } + } + } catch (top::error::xtop_error_t const & eh) { + xwarn("tvm_storage set catch category %s, errc %" PRIi32 " msg %s", eh.category().name(), eh.code().value(), eh.what()); + } catch (std::exception const & eh) { + xwarn("tvm_storage set catch std::exception %s", eh.what()); + } catch (enum_xerror_code ec) { + xwarn("tvm_storage set catch xbase error %d", ec); + } catch (...) { + xwarn("tvm_storage set catch unknonw error"); + } +} +void xtop_vm_storage::storage_remove(xbytes_t const & key) { + assert(m_statectx); + + auto storage_key = decode_storage_key(key); + auto address = common::xaccount_address_t{storage_key.t8_address()}; + + try { + auto account_state = m_statectx->load_account_state(address); + if (nullptr == account_state) { + xassert(false); + return; + } + auto unit_state = account_state->get_unitstate(); + auto state_observer = make_observer(unit_state->get_bstate().get()); + auto canvas = unit_state->get_canvas(); + state_accessor::xstate_accessor_t sa{state_observer, canvas}; + std::error_code ec; + + switch (storage_key.key_type()) { + case storage_key_prefix::Nonce: { + uint64_t nonce_u64 = 0; + xdbg("tvm_storage remove address %s nonce to %llu", address.to_string().c_str(), nonce_u64); + account_state->set_tx_nonce(nonce_u64); + return; + } + case storage_key_prefix::Balance: { + uint64_t balance_u64 = 0; + xdbg("tvm_storage remove address %s balance to %llu", address.to_string().c_str(), balance_u64); + account_state->get_unitstate()->set_token_balance(data::XPROPERTY_BALANCE_AVAILABLE, base::vtoken_t(balance_u64)); + return; + } + case storage_key_prefix::Code: { + auto typeless_property = + state_accessor::properties::xtypeless_property_identifier_t{data::XPROPERTY_EVM_CODE, state_accessor::properties::xproperty_category_t::system}; + auto property = state_accessor::properties::xproperty_identifier_t{typeless_property, tvm_property_type_bytes}; + sa.clear_property(property, ec); + assert(!ec); + top::error::throw_error(ec); + return; + } + case storage_key_prefix::Storage: { + if (storage_key.has_storage_key()) { + auto property = state_accessor::properties::xtypeless_property_identifier_t{data::XPROPERTY_EVM_STORAGE, state_accessor::properties::xproperty_category_t::system}; + sa.remove_property_cell(property, storage_key.storage_key(), ec); + if (ec == static_cast(state_accessor::error::xerrc_t::property_key_not_exist) || + ec == static_cast(state_accessor::error::xerrc_t::property_not_exist)) { + ec.clear(); // Is possible that key not exist when deploying contract, since evm will always try to remove zero value. + } + xdbg("tvm_storage remove address %s storage:%s", address.to_string().c_str(), top::to_hex(storage_key.storage_key()).c_str()); + } else { + auto typeless_property = + state_accessor::properties::xtypeless_property_identifier_t{data::XPROPERTY_EVM_STORAGE, state_accessor::properties::xproperty_category_t::system}; + auto property = state_accessor::properties::xproperty_identifier_t{typeless_property, tvm_property_type_map}; + sa.clear_property(property, ec); + if (ec == static_cast(state_accessor::error::xerrc_t::property_not_exist)) { + ec.clear(); + } + xdbg("tvm_storage remove address %s all storage", address.to_string().c_str()); + } + assert(!ec); + top::error::throw_error(ec); + return; + } + default: { + xassert(false); // NOLINT(clang-diagnostic-disabled-macro-expansion) + __builtin_unreachable(); + } + } + } catch (top::error::xtop_error_t const & eh) { + xwarn("tvm_storage remove catch category %s, errc %" PRIi32 " msg %s", eh.category().name(), eh.code().value(), eh.what()); + } catch (std::exception const & eh) { + xwarn("tvm_storage remove catch std::exception %s", eh.what()); + } catch (enum_xerror_code ec) { + xwarn("tvm_storage remove catch xbase error %d", ec); + } catch (...) { + xwarn("tvm_storage remove catch unknonw error"); + } +} +NS_END2 \ No newline at end of file diff --git a/src/xtopcom/xtvm_runtime/xerror.h b/src/xtopcom/xtvm_runtime/xerror.h new file mode 100644 index 000000000..5ec27577d --- /dev/null +++ b/src/xtopcom/xtvm_runtime/xerror.h @@ -0,0 +1,39 @@ +// Copyright (c) 2017-present Telos Foundation & contributors +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#pragma once + +#include "xbase/xns_macro.h" + +#include +#include +#include + +NS_BEG3(top, tvm, error) + +enum class xenum_errc : uint32_t { + ok = 0, + + protobuf_serilized_error, + + unknown_error, +}; +using xerrc_t = xenum_errc; + +std::error_code make_error_code(xerrc_t const ec) noexcept; +std::error_condition make_error_condition(xerrc_t const ec) noexcept; + +std::error_category const & tvm_category(); + +NS_END3 + +NS_BEG1(std) + +template <> +struct is_error_code_enum : std::true_type {}; + +template <> +struct is_error_condition_enum : std::true_type {}; + +NS_END1 diff --git a/src/xtopcom/xtvm_runtime/xtvm.h b/src/xtopcom/xtvm_runtime/xtvm.h new file mode 100644 index 000000000..d0cd0702c --- /dev/null +++ b/src/xtopcom/xtvm_runtime/xtvm.h @@ -0,0 +1,45 @@ +// Copyright (c) 2017-present Telos Foundation & contributors +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#pragma once + +#if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wpedantic" +#elif defined(__GNUC__) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wpedantic" +#elif defined(_MSC_VER) +# pragma warning(push, 0) +#endif + +#include "xstatectx/xstatectx_face.h" + +#if defined(__clang__) +# pragma clang diagnostic pop +#elif defined(__GNUC__) +# pragma GCC diagnostic pop +#elif defined(_MSC_VER) +# pragma warning(pop) +#endif + +#include "xdata/xtop_action_fwd.h" +#include "xtxexecutor/xvm_face.h" + +NS_BEG2(top, tvm) + +class xtop_vm : public txexecutor::xvm_face_t { +private: + statectx::xstatectx_face_ptr_t m_statectx; + +public: + xtop_vm(statectx::xstatectx_face_ptr_t const statectx); + +public: + txexecutor::enum_execute_result_type execute(txexecutor::xvm_input_t const & input, txexecutor::xvm_output_t & output) override; + evm_common::xevm_transaction_result_t execute_action(std::unique_ptr action, txexecutor::xvm_para_t const & vm_para); +}; +using xtvm_t = xtop_vm; + +NS_END2 \ No newline at end of file diff --git a/src/xtopcom/xtvm_runtime/xtvm_action_runner.h b/src/xtopcom/xtvm_runtime/xtvm_action_runner.h new file mode 100644 index 000000000..a6f086ff0 --- /dev/null +++ b/src/xtopcom/xtvm_runtime/xtvm_action_runner.h @@ -0,0 +1,46 @@ +// Copyright (c) 2017-present Telos Foundation & contributors +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#pragma once + +#include "xdata/xtop_action_fwd.h" +#include "xevm_common/xevm_transaction_result.h" + +#if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wpedantic" +#elif defined(__GNUC__) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wpedantic" +#elif defined(_MSC_VER) +# pragma warning(push, 0) +#endif + +#include "xstatectx/xstatectx_face.h" + +#if defined(__clang__) +# pragma clang diagnostic pop +#elif defined(__GNUC__) +# pragma GCC diagnostic pop +#elif defined(_MSC_VER) +# pragma warning(pop) +#endif + +#include "xtvm_runtime/xtvm_context.h" + +#include + +NS_BEG2(top, tvm) + +class xtop_vm_action_runner { +private: + statectx::xstatectx_face_ptr_t m_statectx; + +public: + xtop_vm_action_runner(statectx::xstatectx_face_ptr_t const statectx); + evm_common::xevm_transaction_result_t execute_action(std::unique_ptr context); +}; +using xtvm_action_runner_t = xtop_vm_action_runner; + +NS_END2 \ No newline at end of file diff --git a/src/xtopcom/xtvm_runtime/xtvm_context.h b/src/xtopcom/xtvm_runtime/xtvm_context.h new file mode 100644 index 000000000..467e52391 --- /dev/null +++ b/src/xtopcom/xtvm_runtime/xtvm_context.h @@ -0,0 +1,41 @@ +// Copyright (c) 2017-present Telos Foundation & contributors +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#pragma once + +#include "xbasic/xbyte_buffer.h" +#include "xcommon/xaccount_address_fwd.h" +#include "xdata/xtop_action_fwd.h" +#include "xtxexecutor/xvm_face.h" + +NS_BEG2(top, tvm) + +class xtop_vm_context { +private: + // data::xtop_evm_action_type m_action_type; + std::unique_ptr m_action; + uint64_t m_gas_price; + common::xaccount_address_t m_sender; + uint64_t m_block_height; + common::xaccount_address_t m_coinbase; + uint64_t m_block_timestamp; + uint64_t m_chain_id; + xbytes_t m_input_data; + +public: + xtop_vm_context(std::unique_ptr action, txexecutor::xvm_para_t const & vm_para); + +public: + // data::xtop_evm_action_type action_type() const; + xbytes_t const & input_data() const; + uint64_t gas_price() const; + common::xaccount_address_t sender() const; + uint64_t block_height() const; + common::xaccount_address_t coinbase() const; + uint64_t block_timestamp() const; + uint64_t chain_id() const; +}; +using xtvm_context_t = xtop_vm_context; + +NS_END2 \ No newline at end of file diff --git a/src/xtopcom/xtvm_runtime/xtvm_logic.h b/src/xtopcom/xtvm_runtime/xtvm_logic.h new file mode 100644 index 000000000..1e474433a --- /dev/null +++ b/src/xtopcom/xtvm_runtime/xtvm_logic.h @@ -0,0 +1,51 @@ +// Copyright (c) 2017-present Telos Foundation & contributors +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#pragma once + +#include "xbasic/xbyte_buffer.h" +#include "xbasic/xmemory.hpp" +#include "xtvm_engine_rs/tvm-c-api/tvm_logic_face.h" +#include "xtvm_runtime/xtvm_context.h" +#include "xtvm_runtime/xtvm_storage.h" + +#include + +NS_BEG2(top, tvm) + +class xtop_vm_logic : public tvm_logic_face { +private: + observer_ptr m_storage; + observer_ptr m_context; + std::map m_registers; + xbytes_t m_return_data_value; + xbytes_t m_call_contract_args; + +public: + xtop_vm_logic(observer_ptr storage_ptr, observer_ptr context); + +public: + // for runtime use + xbytes_t get_return_value() const; + +public: + // override api + void read_register(uint64_t register_id, uint64_t ptr) override; + uint64_t register_len(uint64_t register_id) override; + void input(uint64_t register_id) override; + void result(uint64_t value_len, uint64_t value_ptr) override; + uint64_t storage_write(uint64_t key_len, uint64_t key_ptr, uint64_t value_len, uint64_t value_ptr, uint64_t register_id) override; + uint64_t storage_read(uint64_t key_len, uint64_t key_ptr, uint64_t register_id) override; + uint64_t storage_remove(uint64_t key_len, uint64_t key_ptr, uint64_t register_id) override; + uint64_t gas_price() override; + void origin_address(uint64_t register_id) override; + uint64_t block_height() override; + void block_coinbase(uint64_t register_id) override; + uint64_t block_timestamp() override; + uint64_t chain_id() override; + void log_utf8(uint64_t len, uint64_t ptr) override; +}; +using xtvm_logic_t = xtop_vm_logic; + +NS_END2 \ No newline at end of file diff --git a/src/xtopcom/xtvm_runtime/xtvm_storage.h b/src/xtopcom/xtvm_runtime/xtvm_storage.h new file mode 100644 index 000000000..8af1541e4 --- /dev/null +++ b/src/xtopcom/xtvm_runtime/xtvm_storage.h @@ -0,0 +1,93 @@ +// Copyright (c) 2017-present Telos Foundation & contributors +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#pragma once + +#include "xbasic/xbyte_buffer.h" +#include "xbasic/xhex.h" +#include "xcommon/xaccount_address.h" +#include "xstatectx/xstatectx_face.h" + +#include + +NS_BEG2(top, tvm) +class xtop_vm_storage { +private: + // storage_ctx + statectx::xstatectx_face_ptr_t m_statectx; + +public: + // constructor: + xtop_vm_storage(statectx::xstatectx_face_ptr_t const statectx) : m_statectx{statectx} { + } + +public: + xbytes_t storage_get(xbytes_t const & key); + void storage_set(xbytes_t const & key, xbytes_t const & value); + void storage_remove(xbytes_t const & key); + +private: + enum class storage_key_prefix : uint8_t { + Nonce = 1, + Balance = 2, + Code = 3, + Storage = 4, + }; + + class xtop_vm_storage_key { + friend class xtop_vm_storage; + + private: + storage_key_prefix m_key_type; + xbytes_t m_address_bytes; + xbytes_t m_storage_key; // optional + bool m_has_optional_storage_key{false}; + + private: + // can only be constructed from method `decode_storage_key` + xtop_vm_storage_key() { + } + + public: + inline storage_key_prefix key_type() const { + return m_key_type; + } + + inline bool is_key_type(storage_key_prefix const & key_prefix) const { + return key_type() == key_prefix; + } + + inline bool has_storage_key() const { + return m_has_optional_storage_key; + } + + std::string storage_key() const { + assert(m_has_optional_storage_key); + return top::to_string(m_storage_key); + } + + common::xaccount_address_t t8_address() const { + return common::xaccount_address_t::build_from(top::to_hex(m_address_bytes.begin(), m_address_bytes.end(), "T80000")); + } + }; + using xtvm_storage_key_t = xtop_vm_storage_key; + +protected: + xtvm_storage_key_t decode_storage_key(xbytes_t const & storage_key) { + assert(storage_key.size() == 22 || storage_key.size() == 54); + xtvm_storage_key_t result; + assert(storage_key.at(0) == 1); // VERSION::V1 = 0x01 as u8; + result.m_key_type = static_cast(storage_key.at(1)); + result.m_address_bytes.resize(20, xbyte_t{0}); + std::copy(storage_key.begin() + 2, storage_key.begin() + 22, result.m_address_bytes.begin()); + if (storage_key.size() == 54) { + result.m_has_optional_storage_key = true; + result.m_storage_key.resize(32, xbyte_t{0}); + std::copy(storage_key.begin() + 22, storage_key.end(), result.m_storage_key.begin()); + } + return result; + } +}; +using xtvm_storage_t = xtop_vm_storage; +NS_END2 \ No newline at end of file From d1319d1516e2f86d0b52207a910a30b5f718e0cb Mon Sep 17 00:00:00 2001 From: "Charles.Liu" Date: Tue, 28 Feb 2023 14:54:25 +0800 Subject: [PATCH 2/4] add tvm_engine_rs submodule --- .gitmodules | 3 +++ src/xtopcom/xtvm_engine_rs | 1 + 2 files changed, 4 insertions(+) create mode 160000 src/xtopcom/xtvm_engine_rs diff --git a/.gitmodules b/.gitmodules index 5f7aa0adb..f2bee6c81 100644 --- a/.gitmodules +++ b/.gitmodules @@ -52,3 +52,6 @@ [submodule "src/xtopcom/xdepends/xquic"] path = src/xtopcom/xdepends/xquic url = git@github.com:telosprotocol/xquic.git +[submodule "src/xtopcom/xtvm_engine_rs"] + path = src/xtopcom/xtvm_engine_rs + url = git@github.com:telosprotocol/tvm_engine_rs.git diff --git a/src/xtopcom/xtvm_engine_rs b/src/xtopcom/xtvm_engine_rs new file mode 160000 index 000000000..10013ac94 --- /dev/null +++ b/src/xtopcom/xtvm_engine_rs @@ -0,0 +1 @@ +Subproject commit 10013ac94fa0395658cec22b2213a65f843fdff6 From d2594d485348f5aee4b134640446a947c88b738e Mon Sep 17 00:00:00 2001 From: "Charles.Liu" Date: Tue, 28 Feb 2023 15:05:52 +0800 Subject: [PATCH 3/4] add test --- tests/CMakeLists.txt | 1 + tests/xtvm_test/CMakeLists.txt | 10 + tests/xtvm_test/fixture/xmock_statectx.h | 69 ++++ tests/xtvm_test/fixture/xtvm_test_fixture.cpp | 295 +++++++++++++++++ tests/xtvm_test/fixture/xtvm_test_fixture.h | 77 +++++ .../test_cases/QA_CASES/array/Array.bin | 1 + .../test_cases/QA_CASES/array/Array.json | 85 +++++ .../test_cases/QA_CASES/array/Array.sol | 12 + .../QA_CASES/base/Storage/Storge.bin | 1 + .../QA_CASES/base/Storage/Storge.json | 33 ++ .../QA_CASES/base/Storage/Storge.sol | 28 ++ .../test_cases/QA_CASES/base/owner/Owner.bin | 2 + .../test_cases/QA_CASES/base/owner/Owner.json | 63 ++++ .../test_cases/QA_CASES/base/owner/Owner.sol | 54 ++++ .../test_cases/QA_CASES/bigcontract/SoBig.bin | 1 + .../QA_CASES/bigcontract/SoBig.json | 33 ++ .../test_cases/QA_CASES/bigcontract/SoBig.sol | 252 +++++++++++++++ .../QA_CASES/call_contract/CallContract.json | 105 ++++++ .../QA_CASES/call_contract/CallContractA.bin | 1 + .../QA_CASES/call_contract/CallContractA.sol | 32 ++ .../QA_CASES/call_contract/CallContractB.bin | 1 + .../QA_CASES/call_contract/CallContractB.sol | 22 ++ .../AssertDemo_sol_AssertDemo.bin | 1 + .../ForeverLoop_sol_ForeverLoop.bin | 1 + .../Recursion_sol_Recursion.bin | 1 + .../TestSafeMath_sol_TestSafeMath.bin | 1 + .../many_user_one_contract.json | 156 +++++++++ ...e_user_deploy_one_contract_four_times.json | 156 +++++++++ .../one_user_many_contract.json | 126 ++++++++ .../test_cases/QA_CASES/erc20/Cat.bin | 1 + .../test_cases/QA_CASES/erc20/Cat.json | 133 ++++++++ .../test_cases/QA_CASES/erc20/Cat.sol | 107 +++++++ .../test_cases/QA_CASES/erc20/ERC20.sol | 25 ++ .../test_cases/QA_CASES/erc20/ERC20Basic.sol | 16 + .../test_cases/QA_CASES/erc20/SafeMath.sol | 50 +++ .../test_cases/QA_CASES/import/Foo.sol | 17 + .../test_cases/QA_CASES/import/Import.bin | 1 + .../test_cases/QA_CASES/import/Import.json | 33 ++ .../test_cases/QA_CASES/import/Import.sol | 18 ++ .../QA_CASES/interrupt/AssertDemo.json | 47 +++ .../QA_CASES/interrupt/AssertDemo.sol | 21 ++ .../interrupt/AssertDemo_sol_AssertDemo.abi | 1 + .../interrupt/AssertDemo_sol_AssertDemo.bin | 1 + .../QA_CASES/interrupt/ForeverLoop.json | 48 +++ .../QA_CASES/interrupt/ForeverLoop.sol | 12 + .../interrupt/ForeverLoop_sol_ForeverLoop.abi | 1 + .../interrupt/ForeverLoop_sol_ForeverLoop.bin | 1 + .../QA_CASES/interrupt/Recursion.json | 48 +++ .../QA_CASES/interrupt/Recursion.sol | 12 + .../interrupt/Recursion_sol_Recursion.abi | 1 + .../interrupt/Recursion_sol_Recursion.bin | 1 + .../QA_CASES/library/TestSafeMath.json | 133 ++++++++ .../QA_CASES/library/TestSafeMath.sol | 41 +++ .../library/TestSafeMath_sol_Math.abi | 1 + .../library/TestSafeMath_sol_Math.bin | 1 + .../library/TestSafeMath_sol_SafeMath.abi | 1 + .../library/TestSafeMath_sol_SafeMath.bin | 1 + .../library/TestSafeMath_sol_TestSafeMath.abi | 1 + .../library/TestSafeMath_sol_TestSafeMath.bin | 1 + .../test_cases/QA_CASES/new_swap/Context.sol | 24 ++ .../QA_CASES/new_swap/Context_sol_Context.abi | 1 + .../QA_CASES/new_swap/Context_sol_Context.bin | 0 .../test_cases/QA_CASES/new_swap/ERC20.sol | 303 ++++++++++++++++++ .../QA_CASES/new_swap/ERC20_sol_ERC20.abi | 1 + .../QA_CASES/new_swap/ERC20_sol_ERC20.bin | 1 + .../test_cases/QA_CASES/new_swap/IERC20.sol | 77 +++++ .../QA_CASES/new_swap/IERC20_sol_IERC20.abi | 1 + .../QA_CASES/new_swap/IERC20_sol_IERC20.bin | 0 .../QA_CASES/new_swap/swap.json_not_fixed | 267 +++++++++++++++ .../test_cases/QA_CASES/new_swap/swap.sol | 79 +++++ .../QA_CASES/new_swap/swap_sol_TokenSwap.abi | 1 + .../QA_CASES/new_swap/swap_sol_TokenSwap.bin | 1 + .../QA_CASES/new_swap/swap_sol_golden.abi | 1 + .../QA_CASES/new_swap/swap_sol_golden.bin | 1 + .../QA_CASES/new_swap/swap_sol_moyed.abi | 1 + .../QA_CASES/new_swap/swap_sol_moyed.bin | 1 + .../test_cases/QA_CASES/swap/AliceToken.json | 227 +++++++++++++ .../test_cases/QA_CASES/swap/AliceToken.sol | 50 +++ .../swap/AliceToken_sol_AliceToken.abi | 1 + .../swap/AliceToken_sol_AliceToken.bin | 1 + .../test_cases/QA_CASES/swap/BobToken.json | 180 +++++++++++ .../test_cases/QA_CASES/swap/BobToken.sol | 50 +++ .../QA_CASES/swap/BobToken_sol_BobToken.abi | 1 + .../QA_CASES/swap/BobToken_sol_BobToken.bin | 1 + .../test_cases/QA_CASES/swap/IERC20.sol | 23 ++ .../QA_CASES/swap/IERC20_sol_IERC20.abi | 1 + .../QA_CASES/swap/IERC20_sol_IERC20.bin | 0 .../test_cases/QA_CASES/swap/TokenSwap.sol | 55 ++++ .../QA_CASES/swap/TokenSwap_sol_TokenSwap.abi | 1 + .../QA_CASES/swap/TokenSwap_sol_TokenSwap.bin | 1 + tests/xtvm_test/test_cases/READMD.md | 6 + tests/xtvm_test/test_cases/add/add.bin | 1 + tests/xtvm_test/test_cases/add/add.json | 107 +++++++ tests/xtvm_test/test_cases/add/add.sol | 23 ++ tests/xtvm_test/test_cases/erc20/erc20.bin | 1 + tests/xtvm_test/test_cases/erc20/erc20.json | 90 ++++++ tests/xtvm_test/test_cases/erc20/erc20.sol | 94 ++++++ .../storage_set_zero/storage_set_zero.bin | 1 + .../storage_set_zero/storage_set_zero.json | 117 +++++++ .../storage_set_zero/storage_set_zero.sol | 15 + tests/xtvm_test/test_main.cpp | 57 ++++ tests/xtvm_test/test_tvm_cases_json.cpp | 9 + 102 files changed, 4268 insertions(+) create mode 100644 tests/xtvm_test/CMakeLists.txt create mode 100644 tests/xtvm_test/fixture/xmock_statectx.h create mode 100644 tests/xtvm_test/fixture/xtvm_test_fixture.cpp create mode 100644 tests/xtvm_test/fixture/xtvm_test_fixture.h create mode 100755 tests/xtvm_test/test_cases/QA_CASES/array/Array.bin create mode 100755 tests/xtvm_test/test_cases/QA_CASES/array/Array.json create mode 100755 tests/xtvm_test/test_cases/QA_CASES/array/Array.sol create mode 100755 tests/xtvm_test/test_cases/QA_CASES/base/Storage/Storge.bin create mode 100755 tests/xtvm_test/test_cases/QA_CASES/base/Storage/Storge.json create mode 100755 tests/xtvm_test/test_cases/QA_CASES/base/Storage/Storge.sol create mode 100755 tests/xtvm_test/test_cases/QA_CASES/base/owner/Owner.bin create mode 100755 tests/xtvm_test/test_cases/QA_CASES/base/owner/Owner.json create mode 100755 tests/xtvm_test/test_cases/QA_CASES/base/owner/Owner.sol create mode 100755 tests/xtvm_test/test_cases/QA_CASES/bigcontract/SoBig.bin create mode 100755 tests/xtvm_test/test_cases/QA_CASES/bigcontract/SoBig.json create mode 100755 tests/xtvm_test/test_cases/QA_CASES/bigcontract/SoBig.sol create mode 100755 tests/xtvm_test/test_cases/QA_CASES/call_contract/CallContract.json create mode 100755 tests/xtvm_test/test_cases/QA_CASES/call_contract/CallContractA.bin create mode 100755 tests/xtvm_test/test_cases/QA_CASES/call_contract/CallContractA.sol create mode 100755 tests/xtvm_test/test_cases/QA_CASES/call_contract/CallContractB.bin create mode 100755 tests/xtvm_test/test_cases/QA_CASES/call_contract/CallContractB.sol create mode 100755 tests/xtvm_test/test_cases/QA_CASES/contract_user_relation/AssertDemo_sol_AssertDemo.bin create mode 100755 tests/xtvm_test/test_cases/QA_CASES/contract_user_relation/ForeverLoop_sol_ForeverLoop.bin create mode 100755 tests/xtvm_test/test_cases/QA_CASES/contract_user_relation/Recursion_sol_Recursion.bin create mode 100755 tests/xtvm_test/test_cases/QA_CASES/contract_user_relation/TestSafeMath_sol_TestSafeMath.bin create mode 100755 tests/xtvm_test/test_cases/QA_CASES/contract_user_relation/many_user_one_contract.json create mode 100755 tests/xtvm_test/test_cases/QA_CASES/contract_user_relation/one_user_deploy_one_contract_four_times.json create mode 100755 tests/xtvm_test/test_cases/QA_CASES/contract_user_relation/one_user_many_contract.json create mode 100755 tests/xtvm_test/test_cases/QA_CASES/erc20/Cat.bin create mode 100755 tests/xtvm_test/test_cases/QA_CASES/erc20/Cat.json create mode 100755 tests/xtvm_test/test_cases/QA_CASES/erc20/Cat.sol create mode 100755 tests/xtvm_test/test_cases/QA_CASES/erc20/ERC20.sol create mode 100755 tests/xtvm_test/test_cases/QA_CASES/erc20/ERC20Basic.sol create mode 100755 tests/xtvm_test/test_cases/QA_CASES/erc20/SafeMath.sol create mode 100755 tests/xtvm_test/test_cases/QA_CASES/import/Foo.sol create mode 100755 tests/xtvm_test/test_cases/QA_CASES/import/Import.bin create mode 100755 tests/xtvm_test/test_cases/QA_CASES/import/Import.json create mode 100755 tests/xtvm_test/test_cases/QA_CASES/import/Import.sol create mode 100755 tests/xtvm_test/test_cases/QA_CASES/interrupt/AssertDemo.json create mode 100755 tests/xtvm_test/test_cases/QA_CASES/interrupt/AssertDemo.sol create mode 100755 tests/xtvm_test/test_cases/QA_CASES/interrupt/AssertDemo_sol_AssertDemo.abi create mode 100755 tests/xtvm_test/test_cases/QA_CASES/interrupt/AssertDemo_sol_AssertDemo.bin create mode 100755 tests/xtvm_test/test_cases/QA_CASES/interrupt/ForeverLoop.json create mode 100755 tests/xtvm_test/test_cases/QA_CASES/interrupt/ForeverLoop.sol create mode 100755 tests/xtvm_test/test_cases/QA_CASES/interrupt/ForeverLoop_sol_ForeverLoop.abi create mode 100755 tests/xtvm_test/test_cases/QA_CASES/interrupt/ForeverLoop_sol_ForeverLoop.bin create mode 100755 tests/xtvm_test/test_cases/QA_CASES/interrupt/Recursion.json create mode 100755 tests/xtvm_test/test_cases/QA_CASES/interrupt/Recursion.sol create mode 100755 tests/xtvm_test/test_cases/QA_CASES/interrupt/Recursion_sol_Recursion.abi create mode 100755 tests/xtvm_test/test_cases/QA_CASES/interrupt/Recursion_sol_Recursion.bin create mode 100755 tests/xtvm_test/test_cases/QA_CASES/library/TestSafeMath.json create mode 100755 tests/xtvm_test/test_cases/QA_CASES/library/TestSafeMath.sol create mode 100755 tests/xtvm_test/test_cases/QA_CASES/library/TestSafeMath_sol_Math.abi create mode 100755 tests/xtvm_test/test_cases/QA_CASES/library/TestSafeMath_sol_Math.bin create mode 100755 tests/xtvm_test/test_cases/QA_CASES/library/TestSafeMath_sol_SafeMath.abi create mode 100755 tests/xtvm_test/test_cases/QA_CASES/library/TestSafeMath_sol_SafeMath.bin create mode 100755 tests/xtvm_test/test_cases/QA_CASES/library/TestSafeMath_sol_TestSafeMath.abi create mode 100755 tests/xtvm_test/test_cases/QA_CASES/library/TestSafeMath_sol_TestSafeMath.bin create mode 100755 tests/xtvm_test/test_cases/QA_CASES/new_swap/Context.sol create mode 100755 tests/xtvm_test/test_cases/QA_CASES/new_swap/Context_sol_Context.abi create mode 100755 tests/xtvm_test/test_cases/QA_CASES/new_swap/Context_sol_Context.bin create mode 100755 tests/xtvm_test/test_cases/QA_CASES/new_swap/ERC20.sol create mode 100755 tests/xtvm_test/test_cases/QA_CASES/new_swap/ERC20_sol_ERC20.abi create mode 100755 tests/xtvm_test/test_cases/QA_CASES/new_swap/ERC20_sol_ERC20.bin create mode 100755 tests/xtvm_test/test_cases/QA_CASES/new_swap/IERC20.sol create mode 100755 tests/xtvm_test/test_cases/QA_CASES/new_swap/IERC20_sol_IERC20.abi create mode 100755 tests/xtvm_test/test_cases/QA_CASES/new_swap/IERC20_sol_IERC20.bin create mode 100755 tests/xtvm_test/test_cases/QA_CASES/new_swap/swap.json_not_fixed create mode 100755 tests/xtvm_test/test_cases/QA_CASES/new_swap/swap.sol create mode 100755 tests/xtvm_test/test_cases/QA_CASES/new_swap/swap_sol_TokenSwap.abi create mode 100755 tests/xtvm_test/test_cases/QA_CASES/new_swap/swap_sol_TokenSwap.bin create mode 100755 tests/xtvm_test/test_cases/QA_CASES/new_swap/swap_sol_golden.abi create mode 100755 tests/xtvm_test/test_cases/QA_CASES/new_swap/swap_sol_golden.bin create mode 100755 tests/xtvm_test/test_cases/QA_CASES/new_swap/swap_sol_moyed.abi create mode 100755 tests/xtvm_test/test_cases/QA_CASES/new_swap/swap_sol_moyed.bin create mode 100755 tests/xtvm_test/test_cases/QA_CASES/swap/AliceToken.json create mode 100755 tests/xtvm_test/test_cases/QA_CASES/swap/AliceToken.sol create mode 100755 tests/xtvm_test/test_cases/QA_CASES/swap/AliceToken_sol_AliceToken.abi create mode 100755 tests/xtvm_test/test_cases/QA_CASES/swap/AliceToken_sol_AliceToken.bin create mode 100755 tests/xtvm_test/test_cases/QA_CASES/swap/BobToken.json create mode 100755 tests/xtvm_test/test_cases/QA_CASES/swap/BobToken.sol create mode 100755 tests/xtvm_test/test_cases/QA_CASES/swap/BobToken_sol_BobToken.abi create mode 100755 tests/xtvm_test/test_cases/QA_CASES/swap/BobToken_sol_BobToken.bin create mode 100755 tests/xtvm_test/test_cases/QA_CASES/swap/IERC20.sol create mode 100755 tests/xtvm_test/test_cases/QA_CASES/swap/IERC20_sol_IERC20.abi create mode 100755 tests/xtvm_test/test_cases/QA_CASES/swap/IERC20_sol_IERC20.bin create mode 100755 tests/xtvm_test/test_cases/QA_CASES/swap/TokenSwap.sol create mode 100755 tests/xtvm_test/test_cases/QA_CASES/swap/TokenSwap_sol_TokenSwap.abi create mode 100755 tests/xtvm_test/test_cases/QA_CASES/swap/TokenSwap_sol_TokenSwap.bin create mode 100644 tests/xtvm_test/test_cases/READMD.md create mode 100644 tests/xtvm_test/test_cases/add/add.bin create mode 100644 tests/xtvm_test/test_cases/add/add.json create mode 100644 tests/xtvm_test/test_cases/add/add.sol create mode 100644 tests/xtvm_test/test_cases/erc20/erc20.bin create mode 100644 tests/xtvm_test/test_cases/erc20/erc20.json create mode 100644 tests/xtvm_test/test_cases/erc20/erc20.sol create mode 100644 tests/xtvm_test/test_cases/storage_set_zero/storage_set_zero.bin create mode 100644 tests/xtvm_test/test_cases/storage_set_zero/storage_set_zero.json create mode 100644 tests/xtvm_test/test_cases/storage_set_zero/storage_set_zero.sol create mode 100644 tests/xtvm_test/test_main.cpp create mode 100644 tests/xtvm_test/test_tvm_cases_json.cpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 7fc74be2e..9be4aeaec 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -60,3 +60,4 @@ if (XBUILD_CONSORTIUM) add_subdirectory(xca_auth_test) endif() add_subdirectory(xstatistic_test) +add_subdirectory(xtvm_test) \ No newline at end of file diff --git a/tests/xtvm_test/CMakeLists.txt b/tests/xtvm_test/CMakeLists.txt new file mode 100644 index 000000000..83f08ee04 --- /dev/null +++ b/tests/xtvm_test/CMakeLists.txt @@ -0,0 +1,10 @@ +aux_source_directory(./ tests_src) +aux_source_directory(./fixture fixture_src) + +add_executable(xtvm_test ${tests_src} ${fixture_src}) + +add_dependencies(xtvm_test xtvm_runtime xdata xevm_common xbasic xcommon) + +get_target_property(TVM_ENGINE_DIR tvm_engine LOCATION) +target_link_libraries(xtvm_test PRIVATE ${TVM_ENGINE_DIR}/libtvm_engine.a) +target_link_libraries(xtvm_test PRIVATE xtvm_runtime xdata xevm_common xbasic xcommon gtest pthread dl) \ No newline at end of file diff --git a/tests/xtvm_test/fixture/xmock_statectx.h b/tests/xtvm_test/fixture/xmock_statectx.h new file mode 100644 index 000000000..7a4299098 --- /dev/null +++ b/tests/xtvm_test/fixture/xmock_statectx.h @@ -0,0 +1,69 @@ +#pragma once +#include "xdata/xnative_contract_address.h" +#include "xdata/xsystem_contract/xdata_structures.h" +#include "xdata/xunit_bstate.h" +#include "xstatectx/xstatectx_face.h" + +NS_BEG3(top, tvm, tests) + +class xmock_statectx : public statectx::xstatectx_face_t { +public: + xmock_statectx() { + } + + const data::xtablestate_ptr_t & get_table_state() const { + return m_tablestate_ptr; + } + + data::xunitstate_ptr_t load_unit_state(common::xaccount_address_t const & address) { + data::xaccountstate_ptr_t accountstate = load_account_state(address); + return accountstate->get_unitstate(); + } + + data::xaccountstate_ptr_t load_account_state(common::xaccount_address_t const & address) override { + if (m_mock_bstate.find(address.to_string()) == m_mock_bstate.end()) { + top::base::xauto_ptr bstate(new top::base::xvbstate_t(address.to_string(), 1, 1, "", "", 0, 0, 0)); + // if (address == evm_eth_bridge_contract_address) { + // xobject_ptr_t canvas = make_object_ptr(); + // bstate->new_string_map_var(data::system_contract::XPROPERTY_HEADERS, canvas.get()); + // bstate->new_string_map_var(data::system_contract::XPROPERTY_HEADERS_SUMMARY, canvas.get()); + // bstate->new_string_map_var(data::system_contract::XPROPERTY_ALL_HASHES, canvas.get()); + // bstate->new_string_map_var(data::system_contract::XPROPERTY_EFFECTIVE_HASHES, canvas.get()); + // bstate->new_string_var(data::system_contract::XPROPERTY_LAST_HASH, canvas.get()); + // auto bytes = (evm_common::h256()).asBytes(); + // bstate->load_string_var(data::system_contract::XPROPERTY_LAST_HASH)->reset({bytes.begin(), bytes.end()}, canvas.get()); + // } + auto unitstate_ptr = std::make_shared(bstate.get(), false); + base::xaccount_index_t aindex; + auto accountstate_ptr = std::make_shared(unitstate_ptr, aindex); + m_mock_bstate[address.to_string()] = accountstate_ptr; + } + return m_mock_bstate.at(address.to_string()); + } + + bool do_rollback() { + return false; + } + + size_t do_snapshot() { + return 0; + } + + std::string get_table_address() const { + xassert(false); + return table_address; + } + + bool is_state_dirty() const { + return true; + } + + // void add_balance() + + data::xtablestate_ptr_t m_tablestate_ptr; + std::string table_address; + + std::map m_mock_bstate; +}; + +NS_END3 \ No newline at end of file diff --git a/tests/xtvm_test/fixture/xtvm_test_fixture.cpp b/tests/xtvm_test/fixture/xtvm_test_fixture.cpp new file mode 100644 index 000000000..5b7468e2d --- /dev/null +++ b/tests/xtvm_test/fixture/xtvm_test_fixture.cpp @@ -0,0 +1,295 @@ +#include "tests/xtvm_test/fixture/xtvm_test_fixture.h" + +#include "xbasic/xhex.h" +#include "xdata/xconsensus_action.h" +#include "xtvm_runtime/xtvm.h" + +#include +#include + +#define EXPECT_TRUE_OR_RETURN_FALSE(expr) \ + { \ + EXPECT_TRUE(expr); \ + if ((expr) == false) \ + return false; \ + } + +#define EXPECT_EQ_OR_RETURN_FALSE(lhs, rhs) \ + { \ + EXPECT_EQ(lhs, rhs); \ + if (lhs != rhs) \ + return false; \ + } + +static std::string evm_to_t8_address(std::string const & input) { + if (input.substr(0, 2) == "0x") { + return "T80000" + input.substr(2); + } + if (input.substr(0, 6) == "T80000") { + return input; + } + return "T80000" + input; +} + +void find_json_files(const char * name, std::vector & res, int indent = 0) { + DIR * dir; + struct dirent * entry; + + if (!(dir = opendir(name))) + return; + + while ((entry = readdir(dir)) != NULL) { + if (entry->d_type == DT_DIR) { + char path[1024]; + if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) + continue; + snprintf(path, sizeof(path), "%s/%s", name, entry->d_name); + printf("%*s[%s]\n", indent, "", entry->d_name); + find_json_files(path, res, indent + 2); + } else { + std::string file_name{entry->d_name}; + if (file_name.size() >= 6 && file_name.substr(file_name.size() - 5) == ".json") { + res.push_back(std::string{name} + "/" + file_name); + printf("%*s- %s\n", indent, "", entry->d_name); + // printf("find:%s/%s %s", name, entry->d_name, file_name.c_str()); + } + } + } + closedir(dir); + return; +} + +top::xbytes_t get_contract_bin(std::string const & current_json_file_directory, std::string const & code_file_path) { + std::ifstream code_file_stream(current_json_file_directory + code_file_path); + std::string bytecode_hex_string; + code_file_stream >> bytecode_hex_string; + + std::error_code ec; + auto code_bytes = top::from_hex(bytecode_hex_string, ec); + EXPECT_TRUE(!ec); + return code_bytes; +} + + + +NS_BEG3(top, tvm, tests) + +bool xtest_tvm_fixture::execute() { + if (tvm_tests_argc <= 1) { + std::cout << "no enough args. Please set test_cases directory!" << std::endl; + return false; + } + + std::vector res; + std::cout << "-- find .json files:" << std::endl; + find_json_files(tvm_tests_argv[1], res); + std::cout << "-- " << res.size() << " files found" << std::endl; + m_summary.json_files_num = res.size(); + std::cout << "==================================" << std::endl; + for (auto p : res) { + std::cout << "-- [DO TEST] file: " << p << std::endl; + // init_env(); + execute_test_case(p); + std::cout << "-- finish test_file: " << p << std::endl; + // clean_env(); + deployed_contract_map.clear(); + static_cast(statestore.get())->m_mock_bstate.clear(); + } + std::cout << "==================================" << std::endl; + + m_summary.dump(); + return true; +} + +bool xtest_tvm_fixture::execute_test_case(std::string const & json_file_path) { + std::ifstream i{json_file_path}; + + if (json_file_path.find("/") != std::string::npos) { + current_json_file_directory = json_file_path.substr(0, json_file_path.find_last_of("/") + 1); + } else { + current_json_file_directory = ""; + } + + json j; + i >> j; + auto pre_data = j["pre_data"]; + auto deploy_list = j["deploy_contract"]; + auto testcases_list = j["test_cases"]; + m_summary.deploy_cases_num += deploy_list.size(); + m_summary.call_cases_num += testcases_list.size(); + + // todo pre_data + + std::size_t deploy_case_succ_num = 0; + std::size_t call_case_succ_num = 0; + for (auto each_deploy : deploy_list) { + if (!each_deploy.empty()) { + try { + if (do_deploy_test(each_deploy)) { + deploy_case_succ_num++; + } else { + std::cout << "\033[1;31m -- deploy case failed --\033[0m" << std::endl; + std::cout << " case input:\033[1;32m" << each_deploy << "\033[0m\n" << std::endl; + } + } catch (nlohmann::detail::type_error & e) { + std::cout << " catch json error: " << e.what() << std::endl; + std::cout << "\033[1;31m -- deploy case failed --\033[0m" << std::endl; + std::cout << " case input:\033[1;32m" << each_deploy << "\033[0m\n" << std::endl; + } catch (const std::exception & e) { + std::cout << " catch exception: " << e.what() << std::endl; + std::cout << "\033[1;31m -- deploy case failed --\033[0m" << std::endl; + std::cout << " case input:\033[1;32m" << each_deploy << "\033[0m\n" << std::endl; + } catch (...) { + std::cout << "\033[1;31m -- deploy case failed --\033[0m" << std::endl; + std::cout << " case input:\033[1;32m" << each_deploy << "\033[0m\n" << std::endl; + } + } + } + + // std::cout << testcases_list << std::endl; + for (auto each_call : testcases_list) { + if (!each_call.empty()) { + try { + if (do_call_test(each_call)) { + call_case_succ_num++; + } else { + std::cout << "\033[1;31m -- call case failed --\033[0m" << std::endl; + std::cout << " case input:\033[1;32m" << each_call << "\033[0m\n" << std::endl; + } + } catch (nlohmann::detail::type_error & e) { + std::cout << " catch json error: " << e.what() << std::endl; + std::cout << "\033[1;31m -- call case failed --\033[0m" << std::endl; + std::cout << " case input:\033[1;32m" << each_call << "\033[0m\n" << std::endl; + } catch (const std::exception & e) { + std::cout << " catch exception: " << e.what() << std::endl; + std::cout << "\033[1;31m -- call case failed --\033[0m" << std::endl; + std::cout << " case input:\033[1;32m" << each_call << "\033[0m\n" << std::endl; + } catch (...) { + std::cout << "\033[1;31m -- call case failed --\033[0m" << std::endl; + std::cout << " case input:\033[1;32m" << each_call << "\033[0m\n" << std::endl; + } + } + } + std::cout << " -- succ deploy:" << deploy_case_succ_num << ", succ call:" << call_case_succ_num << std::endl; + + return true; +} + +bool xtest_tvm_fixture::do_deploy_test(json const & each_deploy) { + std::string src_address = each_deploy["src_address"]; + std::string code_file = each_deploy["code_file_path"]; + uint64_t gas_limit = each_deploy["gas_limit"]; + std::string value = each_deploy["value"]; + evm_common::u256 value_256{value}; + + auto expected = each_deploy["expected"]; + std::string contract_name_symbol = expected["extra_message"]; + + auto tvm_action = top::make_unique>( + common::xaccount_address_t{src_address}, eth_zero_address, value_256, get_contract_bin(current_json_file_directory, code_file), gas_limit); + + top::tvm::xtop_vm tvm{statestore}; + + auto action_result = tvm.execute_action(std::move(tvm_action), vm_param); + + auto contract_address = action_result.extra_msg; + std::cout << "[TEST fixture]: deploy contract: " << contract_name_symbol << ": " << contract_address << std::endl; + deployed_contract_map[contract_name_symbol] = contract_address; + + // check + uint32_t expected_result = expected["status"]; + EXPECT_EQ_OR_RETURN_FALSE(action_result.status, expected_result); + + uint64_t expected_gas_used = expected["gas_used"]; + EXPECT_EQ_OR_RETURN_FALSE(action_result.used_gas, expected_gas_used); + + EXPECT_TRUE_OR_RETURN_FALSE(check_logs(action_result.logs, expected["logs"])); + + m_summary.succ_deploy_cases += 1; + + return true; +} + +bool xtest_tvm_fixture::do_call_test(json const & each_call) { + std::string src_address = each_call["src_address"]; + std::string contract_name_symbol = each_call["target_address"]; + EXPECT_TRUE_OR_RETURN_FALSE(deployed_contract_map.find(contract_name_symbol) != deployed_contract_map.end()); + + std::string target_address = deployed_contract_map.at(contract_name_symbol); + uint64_t gas_limit = each_call["gas_limit"]; + std::string value = each_call["value"]; + evm_common::u256 value_256{value}; + + std::error_code ec; + xbytes_t input_data = top::from_hex(each_call["data"], ec); + EXPECT_TRUE(!ec); + + auto expected = each_call["expected"]; + + auto tvm_action = top::make_unique>( + common::xaccount_address_t{src_address}, common::xaccount_address_t{evm_to_t8_address(target_address)}, value_256, input_data, gas_limit); + + top::tvm::xtop_vm tvm{statestore}; + + auto action_result = tvm.execute_action(std::move(tvm_action), vm_param); + + // check + uint32_t expected_result = expected["status"]; + EXPECT_EQ_OR_RETURN_FALSE(action_result.status, expected_result); + + uint64_t expected_gas_used = expected["gas_used"]; + EXPECT_EQ_OR_RETURN_FALSE(action_result.used_gas, expected_gas_used); + + std::string expected_extra_msg = expected["extra_message"]; + if (!expected_extra_msg.empty()) { + EXPECT_EQ_OR_RETURN_FALSE(action_result.extra_msg, expected_extra_msg); + } + + EXPECT_TRUE_OR_RETURN_FALSE(check_logs(action_result.logs, expected["logs"])); + + m_summary.succ_call_cases += 1; + + return true; +} + +bool xtest_tvm_fixture::check_logs(std::vector const & result_logs, json const & expected_json) { + if (expected_json.empty()) { + EXPECT_TRUE_OR_RETURN_FALSE(result_logs.empty()); + } else { + EXPECT_EQ_OR_RETURN_FALSE(result_logs.size(), expected_json.size()); + if (result_logs.size() == expected_json.size()) { + auto index = 0; + for (auto _log : expected_json) { + auto res_log = result_logs[index]; + + std::string contract_name_symbol = _log["address"]; + EXPECT_TRUE_OR_RETURN_FALSE(deployed_contract_map.find(contract_name_symbol) != deployed_contract_map.end()); + EXPECT_EQ_OR_RETURN_FALSE(res_log.address.to_hex_string(), deployed_contract_map[contract_name_symbol]); + + std::vector expected_topics; + for (auto _each_topic : _log["topics"]) { + expected_topics.push_back(_each_topic); + } + std::string expected_data = _log["data"]; + + EXPECT_EQ_OR_RETURN_FALSE(res_log.topics.size(), expected_topics.size()); + if (res_log.topics.size() == expected_topics.size()) { + auto topics_index = 0; + for (auto _topics : expected_topics) { + auto res_topic = top::to_hex_prefixed(res_log.topics[topics_index].asBytes()); + EXPECT_EQ_OR_RETURN_FALSE(res_topic, expected_topics[topics_index]); + } + } + + // EXPECT_EQ_OR_RETURN_FALSE(res_log.topics, expected_topics); + std::string data_hex = res_log.data.size() > 0 ? top::to_hex_prefixed(res_log.data) : ""; + EXPECT_EQ_OR_RETURN_FALSE(data_hex, expected_data); + + index++; + } + } + } + return true; +} + +NS_END3 \ No newline at end of file diff --git a/tests/xtvm_test/fixture/xtvm_test_fixture.h b/tests/xtvm_test/fixture/xtvm_test_fixture.h new file mode 100644 index 000000000..b9157c1dd --- /dev/null +++ b/tests/xtvm_test/fixture/xtvm_test_fixture.h @@ -0,0 +1,77 @@ +#pragma once + +#include "gtest/gtest.h" +#include "tests/xtvm_test/fixture/xmock_statectx.h" +#include "xtvm_runtime/xtvm.h" + +#include +using json = nlohmann::json; + +#include +#include + +extern int tvm_tests_argc; +extern char ** tvm_tests_argv; + +NS_BEG3(top, tvm, tests) +class xtest_tvm_fixture : public testing::Test { +public: + xtest_tvm_fixture() = default; + xtest_tvm_fixture(xtest_tvm_fixture const &) = delete; + xtest_tvm_fixture & operator=(xtest_tvm_fixture const &) = delete; + xtest_tvm_fixture(xtest_tvm_fixture &&) = default; + xtest_tvm_fixture & operator=(xtest_tvm_fixture &&) = default; + ~xtest_tvm_fixture() override = default; + +public: + bool execute(); + bool execute_test_case(std::string const & json_file_path); + +protected: + void SetUp() override { + Test::SetUp(); + } + void TearDown() override { + Test::TearDown(); + } + +private: + bool do_deploy_test(json const & each_deploy); + bool do_call_test(json const & each_call); + + bool check_logs(std::vector const & result_logs, json const & expected_json); + +private: + std::string current_json_file_directory{""}; + using eth_address_str = std::string; + std::map deployed_contract_map; + std::shared_ptr statestore{std::make_shared()}; + txexecutor::xvm_para_t vm_param{0, "random_seed", 0, 0, 0, eth_zero_address}; + + struct summary_infos { + std::size_t json_files_num{0}; + std::size_t deploy_cases_num{0}; + std::size_t call_cases_num{0}; + std::size_t succ_deploy_cases{0}; + std::size_t succ_call_cases{0}; + + void dump() { + xkinfo("[tvm_fixture dump]: deceted json_file number(%zu) - Dect number: deploy cases(%zu), call cases(%zu). - Succ number: deploy cases(%zu), call cases(%zu)", + json_files_num, + deploy_cases_num, + call_cases_num, + succ_deploy_cases, + succ_call_cases); + printf("[tvm_fixture dump]: deceted json_file number(%zu)\n - Dect number: deploy cases(%zu), call cases(%zu).\n - Succ number: deploy cases(%zu), call cases(%zu)\n", + json_files_num, + deploy_cases_num, + call_cases_num, + succ_deploy_cases, + succ_call_cases); + } + }; + + summary_infos m_summary; +}; + +NS_END3 \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/array/Array.bin b/tests/xtvm_test/test_cases/QA_CASES/array/Array.bin new file mode 100755 index 000000000..779527379 --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/array/Array.bin @@ -0,0 +1 @@ +0x608060405234801561001057600080fd5b5061033d806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c8063773d45e014610030575b600080fd5b61004a60048036038101906100459190610199565b610060565b60405161005791906101e8565b60405180910390f35b600080600367ffffffffffffffff81111561007e5761007d610203565b5b6040519080825280602002602001820160405280156100ac5781602001602082028036833780820191505090505b5090506001816000815181106100c5576100c4610232565b5b6020026020010181815250506002816001815181106100e7576100e6610232565b5b60200260200101818152505060038160028151811061010957610108610232565b5b60200260200101818152505080838151811061012857610127610232565b5b602002602001015181858151811061014357610142610232565b5b60200260200101516101559190610290565b91505092915050565b600080fd5b6000819050919050565b61017681610163565b811461018157600080fd5b50565b6000813590506101938161016d565b92915050565b600080604083850312156101b0576101af61015e565b5b60006101be85828601610184565b92505060206101cf85828601610184565b9150509250929050565b6101e281610163565b82525050565b60006020820190506101fd60008301846101d9565b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600061029b82610163565b91506102a683610163565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff038211156102db576102da610261565b5b82820190509291505056fea26469706673582212202438116356d0d7c6c1cc00376d91270403be9174eadff0bff308ef4878cf621864736f6c637823302e382e31332d63692e323032322e322e31362b636f6d6d69742e64613530313736620054 \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/array/Array.json b/tests/xtvm_test/test_cases/QA_CASES/array/Array.json new file mode 100755 index 000000000..00bbe3d87 --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/array/Array.json @@ -0,0 +1,85 @@ +{ + "pre_data": {}, + "deploy_contract": [ + { + "src_address": "T600045B38Da6a701c568545dCfcB03FcB875f56beddC4", + "code_file_path": "Array.bin", + "gas_limit": 265977, + "value": "0", + "expected": { + "status": 0, + "extra_message": "contract_one", + "gas_used": 231284, + "logs": [] + } + } + ], + "test_cases": [ + { + "__comments":"数组越界,执行失败", + "src_address": "T600045B38Da6a701c568545dCfcB03FcB875f56beddC4", + "target_address": "contract_one", + "data": "0x773d45e000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000004", + "gas_limit": 3000000, + "value": "0", + "expected": { + "status": 1, + "extra_message": "", + "gas_used": 22338, + "logs": [] + } + },{ + "__comments":"缺少参数,执行失败", + "src_address": "T60004636A4494f0cbe56528EA1ea51fD4eccDDCF04994", + "target_address": "contract_one", + "data": "0xf88807850ba43b740082978f9432a191017beff8b6dbbbfc5fe9ddac2acfd0edd780a4f0fdf834000000000000000000000000000000000000000000000000000000000000000a2ca0051ba066eec5c08e4e4d12df8fc3b60cb7844d464afff130b5939e69b4e74ec6a061086bbc361423483064b0be428666c8bf79ea57bd8e3cc263a312e820546961", + "gas_limit": 3000000, + "value": "0", + "expected": { + "status": 1, + "extra_message": "", + "gas_used": 22928, + "logs": [] + } + },{ + "__comments":"参数类型异常,执行失败", + "src_address": "T60004636A4494f0cbe56528EA1ea51fD4eccDDCF04994", + "target_address": "contract_one", + "data": "0xf8a907850ba43b740082978f9432a191017beff8b6dbbbfc5fe9ddac2acfd0edd780b844ba3ef0f5000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000636a4494f0cbe56528ea1ea51fd4eccddcf049942ca0a5336abfb98e0f7bdc60ac1592ecf120b4ee3af786cbbddb962217fd612663aca077b01fdf56ebf210f63e2aa15fe2c0a490ca6180fd8dff9d2998aea471fb13d8", + "gas_limit": 3000000, + "value": "0", + "expected": { + "status": 1, + "extra_message": "", + "gas_used": 23312, + "logs": [] + } + },{ + "__comments":"参数过多,执行失败", + "src_address": "T60004636A4494f0cbe56528EA1ea51fD4eccDDCF04994", + "target_address": "contract_one", + "data": "0xf8c907850ba43b740082978f9432a191017beff8b6dbbbfc5fe9ddac2acfd0edd780b864bf3b9e380000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000012ba015fd022d480a801598326ae840bdf8583c33e7d1f1c1f7c28ef97b2f97dd858ca02de43092ba696674c6a92fa42167c524bcb24363ce7683073bfc1a3061879d71", + "gas_limit": 3000000, + "value": "0", + "expected": { + "status": 1, + "extra_message": "", + "gas_used": 23224, + "logs": [] + } + },{ + "__comments":"非法bytecode,执行失败", + "src_address": "T60004636A4494f0cbe56528EA1ea51fD4eccDDCF04994", + "target_address": "contract_one", + "data": "0xf8c907850ba43b740082978f9432a191017beff8b6dbbbfc5fe9ddac2acfd0edd780b864bf3b9e380000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000012ba015fd022d480a801598326ae840bdf8583c33e7d1f1c1f7c28ef97b2f97dd858ca02de43092ba696674c6a92fa42167c524bcb24363ce7683073bfc1a3061879d7198", + "gas_limit": 3000000, + "value": "0", + "expected": { + "status": 1, + "extra_message": "", + "gas_used": 23240, + "logs": [] + } + } + ] +} \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/array/Array.sol b/tests/xtvm_test/test_cases/QA_CASES/array/Array.sol new file mode 100755 index 000000000..1827aef8c --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/array/Array.sol @@ -0,0 +1,12 @@ +pragma solidity ^0.8.10; + +contract Array { + + function a(uint256 x,uint256 y) public returns(uint256){ + uint[] memory a = new uint[](3); + a[0] = 1; + a[1] = 2; + a[2] = 3; + return a[x] + a[y]; + } +} diff --git a/tests/xtvm_test/test_cases/QA_CASES/base/Storage/Storge.bin b/tests/xtvm_test/test_cases/QA_CASES/base/Storage/Storge.bin new file mode 100755 index 000000000..4a0d3a31f --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/base/Storage/Storge.bin @@ -0,0 +1 @@ +608060405234801561001057600080fd5b50610150806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80632e64cec11461003b5780636057361d14610059575b600080fd5b610043610075565b60405161005091906100a1565b60405180910390f35b610073600480360381019061006e91906100ed565b61007e565b005b60008054905090565b8060008190555050565b6000819050919050565b61009b81610088565b82525050565b60006020820190506100b66000830184610092565b92915050565b600080fd5b6100ca81610088565b81146100d557600080fd5b50565b6000813590506100e7816100c1565b92915050565b600060208284031215610103576101026100bc565b5b6000610111848285016100d8565b9150509291505056fea2646970667358221220693db7f6c645da5fc3e0e02e67f874f502d78d9061d19886b3182389f9e60d8e64736f6c634300080d0033 \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/base/Storage/Storge.json b/tests/xtvm_test/test_cases/QA_CASES/base/Storage/Storge.json new file mode 100755 index 000000000..5ef7e374b --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/base/Storage/Storge.json @@ -0,0 +1,33 @@ +{ + "pre_data": {}, + "deploy_contract": [ + { + "src_address": "T600045B38Da6a701c568545dCfcB03FcB875f56beddC4", + "code_file_path": "Owner.bin", + "gas_limit": 144515, + "value": "0", + "expected": { + "status": 0, + "extra_message": "contract_one", + "gas_used": 53000, + "logs": [] + } + } + ], + "test_cases": [ + { + "__comments":"设置存储数值", + "src_address": "T600045B38Da6a701c568545dCfcB03FcB875f56beddC4", + "target_address": "contract_one", + "data": "0x6057361d0000000000000000000000000000000000000000000000000000000000000001", + "gas_limit": 50283, + "value": "0", + "expected": { + "status": 0, + "extra_message": "", + "gas_used": 21204, + "logs": [] + } + } + ] +} \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/base/Storage/Storge.sol b/tests/xtvm_test/test_cases/QA_CASES/base/Storage/Storge.sol new file mode 100755 index 000000000..d27741256 --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/base/Storage/Storge.sol @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: GPL-3.0 + +pragma solidity >=0.7.0 <0.9.0; + +/** + * @title Storage + * @dev Store & retrieve value in a variable + */ +contract Storage { + + uint256 number; + + /** + * @dev Store value in variable + * @param num value to store + */ + function store(uint256 num) public { + number = num; + } + + /** + * @dev Return value + * @return value of 'number' + */ + function retrieve() public view returns (uint256){ + return number; + } +} \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/base/owner/Owner.bin b/tests/xtvm_test/test_cases/QA_CASES/base/owner/Owner.bin new file mode 100755 index 000000000..d13eea5ef --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/base/owner/Owner.bin @@ -0,0 +1,2 @@ +608060405234801561001057600080fd5b50336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167f342827c97908e5e2f71151c08502a66d44b6f758e3ac2f1de95f02eb95f0a73560405160405180910390a3610356806100db6000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c8063893d20e81461003b578063a6f9dae114610059575b600080fd5b610043610075565b604051610050919061022a565b60405180910390f35b610073600480360381019061006e9190610276565b61009e565b005b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461012c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161012390610300565b60405180910390fd5b8073ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f342827c97908e5e2f71151c08502a66d44b6f758e3ac2f1de95f02eb95f0a73560405160405180910390a3806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000610214826101e9565b9050919050565b61022481610209565b82525050565b600060208201905061023f600083018461021b565b92915050565b600080fd5b61025381610209565b811461025e57600080fd5b50565b6000813590506102708161024a565b92915050565b60006020828403121561028c5761028b610245565b5b600061029a84828501610261565b91505092915050565b600082825260208201905092915050565b7f43616c6c6572206973206e6f74206f776e657200000000000000000000000000600082015250565b60006102ea6013836102a3565b91506102f5826102b4565b602082019050919050565b60006020820190508181036000830152610319816102dd565b905091905056fea2646970667358221220a5b3cda320c4df0ab8fe1b80d4e207e44de063ed9421cf26c5add2e091a9c45264736f6c634300080d0033 + \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/base/owner/Owner.json b/tests/xtvm_test/test_cases/QA_CASES/base/owner/Owner.json new file mode 100755 index 000000000..08a5637b0 --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/base/owner/Owner.json @@ -0,0 +1,63 @@ +{ + "pre_data": {}, + "deploy_contract": [ + { + "src_address": "T600045B38Da6a701c568545dCfcB03FcB875f56beddC4", + "code_file_path": "Owner.bin", + "gas_limit": 303525, + "value": "0", + "expected": { + "status": 0, + "extra_message": "contract_one", + "gas_used": 263934, + "logs": [{ + "address": "contract_one", + "topics": [ + "0x342827c97908e5e2f71151c08502a66d44b6f758e3ac2f1de95f02eb95f0a735", + "0x0000000000000000000000000000000000000000000000000000000000000000", + "0x0000000000000000000000005b38da6a701c568545dcfcb03fcb875f56beddc4" + ], + "data": "" + }] + } + } + ], + "test_cases": [ + { + "__comments":"设置owner", + "src_address": "T600045B38Da6a701c568545dCfcB03FcB875f56beddC4", + "target_address": "contract_one", + "data": "0xa6f9dae1000000000000000000000000636a4494f0cbe56528ea1ea51fd4eccddcf04994", + "gas_limit": 33119, + "value": "0", + "expected": { + "status": 0, + "extra_message": "", + "gas_used": 28799, + "logs": [{ + "address": "contract_one", + "topics": [ + "0x342827c97908e5e2f71151c08502a66d44b6f758e3ac2f1de95f02eb95f0a735", + "0x0000000000000000000000005b38da6a701c568545dcfcb03fcb875f56beddc4", + "0x000000000000000000000000636a4494f0cbe56528ea1ea51fd4eccddcf04994" + ], + "data": "" + }] + } + }, + { + "__comments":"非owner用户设置owner,设置失败", + "src_address": "T600045B38Da6a701c568545dCfcB03FcB875f56beddC4", + "target_address": "contract_one", + "data": "0xa6f9dae1000000000000000000000000636a4494f0cbe56528ea1ea51fd4eccddcf04994", + "gas_limit": 3000000, + "value": "0", + "expected": { + "status": 1, + "extra_message": "", + "gas_used": 24341, + "logs": [] + } + } + ] +} \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/base/owner/Owner.sol b/tests/xtvm_test/test_cases/QA_CASES/base/owner/Owner.sol new file mode 100755 index 000000000..25ac2bfe3 --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/base/owner/Owner.sol @@ -0,0 +1,54 @@ +// SPDX-License-Identifier: GPL-3.0 + +pragma solidity >=0.7.0 <0.9.0; + +// import "hardhat/console.sol"; + +/** + * @title Owner + * @dev Set & change owner + */ +contract Owner { + + address private owner; + + // event for EVM logging + event OwnerSet(address indexed oldOwner, address indexed newOwner); + + // modifier to check if caller is owner + modifier isOwner() { + // If the first argument of 'require' evaluates to 'false', execution terminates and all + // changes to the state and to Ether balances are reverted. + // This used to consume all gas in old EVM versions, but not anymore. + // It is often a good idea to use 'require' to check if functions are called correctly. + // As a second argument, you can also provide an explanation about what went wrong. + require(msg.sender == owner, "Caller is not owner"); + _; + } + + /** + * @dev Set contract deployer as owner + */ + constructor() { + // console.log("Owner contract deployed by:", msg.sender); + owner = msg.sender; // 'msg.sender' is sender of current call, contract deployer for a constructor + emit OwnerSet(address(0), owner); + } + + /** + * @dev Change owner + * @param newOwner address of new owner + */ + function changeOwner(address newOwner) public isOwner { + emit OwnerSet(owner, newOwner); + owner = newOwner; + } + + /** + * @dev Return owner address + * @return address of owner + */ + function getOwner() external view returns (address) { + return owner; + } +} \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/bigcontract/SoBig.bin b/tests/xtvm_test/test_cases/QA_CASES/bigcontract/SoBig.bin new file mode 100755 index 000000000..ea9e10fc5 --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/bigcontract/SoBig.bin @@ -0,0 +1 @@ +0x608060405234801561001057600080fd5b50613148806100206000396000f3fe608060405234801561001057600080fd5b50600436106102bb5760003560e01c806373ff9ece11610182578063aa3bdb5b116100e9578063ccffceb3116100a2578063e8e496bb1161007c578063e8e496bb14610b30578063ebd5a3c414610b60578063f559d78114610b90578063f5bba90a14610bc0576102bb565b8063ccffceb314610aa0578063cffe3ba014610ad0578063d0f081b514610b00576102bb565b8063aa3bdb5b14610980578063b20ac45e146109b0578063b52323ef146109e0578063c081436d14610a10578063c276103114610a40578063c6c664a014610a70576102bb565b806392417e791161013b57806392417e791461086057806396628ca61461089057806397842cce146108c05780639c34a15f146108f0578063a4a6fb9314610920578063a61510ae14610950576102bb565b806373ff9ece14610740578063773d45e0146107705780637b33d21a146107a05780638127db60146107d057806385a9f7a5146108005780638887dfe414610830576102bb565b80633a2ae9ae116102265780634f426e0e116101df5780634f426e0e146106205780635016dfbc14610650578063649d5147146106805780636914e460146106b05780637066dc9d146106e0578063716ba98314610710576102bb565b80633a2ae9ae146105005780633bcd4b99146105305780633fa028e5146105605780634078910314610590578063468922be146105c05780634f3464f5146105f0576102bb565b80631f3b231b116102785780631f3b231b146103e05780632021012c14610410578063259ba3eb14610440578063288e45291461047057806333f4ab15146104a05780633479551a146104d0576102bb565b80630345a25b146102c057806309e58646146102f057806313d1aa2e146103205780631aab1adf146103505780631cd65ae4146103805780631da9ac4a146103b0575b600080fd5b6102da60048036038101906102d59190612fc5565b610bf0565b6040516102e79190613014565b60405180910390f35b61030a60048036038101906103059190612fc5565b610caa565b6040516103179190613014565b60405180910390f35b61033a60048036038101906103359190612fc5565b610d64565b6040516103479190613014565b60405180910390f35b61036a60048036038101906103659190612fc5565b610e1e565b6040516103779190613014565b60405180910390f35b61039a60048036038101906103959190612fc5565b610ed8565b6040516103a79190613014565b60405180910390f35b6103ca60048036038101906103c59190612fc5565b610f92565b6040516103d79190613014565b60405180910390f35b6103fa60048036038101906103f59190612fc5565b61104c565b6040516104079190613014565b60405180910390f35b61042a60048036038101906104259190612fc5565b611106565b6040516104379190613014565b60405180910390f35b61045a60048036038101906104559190612fc5565b6111c0565b6040516104679190613014565b60405180910390f35b61048a60048036038101906104859190612fc5565b61127a565b6040516104979190613014565b60405180910390f35b6104ba60048036038101906104b59190612fc5565b611334565b6040516104c79190613014565b60405180910390f35b6104ea60048036038101906104e59190612fc5565b6113ee565b6040516104f79190613014565b60405180910390f35b61051a60048036038101906105159190612fc5565b6114a8565b6040516105279190613014565b60405180910390f35b61054a60048036038101906105459190612fc5565b611562565b6040516105579190613014565b60405180910390f35b61057a60048036038101906105759190612fc5565b61161c565b6040516105879190613014565b60405180910390f35b6105aa60048036038101906105a59190612fc5565b6116d6565b6040516105b79190613014565b60405180910390f35b6105da60048036038101906105d59190612fc5565b611790565b6040516105e79190613014565b60405180910390f35b61060a60048036038101906106059190612fc5565b61184a565b6040516106179190613014565b60405180910390f35b61063a60048036038101906106359190612fc5565b611904565b6040516106479190613014565b60405180910390f35b61066a60048036038101906106659190612fc5565b6119be565b6040516106779190613014565b60405180910390f35b61069a60048036038101906106959190612fc5565b611a78565b6040516106a79190613014565b60405180910390f35b6106ca60048036038101906106c59190612fc5565b611b32565b6040516106d79190613014565b60405180910390f35b6106fa60048036038101906106f59190612fc5565b611bec565b6040516107079190613014565b60405180910390f35b61072a60048036038101906107259190612fc5565b611ca6565b6040516107379190613014565b60405180910390f35b61075a60048036038101906107559190612fc5565b611d60565b6040516107679190613014565b60405180910390f35b61078a60048036038101906107859190612fc5565b611e1a565b6040516107979190613014565b60405180910390f35b6107ba60048036038101906107b59190612fc5565b611ed4565b6040516107c79190613014565b60405180910390f35b6107ea60048036038101906107e59190612fc5565b611f8e565b6040516107f79190613014565b60405180910390f35b61081a60048036038101906108159190612fc5565b612048565b6040516108279190613014565b60405180910390f35b61084a60048036038101906108459190612fc5565b612102565b6040516108579190613014565b60405180910390f35b61087a60048036038101906108759190612fc5565b6121bc565b6040516108879190613014565b60405180910390f35b6108aa60048036038101906108a59190612fc5565b612276565b6040516108b79190613014565b60405180910390f35b6108da60048036038101906108d59190612fc5565b612330565b6040516108e79190613014565b60405180910390f35b61090a60048036038101906109059190612fc5565b6123ea565b6040516109179190613014565b60405180910390f35b61093a60048036038101906109359190612fc5565b6124a4565b6040516109479190613014565b60405180910390f35b61096a60048036038101906109659190612fc5565b61255e565b6040516109779190613014565b60405180910390f35b61099a60048036038101906109959190612fc5565b612618565b6040516109a79190613014565b60405180910390f35b6109ca60048036038101906109c59190612fc5565b6126d2565b6040516109d79190613014565b60405180910390f35b6109fa60048036038101906109f59190612fc5565b61278c565b604051610a079190613014565b60405180910390f35b610a2a6004803603810190610a259190612fc5565b612846565b604051610a379190613014565b60405180910390f35b610a5a6004803603810190610a559190612fc5565b612900565b604051610a679190613014565b60405180910390f35b610a8a6004803603810190610a859190612fc5565b6129ba565b604051610a979190613014565b60405180910390f35b610aba6004803603810190610ab59190612fc5565b612a74565b604051610ac79190613014565b60405180910390f35b610aea6004803603810190610ae59190612fc5565b612b2e565b604051610af79190613014565b60405180910390f35b610b1a6004803603810190610b159190612fc5565b612be8565b604051610b279190613014565b60405180910390f35b610b4a6004803603810190610b459190612fc5565b612ca2565b604051610b579190613014565b60405180910390f35b610b7a6004803603810190610b759190612fc5565b612d5c565b604051610b879190613014565b60405180910390f35b610baa6004803603810190610ba59190612fc5565b612e16565b604051610bb79190613014565b60405180910390f35b610bda6004803603810190610bd59190612fc5565b612ed0565b604051610be79190613014565b60405180910390f35b600080600367ffffffffffffffff811115610c0e57610c0d61302f565b5b604051908082528060200260200182016040528015610c3c5781602001602082028036833780820191505090505b509050600181600081518110610c5557610c5461305e565b5b602002602001018181525050808381518110610c7457610c7361305e565b5b6020026020010151818581518110610c8f57610c8e61305e565b5b6020026020010151610ca191906130bc565b91505092915050565b600080600367ffffffffffffffff811115610cc857610cc761302f565b5b604051908082528060200260200182016040528015610cf65781602001602082028036833780820191505090505b509050600181600081518110610d0f57610d0e61305e565b5b602002602001018181525050808381518110610d2e57610d2d61305e565b5b6020026020010151818581518110610d4957610d4861305e565b5b6020026020010151610d5b91906130bc565b91505092915050565b600080600367ffffffffffffffff811115610d8257610d8161302f565b5b604051908082528060200260200182016040528015610db05781602001602082028036833780820191505090505b509050600181600081518110610dc957610dc861305e565b5b602002602001018181525050808381518110610de857610de761305e565b5b6020026020010151818581518110610e0357610e0261305e565b5b6020026020010151610e1591906130bc565b91505092915050565b600080600367ffffffffffffffff811115610e3c57610e3b61302f565b5b604051908082528060200260200182016040528015610e6a5781602001602082028036833780820191505090505b509050600181600081518110610e8357610e8261305e565b5b602002602001018181525050808381518110610ea257610ea161305e565b5b6020026020010151818581518110610ebd57610ebc61305e565b5b6020026020010151610ecf91906130bc565b91505092915050565b600080600367ffffffffffffffff811115610ef657610ef561302f565b5b604051908082528060200260200182016040528015610f245781602001602082028036833780820191505090505b509050600181600081518110610f3d57610f3c61305e565b5b602002602001018181525050808381518110610f5c57610f5b61305e565b5b6020026020010151818581518110610f7757610f7661305e565b5b6020026020010151610f8991906130bc565b91505092915050565b600080600367ffffffffffffffff811115610fb057610faf61302f565b5b604051908082528060200260200182016040528015610fde5781602001602082028036833780820191505090505b509050600181600081518110610ff757610ff661305e565b5b6020026020010181815250508083815181106110165761101561305e565b5b60200260200101518185815181106110315761103061305e565b5b602002602001015161104391906130bc565b91505092915050565b600080600367ffffffffffffffff81111561106a5761106961302f565b5b6040519080825280602002602001820160405280156110985781602001602082028036833780820191505090505b5090506001816000815181106110b1576110b061305e565b5b6020026020010181815250508083815181106110d0576110cf61305e565b5b60200260200101518185815181106110eb576110ea61305e565b5b60200260200101516110fd91906130bc565b91505092915050565b600080600367ffffffffffffffff8111156111245761112361302f565b5b6040519080825280602002602001820160405280156111525781602001602082028036833780820191505090505b50905060018160008151811061116b5761116a61305e565b5b60200260200101818152505080838151811061118a5761118961305e565b5b60200260200101518185815181106111a5576111a461305e565b5b60200260200101516111b791906130bc565b91505092915050565b600080600367ffffffffffffffff8111156111de576111dd61302f565b5b60405190808252806020026020018201604052801561120c5781602001602082028036833780820191505090505b5090506001816000815181106112255761122461305e565b5b6020026020010181815250508083815181106112445761124361305e565b5b602002602001015181858151811061125f5761125e61305e565b5b602002602001015161127191906130bc565b91505092915050565b600080600367ffffffffffffffff8111156112985761129761302f565b5b6040519080825280602002602001820160405280156112c65781602001602082028036833780820191505090505b5090506001816000815181106112df576112de61305e565b5b6020026020010181815250508083815181106112fe576112fd61305e565b5b60200260200101518185815181106113195761131861305e565b5b602002602001015161132b91906130bc565b91505092915050565b600080600367ffffffffffffffff8111156113525761135161302f565b5b6040519080825280602002602001820160405280156113805781602001602082028036833780820191505090505b5090506001816000815181106113995761139861305e565b5b6020026020010181815250508083815181106113b8576113b761305e565b5b60200260200101518185815181106113d3576113d261305e565b5b60200260200101516113e591906130bc565b91505092915050565b600080600367ffffffffffffffff81111561140c5761140b61302f565b5b60405190808252806020026020018201604052801561143a5781602001602082028036833780820191505090505b5090506001816000815181106114535761145261305e565b5b6020026020010181815250508083815181106114725761147161305e565b5b602002602001015181858151811061148d5761148c61305e565b5b602002602001015161149f91906130bc565b91505092915050565b600080600367ffffffffffffffff8111156114c6576114c561302f565b5b6040519080825280602002602001820160405280156114f45781602001602082028036833780820191505090505b50905060018160008151811061150d5761150c61305e565b5b60200260200101818152505080838151811061152c5761152b61305e565b5b60200260200101518185815181106115475761154661305e565b5b602002602001015161155991906130bc565b91505092915050565b600080600367ffffffffffffffff8111156115805761157f61302f565b5b6040519080825280602002602001820160405280156115ae5781602001602082028036833780820191505090505b5090506001816000815181106115c7576115c661305e565b5b6020026020010181815250508083815181106115e6576115e561305e565b5b60200260200101518185815181106116015761160061305e565b5b602002602001015161161391906130bc565b91505092915050565b600080600367ffffffffffffffff81111561163a5761163961302f565b5b6040519080825280602002602001820160405280156116685781602001602082028036833780820191505090505b5090506001816000815181106116815761168061305e565b5b6020026020010181815250508083815181106116a05761169f61305e565b5b60200260200101518185815181106116bb576116ba61305e565b5b60200260200101516116cd91906130bc565b91505092915050565b600080600367ffffffffffffffff8111156116f4576116f361302f565b5b6040519080825280602002602001820160405280156117225781602001602082028036833780820191505090505b50905060018160008151811061173b5761173a61305e565b5b60200260200101818152505080838151811061175a5761175961305e565b5b60200260200101518185815181106117755761177461305e565b5b602002602001015161178791906130bc565b91505092915050565b600080600367ffffffffffffffff8111156117ae576117ad61302f565b5b6040519080825280602002602001820160405280156117dc5781602001602082028036833780820191505090505b5090506001816000815181106117f5576117f461305e565b5b6020026020010181815250508083815181106118145761181361305e565b5b602002602001015181858151811061182f5761182e61305e565b5b602002602001015161184191906130bc565b91505092915050565b600080600367ffffffffffffffff8111156118685761186761302f565b5b6040519080825280602002602001820160405280156118965781602001602082028036833780820191505090505b5090506001816000815181106118af576118ae61305e565b5b6020026020010181815250508083815181106118ce576118cd61305e565b5b60200260200101518185815181106118e9576118e861305e565b5b60200260200101516118fb91906130bc565b91505092915050565b600080600367ffffffffffffffff8111156119225761192161302f565b5b6040519080825280602002602001820160405280156119505781602001602082028036833780820191505090505b5090506001816000815181106119695761196861305e565b5b6020026020010181815250508083815181106119885761198761305e565b5b60200260200101518185815181106119a3576119a261305e565b5b60200260200101516119b591906130bc565b91505092915050565b600080600367ffffffffffffffff8111156119dc576119db61302f565b5b604051908082528060200260200182016040528015611a0a5781602001602082028036833780820191505090505b509050600181600081518110611a2357611a2261305e565b5b602002602001018181525050808381518110611a4257611a4161305e565b5b6020026020010151818581518110611a5d57611a5c61305e565b5b6020026020010151611a6f91906130bc565b91505092915050565b600080600367ffffffffffffffff811115611a9657611a9561302f565b5b604051908082528060200260200182016040528015611ac45781602001602082028036833780820191505090505b509050600181600081518110611add57611adc61305e565b5b602002602001018181525050808381518110611afc57611afb61305e565b5b6020026020010151818581518110611b1757611b1661305e565b5b6020026020010151611b2991906130bc565b91505092915050565b600080600367ffffffffffffffff811115611b5057611b4f61302f565b5b604051908082528060200260200182016040528015611b7e5781602001602082028036833780820191505090505b509050600181600081518110611b9757611b9661305e565b5b602002602001018181525050808381518110611bb657611bb561305e565b5b6020026020010151818581518110611bd157611bd061305e565b5b6020026020010151611be391906130bc565b91505092915050565b600080600367ffffffffffffffff811115611c0a57611c0961302f565b5b604051908082528060200260200182016040528015611c385781602001602082028036833780820191505090505b509050600181600081518110611c5157611c5061305e565b5b602002602001018181525050808381518110611c7057611c6f61305e565b5b6020026020010151818581518110611c8b57611c8a61305e565b5b6020026020010151611c9d91906130bc565b91505092915050565b600080600367ffffffffffffffff811115611cc457611cc361302f565b5b604051908082528060200260200182016040528015611cf25781602001602082028036833780820191505090505b509050600181600081518110611d0b57611d0a61305e565b5b602002602001018181525050808381518110611d2a57611d2961305e565b5b6020026020010151818581518110611d4557611d4461305e565b5b6020026020010151611d5791906130bc565b91505092915050565b600080600367ffffffffffffffff811115611d7e57611d7d61302f565b5b604051908082528060200260200182016040528015611dac5781602001602082028036833780820191505090505b509050600181600081518110611dc557611dc461305e565b5b602002602001018181525050808381518110611de457611de361305e565b5b6020026020010151818581518110611dff57611dfe61305e565b5b6020026020010151611e1191906130bc565b91505092915050565b600080600367ffffffffffffffff811115611e3857611e3761302f565b5b604051908082528060200260200182016040528015611e665781602001602082028036833780820191505090505b509050600181600081518110611e7f57611e7e61305e565b5b602002602001018181525050808381518110611e9e57611e9d61305e565b5b6020026020010151818581518110611eb957611eb861305e565b5b6020026020010151611ecb91906130bc565b91505092915050565b600080600367ffffffffffffffff811115611ef257611ef161302f565b5b604051908082528060200260200182016040528015611f205781602001602082028036833780820191505090505b509050600181600081518110611f3957611f3861305e565b5b602002602001018181525050808381518110611f5857611f5761305e565b5b6020026020010151818581518110611f7357611f7261305e565b5b6020026020010151611f8591906130bc565b91505092915050565b600080600367ffffffffffffffff811115611fac57611fab61302f565b5b604051908082528060200260200182016040528015611fda5781602001602082028036833780820191505090505b509050600181600081518110611ff357611ff261305e565b5b6020026020010181815250508083815181106120125761201161305e565b5b602002602001015181858151811061202d5761202c61305e565b5b602002602001015161203f91906130bc565b91505092915050565b600080600367ffffffffffffffff8111156120665761206561302f565b5b6040519080825280602002602001820160405280156120945781602001602082028036833780820191505090505b5090506001816000815181106120ad576120ac61305e565b5b6020026020010181815250508083815181106120cc576120cb61305e565b5b60200260200101518185815181106120e7576120e661305e565b5b60200260200101516120f991906130bc565b91505092915050565b600080600367ffffffffffffffff8111156121205761211f61302f565b5b60405190808252806020026020018201604052801561214e5781602001602082028036833780820191505090505b5090506001816000815181106121675761216661305e565b5b6020026020010181815250508083815181106121865761218561305e565b5b60200260200101518185815181106121a1576121a061305e565b5b60200260200101516121b391906130bc565b91505092915050565b600080600367ffffffffffffffff8111156121da576121d961302f565b5b6040519080825280602002602001820160405280156122085781602001602082028036833780820191505090505b5090506001816000815181106122215761222061305e565b5b6020026020010181815250508083815181106122405761223f61305e565b5b602002602001015181858151811061225b5761225a61305e565b5b602002602001015161226d91906130bc565b91505092915050565b600080600367ffffffffffffffff8111156122945761229361302f565b5b6040519080825280602002602001820160405280156122c25781602001602082028036833780820191505090505b5090506001816000815181106122db576122da61305e565b5b6020026020010181815250508083815181106122fa576122f961305e565b5b60200260200101518185815181106123155761231461305e565b5b602002602001015161232791906130bc565b91505092915050565b600080600367ffffffffffffffff81111561234e5761234d61302f565b5b60405190808252806020026020018201604052801561237c5781602001602082028036833780820191505090505b5090506001816000815181106123955761239461305e565b5b6020026020010181815250508083815181106123b4576123b361305e565b5b60200260200101518185815181106123cf576123ce61305e565b5b60200260200101516123e191906130bc565b91505092915050565b600080600367ffffffffffffffff8111156124085761240761302f565b5b6040519080825280602002602001820160405280156124365781602001602082028036833780820191505090505b50905060018160008151811061244f5761244e61305e565b5b60200260200101818152505080838151811061246e5761246d61305e565b5b60200260200101518185815181106124895761248861305e565b5b602002602001015161249b91906130bc565b91505092915050565b600080600367ffffffffffffffff8111156124c2576124c161302f565b5b6040519080825280602002602001820160405280156124f05781602001602082028036833780820191505090505b5090506001816000815181106125095761250861305e565b5b6020026020010181815250508083815181106125285761252761305e565b5b60200260200101518185815181106125435761254261305e565b5b602002602001015161255591906130bc565b91505092915050565b600080600367ffffffffffffffff81111561257c5761257b61302f565b5b6040519080825280602002602001820160405280156125aa5781602001602082028036833780820191505090505b5090506001816000815181106125c3576125c261305e565b5b6020026020010181815250508083815181106125e2576125e161305e565b5b60200260200101518185815181106125fd576125fc61305e565b5b602002602001015161260f91906130bc565b91505092915050565b600080600367ffffffffffffffff8111156126365761263561302f565b5b6040519080825280602002602001820160405280156126645781602001602082028036833780820191505090505b50905060018160008151811061267d5761267c61305e565b5b60200260200101818152505080838151811061269c5761269b61305e565b5b60200260200101518185815181106126b7576126b661305e565b5b60200260200101516126c991906130bc565b91505092915050565b600080600367ffffffffffffffff8111156126f0576126ef61302f565b5b60405190808252806020026020018201604052801561271e5781602001602082028036833780820191505090505b5090506001816000815181106127375761273661305e565b5b6020026020010181815250508083815181106127565761275561305e565b5b60200260200101518185815181106127715761277061305e565b5b602002602001015161278391906130bc565b91505092915050565b600080600367ffffffffffffffff8111156127aa576127a961302f565b5b6040519080825280602002602001820160405280156127d85781602001602082028036833780820191505090505b5090506001816000815181106127f1576127f061305e565b5b6020026020010181815250508083815181106128105761280f61305e565b5b602002602001015181858151811061282b5761282a61305e565b5b602002602001015161283d91906130bc565b91505092915050565b600080600367ffffffffffffffff8111156128645761286361302f565b5b6040519080825280602002602001820160405280156128925781602001602082028036833780820191505090505b5090506001816000815181106128ab576128aa61305e565b5b6020026020010181815250508083815181106128ca576128c961305e565b5b60200260200101518185815181106128e5576128e461305e565b5b60200260200101516128f791906130bc565b91505092915050565b600080600367ffffffffffffffff81111561291e5761291d61302f565b5b60405190808252806020026020018201604052801561294c5781602001602082028036833780820191505090505b5090506001816000815181106129655761296461305e565b5b6020026020010181815250508083815181106129845761298361305e565b5b602002602001015181858151811061299f5761299e61305e565b5b60200260200101516129b191906130bc565b91505092915050565b600080600367ffffffffffffffff8111156129d8576129d761302f565b5b604051908082528060200260200182016040528015612a065781602001602082028036833780820191505090505b509050600181600081518110612a1f57612a1e61305e565b5b602002602001018181525050808381518110612a3e57612a3d61305e565b5b6020026020010151818581518110612a5957612a5861305e565b5b6020026020010151612a6b91906130bc565b91505092915050565b600080600367ffffffffffffffff811115612a9257612a9161302f565b5b604051908082528060200260200182016040528015612ac05781602001602082028036833780820191505090505b509050600181600081518110612ad957612ad861305e565b5b602002602001018181525050808381518110612af857612af761305e565b5b6020026020010151818581518110612b1357612b1261305e565b5b6020026020010151612b2591906130bc565b91505092915050565b600080600367ffffffffffffffff811115612b4c57612b4b61302f565b5b604051908082528060200260200182016040528015612b7a5781602001602082028036833780820191505090505b509050600181600081518110612b9357612b9261305e565b5b602002602001018181525050808381518110612bb257612bb161305e565b5b6020026020010151818581518110612bcd57612bcc61305e565b5b6020026020010151612bdf91906130bc565b91505092915050565b600080600367ffffffffffffffff811115612c0657612c0561302f565b5b604051908082528060200260200182016040528015612c345781602001602082028036833780820191505090505b509050600181600081518110612c4d57612c4c61305e565b5b602002602001018181525050808381518110612c6c57612c6b61305e565b5b6020026020010151818581518110612c8757612c8661305e565b5b6020026020010151612c9991906130bc565b91505092915050565b600080600367ffffffffffffffff811115612cc057612cbf61302f565b5b604051908082528060200260200182016040528015612cee5781602001602082028036833780820191505090505b509050600181600081518110612d0757612d0661305e565b5b602002602001018181525050808381518110612d2657612d2561305e565b5b6020026020010151818581518110612d4157612d4061305e565b5b6020026020010151612d5391906130bc565b91505092915050565b600080600367ffffffffffffffff811115612d7a57612d7961302f565b5b604051908082528060200260200182016040528015612da85781602001602082028036833780820191505090505b509050600181600081518110612dc157612dc061305e565b5b602002602001018181525050808381518110612de057612ddf61305e565b5b6020026020010151818581518110612dfb57612dfa61305e565b5b6020026020010151612e0d91906130bc565b91505092915050565b600080600367ffffffffffffffff811115612e3457612e3361302f565b5b604051908082528060200260200182016040528015612e625781602001602082028036833780820191505090505b509050600181600081518110612e7b57612e7a61305e565b5b602002602001018181525050808381518110612e9a57612e9961305e565b5b6020026020010151818581518110612eb557612eb461305e565b5b6020026020010151612ec791906130bc565b91505092915050565b600080600367ffffffffffffffff811115612eee57612eed61302f565b5b604051908082528060200260200182016040528015612f1c5781602001602082028036833780820191505090505b509050600181600081518110612f3557612f3461305e565b5b602002602001018181525050808381518110612f5457612f5361305e565b5b6020026020010151818581518110612f6f57612f6e61305e565b5b6020026020010151612f8191906130bc565b91505092915050565b600080fd5b6000819050919050565b612fa281612f8f565b8114612fad57600080fd5b50565b600081359050612fbf81612f99565b92915050565b60008060408385031215612fdc57612fdb612f8a565b5b6000612fea85828601612fb0565b9250506020612ffb85828601612fb0565b9150509250929050565b61300e81612f8f565b82525050565b60006020820190506130296000830184613005565b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60006130c782612f8f565b91506130d283612f8f565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff038211156131075761310661308d565b5b82820190509291505056fea2646970667358221220ff62bab7af9d76e79c43666baad879bb81631965e70d110e63e602790098ba5b64736f6c634300080d0033 \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/bigcontract/SoBig.json b/tests/xtvm_test/test_cases/QA_CASES/bigcontract/SoBig.json new file mode 100755 index 000000000..ac43f77b2 --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/bigcontract/SoBig.json @@ -0,0 +1,33 @@ +{ + "pre_data": {}, + "deploy_contract": [ + { + "src_address": "T600045B38Da6a701c568545dCfcB03FcB875f56beddC4", + "code_file_path": "SoBig.bin", + "gas_limit": 3195493, + "value": "0", + "expected": { + "status": 0, + "extra_message": "contract_one", + "gas_used": 2778689, + "logs": [] + } + } + ], + "test_cases": [ + { + "__comments":"调用超大合约", + "src_address": "T600045B38Da6a701c568545dCfcB03FcB875f56beddC4", + "target_address": "contract_one", + "data": "0x773d45e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "gas_limit": 26107, + "value": "0", + "expected": { + "status": 0, + "extra_message": "", + "gas_used": 22701, + "logs": [] + } + } + ] +} \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/bigcontract/SoBig.sol b/tests/xtvm_test/test_cases/QA_CASES/bigcontract/SoBig.sol new file mode 100755 index 000000000..51ef8a22c --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/bigcontract/SoBig.sol @@ -0,0 +1,252 @@ +pragma solidity ^0.8.10; + +contract Array { + + function a(uint256 x,uint256 y) public returns(uint256){ + uint[] memory a = new uint[](3); + a[0] = 1; + return a[x] + a[y]; + } + function b(uint256 x,uint256 y) public returns(uint256){ + uint[] memory a = new uint[](3); + a[0] = 1; + return a[x] + a[y]; + } + function c(uint256 x,uint256 y) public returns(uint256){ + uint[] memory a = new uint[](3); + a[0] = 1; + return a[x] + a[y]; + } + function d(uint256 x,uint256 y) public returns(uint256){ + uint[] memory a = new uint[](3); + a[0] = 1; + return a[x] + a[y]; + } + function e(uint256 x,uint256 y) public returns(uint256){ + uint[] memory a = new uint[](3); + a[0] = 1; + return a[x] + a[y]; + } + function f(uint256 x,uint256 y) public returns(uint256){ + uint[] memory a = new uint[](3); + a[0] = 1; + return a[x] + a[y]; + } + function g(uint256 x,uint256 y) public returns(uint256){ + uint[] memory a = new uint[](3); + a[0] = 1; + return a[x] + a[y]; + } + function h(uint256 x,uint256 y) public returns(uint256){ + uint[] memory a = new uint[](3); + a[0] = 1; + return a[x] + a[y]; + } + function i(uint256 x,uint256 y) public returns(uint256){ + uint[] memory a = new uint[](3); + a[0] = 1; + return a[x] + a[y]; + } + function j(uint256 x,uint256 y) public returns(uint256){ + uint[] memory a = new uint[](3); + a[0] = 1; + return a[x] + a[y]; + } + function k(uint256 x,uint256 y) public returns(uint256){ + uint[] memory a = new uint[](3); + a[0] = 1; + return a[x] + a[y]; + } + function l(uint256 x,uint256 y) public returns(uint256){ + uint[] memory a = new uint[](3); + a[0] = 1; + return a[x] + a[y]; + } + function m(uint256 x,uint256 y) public returns(uint256){ + uint[] memory a = new uint[](3); + a[0] = 1; + return a[x] + a[y]; + } + function n(uint256 x,uint256 y) public returns(uint256){ + uint[] memory a = new uint[](3); + a[0] = 1; + return a[x] + a[y]; + } + function o(uint256 x,uint256 y) public returns(uint256){ + uint[] memory a = new uint[](3); + a[0] = 1; + return a[x] + a[y]; + } + function p(uint256 x,uint256 y) public returns(uint256){ + uint[] memory a = new uint[](3); + a[0] = 1; + return a[x] + a[y]; + } + function q(uint256 x,uint256 y) public returns(uint256){ + uint[] memory a = new uint[](3); + a[0] = 1; + return a[x] + a[y]; + } + function r(uint256 x,uint256 y) public returns(uint256){ + uint[] memory a = new uint[](3); + a[0] = 1; + return a[x] + a[y]; + } + function s(uint256 x,uint256 y) public returns(uint256){ + uint[] memory a = new uint[](3); + a[0] = 1; + return a[x] + a[y]; + } + function t(uint256 x,uint256 y) public returns(uint256){ + uint[] memory a = new uint[](3); + a[0] = 1; + return a[x] + a[y]; + } + function u(uint256 x,uint256 y) public returns(uint256){ + uint[] memory a = new uint[](3); + a[0] = 1; + return a[x] + a[y]; + } + function v(uint256 x,uint256 y) public returns(uint256){ + uint[] memory a = new uint[](3); + a[0] = 1; + return a[x] + a[y]; + } + function w(uint256 x,uint256 y) public returns(uint256){ + uint[] memory a = new uint[](3); + a[0] = 1; + return a[x] + a[y]; + } + function x(uint256 x,uint256 y) public returns(uint256){ + uint[] memory a = new uint[](3); + a[0] = 1; + return a[x] + a[y]; + } + function y(uint256 x,uint256 y) public returns(uint256){ + uint[] memory a = new uint[](3); + a[0] = 1; + return a[x] + a[y]; + } + function z(uint256 x,uint256 y) public returns(uint256){ + uint[] memory a = new uint[](3); + a[0] = 1; + return a[x] + a[y]; + } + function aa(uint256 x,uint256 y) public returns(uint256){ + uint[] memory a = new uint[](3); + a[0] = 1; + return a[x] + a[y]; + } + function bb(uint256 x,uint256 y) public returns(uint256){ + uint[] memory a = new uint[](3); + a[0] = 1; + return a[x] + a[y]; + } + function cc(uint256 x,uint256 y) public returns(uint256){ + uint[] memory a = new uint[](3); + a[0] = 1; + return a[x] + a[y]; + } + function dd(uint256 x,uint256 y) public returns(uint256){ + uint[] memory a = new uint[](3); + a[0] = 1; + return a[x] + a[y]; + } + function ee(uint256 x,uint256 y) public returns(uint256){ + uint[] memory a = new uint[](3); + a[0] = 1; + return a[x] + a[y]; + } + function ff(uint256 x,uint256 y) public returns(uint256){ + uint[] memory a = new uint[](3); + a[0] = 1; + return a[x] + a[y]; + } + function gg(uint256 x,uint256 y) public returns(uint256){ + uint[] memory a = new uint[](3); + a[0] = 1; + return a[x] + a[y]; + } + function hh(uint256 x,uint256 y) public returns(uint256){ + uint[] memory a = new uint[](3); + a[0] = 1; + return a[x] + a[y]; + } + function ii(uint256 x,uint256 y) public returns(uint256){ + uint[] memory a = new uint[](3); + a[0] = 1; + return a[x] + a[y]; + } + function jj(uint256 x,uint256 y) public returns(uint256){ + uint[] memory a = new uint[](3); + a[0] = 1; + return a[x] + a[y]; + } + function kk(uint256 x,uint256 y) public returns(uint256){ + uint[] memory a = new uint[](3); + a[0] = 1; + return a[x] + a[y]; + } + function ll(uint256 x,uint256 y) public returns(uint256){ + uint[] memory a = new uint[](3); + a[0] = 1; + return a[x] + a[y]; + } + function mm(uint256 x,uint256 y) public returns(uint256){ + uint[] memory a = new uint[](3); + a[0] = 1; + return a[x] + a[y]; + } + function nn(uint256 x,uint256 y) public returns(uint256){ + uint[] memory a = new uint[](3); + a[0] = 1; + return a[x] + a[y]; + } + function oo(uint256 x,uint256 y) public returns(uint256){ + uint[] memory a = new uint[](3); + a[0] = 1; + return a[x] + a[y]; + } + function pp(uint256 x,uint256 y) public returns(uint256){ + uint[] memory a = new uint[](3); + a[0] = 1; + return a[x] + a[y]; + } + function qq(uint256 x,uint256 y) public returns(uint256){ + uint[] memory a = new uint[](3); + a[0] = 1; + return a[x] + a[y]; + } + function rr(uint256 x,uint256 y) public returns(uint256){ + uint[] memory a = new uint[](3); + a[0] = 1; + return a[x] + a[y]; + } + function ss(uint256 x,uint256 y) public returns(uint256){ + uint[] memory a = new uint[](3); + a[0] = 1; + return a[x] + a[y]; + } + function tt(uint256 x,uint256 y) public returns(uint256){ + uint[] memory a = new uint[](3); + a[0] = 1; + return a[x] + a[y]; + } + function uu(uint256 x,uint256 y) public returns(uint256){ + uint[] memory a = new uint[](3); + a[0] = 1; + return a[x] + a[y]; + } + function vv(uint256 x,uint256 y) public returns(uint256){ + uint[] memory a = new uint[](3); + a[0] = 1; + return a[x] + a[y]; + } + function ww(uint256 x,uint256 y) public returns(uint256){ + uint[] memory a = new uint[](3); + a[0] = 1; + return a[x] + a[y]; + } + +} + diff --git a/tests/xtvm_test/test_cases/QA_CASES/call_contract/CallContract.json b/tests/xtvm_test/test_cases/QA_CASES/call_contract/CallContract.json new file mode 100755 index 000000000..910bda4fd --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/call_contract/CallContract.json @@ -0,0 +1,105 @@ +{ + "pre_data": {}, + "deploy_contract": [ + { + "src_address": "T60004Ab8483F64d9C6d1EcF9b849Ae677dD3315835cb2", + "code_file_path": "CallContractA.bin", + "gas_limit": 501259, + "value": "0", + "expected": { + "status": 0, + "__address_in_evm": "a131ad247055fd2e2aa8b156a11bdec81b9ead95", + "__address_in_top_shard": "4fa78b63dcb90476269f4b6aaba13fdb1d14caf1", + "extra_message": "contract_one", + "gas_used": 435877, + "logs": [] + } + }, + { + "src_address": "T60004Ab8483F64d9C6d1EcF9b849Ae677dD3315835cb2", + "code_file_path": "CallContractB.bin", + "gas_limit": 314375, + "value": "0", + "expected": { + "status": 0, + "__address_in_evm": "652c9accc53e765e1d96e2455e618daab79ba595", + "__address_in_top_shard": "1cc92a96cd9cda025ae707547d0c2b8722da6be5", + "extra_message": "contract_two", + "gas_used": 273369, + "logs": [] + } + } + ], + "test_cases": [ + { + "__comments": "设置合约B", + "src_address": "T60004Ab8483F64d9C6d1EcF9b849Ae677dD3315835cb2", + "target_address": "contract_one", + "data": "0xa1601cdc0000000000000000000000001cc92a96cd9cda025ae707547d0c2b8722da6be5000000000000000000000000000000000000000000000000000000000001e240", + "gas_limit": 61136, + "value": "0", + "expected": { + "status": 0, + "extra_message": "", + "gas_used": 53161, + "logs": [ + { + "address": "contract_two", + "topics": [ + "0xbea1de5942ddf17128f3c4490dc91e0d1012f7b9806ca3eed0799cdbf5281727" + ], + "data": "0x0000000000000000000000004fa78b63dcb90476269f4b6aaba13fdb1d14caf1000000000000000000000000000000000000000000000000000000000001e241000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000107365745f42207761732063616c6c656400000000000000000000000000000000" + }, + { + "address": "contract_one", + "topics": [ + "0xa3bbb89550b7993d088fab590047782dfb510e1ad00e5cb7aabffe38f78ebcdb" + ], + "data": "0x000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000" + } + ] + } + },{ + "__comments": "调用不存在的合约", + "src_address": "T60004Ab8483F64d9C6d1EcF9b849Ae677dD3315835cb2", + "target_address": "contract_one", + "data": "0xff00726c0000000000000000000000001cc92a96cd9cda025ae707547d0c2b8722da6be5", + "gas_limit": 40539, + "value": "0", + "expected": { + "status": 0, + "extra_message": "", + "gas_used": 35251, + "logs": [{ + "address": "contract_two", + "topics": ["0xbea1de5942ddf17128f3c4490dc91e0d1012f7b9806ca3eed0799cdbf5281727"], + "data": "0x0000000000000000000000004fa78b63dcb90476269f4b6aaba13fdb1d14caf1000000000000000000000000000000000000000000000000000000000001e2430000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000001366616c6c6261636b207761732063616c6c656400000000000000000000000000" + }, + { + "address": "contract_one", + "topics": ["0xa3bbb89550b7993d088fab590047782dfb510e1ad00e5cb7aabffe38f78ebcdb"], + "data": "0x000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000" + } + ] + } + },{ + "__comments": "查询合约", + "src_address": "T60004Ab8483F64d9C6d1EcF9b849Ae677dD3315835cb2", + "target_address": "contract_one", + "data": "0x598a4f5c0000000000000000000000001cc92a96cd9cda025ae707547d0c2b8722da6be5", + "gas_limit": 35319, + "value": "0", + "expected": { + "status": 0, + "extra_message": "0x000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000001e243", + "gas_used": 30712, + "logs": [{ + "address": "contract_one", + "topics": ["0xa3bbb89550b7993d088fab590047782dfb510e1ad00e5cb7aabffe38f78ebcdb"], + "data": "0x000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000001e243" + } + ] + } + } + ] +} \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/call_contract/CallContractA.bin b/tests/xtvm_test/test_cases/QA_CASES/call_contract/CallContractA.bin new file mode 100755 index 000000000..12bfa9709 --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/call_contract/CallContractA.bin @@ -0,0 +1 @@ +608060405234801561001057600080fd5b506106f1806100206000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c8063598a4f5c14610046578063a1601cdc14610077578063ff00726c14610093575b600080fd5b610060600480360381019061005b91906104b7565b6100af565b60405161006e929190610598565b60405180910390f35b610091600480360381019061008c91906105fe565b6101ea565b005b6100ad60048036038101906100a891906104b7565b610325565b005b600060606000808473ffffffffffffffffffffffffffffffffffffffff166040516024016040516020818303038152906040527f7125833a000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff838183161783525050505060405161015d919061067a565b6000604051808303816000865af19150503d806000811461019a576040519150601f19603f3d011682016040523d82523d6000602084013e61019f565b606091505b50915091507fa3bbb89550b7993d088fab590047782dfb510e1ad00e5cb7aabffe38f78ebcdb82826040516101d5929190610598565b60405180910390a18181935093505050915091565b6000808373ffffffffffffffffffffffffffffffffffffffff168360405160240161021591906106a0565b6040516020818303038152906040527f66cfffe6000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff838183161783525050505060405161029f919061067a565b6000604051808303816000865af19150503d80600081146102dc576040519150601f19603f3d011682016040523d82523d6000602084013e6102e1565b606091505b50915091507fa3bbb89550b7993d088fab590047782dfb510e1ad00e5cb7aabffe38f78ebcdb8282604051610317929190610598565b60405180910390a150505050565b6000808273ffffffffffffffffffffffffffffffffffffffff166040516024016040516020818303038152906040527f1dcc85ae000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506040516103cf919061067a565b6000604051808303816000865af19150503d806000811461040c576040519150601f19603f3d011682016040523d82523d6000602084013e610411565b606091505b50915091507fa3bbb89550b7993d088fab590047782dfb510e1ad00e5cb7aabffe38f78ebcdb8282604051610447929190610598565b60405180910390a1505050565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061048482610459565b9050919050565b61049481610479565b811461049f57600080fd5b50565b6000813590506104b18161048b565b92915050565b6000602082840312156104cd576104cc610454565b5b60006104db848285016104a2565b91505092915050565b60008115159050919050565b6104f9816104e4565b82525050565b600081519050919050565b600082825260208201905092915050565b60005b8381101561053957808201518184015260208101905061051e565b83811115610548576000848401525b50505050565b6000601f19601f8301169050919050565b600061056a826104ff565b610574818561050a565b935061058481856020860161051b565b61058d8161054e565b840191505092915050565b60006040820190506105ad60008301856104f0565b81810360208301526105bf818461055f565b90509392505050565b6000819050919050565b6105db816105c8565b81146105e657600080fd5b50565b6000813590506105f8816105d2565b92915050565b6000806040838503121561061557610614610454565b5b6000610623858286016104a2565b9250506020610634858286016105e9565b9150509250929050565b600081905092915050565b6000610654826104ff565b61065e818561063e565b935061066e81856020860161051b565b80840191505092915050565b60006106868284610649565b915081905092915050565b61069a816105c8565b82525050565b60006020820190506106b56000830184610691565b9291505056fea26469706673582212207ca6308aec6a4a9cecf9115e6878f12c1ad7cf55dedb2d46fdd3308f52f85d5f64736f6c634300080d0033 \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/call_contract/CallContractA.sol b/tests/xtvm_test/test_cases/QA_CASES/call_contract/CallContractA.sol new file mode 100755 index 000000000..4772cfc8a --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/call_contract/CallContractA.sol @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.4.22 <0.9.0; + + +// 调用别的合约 +contract A { + event ALog(bool success, bytes data); + + // 调用其他合约中的函数 + function testCallSetB(address _addr, uint256 num) public { + (bool success, bytes memory data) = _addr.call( + abi.encodeWithSignature("set_B(uint256)", num) + ); + emit ALog(success, data); + } + + function testCallGetB(address _addr) public returns (bool, bytes memory) { + (bool success, bytes memory data) = _addr.call( + abi.encodeWithSignature("get_B()") + ); + emit ALog(success, data); + return (success, data); + } + + // 调用其他合约中不存在的函数 + function testCallDoesNotExist(address _addr) public { + (bool success, bytes memory data) = _addr.call( + abi.encodeWithSignature("doesNotExist()") + ); + emit ALog(success, data); + } +} diff --git a/tests/xtvm_test/test_cases/QA_CASES/call_contract/CallContractB.bin b/tests/xtvm_test/test_cases/QA_CASES/call_contract/CallContractB.bin new file mode 100755 index 000000000..d6a3e29ed --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/call_contract/CallContractB.bin @@ -0,0 +1 @@ +608060405234801561001057600080fd5b506103ff806100206000396000f3fe608060405234801561001057600080fd5b50600436106100455760003560e01c80634e70b1dc1461009857806366cfffe6146100b65780637125833a146100d257610046565b5b60026000546100559190610189565b6000819055507fbea1de5942ddf17128f3c4490dc91e0d1012f7b9806ca3eed0799cdbf52817273360005460405161008e92919061028c565b60405180910390a1005b6100a06100f0565b6040516100ad91906102c8565b60405180910390f35b6100d060048036038101906100cb9190610314565b6100f6565b005b6100da610147565b6040516100e791906102c8565b60405180910390f35b60005481565b6001816101039190610189565b6000819055507fbea1de5942ddf17128f3c4490dc91e0d1012f7b9806ca3eed0799cdbf52817273360005460405161013c92919061038d565b60405180910390a150565b60008054905090565b6000819050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600061019482610150565b915061019f83610150565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff038211156101d4576101d361015a565b5b828201905092915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061020a826101df565b9050919050565b61021a816101ff565b82525050565b61022981610150565b82525050565b600082825260208201905092915050565b7f66616c6c6261636b207761732063616c6c656400000000000000000000000000600082015250565b600061027660138361022f565b915061028182610240565b602082019050919050565b60006060820190506102a16000830185610211565b6102ae6020830184610220565b81810360408301526102bf81610269565b90509392505050565b60006020820190506102dd6000830184610220565b92915050565b600080fd5b6102f181610150565b81146102fc57600080fd5b50565b60008135905061030e816102e8565b92915050565b60006020828403121561032a576103296102e3565b5b6000610338848285016102ff565b91505092915050565b7f7365745f42207761732063616c6c656400000000000000000000000000000000600082015250565b600061037760108361022f565b915061038282610341565b602082019050919050565b60006060820190506103a26000830185610211565b6103af6020830184610220565b81810360408301526103c08161036a565b9050939250505056fea2646970667358221220d98ff0c5d09be76c61418d72aebb01f6a146f3d2b0e433fc1e4f328855a8cb4764736f6c634300080d0033 \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/call_contract/CallContractB.sol b/tests/xtvm_test/test_cases/QA_CASES/call_contract/CallContractB.sol new file mode 100755 index 000000000..8add436fb --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/call_contract/CallContractB.sol @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.4.22 <0.9.0; + +// 被调用的合约 +contract B { + uint256 public num; + event BLog(address caller, uint256 amount, string message); + + function set_B(uint256 _num) public { + num = _num + 1; + emit BLog(msg.sender, num, "set_B was called"); + } + + function get_B() public view returns (uint256) { + return num; + } + + fallback() external { + num = num + 2; + emit BLog(msg.sender, num, "fallback was called"); + } +} \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/contract_user_relation/AssertDemo_sol_AssertDemo.bin b/tests/xtvm_test/test_cases/QA_CASES/contract_user_relation/AssertDemo_sol_AssertDemo.bin new file mode 100755 index 000000000..a92a1ab9b --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/contract_user_relation/AssertDemo_sol_AssertDemo.bin @@ -0,0 +1 @@ +608060405234801561001057600080fd5b506040518060400160405280600781526020017f77656c69676874000000000000000000000000000000000000000000000000008152506000908051906020019061005c929190610062565b50610165565b82805461006e90610134565b90600052602060002090601f01602090048101928261009057600085556100d7565b82601f106100a957805160ff19168380011785556100d7565b828001600101855582156100d7579182015b828111156100d65782518255916020019190600101906100bb565b5b5090506100e491906100e8565b5090565b5b808211156101015760008160009055506001016100e9565b5090565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b6000600282049050600182168061014c57607f821691505b60208210810361015f5761015e610105565b5b50919050565b61058f806101746000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80634ed3885e1461003b5780636d4ce63c14610057575b600080fd5b61005560048036038101906100509190610366565b610075565b005b61005f6100d7565b60405161006c9190610437565b60405180910390f35b600061008457610083610459565b5b806000908051906020019061009a929190610169565b507fde696604ac839ef8a5d0fcb2310ea48463357a6247e0d961d77c41d136a5d94633826040516100cc9291906104c9565b60405180910390a150565b6060600080546100e690610528565b80601f016020809104026020016040519081016040528092919081815260200182805461011290610528565b801561015f5780601f106101345761010080835404028352916020019161015f565b820191906000526020600020905b81548152906001019060200180831161014257829003601f168201915b5050505050905090565b82805461017590610528565b90600052602060002090601f01602090048101928261019757600085556101de565b82601f106101b057805160ff19168380011785556101de565b828001600101855582156101de579182015b828111156101dd5782518255916020019190600101906101c2565b5b5090506101eb91906101ef565b5090565b5b808211156102085760008160009055506001016101f0565b5090565b6000604051905090565b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6102738261022a565b810181811067ffffffffffffffff821117156102925761029161023b565b5b80604052505050565b60006102a561020c565b90506102b1828261026a565b919050565b600067ffffffffffffffff8211156102d1576102d061023b565b5b6102da8261022a565b9050602081019050919050565b82818337600083830152505050565b6000610309610304846102b6565b61029b565b90508281526020810184848401111561032557610324610225565b5b6103308482856102e7565b509392505050565b600082601f83011261034d5761034c610220565b5b813561035d8482602086016102f6565b91505092915050565b60006020828403121561037c5761037b610216565b5b600082013567ffffffffffffffff81111561039a5761039961021b565b5b6103a684828501610338565b91505092915050565b600081519050919050565b600082825260208201905092915050565b60005b838110156103e95780820151818401526020810190506103ce565b838111156103f8576000848401525b50505050565b6000610409826103af565b61041381856103ba565b93506104238185602086016103cb565b61042c8161022a565b840191505092915050565b6000602082019050818103600083015261045181846103fe565b905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052600160045260246000fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006104b382610488565b9050919050565b6104c3816104a8565b82525050565b60006040820190506104de60008301856104ba565b81810360208301526104f081846103fe565b90509392505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b6000600282049050600182168061054057607f821691505b602082108103610553576105526104f9565b5b5091905056fea264697066735822122085acf1966f2fe652bb379836731fe058fb5df5e65ce28800cae247d815c8957464736f6c634300080d0033 \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/contract_user_relation/ForeverLoop_sol_ForeverLoop.bin b/tests/xtvm_test/test_cases/QA_CASES/contract_user_relation/ForeverLoop_sol_ForeverLoop.bin new file mode 100755 index 000000000..f61e88577 --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/contract_user_relation/ForeverLoop_sol_ForeverLoop.bin @@ -0,0 +1 @@ +60806040526000805534801561001457600080fd5b50610180806100246000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80639ff9a6031461003b578063e5aa3d5814610045575b600080fd5b610043610063565b005b61004d61008b565b60405161005a91906100aa565b60405180910390f35b5b60011561008957600160008082825461007d91906100f4565b92505081905550610064565b565b60005481565b6000819050919050565b6100a481610091565b82525050565b60006020820190506100bf600083018461009b565b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60006100ff82610091565b915061010a83610091565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0382111561013f5761013e6100c5565b5b82820190509291505056fea26469706673582212209e7606328dbe026152dc90dc0e7ac66b63562522eb013eae785ac2eaf110a60a64736f6c634300080d0033 \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/contract_user_relation/Recursion_sol_Recursion.bin b/tests/xtvm_test/test_cases/QA_CASES/contract_user_relation/Recursion_sol_Recursion.bin new file mode 100755 index 000000000..cc96678b2 --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/contract_user_relation/Recursion_sol_Recursion.bin @@ -0,0 +1 @@ +608060405234801561001057600080fd5b5060c68061001f6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c80634d99ebc914602d575b600080fd5b605660048036036020811015604157600080fd5b8101908080359060200190929190505050606c565b6040518082815260200191505060405180910390f35b60006001821415607d57819050608c565b608760018301606c565b820290505b91905056fea265627a7a72315820147a7de8945e47b5d7c480bc3c21aefdaadd86d5c02d618f81e9b544d1eca60564736f6c63430005110032 \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/contract_user_relation/TestSafeMath_sol_TestSafeMath.bin b/tests/xtvm_test/test_cases/QA_CASES/contract_user_relation/TestSafeMath_sol_TestSafeMath.bin new file mode 100755 index 000000000..13e2edf5a --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/contract_user_relation/TestSafeMath_sol_TestSafeMath.bin @@ -0,0 +1 @@ +0x60806040527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff60005534801561003457600080fd5b5061043b806100446000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c80636039b0bd146100465780637c3ffef214610076578063e5b5019a146100a6575b600080fd5b610060600480360381019061005b919061020c565b6100c4565b60405161006d9190610248565b60405180910390f35b610090600480360381019061008b9190610263565b6100d6565b60405161009d9190610248565b60405180910390f35b6100ae6100f3565b6040516100bb9190610248565b60405180910390f35b60006100cf826100f9565b9050919050565b60006100eb828461017390919063ffffffff16565b905092915050565b60005481565b6000600382111561016057819050600060016002846101189190610301565b6101229190610332565b90505b8181101561015a57809150600281828561013f9190610301565b6101499190610332565b6101539190610301565b9050610125565b5061016e565b6000821461016d57600190505b5b919050565b60008082846101829190610332565b9050838110156101c7576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101be906103e5565b60405180910390fd5b8091505092915050565b600080fd5b6000819050919050565b6101e9816101d6565b81146101f457600080fd5b50565b600081359050610206816101e0565b92915050565b600060208284031215610222576102216101d1565b5b6000610230848285016101f7565b91505092915050565b610242816101d6565b82525050565b600060208201905061025d6000830184610239565b92915050565b6000806040838503121561027a576102796101d1565b5b6000610288858286016101f7565b9250506020610299858286016101f7565b9150509250929050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600061030c826101d6565b9150610317836101d6565b925082610327576103266102a3565b5b828204905092915050565b600061033d826101d6565b9150610348836101d6565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0382111561037d5761037c6102d2565b5b828201905092915050565b600082825260208201905092915050565b7f75696e74206f766572666c6f7700000000000000000000000000000000000000600082015250565b60006103cf600d83610388565b91506103da82610399565b602082019050919050565b600060208201905081810360008301526103fe816103c2565b905091905056fea2646970667358221220e994386c4e2f16502800cfd0c0da1cb3083d880a355cb62d0eee6fe6b0773aee64736f6c634300080d0033 \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/contract_user_relation/many_user_one_contract.json b/tests/xtvm_test/test_cases/QA_CASES/contract_user_relation/many_user_one_contract.json new file mode 100755 index 000000000..66caf142e --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/contract_user_relation/many_user_one_contract.json @@ -0,0 +1,156 @@ +{ + "pre_data": {}, + "__comments":"多个用户部署相同合约,合约都可以使用", + "deploy_contract": [ + { + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea2", + "code_file_path": "TestSafeMath_sol_TestSafeMath.bin", + "gas_limit": 308435, + "value": "0", + "expected": { + "status": 0, + "extra_message": "contract1", + "gas_used": 308435, + "logs": [] + } + }, + { + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea3", + "code_file_path": "TestSafeMath_sol_TestSafeMath.bin", + "gas_limit": 308435, + "value": "0", + "expected": { + "status": 0, + "extra_message": "contract2", + "gas_used": 308435, + "logs": [] + } + }, + { + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea4", + "code_file_path": "TestSafeMath_sol_TestSafeMath.bin", + "gas_limit": 308435, + "value": "0", + "expected": { + "status": 0, + "extra_message": "contract3", + "gas_used": 308435, + "logs": [] + } + }, + { + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea5", + "code_file_path": "TestSafeMath_sol_TestSafeMath.bin", + "gas_limit": 308435, + "value": "0", + "expected": { + "status": 0, + "extra_message": "contract4", + "gas_used": 308435, + "logs": [] + } + } + ], + "test_cases": [ + { + "__comments":"获取MAX_UINT成员变量", + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea2", + "target_address": "contract1", + "data": "0xe5b5019a", + "gas_limit": 23515, + "value": "0", + "expected": { + "status": 0, + "extra_message": "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", + "gas_used": 23515, + "logs": [] + } + }, + { + "__comments":"执行add(1,2)", + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea3", + "target_address": "contract2", + "data": "0x7c3ffef200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002", + "gas_limit": 22415, + "value": "0", + "expected": { + "status": 0, + "extra_message": "0x0000000000000000000000000000000000000000000000000000000000000003", + "gas_used": 22415, + "logs": [] + } + }, + { + "__comments":"执行add(0,0)", + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea4", + "target_address": "contract3", + "data": "0x7c3ffef200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "gas_limit": 22391, + "value": "0", + "expected": { + "status": 0, + "extra_message": "0x0000000000000000000000000000000000000000000000000000000000000000", + "gas_used": 22391, + "logs": [] + } + }, + { + "__comments":"执行add(2000000000000000000000000000000000000000000000,2000000000000000000000000000000000000000000000)", + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea5", + "target_address": "contract4", + "data": "0x7c3ffef20000000000000000000000000059aedfc10d7279c5eed14016454000000000000000000000000000000000000059aedfc10d7279c5eed1401645400000000000", + "gas_limit": 22727, + "value": "0", + "expected": { + "status": 0, + "extra_message": "0x00000000000000000000000000b35dbf821ae4f38bdda2802c8a800000000000", + "gas_used": 22727, + "logs": [] + } + }, + { + "__comments":"执行sqrt(1)", + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea2", + "target_address": "contract1", + "data": "0x6039b0bd0000000000000000000000000000000000000000000000000000000000000001", + "gas_limit": 21877 , + "value": "0", + "expected": { + "status": 0, + "extra_message": "0x0000000000000000000000000000000000000000000000000000000000000001", + "gas_used": 21877 , + "logs": [] + } + }, + { + "__comments":"执行sqrt(0)", + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea3", + "target_address": "contract2", + "data": "0x6039b0bd0000000000000000000000000000000000000000000000000000000000000000", + "gas_limit": 21857 , + "value": "0", + "expected": { + "status": 0, + "extra_message": "0x0000000000000000000000000000000000000000000000000000000000000000", + "gas_used": 21857 , + "logs": [] + } + }, + { + "__comments":"执行sqrt(100000000000000000000000000000000000000000000000000000000000)", + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea4", + "target_address": "contract3", + "data": "0x6039b0bd000000000000000fee50b7025c36a0802f236d04753d5b48e800000000000000", + "gas_limit": 85819 , + "value": "0", + "expected": { + "status": 0, + "extra_message": "0x0000000000000000000000000000000000000003fdc97a29c8e052fd00e94ecb", + "gas_used": 85819 , + "logs": [] + } + } + + + ] +} \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/contract_user_relation/one_user_deploy_one_contract_four_times.json b/tests/xtvm_test/test_cases/QA_CASES/contract_user_relation/one_user_deploy_one_contract_four_times.json new file mode 100755 index 000000000..8aa500f86 --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/contract_user_relation/one_user_deploy_one_contract_four_times.json @@ -0,0 +1,156 @@ +{ + "pre_data": {}, + "__comments":"同1用户部署多个相同合约,合约都可以使用", + "deploy_contract": [ + { + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea2", + "code_file_path": "TestSafeMath_sol_TestSafeMath.bin", + "gas_limit": 308435, + "value": "0", + "expected": { + "status": 0, + "extra_message": "contract1", + "gas_used": 308435, + "logs": [] + } + }, + { + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea2", + "code_file_path": "TestSafeMath_sol_TestSafeMath.bin", + "gas_limit": 308435, + "value": "0", + "expected": { + "status": 0, + "extra_message": "contract2", + "gas_used": 308435, + "logs": [] + } + }, + { + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea2", + "code_file_path": "TestSafeMath_sol_TestSafeMath.bin", + "gas_limit": 308435, + "value": "0", + "expected": { + "status": 0, + "extra_message": "contract3", + "gas_used": 308435, + "logs": [] + } + }, + { + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea2", + "code_file_path": "TestSafeMath_sol_TestSafeMath.bin", + "gas_limit": 308435, + "value": "0", + "expected": { + "status": 0, + "extra_message": "contract4", + "gas_used": 308435, + "logs": [] + } + } + ], + "test_cases": [ + { + "__comments":"获取MAX_UINT成员变量", + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea2", + "target_address": "contract1", + "data": "0xe5b5019a", + "gas_limit": 23515, + "value": "0", + "expected": { + "status": 0, + "extra_message": "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", + "gas_used": 23515, + "logs": [] + } + }, + { + "__comments":"执行add(1,2)", + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea2", + "target_address": "contract2", + "data": "0x7c3ffef200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002", + "gas_limit": 22415, + "value": "0", + "expected": { + "status": 0, + "extra_message": "0x0000000000000000000000000000000000000000000000000000000000000003", + "gas_used": 22415, + "logs": [] + } + }, + { + "__comments":"执行add(0,0)", + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea2", + "target_address": "contract3", + "data": "0x7c3ffef200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "gas_limit": 22391, + "value": "0", + "expected": { + "status": 0, + "extra_message": "0x0000000000000000000000000000000000000000000000000000000000000000", + "gas_used": 22391, + "logs": [] + } + }, + { + "__comments":"执行add(2000000000000000000000000000000000000000000000,2000000000000000000000000000000000000000000000)", + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea2", + "target_address": "contract4", + "data": "0x7c3ffef20000000000000000000000000059aedfc10d7279c5eed14016454000000000000000000000000000000000000059aedfc10d7279c5eed1401645400000000000", + "gas_limit": 22727, + "value": "0", + "expected": { + "status": 0, + "extra_message": "0x00000000000000000000000000b35dbf821ae4f38bdda2802c8a800000000000", + "gas_used": 22727, + "logs": [] + } + }, + { + "__comments":"执行sqrt(1)", + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea2", + "target_address": "contract1", + "data": "0x6039b0bd0000000000000000000000000000000000000000000000000000000000000001", + "gas_limit": 21877 , + "value": "0", + "expected": { + "status": 0, + "extra_message": "0x0000000000000000000000000000000000000000000000000000000000000001", + "gas_used": 21877 , + "logs": [] + } + }, + { + "__comments":"执行sqrt(0)", + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea2", + "target_address": "contract2", + "data": "0x6039b0bd0000000000000000000000000000000000000000000000000000000000000000", + "gas_limit": 21857 , + "value": "0", + "expected": { + "status": 0, + "extra_message": "0x0000000000000000000000000000000000000000000000000000000000000000", + "gas_used": 21857 , + "logs": [] + } + }, + { + "__comments":"执行sqrt(100000000000000000000000000000000000000000000000000000000000)", + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea2", + "target_address": "contract3", + "data": "0x6039b0bd000000000000000fee50b7025c36a0802f236d04753d5b48e800000000000000", + "gas_limit": 85819 , + "value": "0", + "expected": { + "status": 0, + "extra_message": "0x0000000000000000000000000000000000000003fdc97a29c8e052fd00e94ecb", + "gas_used": 85819 , + "logs": [] + } + } + + + ] +} \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/contract_user_relation/one_user_many_contract.json b/tests/xtvm_test/test_cases/QA_CASES/contract_user_relation/one_user_many_contract.json new file mode 100755 index 000000000..e01a68e4e --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/contract_user_relation/one_user_many_contract.json @@ -0,0 +1,126 @@ +{ + "pre_data": {}, + "__comments":"同1用户部署多个不同合约,合约都可以使用", + "deploy_contract": [ + { + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea2", + "code_file_path": "TestSafeMath_sol_TestSafeMath.bin", + "gas_limit": 308435, + "value": "0", + "expected": { + "status": 0, + "extra_message": "contract1", + "gas_used": 308435, + "logs": [] + } + }, + { + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea2", + "code_file_path": "ForeverLoop_sol_ForeverLoop.bin", + "gas_limit": 138009, + "value": "0", + "expected": { + "status": 0, + "extra_message": "contract2", + "gas_used": 138009, + "logs": [] + } + }, + { + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea2", + "code_file_path": "AssertDemo_sol_AssertDemo.bin", + "gas_limit": 386507, + "value": "0", + "expected": { + "status": 0, + "extra_message": "contract3", + "gas_used": 386507, + "logs": [] + } + }, + { + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea2", + + "code_file_path": "Recursion_sol_Recursion.bin", + "gas_limit": 96213, + "value": "0", + "expected": { + "status": 0, + "extra_message": "contract4", + "gas_used": 96213, + "logs": [] + } + }, + { + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea2", + + "code_file_path": "Recursion_sol_Recursion.bin", + "gas_limit": 96213, + "value": "0", + "expected": { + "status": 0, + "extra_message": "contract5", + "gas_used": 96213, + "logs": [] + } + } + ], + "test_cases": [ + { + "__comments":"获取MAX_UINT成员变量", + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea2", + "target_address": "contract1", + "data": "0xe5b5019a", + "gas_limit": 23515, + "value": "0", + "expected": { + "status": 0, + "extra_message": "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", + "gas_used": 23515, + "logs": [] + } + }, + { + "__comments":"n > 1 死循环,消耗完gas退出", + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea2", + "target_address": "contract4", + "data": "0x4d99ebc90000000000000000000000000000000000000000000000000000000000000003", + "gas_limit": 21519, + "value": "0", + "expected": { + "status": 2, + "extra_message": "", + "gas_used": 21519, + "logs": [] + } + }, + { + "__comments":"执行forever死循环,执行消耗完gas退出", + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea2", + "target_address": "contract2", + "data": "0x9ff9a603", + "gas_limit": 2349300, + "value": "0", + "expected": { + "status": 2, + "extra_message": "", + "gas_used": 2349300, + "logs": [] + } + }, + { + "__comments":"set(111), 返回assert(false),合约执行不成功", + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea2", + "target_address": "contract3", + "data": "0x4ed3885e000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000033131310000000000000000000000000000000000000000000000000000000000", + "gas_limit": 22474, + "value": "0", + "expected": { + "status": 1, + "extra_message": "", + "gas_used": 22474, + "logs": [] + } + } + ] +} \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/erc20/Cat.bin b/tests/xtvm_test/test_cases/QA_CASES/erc20/Cat.bin new file mode 100755 index 000000000..dfc1ec3d4 --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/erc20/Cat.bin @@ -0,0 +1 @@ +60806040523480156200001157600080fd5b506b204fce5e3e25026110000000600081905550600054600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055507f2e90d1cd7a5e9a5b99747c36130d866c8687bff313d44cdd245df73bcda43621600033600054604051620000a3939291906200015e565b60405180910390a16200019b565b6000819050919050565b6000819050919050565b6000819050919050565b6000620000f0620000ea620000e484620000b1565b620000c5565b620000bb565b9050919050565b6200010281620000cf565b82525050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000620001358262000108565b9050919050565b620001478162000128565b82525050565b6200015881620000bb565b82525050565b6000606082019050620001756000830186620000f7565b6200018460208301856200013c565b6200019360408301846200014d565b949350505050565b6111f480620001ab6000396000f3fe608060405234801561001057600080fd5b506004361061009e5760003560e01c8063313ce56711610066578063313ce5671461016f57806370a082311461018d57806395d89b41146101bd578063a9059cbb146101db578063dd62ed3e1461020b5761009e565b806306fdde03146100a3578063095ea7b3146100c157806318160ddd146100f157806323b872dd1461010f57806327e235e31461013f575b600080fd5b6100ab61023b565b6040516100b89190610c62565b60405180910390f35b6100db60048036038101906100d69190610d1d565b610274565b6040516100e89190610d78565b60405180910390f35b6100f9610366565b6040516101069190610da2565b60405180910390f35b61012960048036038101906101249190610dbd565b61036f565b6040516101369190610d78565b60405180910390f35b61015960048036038101906101549190610e10565b6107ca565b6040516101669190610da2565b60405180910390f35b6101776107e2565b6040516101849190610e59565b60405180910390f35b6101a760048036038101906101a29190610e10565b6107e7565b6040516101b49190610da2565b60405180910390f35b6101c5610830565b6040516101d29190610c62565b60405180910390f35b6101f560048036038101906101f09190610d1d565b610869565b6040516102029190610d78565b60405180910390f35b61022560048036038101906102209190610e74565b610af4565b6040516102329190610da2565b60405180910390f35b6040518060400160405280600981526020017f43415420546f6b656e000000000000000000000000000000000000000000000081525081565b600081600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040516103549190610da2565b60405180910390a36001905092915050565b60008054905090565b6000600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020548211156103f3576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103ea90610f26565b60405180910390fd5b600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020548211156104b2576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016104a990610fb8565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1603610521576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161051890611024565b60405180910390fd5b61057382600160008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610b7b90919063ffffffff16565b600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555061060882600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610ba290919063ffffffff16565b600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506106da82600260008773ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610b7b90919063ffffffff16565b600260008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516107b79190610da2565b60405180910390a3600190509392505050565b60016020528060005260406000206000915090505481565b601281565b6000600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b6040518060400160405280600381526020017f434154000000000000000000000000000000000000000000000000000000000081525081565b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16036108d9576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016108d090611024565b60405180910390fd5b600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205482111561095b576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610952906110b6565b60405180910390fd5b6109ad82600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610b7b90919063ffffffff16565b600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550610a4282600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054610ba290919063ffffffff16565b600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef84604051610ae29190610da2565b60405180910390a36001905092915050565b6000600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600082821115610b8e57610b8d6110d6565b5b8183610b9a9190611134565b905092915050565b60008183610bb09190611168565b905082811015610bc357610bc26110d6565b5b92915050565b600081519050919050565b600082825260208201905092915050565b60005b83811015610c03578082015181840152602081019050610be8565b83811115610c12576000848401525b50505050565b6000601f19601f8301169050919050565b6000610c3482610bc9565b610c3e8185610bd4565b9350610c4e818560208601610be5565b610c5781610c18565b840191505092915050565b60006020820190508181036000830152610c7c8184610c29565b905092915050565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000610cb482610c89565b9050919050565b610cc481610ca9565b8114610ccf57600080fd5b50565b600081359050610ce181610cbb565b92915050565b6000819050919050565b610cfa81610ce7565b8114610d0557600080fd5b50565b600081359050610d1781610cf1565b92915050565b60008060408385031215610d3457610d33610c84565b5b6000610d4285828601610cd2565b9250506020610d5385828601610d08565b9150509250929050565b60008115159050919050565b610d7281610d5d565b82525050565b6000602082019050610d8d6000830184610d69565b92915050565b610d9c81610ce7565b82525050565b6000602082019050610db76000830184610d93565b92915050565b600080600060608486031215610dd657610dd5610c84565b5b6000610de486828701610cd2565b9350506020610df586828701610cd2565b9250506040610e0686828701610d08565b9150509250925092565b600060208284031215610e2657610e25610c84565b5b6000610e3484828501610cd2565b91505092915050565b600060ff82169050919050565b610e5381610e3d565b82525050565b6000602082019050610e6e6000830184610e4a565b92915050565b60008060408385031215610e8b57610e8a610c84565b5b6000610e9985828601610cd2565b9250506020610eaa85828601610cd2565b9150509250929050565b7f5f66726f6d20646f65736e74206861766520656e6f7567682062616c616e636560008201527f2e00000000000000000000000000000000000000000000000000000000000000602082015250565b6000610f10602183610bd4565b9150610f1b82610eb4565b604082019050919050565b60006020820190508181036000830152610f3f81610f03565b9050919050565b7f416c6c6f77616e6365206f66206d73672e73656e646572206973206e6f74206560008201527f6e6f7567682e0000000000000000000000000000000000000000000000000000602082015250565b6000610fa2602683610bd4565b9150610fad82610f46565b604082019050919050565b60006020820190508181036000830152610fd181610f95565b9050919050565b7f43616e6e6f742073656e6420746f20616c6c207a65726f20616464726573732e600082015250565b600061100e602083610bd4565b915061101982610fd8565b602082019050919050565b6000602082019050818103600083015261103d81611001565b9050919050565b7f6d73672e73656e6465722062616c616e6365206973206e6f7420656e6f75676860008201527f2e00000000000000000000000000000000000000000000000000000000000000602082015250565b60006110a0602183610bd4565b91506110ab82611044565b604082019050919050565b600060208201905081810360008301526110cf81611093565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052600160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600061113f82610ce7565b915061114a83610ce7565b92508282101561115d5761115c611105565b5b828203905092915050565b600061117382610ce7565b915061117e83610ce7565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff038211156111b3576111b2611105565b5b82820190509291505056fea26469706673582212201ea2cf626955a74397bfe004b8eba42599e3665a9e102586c44870f4e28675d564736f6c634300080d0033 \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/erc20/Cat.json b/tests/xtvm_test/test_cases/QA_CASES/erc20/Cat.json new file mode 100755 index 000000000..621994789 --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/erc20/Cat.json @@ -0,0 +1,133 @@ +{ + "pre_data": {}, + "deploy_contract": [ + { + "src_address": "T600045B38Da6a701c568545dCfcB03FcB875f56beddC4", + "code_file_path": "Cat.bin", + "gas_limit": 1257983, + "value": "0", + "expected": { + "status": 0, + "extra_message": "contract_one", + "gas_used": 1093898, + "logs": [{ + "address": "contract_one", + "topics": [ + "0x2e90d1cd7a5e9a5b99747c36130d866c8687bff313d44cdd245df73bcda43621" + ], + "data": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000005b38da6a701c568545dcfcb03fcb875f56beddc40000000000000000000000000000000000000000204fce5e3e25026110000000" + }] + } + } + ], + "test_cases": [ + { + "__comments":"转账token", + "src_address": "T600045B38Da6a701c568545dCfcB03FcB875f56beddC4", + "target_address": "contract_one", + "data": "0xa9059cbb000000000000000000000000636a4494f0cbe56528ea1ea51fd4eccddcf049940000000000000000000000000000000000000000000000000000000000000064", + "gas_limit": 60624, + "value": "0", + "expected": { + "status": 0, + "extra_message": "0x0000000000000000000000000000000000000000000000000000000000000001", + "gas_used": 52716, + "logs": [{ + "address": "contract_one", + "topics": [ + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "0x0000000000000000000000005b38da6a701c568545dcfcb03fcb875f56beddc4", + "0x000000000000000000000000636a4494f0cbe56528ea1ea51fd4eccddcf04994" + ], + "data": "0x0000000000000000000000000000000000000000000000000000000000000064" + }] + } + }, + { + "__comments":"转账token大于余额", + "src_address": "T600045B38Da6a701c568545dCfcB03FcB875f56beddC4", + "target_address": "contract_one", + "data": "0xa9059cbb000000000000000000000000636a4494f0cbe56528ea1ea51fd4eccddcf049940000000000000000000000000000000000000001431e0fae6d7217caa0000000", + "gas_limit": 3000000, + "value": "0", + "expected": { + "status": 1, + "extra_message": "", + "gas_used": 24930, + "logs": [] + } + }, + { + "__comments":"未授权调用transferFrom,调用失败", + "src_address": "T600045B38Da6a701c568545dCfcB03FcB875f56beddC4", + "target_address": "contract_one", + "data": "0xa9059cbb000000000000000000000000636a4494f0cbe56528ea1ea51fd4eccddcf049940000000000000000000000000000000000000001431e0fae6d7217caa0000000", + "gas_limit": 3000000, + "value": "0", + "expected": { + "status": 1, + "extra_message": "", + "gas_used": 24930, + "logs": [] + } + }, + { + "__comments":"授权调用approve", + "src_address": "T600045B38Da6a701c568545dCfcB03FcB875f56beddC4", + "target_address": "contract_one", + "data": "0x095ea7b30000000000000000000000005b38da6a701c568545dcfcb03fcb875f56beddc4000000000000000000000000000000000000000000000000000000003b9aca00", + "gas_limit": 53699, + "value": "0", + "expected": { + "status": 0, + "extra_message": "0x0000000000000000000000000000000000000000000000000000000000000001", + "gas_used": 46694, + "logs": [{ + "address": "contract_one", + "topics": [ + "0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925", + "0x0000000000000000000000005b38da6a701c568545dcfcb03fcb875f56beddc4", + "0x0000000000000000000000005b38da6a701c568545dcfcb03fcb875f56beddc4" + ], + "data": "0x000000000000000000000000000000000000000000000000000000003b9aca00" + }] + } + }, + { + "__comments":"授权调用transferFrom", + "src_address": "T600045B38Da6a701c568545dCfcB03FcB875f56beddC4", + "target_address": "contract_one", + "data": "0x23b872dd0000000000000000000000005b38da6a701c568545dcfcb03fcb875f56beddc4000000000000000000000000636a4494f0cbe56528ea1ea51fd4eccddcf04994000000000000000000000000000000000000000000000000000000000000000a", + "gas_limit": 48487, + "value": "0", + "expected": { + "status": 0, + "extra_message": "0x0000000000000000000000000000000000000000000000000000000000000001", + "gas_used": 42162, + "logs": [{ + "address": "contract_one", + "topics": [ + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "0x0000000000000000000000005b38da6a701c568545dcfcb03fcb875f56beddc4", + "0x000000000000000000000000636a4494f0cbe56528ea1ea51fd4eccddcf04994" + ], + "data": "0x000000000000000000000000000000000000000000000000000000000000000a" + }] + } + }, + { + "__comments":"授权额度不足调用transferFrom,调用失败", + "src_address": "T600045B38Da6a701c568545dCfcB03FcB875f56beddC4", + "target_address": "contract_one", + "data": "0x23b872dd0000000000000000000000005b38da6a701c568545dcfcb03fcb875f56beddc4000000000000000000000000636a4494f0cbe56528ea1ea51fd4eccddcf0499400000000000000000000000000000000000000000000003635c9adc5dea00000", + "gas_limit": 3000000, + "value": "0", + "expected": { + "status": 1, + "extra_message": "", + "gas_used": 27751, + "logs": [] + } + } + ] +} \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/erc20/Cat.sol b/tests/xtvm_test/test_cases/QA_CASES/erc20/Cat.sol new file mode 100755 index 000000000..b59ecfa00 --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/erc20/Cat.sol @@ -0,0 +1,107 @@ +pragma solidity >=0.4.22 <0.9.0; + +import "./ERC20.sol"; +import "./SafeMath.sol"; + +/** + * @title CAT Token + * @dev Compatible with ERC20/VIP180 Standard. + * Special thanks go to openzeppelin-solidity project. + */ +contract Cat is ERC20 { + using SafeMath for uint256; + + // Name of token + string public constant name = "CAT Token"; + // Symbol of token + string public constant symbol = "CAT"; + // Decimals of token + uint8 public constant decimals = 18; + // Total supply of the tokens + uint256 internal totalSupply_; + + // balances: (_holder => _value) + mapping(address => uint256) public balances; + + + // allowed: (_owner, => (_spender, _value)) + mapping (address => mapping (address => uint256)) internal allowed; + + event Transfer( + uint zero, + address address_, + uint256 balance_ + ); + + + constructor() { + totalSupply_ = 1 * (10 ** 10) * (10 ** 18); // 10 000 000 000 tokens of 18 decimals. + balances[msg.sender] = totalSupply_; + emit Transfer(0, msg.sender, totalSupply_); // init mint of coins complete. + } + + // Get the total supply of the coins + function totalSupply() public override view returns (uint256) { + return totalSupply_; + } + + // Get the balance of _owner + function balanceOf(address _owner) public override view returns (uint256 balance) { + return balances[_owner]; + } + + /** Make a Transfer. + * @dev This operation will deduct the msg.sender's balance. + * @param _to address The address the funds go to. + * @param _value uint256 The amount of funds. + */ + function transfer(address _to, uint256 _value) public override returns (bool) { + require(_to != address(0), "Cannot send to all zero address."); + require(_value <= balances[msg.sender], "msg.sender balance is not enough."); + + // SafeMath.sub will throw if there is not enough balance. + balances[msg.sender] = balances[msg.sender].sub(_value); + balances[_to] = balances[_to].add(_value); + emit Transfer(msg.sender, _to, _value); + return true; + } + + /** + * @dev Check the allowed funds that _spender can take from _owner. + * @param _owner address The address which owns the funds. + * @param _spender address The address which will spend the funds. + * @return A uint256 specifying the amount of tokens still available for the spender. + */ + function allowance(address _owner, address _spender) public override view returns (uint256) { + return allowed[_owner][_spender]; + } + + /** + * @dev Transfer tokens from one address to another + * @param _from address The address which you want to send tokens from + * @param _to address The address which you want to transfer to + * @param _value uint256 the amount of tokens to be transferred + */ + function transferFrom(address _from, address _to, uint256 _value) public override returns (bool) { + require(_value <= balances[_from], "_from doesnt have enough balance."); + require(_value <= allowed[_from][msg.sender], "Allowance of msg.sender is not enough."); + require(_to != address(0), "Cannot send to all zero address."); + + balances[_from] = balances[_from].sub(_value); + balances[_to] = balances[_to].add(_value); + allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value); + emit Transfer(_from, _to, _value); + return true; + } + + /** + * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. + * @param _spender The address which will spend the funds. + * @param _value The amount of tokens to be spent. + */ + function approve(address _spender, uint256 _value) public override returns (bool) { + allowed[msg.sender][_spender] = _value; + emit Approval(msg.sender, _spender, _value); + return true; + } +} \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/erc20/ERC20.sol b/tests/xtvm_test/test_cases/QA_CASES/erc20/ERC20.sol new file mode 100755 index 000000000..d98b46046 --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/erc20/ERC20.sol @@ -0,0 +1,25 @@ +pragma solidity >=0.4.22 <0.9.0; + +import "./ERC20Basic.sol"; +/** + * @title ERC20 interface + * @dev Enhanced interface with allowance functions. + * See https://github.com/ethereum/EIPs/issues/20 + */ +abstract contract ERC20 is ERC20Basic { + // Check the allowed value that the _owner allows the _spender to take from his balance. + function allowance(address _owner, address _spender) external virtual view returns (uint256); + + // Transfer _value from the balance of holder _from to the receiver _to. + function transferFrom(address _from, address _to, uint256 _value) external virtual returns (bool); + + // Approve _spender to take some _value from the balance of msg.sender. + function approve(address _spender, uint256 _value) external virtual returns (bool); + + // Fired when an approval is made. + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/erc20/ERC20Basic.sol b/tests/xtvm_test/test_cases/QA_CASES/erc20/ERC20Basic.sol new file mode 100755 index 000000000..a7794b215 --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/erc20/ERC20Basic.sol @@ -0,0 +1,16 @@ +pragma solidity >=0.4.22 <0.9.0; + +abstract contract ERC20Basic { + // Total supply of token. + function totalSupply() external virtual view returns (uint256); + // Balance of a holder _who + function balanceOf(address _who) external virtual view returns (uint256); + // Transfer _value from msg.sender to receiver _to. + function transfer(address _to, uint256 _value) external virtual returns (bool); + // Fired when a transfer is made + event Transfer( + address indexed from, + address indexed to, + uint256 value + ); +} \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/erc20/SafeMath.sol b/tests/xtvm_test/test_cases/QA_CASES/erc20/SafeMath.sol new file mode 100755 index 000000000..088af246a --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/erc20/SafeMath.sol @@ -0,0 +1,50 @@ +pragma solidity >=0.4.22 <0.9.0; + +/** + * @title SafeMath + * @dev Math operations with safety checks that throw on error + */ +library SafeMath { + /** + * @dev Multiplies two numbers, throws on overflow. + */ + function mul(uint256 _a, uint256 _b) internal pure returns (uint256 c) { + // Gas optimization: this is cheaper than asserting 'a' not being zero, but the + // benefit is lost if 'b' is also tested. + // See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522 + if (_a == 0) { + return 0; + } + + c = _a * _b; + assert(c / _a == _b); + return c; + } + + /** + * @dev Integer division of two numbers, truncating the quotient. + */ + function div(uint256 _a, uint256 _b) internal pure returns (uint256) { + // assert(_b > 0); // Solidity automatically throws when dividing by 0 + // uint256 c = _a / _b; + // assert(_a == _b * c + _a % _b); // There is no case in which this doesn't hold + return _a / _b; + } + + /** + * @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). + */ + function sub(uint256 _a, uint256 _b) internal pure returns (uint256) { + assert(_b <= _a); + return _a - _b; + } + + /** + * @dev Adds two numbers, throws on overflow. + */ + function add(uint256 _a, uint256 _b) internal pure returns (uint256 c) { + c = _a + _b; + assert(c >= _a); + return c; + } +} \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/import/Foo.sol b/tests/xtvm_test/test_cases/QA_CASES/import/Foo.sol new file mode 100755 index 000000000..bd74ecdd2 --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/import/Foo.sol @@ -0,0 +1,17 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.10; + +struct Point { + uint256 x; + uint256 y; +} + +error Unauthorized(address caller); + +function add(uint256 x, uint256 y) pure returns (uint256) { + return x + y; +} + +contract Foo { + string public name = "Foo"; +} diff --git a/tests/xtvm_test/test_cases/QA_CASES/import/Import.bin b/tests/xtvm_test/test_cases/QA_CASES/import/Import.bin new file mode 100755 index 000000000..3cfe2d19d --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/import/Import.bin @@ -0,0 +1 @@ +60806040526040516100109061007e565b604051809103906000f08015801561002c573d6000803e3d6000fd5b506000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555034801561007857600080fd5b5061008b565b6103a18061066883390190565b6105ce8061009a6000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c8063771602f714610046578063c298557814610076578063c626126114610094575b600080fd5b610060600480360381019061005b91906101e5565b6100b2565b60405161006d9190610234565b60405180910390f35b61007e6100c6565b60405161008b91906102ce565b60405180910390f35b61009c6100ea565b6040516100a99190610382565b60405180910390f35b60006100be8383610185565b905092915050565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b606060008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166306fdde036040518163ffffffff1660e01b8152600401600060405180830381865afa158015610157573d6000803e3d6000fd5b505050506040513d6000823e3d601f19601f8201168201806040525081019061018091906104ca565b905090565b600081836101939190610542565b905092915050565b6000604051905090565b600080fd5b600080fd5b6000819050919050565b6101c2816101af565b81146101cd57600080fd5b50565b6000813590506101df816101b9565b92915050565b600080604083850312156101fc576101fb6101a5565b5b600061020a858286016101d0565b925050602061021b858286016101d0565b9150509250929050565b61022e816101af565b82525050565b60006020820190506102496000830184610225565b92915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b600061029461028f61028a8461024f565b61026f565b61024f565b9050919050565b60006102a682610279565b9050919050565b60006102b88261029b565b9050919050565b6102c8816102ad565b82525050565b60006020820190506102e360008301846102bf565b92915050565b600081519050919050565b600082825260208201905092915050565b60005b83811015610323578082015181840152602081019050610308565b83811115610332576000848401525b50505050565b6000601f19601f8301169050919050565b6000610354826102e9565b61035e81856102f4565b935061036e818560208601610305565b61037781610338565b840191505092915050565b6000602082019050818103600083015261039c8184610349565b905092915050565b600080fd5b600080fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6103e682610338565b810181811067ffffffffffffffff82111715610405576104046103ae565b5b80604052505050565b600061041861019b565b905061042482826103dd565b919050565b600067ffffffffffffffff821115610444576104436103ae565b5b61044d82610338565b9050602081019050919050565b600061046d61046884610429565b61040e565b905082815260208101848484011115610489576104886103a9565b5b610494848285610305565b509392505050565b600082601f8301126104b1576104b06103a4565b5b81516104c184826020860161045a565b91505092915050565b6000602082840312156104e0576104df6101a5565b5b600082015167ffffffffffffffff8111156104fe576104fd6101aa565b5b61050a8482850161049c565b91505092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600061054d826101af565b9150610558836101af565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0382111561058d5761058c610513565b5b82820190509291505056fea264697066735822122050f6ebd4ebf80c604e5b9f30601ef9e076f4a89062eb728f9178e9355e2d25a564736f6c634300080d003360806040526040518060400160405280600381526020017f466f6f00000000000000000000000000000000000000000000000000000000008152506000908051906020019061004f929190610062565b5034801561005c57600080fd5b50610165565b82805461006e90610134565b90600052602060002090601f01602090048101928261009057600085556100d7565b82601f106100a957805160ff19168380011785556100d7565b828001600101855582156100d7579182015b828111156100d65782518255916020019190600101906100bb565b5b5090506100e491906100e8565b5090565b5b808211156101015760008160009055506001016100e9565b5090565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b6000600282049050600182168061014c57607f821691505b60208210810361015f5761015e610105565b5b50919050565b61022d806101746000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c806306fdde0314610030575b600080fd5b61003861004e565b6040516100459190610175565b60405180910390f35b6000805461005b906101c6565b80601f0160208091040260200160405190810160405280929190818152602001828054610087906101c6565b80156100d45780601f106100a9576101008083540402835291602001916100d4565b820191906000526020600020905b8154815290600101906020018083116100b757829003601f168201915b505050505081565b600081519050919050565b600082825260208201905092915050565b60005b838110156101165780820151818401526020810190506100fb565b83811115610125576000848401525b50505050565b6000601f19601f8301169050919050565b6000610147826100dc565b61015181856100e7565b93506101618185602086016100f8565b61016a8161012b565b840191505092915050565b6000602082019050818103600083015261018f818461013c565b905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b600060028204905060018216806101de57607f821691505b6020821081036101f1576101f0610197565b5b5091905056fea264697066735822122037614a5b68372c0b4ac494c4ba93267e0f546708a4fb30202506741354ee759b64736f6c634300080d0033 \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/import/Import.json b/tests/xtvm_test/test_cases/QA_CASES/import/Import.json new file mode 100755 index 000000000..a4901caf3 --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/import/Import.json @@ -0,0 +1,33 @@ +{ + "pre_data": {}, + "deploy_contract": [ + { + "src_address": "T60004Ab8483F64d9C6d1EcF9b849Ae677dD3315835cb2", + "code_file_path": "Import.bin", + "gas_limit": 663233, + "value": "0", + "expected": { + "status": 0, + "extra_message": "contract_one", + "gas_used": 576724, + "logs": [] + } + } + ], + "test_cases": [ + { + "__comments":"调用引用的func", + "src_address": "T60004Ab8483F64d9C6d1EcF9b849Ae677dD3315835cb2", + "target_address": "contract_one", + "data": "0x771602f700000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003", + "gas_limit": 25690, + "value": "0", + "expected": { + "status": 0, + "extra_message": "0x0000000000000000000000000000000000000000000000000000000000000005", + "gas_used": 22339, + "logs": [] + } + } + ] +} \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/import/Import.sol b/tests/xtvm_test/test_cases/QA_CASES/import/Import.sol new file mode 100755 index 000000000..f8692e37b --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/import/Import.sol @@ -0,0 +1,18 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.10; + +import "./Foo.sol"; + +import {Unauthorized, add as func, Point} from "./Foo.sol"; + +contract Import { + Foo public foo = new Foo(); + + function getFooName() public view returns (string memory) { + return foo.name(); + } + + function add(uint256 x,uint256 y) public returns (uint256) { + return add(x,y); + } +} diff --git a/tests/xtvm_test/test_cases/QA_CASES/interrupt/AssertDemo.json b/tests/xtvm_test/test_cases/QA_CASES/interrupt/AssertDemo.json new file mode 100755 index 000000000..7f6fb1e5c --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/interrupt/AssertDemo.json @@ -0,0 +1,47 @@ +{ + "pre_data": {}, + "deploy_contract": [ + { + "src_address": "T60004befc5d4c0cf44e2295c01920bac668d2c4d61a4b", + "code_file_path": "AssertDemo_sol_AssertDemo.bin", + "gas_limit": 386507, + "value": "0", + "expected": { + "status": 0, + "extra_message": "contract_one", + "gas_used": 386507, + "logs": [] + } + } + ], + "test_cases": [ + { + "__comments":"执行get", + "src_address": "T60004befc5d4c0cf44e2295c01920bac668d2c4d61a4b", + "target_address": "contract_one", + "data": "0x6d4ce63c", + "gas_limit": 24521, + "value": "0", + "expected": { + "status": 0, + "extra_message": "", + "gas_used": 24521, + "logs": [] + } + }, + { + "__comments":"set(111), 返回assert(false),合约执行不成功", + "src_address": "T60004befc5d4c0cf44e2295c01920bac668d2c4d61a4b", + "target_address": "contract_one", + "data": "0x4ed3885e000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000033131310000000000000000000000000000000000000000000000000000000000", + "gas_limit": 22474, + "value": "0", + "expected": { + "status": 1, + "extra_message": "", + "gas_used": 22474, + "logs": [] + } + } + ] +} \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/interrupt/AssertDemo.sol b/tests/xtvm_test/test_cases/QA_CASES/interrupt/AssertDemo.sol new file mode 100755 index 000000000..892412ca7 --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/interrupt/AssertDemo.sol @@ -0,0 +1,21 @@ +pragma solidity =0.8.13; + +contract AssertDemo { + string name; + + constructor() public { + name = "welight"; + } + + function get() public view returns (string memory) { + return name; + } + + event Set(address indexed_from, string n); + + function set(string memory n) public { + assert(false); + name = n; + emit Set(msg.sender, n); + } +} diff --git a/tests/xtvm_test/test_cases/QA_CASES/interrupt/AssertDemo_sol_AssertDemo.abi b/tests/xtvm_test/test_cases/QA_CASES/interrupt/AssertDemo_sol_AssertDemo.abi new file mode 100755 index 000000000..b245fde8d --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/interrupt/AssertDemo_sol_AssertDemo.abi @@ -0,0 +1 @@ +[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"indexed_from","type":"address"},{"indexed":false,"internalType":"string","name":"n","type":"string"}],"name":"Set","type":"event"},{"inputs":[],"name":"get","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"n","type":"string"}],"name":"set","outputs":[],"stateMutability":"nonpayable","type":"function"}] \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/interrupt/AssertDemo_sol_AssertDemo.bin b/tests/xtvm_test/test_cases/QA_CASES/interrupt/AssertDemo_sol_AssertDemo.bin new file mode 100755 index 000000000..a92a1ab9b --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/interrupt/AssertDemo_sol_AssertDemo.bin @@ -0,0 +1 @@ +608060405234801561001057600080fd5b506040518060400160405280600781526020017f77656c69676874000000000000000000000000000000000000000000000000008152506000908051906020019061005c929190610062565b50610165565b82805461006e90610134565b90600052602060002090601f01602090048101928261009057600085556100d7565b82601f106100a957805160ff19168380011785556100d7565b828001600101855582156100d7579182015b828111156100d65782518255916020019190600101906100bb565b5b5090506100e491906100e8565b5090565b5b808211156101015760008160009055506001016100e9565b5090565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b6000600282049050600182168061014c57607f821691505b60208210810361015f5761015e610105565b5b50919050565b61058f806101746000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80634ed3885e1461003b5780636d4ce63c14610057575b600080fd5b61005560048036038101906100509190610366565b610075565b005b61005f6100d7565b60405161006c9190610437565b60405180910390f35b600061008457610083610459565b5b806000908051906020019061009a929190610169565b507fde696604ac839ef8a5d0fcb2310ea48463357a6247e0d961d77c41d136a5d94633826040516100cc9291906104c9565b60405180910390a150565b6060600080546100e690610528565b80601f016020809104026020016040519081016040528092919081815260200182805461011290610528565b801561015f5780601f106101345761010080835404028352916020019161015f565b820191906000526020600020905b81548152906001019060200180831161014257829003601f168201915b5050505050905090565b82805461017590610528565b90600052602060002090601f01602090048101928261019757600085556101de565b82601f106101b057805160ff19168380011785556101de565b828001600101855582156101de579182015b828111156101dd5782518255916020019190600101906101c2565b5b5090506101eb91906101ef565b5090565b5b808211156102085760008160009055506001016101f0565b5090565b6000604051905090565b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6102738261022a565b810181811067ffffffffffffffff821117156102925761029161023b565b5b80604052505050565b60006102a561020c565b90506102b1828261026a565b919050565b600067ffffffffffffffff8211156102d1576102d061023b565b5b6102da8261022a565b9050602081019050919050565b82818337600083830152505050565b6000610309610304846102b6565b61029b565b90508281526020810184848401111561032557610324610225565b5b6103308482856102e7565b509392505050565b600082601f83011261034d5761034c610220565b5b813561035d8482602086016102f6565b91505092915050565b60006020828403121561037c5761037b610216565b5b600082013567ffffffffffffffff81111561039a5761039961021b565b5b6103a684828501610338565b91505092915050565b600081519050919050565b600082825260208201905092915050565b60005b838110156103e95780820151818401526020810190506103ce565b838111156103f8576000848401525b50505050565b6000610409826103af565b61041381856103ba565b93506104238185602086016103cb565b61042c8161022a565b840191505092915050565b6000602082019050818103600083015261045181846103fe565b905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052600160045260246000fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006104b382610488565b9050919050565b6104c3816104a8565b82525050565b60006040820190506104de60008301856104ba565b81810360208301526104f081846103fe565b90509392505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b6000600282049050600182168061054057607f821691505b602082108103610553576105526104f9565b5b5091905056fea264697066735822122085acf1966f2fe652bb379836731fe058fb5df5e65ce28800cae247d815c8957464736f6c634300080d0033 \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/interrupt/ForeverLoop.json b/tests/xtvm_test/test_cases/QA_CASES/interrupt/ForeverLoop.json new file mode 100755 index 000000000..22e6cd089 --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/interrupt/ForeverLoop.json @@ -0,0 +1,48 @@ +{ + "pre_data": {}, + "deploy_contract": [ + { + "src_address": "T600040fe636046a92ae04c0df0364120e0223bb319446", + + "code_file_path": "ForeverLoop_sol_ForeverLoop.bin", + "gas_limit": 138009, + "value": "0", + "expected": { + "status": 0, + "extra_message": "contract_one", + "gas_used": 138009, + "logs": [] + } + } + ], + "test_cases": [ + { + "__comments":"获取成员变量i,初始0", + "src_address": "T600040fe636046a92ae04c0df0364120e0223bb319446", + "target_address": "contract_one", + "data": "0xe5aa3d58", + "gas_limit": 23493, + "value": "0", + "expected": { + "status": 0, + "extra_message": "0x0000000000000000000000000000000000000000000000000000000000000000", + "gas_used": 23493, + "logs": [] + } + }, + { + "__comments":"执行forever死循环,执行消耗完gas退出", + "src_address": "T600040fe636046a92ae04c0df0364120e0223bb319446", + "target_address": "contract_one", + "data": "0x9ff9a603", + "gas_limit": 2349300, + "value": "0", + "expected": { + "status": 2, + "extra_message": "", + "gas_used": 2349300, + "logs": [] + } + } + ] +} \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/interrupt/ForeverLoop.sol b/tests/xtvm_test/test_cases/QA_CASES/interrupt/ForeverLoop.sol new file mode 100755 index 000000000..2ef491f01 --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/interrupt/ForeverLoop.sol @@ -0,0 +1,12 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.10; + +contract ForeverLoop { + uint public i = 0; + + function forever() public { + while (true) { + i += 1; + } + } +} diff --git a/tests/xtvm_test/test_cases/QA_CASES/interrupt/ForeverLoop_sol_ForeverLoop.abi b/tests/xtvm_test/test_cases/QA_CASES/interrupt/ForeverLoop_sol_ForeverLoop.abi new file mode 100755 index 000000000..540a5fbc5 --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/interrupt/ForeverLoop_sol_ForeverLoop.abi @@ -0,0 +1 @@ +[{"inputs":[],"name":"forever","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"i","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}] \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/interrupt/ForeverLoop_sol_ForeverLoop.bin b/tests/xtvm_test/test_cases/QA_CASES/interrupt/ForeverLoop_sol_ForeverLoop.bin new file mode 100755 index 000000000..f61e88577 --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/interrupt/ForeverLoop_sol_ForeverLoop.bin @@ -0,0 +1 @@ +60806040526000805534801561001457600080fd5b50610180806100246000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80639ff9a6031461003b578063e5aa3d5814610045575b600080fd5b610043610063565b005b61004d61008b565b60405161005a91906100aa565b60405180910390f35b5b60011561008957600160008082825461007d91906100f4565b92505081905550610064565b565b60005481565b6000819050919050565b6100a481610091565b82525050565b60006020820190506100bf600083018461009b565b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60006100ff82610091565b915061010a83610091565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0382111561013f5761013e6100c5565b5b82820190509291505056fea26469706673582212209e7606328dbe026152dc90dc0e7ac66b63562522eb013eae785ac2eaf110a60a64736f6c634300080d0033 \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/interrupt/Recursion.json b/tests/xtvm_test/test_cases/QA_CASES/interrupt/Recursion.json new file mode 100755 index 000000000..dc0d77215 --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/interrupt/Recursion.json @@ -0,0 +1,48 @@ +{ + "pre_data": {}, + "deploy_contract": [ + { + "src_address": "T600040fe636046a92ae04c0df0364120e0223bb319446", + + "code_file_path": "Recursion_sol_Recursion.bin", + "gas_limit": 96213, + "value": "0", + "expected": { + "status": 0, + "extra_message": "contract_one", + "gas_used": 96213, + "logs": [] + } + } + ], + "test_cases": [ + { + "__comments":"n=1 ,返回1", + "src_address": "T600047767d8d47a370ec7c49b153f2731360fb08239e8", + "target_address": "contract_one", + "data": "0x4d99ebc90000000000000000000000000000000000000000000000000000000000000001", + "gas_limit": 21519, + "value": "0", + "expected": { + "status": 0, + "extra_message": "", + "gas_used": 21519, + "logs": [] + } + }, + { + "__comments":"n > 1 死循环,消耗完gas退出", + "src_address": "T600047767d8d47a370ec7c49b153f2731360fb08239e8", + "target_address": "contract_one", + "data": "0x4d99ebc90000000000000000000000000000000000000000000000000000000000000003", + "gas_limit": 21519, + "value": "0", + "expected": { + "status": 2, + "extra_message": "", + "gas_used": 21519, + "logs": [] + } + } + ] +} \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/interrupt/Recursion.sol b/tests/xtvm_test/test_cases/QA_CASES/interrupt/Recursion.sol new file mode 100755 index 000000000..2bb3977df --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/interrupt/Recursion.sol @@ -0,0 +1,12 @@ +pragma solidity ^0.8.10; + +contract Recursion { + + function sum2(uint256 n) public pure returns (uint256){ + if(n == 1){ + return n; + }else{ + return n * sum2(n+1); + } + } +} \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/interrupt/Recursion_sol_Recursion.abi b/tests/xtvm_test/test_cases/QA_CASES/interrupt/Recursion_sol_Recursion.abi new file mode 100755 index 000000000..bd41f63f9 --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/interrupt/Recursion_sol_Recursion.abi @@ -0,0 +1 @@ +[{"inputs":[{"internalType":"uint256","name":"n","type":"uint256"}],"name":"sum2","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"}] \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/interrupt/Recursion_sol_Recursion.bin b/tests/xtvm_test/test_cases/QA_CASES/interrupt/Recursion_sol_Recursion.bin new file mode 100755 index 000000000..cc96678b2 --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/interrupt/Recursion_sol_Recursion.bin @@ -0,0 +1 @@ +608060405234801561001057600080fd5b5060c68061001f6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c80634d99ebc914602d575b600080fd5b605660048036036020811015604157600080fd5b8101908080359060200190929190505050606c565b6040518082815260200191505060405180910390f35b60006001821415607d57819050608c565b608760018301606c565b820290505b91905056fea265627a7a72315820147a7de8945e47b5d7c480bc3c21aefdaadd86d5c02d618f81e9b544d1eca60564736f6c63430005110032 \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/library/TestSafeMath.json b/tests/xtvm_test/test_cases/QA_CASES/library/TestSafeMath.json new file mode 100755 index 000000000..dbc58616a --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/library/TestSafeMath.json @@ -0,0 +1,133 @@ +{ + "pre_data": {}, + "deploy_contract": [ + { + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea2", + "code_file_path": "TestSafeMath_sol_TestSafeMath.bin", + "gas_limit": 308435, + "value": "0", + "expected": { + "status": 0, + "extra_message": "contract_one", + "gas_used": 308435, + "logs": [] + } + } + ], + "test_cases": [ + { + "__comments":"获取MAX_UINT成员变量", + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea2", + "target_address": "contract_one", + "data": "0xe5b5019a", + "gas_limit": 23515, + "value": "0", + "expected": { + "status": 0, + "extra_message": "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", + "gas_used": 23515, + "logs": [] + } + }, + { + "__comments":"执行add(1,2)", + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea2", + "target_address": "contract_one", + "data": "0x7c3ffef200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002", + "gas_limit": 22415, + "value": "0", + "expected": { + "status": 0, + "extra_message": "0x0000000000000000000000000000000000000000000000000000000000000003", + "gas_used": 22415, + "logs": [] + } + }, + { + "__comments":"执行add(0,0)", + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea2", + "target_address": "contract_one", + "data": "0x7c3ffef200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "gas_limit": 22391, + "value": "0", + "expected": { + "status": 0, + "extra_message": "0x0000000000000000000000000000000000000000000000000000000000000000", + "gas_used": 22391, + "logs": [] + } + }, + { + "__comments":"执行add(2000000000000000000000000000000000000000000000,2000000000000000000000000000000000000000000000)", + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea2", + "target_address": "contract_one", + "data": "0x7c3ffef20000000000000000000000000059aedfc10d7279c5eed14016454000000000000000000000000000000000000059aedfc10d7279c5eed1401645400000000000", + "gas_limit": 22727, + "value": "0", + "expected": { + "status": 0, + "extra_message": "0x00000000000000000000000000b35dbf821ae4f38bdda2802c8a800000000000", + "gas_used": 22727, + "logs": [] + } + }, + { + "__comments":"溢出测试,执行add(115792089237316195423570985008687907853269984665640564039457584007913129639935,1)", + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea2", + "target_address": "contract_one", + "data": "0x7c3ffef2ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000000000000001", + "gas_limit": 22529, + "value": "0", + "expected": { + "status": 1, + "extra_message": "0x4e487b710000000000000000000000000000000000000000000000000000000000000011", + "gas_used": 22529, + "logs": [] + } + }, + { + "__comments":"执行sqrt(1)", + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea2", + "target_address": "contract_one", + "data": "0x6039b0bd0000000000000000000000000000000000000000000000000000000000000001", + "gas_limit": 21877 , + "value": "0", + "expected": { + "status": 0, + "extra_message": "0x0000000000000000000000000000000000000000000000000000000000000001", + "gas_used": 21877 , + "logs": [] + } + }, + { + "__comments":"执行sqrt(0)", + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea2", + "target_address": "contract_one", + "data": "0x6039b0bd0000000000000000000000000000000000000000000000000000000000000000", + "gas_limit": 21857 , + "value": "0", + "expected": { + "status": 0, + "extra_message": "0x0000000000000000000000000000000000000000000000000000000000000000", + "gas_used": 21857 , + "logs": [] + } + }, + { + "__comments":"执行sqrt(100000000000000000000000000000000000000000000000000000000000)", + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea2", + "target_address": "contract_one", + "data": "0x6039b0bd000000000000000fee50b7025c36a0802f236d04753d5b48e800000000000000", + "gas_limit": 85819 , + "value": "0", + "expected": { + "status": 0, + "extra_message": "0x0000000000000000000000000000000000000003fdc97a29c8e052fd00e94ecb", + "gas_used": 85819 , + "logs": [] + } + } + + + ] +} \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/library/TestSafeMath.sol b/tests/xtvm_test/test_cases/QA_CASES/library/TestSafeMath.sol new file mode 100755 index 000000000..0db8cc444 --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/library/TestSafeMath.sol @@ -0,0 +1,41 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.10; + +library SafeMath { + function add(uint256 x, uint256 y) internal pure returns (uint256) { + uint256 z = x + y; + require(z >= x, "uint overflow"); + + return z; + } +} + +library Math { + function sqrt(uint256 y) internal pure returns (uint256 z) { + if (y > 3) { + z = y; + uint256 x = y / 2 + 1; + while (x < z) { + z = x; + x = (y / x + x) / 2; + } + } else if (y != 0) { + z = 1; + } + // else z = 0 (default value) + } +} + +contract TestSafeMath { + using SafeMath for uint256; + + uint256 public MAX_UINT = 2**256 - 1; + + function testAdd(uint256 x, uint256 y) public pure returns (uint256) { + return x.add(y); + } + + function testSquareRoot(uint256 x) public pure returns (uint256) { + return Math.sqrt(x); + } +} diff --git a/tests/xtvm_test/test_cases/QA_CASES/library/TestSafeMath_sol_Math.abi b/tests/xtvm_test/test_cases/QA_CASES/library/TestSafeMath_sol_Math.abi new file mode 100755 index 000000000..0637a088a --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/library/TestSafeMath_sol_Math.abi @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/library/TestSafeMath_sol_Math.bin b/tests/xtvm_test/test_cases/QA_CASES/library/TestSafeMath_sol_Math.bin new file mode 100755 index 000000000..cc67010d9 --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/library/TestSafeMath_sol_Math.bin @@ -0,0 +1 @@ +60566050600b82828239805160001a6073146043577f4e487b7100000000000000000000000000000000000000000000000000000000600052600060045260246000fd5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600080fdfea2646970667358221220b66fadbe2d13990ca124d4576c247e39ce80fecdc74d8c84f179590bd2b263ed64736f6c634300080d0033 \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/library/TestSafeMath_sol_SafeMath.abi b/tests/xtvm_test/test_cases/QA_CASES/library/TestSafeMath_sol_SafeMath.abi new file mode 100755 index 000000000..0637a088a --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/library/TestSafeMath_sol_SafeMath.abi @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/library/TestSafeMath_sol_SafeMath.bin b/tests/xtvm_test/test_cases/QA_CASES/library/TestSafeMath_sol_SafeMath.bin new file mode 100755 index 000000000..262edc82e --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/library/TestSafeMath_sol_SafeMath.bin @@ -0,0 +1 @@ +60566050600b82828239805160001a6073146043577f4e487b7100000000000000000000000000000000000000000000000000000000600052600060045260246000fd5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600080fdfea26469706673582212208a8a8ae4a8308623532c292ed5f032f57dff00aa3051d9c162a0e62bc5a7891164736f6c634300080d0033 \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/library/TestSafeMath_sol_TestSafeMath.abi b/tests/xtvm_test/test_cases/QA_CASES/library/TestSafeMath_sol_TestSafeMath.abi new file mode 100755 index 000000000..b182ad37a --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/library/TestSafeMath_sol_TestSafeMath.abi @@ -0,0 +1 @@ +[{"inputs":[],"name":"MAX_UINT","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"x","type":"uint256"},{"internalType":"uint256","name":"y","type":"uint256"}],"name":"testAdd","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"x","type":"uint256"}],"name":"testSquareRoot","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"}] \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/library/TestSafeMath_sol_TestSafeMath.bin b/tests/xtvm_test/test_cases/QA_CASES/library/TestSafeMath_sol_TestSafeMath.bin new file mode 100755 index 000000000..13e2edf5a --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/library/TestSafeMath_sol_TestSafeMath.bin @@ -0,0 +1 @@ +0x60806040527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff60005534801561003457600080fd5b5061043b806100446000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c80636039b0bd146100465780637c3ffef214610076578063e5b5019a146100a6575b600080fd5b610060600480360381019061005b919061020c565b6100c4565b60405161006d9190610248565b60405180910390f35b610090600480360381019061008b9190610263565b6100d6565b60405161009d9190610248565b60405180910390f35b6100ae6100f3565b6040516100bb9190610248565b60405180910390f35b60006100cf826100f9565b9050919050565b60006100eb828461017390919063ffffffff16565b905092915050565b60005481565b6000600382111561016057819050600060016002846101189190610301565b6101229190610332565b90505b8181101561015a57809150600281828561013f9190610301565b6101499190610332565b6101539190610301565b9050610125565b5061016e565b6000821461016d57600190505b5b919050565b60008082846101829190610332565b9050838110156101c7576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101be906103e5565b60405180910390fd5b8091505092915050565b600080fd5b6000819050919050565b6101e9816101d6565b81146101f457600080fd5b50565b600081359050610206816101e0565b92915050565b600060208284031215610222576102216101d1565b5b6000610230848285016101f7565b91505092915050565b610242816101d6565b82525050565b600060208201905061025d6000830184610239565b92915050565b6000806040838503121561027a576102796101d1565b5b6000610288858286016101f7565b9250506020610299858286016101f7565b9150509250929050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600061030c826101d6565b9150610317836101d6565b925082610327576103266102a3565b5b828204905092915050565b600061033d826101d6565b9150610348836101d6565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0382111561037d5761037c6102d2565b5b828201905092915050565b600082825260208201905092915050565b7f75696e74206f766572666c6f7700000000000000000000000000000000000000600082015250565b60006103cf600d83610388565b91506103da82610399565b602082019050919050565b600060208201905081810360008301526103fe816103c2565b905091905056fea2646970667358221220e994386c4e2f16502800cfd0c0da1cb3083d880a355cb62d0eee6fe6b0773aee64736f6c634300080d0033 \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/new_swap/Context.sol b/tests/xtvm_test/test_cases/QA_CASES/new_swap/Context.sol new file mode 100755 index 000000000..b2c1ecd06 --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/new_swap/Context.sol @@ -0,0 +1,24 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.0; + +/* + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract Context { + function _msgSender() internal view virtual returns (address) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes calldata) { + this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 + return msg.data; + } +} \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/new_swap/Context_sol_Context.abi b/tests/xtvm_test/test_cases/QA_CASES/new_swap/Context_sol_Context.abi new file mode 100755 index 000000000..0637a088a --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/new_swap/Context_sol_Context.abi @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/new_swap/Context_sol_Context.bin b/tests/xtvm_test/test_cases/QA_CASES/new_swap/Context_sol_Context.bin new file mode 100755 index 000000000..e69de29bb diff --git a/tests/xtvm_test/test_cases/QA_CASES/new_swap/ERC20.sol b/tests/xtvm_test/test_cases/QA_CASES/new_swap/ERC20.sol new file mode 100755 index 000000000..18e8d4fc5 --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/new_swap/ERC20.sol @@ -0,0 +1,303 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.0; + +import "./IERC20.sol"; +import "./Context.sol"; + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin guidelines: functions revert instead + * of returning `false` on failure. This behavior is nonetheless conventional + * and does not conflict with the expectations of ERC20 applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20 is Context, IERC20 { + mapping (address => uint256) private _balances; + + mapping (address => mapping (address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + + /** + * @dev Sets the values for {name} and {symbol}. + * + * The defaut value of {decimals} is 18. To select a different value for + * {decimals} you should overload it. + * + * All three of these values are immutable: they can only be set once during + * construction. + */ + constructor (string memory name_, string memory symbol_) { + _name = name_; + _symbol = symbol_; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view virtual returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view virtual returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5,05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless this function is + * overloaded; + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view virtual returns (uint8) { + return 18; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view virtual override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view virtual override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + + uint256 currentAllowance = _allowances[sender][_msgSender()]; + require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); + _approve(sender, _msgSender(), currentAllowance - amount); + + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + uint256 currentAllowance = _allowances[_msgSender()][spender]; + require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); + _approve(_msgSender(), spender, currentAllowance - subtractedValue); + + return true; + } + + /** + * @dev Moves tokens `amount` from `sender` to `recipient`. + * + * This is internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer(address sender, address recipient, uint256 amount) internal virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + uint256 senderBalance = _balances[sender]; + require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); + _balances[sender] = senderBalance - amount; + _balances[recipient] += amount; + + emit Transfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `to` cannot be the zero address. + */ + function _mint(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply += amount; + _balances[account] += amount; + emit Transfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) internal virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + uint256 accountBalance = _balances[account]; + require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); + _balances[account] = accountBalance - amount; + _totalSupply -= amount; + + emit Transfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve(address owner, address spender, uint256 amount) internal virtual { + require(owner != address(0), "ERC20: approve from the zero address"); + require(spender != address(0), "ERC20: approve to the zero address"); + + _allowances[owner][spender] = amount; + emit Approval(owner, spender, amount); + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be to transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } +} \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/new_swap/ERC20_sol_ERC20.abi b/tests/xtvm_test/test_cases/QA_CASES/new_swap/ERC20_sol_ERC20.abi new file mode 100755 index 000000000..ca85fff49 --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/new_swap/ERC20_sol_ERC20.abi @@ -0,0 +1 @@ +[{"inputs":[{"internalType":"string","name":"name_","type":"string"},{"internalType":"string","name":"symbol_","type":"string"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}] \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/new_swap/ERC20_sol_ERC20.bin b/tests/xtvm_test/test_cases/QA_CASES/new_swap/ERC20_sol_ERC20.bin new file mode 100755 index 000000000..df8036e51 --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/new_swap/ERC20_sol_ERC20.bin @@ -0,0 +1 @@ +60806040523480156200001157600080fd5b506040516200179b3803806200179b8339818101604052810190620000379190620002be565b81600390805190602001906200004f92919062000071565b5080600490805190602001906200006892919062000071565b505050620003a7565b8280546200007f9062000372565b90600052602060002090601f016020900481019282620000a35760008555620000ef565b82601f10620000be57805160ff1916838001178555620000ef565b82800160010185558215620000ef579182015b82811115620000ee578251825591602001919060010190620000d1565b5b509050620000fe919062000102565b5090565b5b808211156200011d57600081600090555060010162000103565b5090565b6000604051905090565b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6200018a826200013f565b810181811067ffffffffffffffff82111715620001ac57620001ab62000150565b5b80604052505050565b6000620001c162000121565b9050620001cf82826200017f565b919050565b600067ffffffffffffffff821115620001f257620001f162000150565b5b620001fd826200013f565b9050602081019050919050565b60005b838110156200022a5780820151818401526020810190506200020d565b838111156200023a576000848401525b50505050565b6000620002576200025184620001d4565b620001b5565b9050828152602081018484840111156200027657620002756200013a565b5b620002838482856200020a565b509392505050565b600082601f830112620002a357620002a262000135565b5b8151620002b584826020860162000240565b91505092915050565b60008060408385031215620002d857620002d76200012b565b5b600083015167ffffffffffffffff811115620002f957620002f862000130565b5b62000307858286016200028b565b925050602083015167ffffffffffffffff8111156200032b576200032a62000130565b5b62000339858286016200028b565b9150509250929050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b600060028204905060018216806200038b57607f821691505b602082108103620003a157620003a062000343565b5b50919050565b6113e480620003b76000396000f3fe608060405234801561001057600080fd5b50600436106100a95760003560e01c80633950935111610071578063395093511461016857806370a082311461019857806395d89b41146101c8578063a457c2d7146101e6578063a9059cbb14610216578063dd62ed3e14610246576100a9565b806306fdde03146100ae578063095ea7b3146100cc57806318160ddd146100fc57806323b872dd1461011a578063313ce5671461014a575b600080fd5b6100b6610276565b6040516100c39190610c45565b60405180910390f35b6100e660048036038101906100e19190610d00565b610308565b6040516100f39190610d5b565b60405180910390f35b610104610326565b6040516101119190610d85565b60405180910390f35b610134600480360381019061012f9190610da0565b610330565b6040516101419190610d5b565b60405180910390f35b610152610431565b60405161015f9190610e0f565b60405180910390f35b610182600480360381019061017d9190610d00565b61043a565b60405161018f9190610d5b565b60405180910390f35b6101b260048036038101906101ad9190610e2a565b6104e6565b6040516101bf9190610d85565b60405180910390f35b6101d061052e565b6040516101dd9190610c45565b60405180910390f35b61020060048036038101906101fb9190610d00565b6105c0565b60405161020d9190610d5b565b60405180910390f35b610230600480360381019061022b9190610d00565b6106b4565b60405161023d9190610d5b565b60405180910390f35b610260600480360381019061025b9190610e57565b6106d2565b60405161026d9190610d85565b60405180910390f35b60606003805461028590610ec6565b80601f01602080910402602001604051908101604052809291908181526020018280546102b190610ec6565b80156102fe5780601f106102d3576101008083540402835291602001916102fe565b820191906000526020600020905b8154815290600101906020018083116102e157829003601f168201915b5050505050905090565b600061031c610315610759565b8484610761565b6001905092915050565b6000600254905090565b600061033d84848461092a565b6000600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000610388610759565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905082811015610408576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103ff90610f69565b60405180910390fd5b61042585610414610759565b85846104209190610fb8565b610761565b60019150509392505050565b60006012905090565b60006104dc610447610759565b848460016000610455610759565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546104d79190610fec565b610761565b6001905092915050565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b60606004805461053d90610ec6565b80601f016020809104026020016040519081016040528092919081815260200182805461056990610ec6565b80156105b65780601f1061058b576101008083540402835291602001916105b6565b820191906000526020600020905b81548152906001019060200180831161059957829003601f168201915b5050505050905090565b600080600160006105cf610759565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205490508281101561068c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610683906110b4565b60405180910390fd5b6106a9610697610759565b8585846106a49190610fb8565b610761565b600191505092915050565b60006106c86106c1610759565b848461092a565b6001905092915050565b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16036107d0576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016107c790611146565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff160361083f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610836906111d8565b60405180910390fd5b80600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9258360405161091d9190610d85565b60405180910390a3505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1603610999576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109909061126a565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1603610a08576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109ff906112fc565b60405180910390fd5b610a13838383610ba7565b60008060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905081811015610a99576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a909061138e565b60405180910390fd5b8181610aa59190610fb8565b6000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254610b359190610fec565b925050819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef84604051610b999190610d85565b60405180910390a350505050565b505050565b600081519050919050565b600082825260208201905092915050565b60005b83811015610be6578082015181840152602081019050610bcb565b83811115610bf5576000848401525b50505050565b6000601f19601f8301169050919050565b6000610c1782610bac565b610c218185610bb7565b9350610c31818560208601610bc8565b610c3a81610bfb565b840191505092915050565b60006020820190508181036000830152610c5f8184610c0c565b905092915050565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000610c9782610c6c565b9050919050565b610ca781610c8c565b8114610cb257600080fd5b50565b600081359050610cc481610c9e565b92915050565b6000819050919050565b610cdd81610cca565b8114610ce857600080fd5b50565b600081359050610cfa81610cd4565b92915050565b60008060408385031215610d1757610d16610c67565b5b6000610d2585828601610cb5565b9250506020610d3685828601610ceb565b9150509250929050565b60008115159050919050565b610d5581610d40565b82525050565b6000602082019050610d706000830184610d4c565b92915050565b610d7f81610cca565b82525050565b6000602082019050610d9a6000830184610d76565b92915050565b600080600060608486031215610db957610db8610c67565b5b6000610dc786828701610cb5565b9350506020610dd886828701610cb5565b9250506040610de986828701610ceb565b9150509250925092565b600060ff82169050919050565b610e0981610df3565b82525050565b6000602082019050610e246000830184610e00565b92915050565b600060208284031215610e4057610e3f610c67565b5b6000610e4e84828501610cb5565b91505092915050565b60008060408385031215610e6e57610e6d610c67565b5b6000610e7c85828601610cb5565b9250506020610e8d85828601610cb5565b9150509250929050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b60006002820490506001821680610ede57607f821691505b602082108103610ef157610ef0610e97565b5b50919050565b7f45524332303a207472616e7366657220616d6f756e742065786365656473206160008201527f6c6c6f77616e6365000000000000000000000000000000000000000000000000602082015250565b6000610f53602883610bb7565b9150610f5e82610ef7565b604082019050919050565b60006020820190508181036000830152610f8281610f46565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000610fc382610cca565b9150610fce83610cca565b925082821015610fe157610fe0610f89565b5b828203905092915050565b6000610ff782610cca565b915061100283610cca565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0382111561103757611036610f89565b5b828201905092915050565b7f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f7760008201527f207a65726f000000000000000000000000000000000000000000000000000000602082015250565b600061109e602583610bb7565b91506110a982611042565b604082019050919050565b600060208201905081810360008301526110cd81611091565b9050919050565b7f45524332303a20617070726f76652066726f6d20746865207a65726f2061646460008201527f7265737300000000000000000000000000000000000000000000000000000000602082015250565b6000611130602483610bb7565b915061113b826110d4565b604082019050919050565b6000602082019050818103600083015261115f81611123565b9050919050565b7f45524332303a20617070726f766520746f20746865207a65726f20616464726560008201527f7373000000000000000000000000000000000000000000000000000000000000602082015250565b60006111c2602283610bb7565b91506111cd82611166565b604082019050919050565b600060208201905081810360008301526111f1816111b5565b9050919050565b7f45524332303a207472616e736665722066726f6d20746865207a65726f20616460008201527f6472657373000000000000000000000000000000000000000000000000000000602082015250565b6000611254602583610bb7565b915061125f826111f8565b604082019050919050565b6000602082019050818103600083015261128381611247565b9050919050565b7f45524332303a207472616e7366657220746f20746865207a65726f206164647260008201527f6573730000000000000000000000000000000000000000000000000000000000602082015250565b60006112e6602383610bb7565b91506112f18261128a565b604082019050919050565b60006020820190508181036000830152611315816112d9565b9050919050565b7f45524332303a207472616e7366657220616d6f756e742065786365656473206260008201527f616c616e63650000000000000000000000000000000000000000000000000000602082015250565b6000611378602683610bb7565b91506113838261131c565b604082019050919050565b600060208201905081810360008301526113a78161136b565b905091905056fea2646970667358221220e707d87713f47c715f299fcab72458a615eb2232b00b65dabc85e289b00fde9464736f6c634300080d0033 \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/new_swap/IERC20.sol b/tests/xtvm_test/test_cases/QA_CASES/new_swap/IERC20.sol new file mode 100755 index 000000000..b4127d6b5 --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/new_swap/IERC20.sol @@ -0,0 +1,77 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.0; + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20 { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/new_swap/IERC20_sol_IERC20.abi b/tests/xtvm_test/test_cases/QA_CASES/new_swap/IERC20_sol_IERC20.abi new file mode 100755 index 000000000..38876a993 --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/new_swap/IERC20_sol_IERC20.abi @@ -0,0 +1 @@ +[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}] \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/new_swap/IERC20_sol_IERC20.bin b/tests/xtvm_test/test_cases/QA_CASES/new_swap/IERC20_sol_IERC20.bin new file mode 100755 index 000000000..e69de29bb diff --git a/tests/xtvm_test/test_cases/QA_CASES/new_swap/swap.json_not_fixed b/tests/xtvm_test/test_cases/QA_CASES/new_swap/swap.json_not_fixed new file mode 100755 index 000000000..2b747f81c --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/new_swap/swap.json_not_fixed @@ -0,0 +1,267 @@ +{ + "pre_data": {}, + "deploy_contract": [ + { + "__comments":"部署合约1 goden币", + "src_address": "T600045B38Da6a701c568545dCfcB03FcB875f56beddC4", + "code_file_path": "swap_sol_golden.bin", + "gas_limit": 8765850, + "value": "0", + "expected": { + "status": 0, + "__address_in_evm": "d9145cce52d386f254917e481eb44e9943f39138", + "__address_in_top_shard": "3f18a128c9def31bc1ca5b3a109e54304301182c", + "extra_message": "contract_one", + "gas_used": 1255197, + "logs": [ + { + "address": "contract_one", + "topics": [ + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "0x0000000000000000000000000000000000000000000000000000000000000000", + "0x0000000000000000000000005b38da6a701c568545dcfcb03fcb875f56beddc4" + ], + "data": "0x0000000000000000000000000000000000000000000000056bc75e2d63100000" + } + + ] + } + }, + { + "__comments":"部署合约2 moyed币", + "src_address": "T60004Ab8483F64d9C6d1EcF9b849Ae677dD3315835cb2", + "code_file_path": "swap_sol_moyed.bin", + "gas_limit": 876549000, + "value": "0", + "expected": { + "status": 0, + "__address_in_evm": "a131ad247055fd2e2aa8b156a11bdec81b9ead95", + "__address_in_top_shard": "1607d24db842dcf6259a06561be353513db4ce7d", + "extra_message": "contract_two", + "gas_used": 1255185, + "logs": [ + { + "address": "contract_two", + "topics": [ + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "0x0000000000000000000000000000000000000000000000000000000000000000", + "0x000000000000000000000000ab8483f64d9c6d1ecf9b849ae677dd3315835cb2"], + "data": "0x0000000000000000000000000000000000000000000000056bc75e2d63100000" + } + + ] + } + }, + { + "__comments":"部署合约3 swap", + "src_address": "T600044B20993Bc481177ec7E8f571ceCaE8A9e22C02db", + "code_file_path": "swap_sol_TokenSwap.bin", + "gas_limit": 876549000, + "value": "0", + "expected": { + "status": 0, + "__address_in_evm": "9ecea68de55f316b702f27ee389d10c2ee0dde84", + "__address_in_top_shard": "62af2bc91b7f29a6f2546a32aede4a33eaa8a8a0", + "extra_message": "contract_three", + "gas_used": 796799, + "logs": [] + } + } + ], + "test_cases": [ + { + "__comments":"合约1 给swap合约转账 transfer(0x62af2bc91b7f29a6f2546a32aede4a33eaa8a8a0,10000)", + "src_address": "T600045B38Da6a701c568545dCfcB03FcB875f56beddC4", + "target_address": "contract_one", + "data": "0xa9059cbb00000000000000000000000062af2bc91b7f29a6f2546a32aede4a33eaa8a8a00000000000000000000000000000000000000000000000000000000000002710", + "gas_limit": 342250, + "value": "0", + "expected": { + "status": 0, + "extra_message": "", + "gas_used": 52469, + "logs": [ + { + "address": "contract_one", + "topics": [ + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "0x0000000000000000000000005b38da6a701c568545dcfcb03fcb875f56beddc4", + "0x00000000000000000000000062af2bc91b7f29a6f2546a32aede4a33eaa8a8a0"], + "data": "0x0000000000000000000000000000000000000000000000000000000000002710" + } + ] + } + }, + { + "__comments":"合约1 查看金额swap合约0x62af2bc91b7f29a6f2546a32aede4a33eaa8a8a0,10000", + "src_address": "T600045B38Da6a701c568545dCfcB03FcB875f56beddC4", + "target_address": "contract_one", + "data": "0x70a0823100000000000000000000000062af2bc91b7f29a6f2546a32aede4a33eaa8a8a0", + "gas_limit": 342250, + "value": "0", + "expected": { + "status": 0, + "extra_message": "0x0000000000000000000000000000000000000000000000000000000000002710", + "gas_used": 24295 , + "logs": [] + } + }, + { + "__comments":"合约1 approve Ab8483F64d9C6d1EcF9b849Ae677dD3315835cb2 100000", + "src_address": "T600045B38Da6a701c568545dCfcB03FcB875f56beddC4", + "target_address": "contract_one", + "data": "0x095ea7b3000000000000000000000000ab8483f64d9c6d1ecf9b849ae677dd3315835cb200000000000000000000000000000000000000000000000000000000000186a0", + "gas_limit": 46839 , + "value": "0", + "expected": { + "status": 0, + "extra_message": "", + "gas_used": 46839 , + "logs": [ + { + "address": "contract_one", + "topics": [ + "0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925", + "0x0000000000000000000000005b38da6a701c568545dcfcb03fcb875f56beddc4", + "0x000000000000000000000000ab8483f64d9c6d1ecf9b849ae677dd3315835cb2"], + "data": "0x00000000000000000000000000000000000000000000000000000000000186a0" + } + ] + } + }, + { + "__comments":"合约1 查看allowance(0x5B38Da6a701c568545dCfcB03FcB875f56beddC4->0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2)生效,10000", + "src_address": "T600045B38Da6a701c568545dCfcB03FcB875f56beddC4", + "target_address": "contract_one", + "data": "0xdd62ed3e0000000000000000000000005b38da6a701c568545dcfcb03fcb875f56beddc4000000000000000000000000ab8483f64d9c6d1ecf9b849ae677dd3315835cb2", + "gas_limit": 25063 , + "value": "0", + "expected": { + "status": 0, + "extra_message": "0x00000000000000000000000000000000000000000000000000000000000186a0", + "gas_used": 25063 , + "logs": [] + } + }, + { + "__comments":"合约2 transfer(0x62af2bc91b7f29a6f2546a32aede4a33eaa8a8a0,10000)", + "src_address": "T60004Ab8483F64d9C6d1EcF9b849Ae677dD3315835cb2", + "target_address": "contract_two", + "data": "0xa9059cbb00000000000000000000000062af2bc91b7f29a6f2546a32aede4a33eaa8a8a00000000000000000000000000000000000000000000000000000000000002710", + "gas_limit": 342250, + "value": "0", + "expected": { + "status": 0, + "extra_message": "", + "gas_used": 52469, + "logs": [ + { + "address": "contract_two", + "topics": [ + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "0x000000000000000000000000ab8483f64d9c6d1ecf9b849ae677dd3315835cb2", + "0x00000000000000000000000062af2bc91b7f29a6f2546a32aede4a33eaa8a8a0" + ], + "data": "0x0000000000000000000000000000000000000000000000000000000000002710" + } + ] + } + }, + { + "__comments":"合约2 approve(5B38Da6a701c568545dCfcB03FcB875f56beddC4, 100000)", + "src_address": "T60004Ab8483F64d9C6d1EcF9b849Ae677dD3315835cb2", + "target_address": "contract_two", + "data": "0x095ea7b30000000000000000000000005b38da6a701c568545dcfcb03fcb875f56beddc400000000000000000000000000000000000000000000000000000000000186a0", + "gas_limit": 342250, + "value": "0", + "expected": { + "status": 0, + "extra_message": "", + "gas_used": 46839 , + "logs": [ + { + "address": "contract_two", + "topics": [ + "0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925", + "0x000000000000000000000000ab8483f64d9c6d1ecf9b849ae677dd3315835cb2", + "0x0000000000000000000000005b38da6a701c568545dcfcb03fcb875f56beddc4" ], + "data": "0x00000000000000000000000000000000000000000000000000000000000186a0" + } + ] + } + }, + { + "__comments":"合约2 查看allowance(0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2->0x5B38Da6a701c568545dCfcB03FcB875f56beddC4)生效,10000", + "src_address": "T60004Ab8483F64d9C6d1EcF9b849Ae677dD3315835cb2", + "target_address": "contract_two", + "data": "0xdd62ed3e000000000000000000000000ab8483f64d9c6d1ecf9b849ae677dd3315835cb20000000000000000000000005b38da6a701c568545dcfcb03fcb875f56beddc4", + "gas_limit": 25063 , + "value": "0", + "expected": { + "status": 0, + "extra_message": "0x00000000000000000000000000000000000000000000000000000000000186a0", + "gas_used": 25063 , + "logs": [] + } + }, + { + "__comments":"执行swap, 合约1 10个换 合约2 20个", + "src_address": "T600045B38Da6a701c568545dCfcB03FcB875f56beddC4", + "target_address": "contract_three", + "data": "0x8119c065", + "gas_limit": 3422500, + "value": "0", + "expected": { + "status": 0, + "extra_message": "", + "gas_used": 112244, + "logs": [ + { + "address": "contract_one", + "topics": [ + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "0x00000000000000000000000062af2bc91b7f29a6f2546a32aede4a33eaa8a8a0", + "0x000000000000000000000000ab8483f64d9c6d1ecf9b849ae677dd3315835cb2" ], + "data": "0x000000000000000000000000000000000000000000000000000000000000000a" + }, + { + "address": "contract_two", + "topics": [ + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "0x00000000000000000000000062af2bc91b7f29a6f2546a32aede4a33eaa8a8a0", + "0x0000000000000000000000005b38da6a701c568545dcfcb03fcb875f56beddc4"], + "data": "0x0000000000000000000000000000000000000000000000000000000000000014" + } + ] + } + }, + { + "__comments":"合约2查看swap地址0x62af2bc91b7f29a6f2546a32aede4a33eaa8a8a0,1000减少10,变成990", + "src_address": "T60004Ab8483F64d9C6d1EcF9b849Ae677dD3315835cb2", + "target_address": "contract_two", + "data": "0x70a0823100000000000000000000000062af2bc91b7f29a6f2546a32aede4a33eaa8a8a0", + "gas_limit": 24295 , + "value": "0", + "expected": { + "status": 0, + "extra_message": "0x00000000000000000000000000000000000000000000000000000000000026fc", + "gas_used": 24295 , + "logs": [] + } + }, + { + "__comments":"合约1查看swap地址0x62af2bc91b7f29a6f2546a32aede4a33eaa8a8a0,1000加10,变成1010", + "src_address": "T600045B38Da6a701c568545dCfcB03FcB875f56beddC4", + "target_address": "contract_one", + "data": "0x70a0823100000000000000000000000062af2bc91b7f29a6f2546a32aede4a33eaa8a8a0", + "gas_limit": 24295 , + "value": "0", + "expected": { + "status": 0, + "extra_message": "0x0000000000000000000000000000000000000000000000000000000000002706", + "gas_used": 24295 , + "logs": [] + } + } + ] +} \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/new_swap/swap.sol b/tests/xtvm_test/test_cases/QA_CASES/new_swap/swap.sol new file mode 100755 index 000000000..8a98ab08f --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/new_swap/swap.sol @@ -0,0 +1,79 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.10; + +import "./IERC20.sol"; +import "./ERC20.sol"; + +/* +How to swap tokens + +1. Alice has 100 tokens from AliceCoin, which is a ERC20 token. +2. Bob has 100 tokens from BobCoin, which is also a ERC20 token. +3. Alice and Bob wants to trade 10 AliceCoin for 20 BobCoin. +4. Alice or Bob deploys TokenSwap +5. Alice appproves TokenSwap to withdraw 10 tokens from AliceCoin +6. Bob appproves TokenSwap to withdraw 20 tokens from BobCoin +7. Alice or Bob calls TokenSwap.swap() +8. Alice and Bob traded tokens successfully. +*/ +contract moyed is ERC20 { + constructor() ERC20("MOYED", "MYD") { + _mint(msg.sender, 100 * 10**18); + } +} + +contract golden is ERC20 { + constructor() ERC20("GOLDEN", "GLD") { + _mint(msg.sender, 100 * 10**18); + } +} + +contract TokenSwap { + IERC20 public token1; + address public owner1; + uint public amount1; + IERC20 public token2; + address public owner2; + uint public amount2; + + constructor( + address _token1, + address _owner1, + uint _amount1, + address _token2, + address _owner2, + uint _amount2 + ) { + token1 = IERC20(_token1); + owner1 = _owner1; + amount1 = _amount1; + token2 = IERC20(_token2); + owner2 = _owner2; + amount2 = _amount2; + } + + function swap() public { + require(msg.sender == owner1 || msg.sender == owner2, "Not authorized"); + require( + token1.allowance(owner1, owner2) >= amount1, + "Token 1 allowance too low" + ); + require( + token2.allowance(owner2, owner1) >= amount2, + "Token 2 allowance too low" + ); + + _safeTransferFrom(token1, owner1, owner2, amount1); + _safeTransferFrom(token2, owner2, owner1, amount2); + } + + function _safeTransferFrom( + IERC20 token, + address sender, + address recipient, + uint amount + ) private { + bool sent = token.transfer(recipient, amount); + require(sent, "Token transfer failed"); + } +} \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/new_swap/swap_sol_TokenSwap.abi b/tests/xtvm_test/test_cases/QA_CASES/new_swap/swap_sol_TokenSwap.abi new file mode 100755 index 000000000..f24464b42 --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/new_swap/swap_sol_TokenSwap.abi @@ -0,0 +1 @@ +[{"inputs":[{"internalType":"address","name":"_token1","type":"address"},{"internalType":"address","name":"_owner1","type":"address"},{"internalType":"uint256","name":"_amount1","type":"uint256"},{"internalType":"address","name":"_token2","type":"address"},{"internalType":"address","name":"_owner2","type":"address"},{"internalType":"uint256","name":"_amount2","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"amount1","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"amount2","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner1","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner2","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"swap","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"token1","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"token2","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"}] \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/new_swap/swap_sol_TokenSwap.bin b/tests/xtvm_test/test_cases/QA_CASES/new_swap/swap_sol_TokenSwap.bin new file mode 100755 index 000000000..6740723bf --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/new_swap/swap_sol_TokenSwap.bin @@ -0,0 +1 @@ +0x60806040523480156200001157600080fd5b5060405162000d8038038062000d808339818101604052810190620000379190620001f9565b856000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555084600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508360028190555082600360006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555081600460006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508060058190555050505050505062000295565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000620001868262000159565b9050919050565b620001988162000179565b8114620001a457600080fd5b50565b600081519050620001b8816200018d565b92915050565b6000819050919050565b620001d381620001be565b8114620001df57600080fd5b50565b600081519050620001f381620001c8565b92915050565b60008060008060008060c0878903121562000219576200021862000154565b5b60006200022989828a01620001a7565b96505060206200023c89828a01620001a7565b95505060406200024f89828a01620001e2565b94505060606200026289828a01620001a7565b93505060806200027589828a01620001a7565b92505060a06200028889828a01620001e2565b9150509295509295509295565b610adb80620002a56000396000f3fe608060405234801561001057600080fd5b506004361061007d5760003560e01c8063736889141161005b57806373688914146100dc5780638119c065146100fa578063d21220a714610104578063f400fde4146101225761007d565b8063057bfcc71461008257806325be124e146100a057806352709725146100be575b600080fd5b61008a610140565b60405161009791906106de565b60405180910390f35b6100a8610146565b6040516100b59190610778565b60405180910390f35b6100c661016c565b6040516100d391906107b4565b60405180910390f35b6100e4610192565b6040516100f191906107b4565b60405180910390f35b6101026101b8565b005b61010c6105d2565b6040516101199190610778565b60405180910390f35b61012a6105f6565b60405161013791906106de565b60405180910390f35b60055481565b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614806102615750600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16145b6102a0576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016102979061082c565b60405180910390fd5b60025460008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663dd62ed3e600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166040518363ffffffff1660e01b815260040161034292919061084c565b602060405180830381865afa15801561035f573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061038391906108a6565b10156103c4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103bb9061091f565b60405180910390fd5b600554600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663dd62ed3e600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166040518363ffffffff1660e01b815260040161046892919061084c565b602060405180830381865afa158015610485573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104a991906108a6565b10156104ea576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016104e19061098b565b60405180910390fd5b61055c60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff16600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166002546105fc565b6105d0600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166005546105fc565b565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60025481565b60008473ffffffffffffffffffffffffffffffffffffffff1663a9059cbb84846040518363ffffffff1660e01b81526004016106399291906109ab565b6020604051808303816000875af1158015610658573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061067c9190610a0c565b9050806106be576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016106b590610a85565b60405180910390fd5b5050505050565b6000819050919050565b6106d8816106c5565b82525050565b60006020820190506106f360008301846106cf565b92915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b600061073e610739610734846106f9565b610719565b6106f9565b9050919050565b600061075082610723565b9050919050565b600061076282610745565b9050919050565b61077281610757565b82525050565b600060208201905061078d6000830184610769565b92915050565b600061079e826106f9565b9050919050565b6107ae81610793565b82525050565b60006020820190506107c960008301846107a5565b92915050565b600082825260208201905092915050565b7f4e6f7420617574686f72697a6564000000000000000000000000000000000000600082015250565b6000610816600e836107cf565b9150610821826107e0565b602082019050919050565b6000602082019050818103600083015261084581610809565b9050919050565b600060408201905061086160008301856107a5565b61086e60208301846107a5565b9392505050565b600080fd5b610883816106c5565b811461088e57600080fd5b50565b6000815190506108a08161087a565b92915050565b6000602082840312156108bc576108bb610875565b5b60006108ca84828501610891565b91505092915050565b7f546f6b656e203120616c6c6f77616e636520746f6f206c6f7700000000000000600082015250565b60006109096019836107cf565b9150610914826108d3565b602082019050919050565b60006020820190508181036000830152610938816108fc565b9050919050565b7f546f6b656e203220616c6c6f77616e636520746f6f206c6f7700000000000000600082015250565b60006109756019836107cf565b91506109808261093f565b602082019050919050565b600060208201905081810360008301526109a481610968565b9050919050565b60006040820190506109c060008301856107a5565b6109cd60208301846106cf565b9392505050565b60008115159050919050565b6109e9816109d4565b81146109f457600080fd5b50565b600081519050610a06816109e0565b92915050565b600060208284031215610a2257610a21610875565b5b6000610a30848285016109f7565b91505092915050565b7f546f6b656e207472616e73666572206661696c65640000000000000000000000600082015250565b6000610a6f6015836107cf565b9150610a7a82610a39565b602082019050919050565b60006020820190508181036000830152610a9e81610a62565b905091905056fea2646970667358221220627f0d2cfa06b87b749a589e1901b2654d2f97f323961413b9309d8f8f9170d064736f6c634300080d00330000000000000000000000003f18a128c9def31bc1ca5b3a109e54304301182c0000000000000000000000005b38da6a701c568545dcfcb03fcb875f56beddc4000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000001607d24db842dcf6259a06561be353513db4ce7d000000000000000000000000ab8483f64d9c6d1ecf9b849ae677dd3315835cb20000000000000000000000000000000000000000000000000000000000000014 \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/new_swap/swap_sol_golden.abi b/tests/xtvm_test/test_cases/QA_CASES/new_swap/swap_sol_golden.abi new file mode 100755 index 000000000..b15982af1 --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/new_swap/swap_sol_golden.abi @@ -0,0 +1 @@ +[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}] \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/new_swap/swap_sol_golden.bin b/tests/xtvm_test/test_cases/QA_CASES/new_swap/swap_sol_golden.bin new file mode 100755 index 000000000..e51bc106d --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/new_swap/swap_sol_golden.bin @@ -0,0 +1 @@ +0x60806040523480156200001157600080fd5b506040518060400160405280600681526020017f474f4c44454e00000000000000000000000000000000000000000000000000008152506040518060400160405280600381526020017f474c4400000000000000000000000000000000000000000000000000000000008152508160039080519060200190620000969291906200023c565b508060049080519060200190620000af9291906200023c565b505050620000cd3368056bc75e2d63100000620000d360201b60201c565b62000497565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff160362000145576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016200013c906200034d565b60405180910390fd5b62000159600083836200023760201b60201c565b80600260008282546200016d9190620003a8565b92505081905550806000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254620001c49190620003a8565b925050819055508173ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040516200022b919062000416565b60405180910390a35050565b505050565b8280546200024a9062000462565b90600052602060002090601f0160209004810192826200026e5760008555620002ba565b82601f106200028957805160ff1916838001178555620002ba565b82800160010185558215620002ba579182015b82811115620002b95782518255916020019190600101906200029c565b5b509050620002c99190620002cd565b5090565b5b80821115620002e8576000816000905550600101620002ce565b5090565b600082825260208201905092915050565b7f45524332303a206d696e7420746f20746865207a65726f206164647265737300600082015250565b600062000335601f83620002ec565b91506200034282620002fd565b602082019050919050565b60006020820190508181036000830152620003688162000326565b9050919050565b6000819050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000620003b5826200036f565b9150620003c2836200036f565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff03821115620003fa57620003f962000379565b5b828201905092915050565b62000410816200036f565b82525050565b60006020820190506200042d600083018462000405565b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b600060028204905060018216806200047b57607f821691505b60208210810362000491576200049062000433565b5b50919050565b6113e480620004a76000396000f3fe608060405234801561001057600080fd5b50600436106100a95760003560e01c80633950935111610071578063395093511461016857806370a082311461019857806395d89b41146101c8578063a457c2d7146101e6578063a9059cbb14610216578063dd62ed3e14610246576100a9565b806306fdde03146100ae578063095ea7b3146100cc57806318160ddd146100fc57806323b872dd1461011a578063313ce5671461014a575b600080fd5b6100b6610276565b6040516100c39190610c45565b60405180910390f35b6100e660048036038101906100e19190610d00565b610308565b6040516100f39190610d5b565b60405180910390f35b610104610326565b6040516101119190610d85565b60405180910390f35b610134600480360381019061012f9190610da0565b610330565b6040516101419190610d5b565b60405180910390f35b610152610431565b60405161015f9190610e0f565b60405180910390f35b610182600480360381019061017d9190610d00565b61043a565b60405161018f9190610d5b565b60405180910390f35b6101b260048036038101906101ad9190610e2a565b6104e6565b6040516101bf9190610d85565b60405180910390f35b6101d061052e565b6040516101dd9190610c45565b60405180910390f35b61020060048036038101906101fb9190610d00565b6105c0565b60405161020d9190610d5b565b60405180910390f35b610230600480360381019061022b9190610d00565b6106b4565b60405161023d9190610d5b565b60405180910390f35b610260600480360381019061025b9190610e57565b6106d2565b60405161026d9190610d85565b60405180910390f35b60606003805461028590610ec6565b80601f01602080910402602001604051908101604052809291908181526020018280546102b190610ec6565b80156102fe5780601f106102d3576101008083540402835291602001916102fe565b820191906000526020600020905b8154815290600101906020018083116102e157829003601f168201915b5050505050905090565b600061031c610315610759565b8484610761565b6001905092915050565b6000600254905090565b600061033d84848461092a565b6000600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000610388610759565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905082811015610408576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103ff90610f69565b60405180910390fd5b61042585610414610759565b85846104209190610fb8565b610761565b60019150509392505050565b60006012905090565b60006104dc610447610759565b848460016000610455610759565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546104d79190610fec565b610761565b6001905092915050565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b60606004805461053d90610ec6565b80601f016020809104026020016040519081016040528092919081815260200182805461056990610ec6565b80156105b65780601f1061058b576101008083540402835291602001916105b6565b820191906000526020600020905b81548152906001019060200180831161059957829003601f168201915b5050505050905090565b600080600160006105cf610759565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205490508281101561068c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610683906110b4565b60405180910390fd5b6106a9610697610759565b8585846106a49190610fb8565b610761565b600191505092915050565b60006106c86106c1610759565b848461092a565b6001905092915050565b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16036107d0576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016107c790611146565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff160361083f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610836906111d8565b60405180910390fd5b80600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9258360405161091d9190610d85565b60405180910390a3505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1603610999576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109909061126a565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1603610a08576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109ff906112fc565b60405180910390fd5b610a13838383610ba7565b60008060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905081811015610a99576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a909061138e565b60405180910390fd5b8181610aa59190610fb8565b6000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254610b359190610fec565b925050819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef84604051610b999190610d85565b60405180910390a350505050565b505050565b600081519050919050565b600082825260208201905092915050565b60005b83811015610be6578082015181840152602081019050610bcb565b83811115610bf5576000848401525b50505050565b6000601f19601f8301169050919050565b6000610c1782610bac565b610c218185610bb7565b9350610c31818560208601610bc8565b610c3a81610bfb565b840191505092915050565b60006020820190508181036000830152610c5f8184610c0c565b905092915050565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000610c9782610c6c565b9050919050565b610ca781610c8c565b8114610cb257600080fd5b50565b600081359050610cc481610c9e565b92915050565b6000819050919050565b610cdd81610cca565b8114610ce857600080fd5b50565b600081359050610cfa81610cd4565b92915050565b60008060408385031215610d1757610d16610c67565b5b6000610d2585828601610cb5565b9250506020610d3685828601610ceb565b9150509250929050565b60008115159050919050565b610d5581610d40565b82525050565b6000602082019050610d706000830184610d4c565b92915050565b610d7f81610cca565b82525050565b6000602082019050610d9a6000830184610d76565b92915050565b600080600060608486031215610db957610db8610c67565b5b6000610dc786828701610cb5565b9350506020610dd886828701610cb5565b9250506040610de986828701610ceb565b9150509250925092565b600060ff82169050919050565b610e0981610df3565b82525050565b6000602082019050610e246000830184610e00565b92915050565b600060208284031215610e4057610e3f610c67565b5b6000610e4e84828501610cb5565b91505092915050565b60008060408385031215610e6e57610e6d610c67565b5b6000610e7c85828601610cb5565b9250506020610e8d85828601610cb5565b9150509250929050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b60006002820490506001821680610ede57607f821691505b602082108103610ef157610ef0610e97565b5b50919050565b7f45524332303a207472616e7366657220616d6f756e742065786365656473206160008201527f6c6c6f77616e6365000000000000000000000000000000000000000000000000602082015250565b6000610f53602883610bb7565b9150610f5e82610ef7565b604082019050919050565b60006020820190508181036000830152610f8281610f46565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000610fc382610cca565b9150610fce83610cca565b925082821015610fe157610fe0610f89565b5b828203905092915050565b6000610ff782610cca565b915061100283610cca565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0382111561103757611036610f89565b5b828201905092915050565b7f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f7760008201527f207a65726f000000000000000000000000000000000000000000000000000000602082015250565b600061109e602583610bb7565b91506110a982611042565b604082019050919050565b600060208201905081810360008301526110cd81611091565b9050919050565b7f45524332303a20617070726f76652066726f6d20746865207a65726f2061646460008201527f7265737300000000000000000000000000000000000000000000000000000000602082015250565b6000611130602483610bb7565b915061113b826110d4565b604082019050919050565b6000602082019050818103600083015261115f81611123565b9050919050565b7f45524332303a20617070726f766520746f20746865207a65726f20616464726560008201527f7373000000000000000000000000000000000000000000000000000000000000602082015250565b60006111c2602283610bb7565b91506111cd82611166565b604082019050919050565b600060208201905081810360008301526111f1816111b5565b9050919050565b7f45524332303a207472616e736665722066726f6d20746865207a65726f20616460008201527f6472657373000000000000000000000000000000000000000000000000000000602082015250565b6000611254602583610bb7565b915061125f826111f8565b604082019050919050565b6000602082019050818103600083015261128381611247565b9050919050565b7f45524332303a207472616e7366657220746f20746865207a65726f206164647260008201527f6573730000000000000000000000000000000000000000000000000000000000602082015250565b60006112e6602383610bb7565b91506112f18261128a565b604082019050919050565b60006020820190508181036000830152611315816112d9565b9050919050565b7f45524332303a207472616e7366657220616d6f756e742065786365656473206260008201527f616c616e63650000000000000000000000000000000000000000000000000000602082015250565b6000611378602683610bb7565b91506113838261131c565b604082019050919050565b600060208201905081810360008301526113a78161136b565b905091905056fea264697066735822122099c0a3fa57a651840e324ef1d5166676aa7c29dcdd95f5845b401c2d11bd6bb864736f6c634300080d0033 \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/new_swap/swap_sol_moyed.abi b/tests/xtvm_test/test_cases/QA_CASES/new_swap/swap_sol_moyed.abi new file mode 100755 index 000000000..b15982af1 --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/new_swap/swap_sol_moyed.abi @@ -0,0 +1 @@ +[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}] \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/new_swap/swap_sol_moyed.bin b/tests/xtvm_test/test_cases/QA_CASES/new_swap/swap_sol_moyed.bin new file mode 100755 index 000000000..d81108251 --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/new_swap/swap_sol_moyed.bin @@ -0,0 +1 @@ +60806040523480156200001157600080fd5b506040518060400160405280600581526020017f4d4f5945440000000000000000000000000000000000000000000000000000008152506040518060400160405280600381526020017f4d594400000000000000000000000000000000000000000000000000000000008152508160039080519060200190620000969291906200023c565b508060049080519060200190620000af9291906200023c565b505050620000cd3368056bc75e2d63100000620000d360201b60201c565b62000497565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff160362000145576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016200013c906200034d565b60405180910390fd5b62000159600083836200023760201b60201c565b80600260008282546200016d9190620003a8565b92505081905550806000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254620001c49190620003a8565b925050819055508173ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040516200022b919062000416565b60405180910390a35050565b505050565b8280546200024a9062000462565b90600052602060002090601f0160209004810192826200026e5760008555620002ba565b82601f106200028957805160ff1916838001178555620002ba565b82800160010185558215620002ba579182015b82811115620002b95782518255916020019190600101906200029c565b5b509050620002c99190620002cd565b5090565b5b80821115620002e8576000816000905550600101620002ce565b5090565b600082825260208201905092915050565b7f45524332303a206d696e7420746f20746865207a65726f206164647265737300600082015250565b600062000335601f83620002ec565b91506200034282620002fd565b602082019050919050565b60006020820190508181036000830152620003688162000326565b9050919050565b6000819050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000620003b5826200036f565b9150620003c2836200036f565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff03821115620003fa57620003f962000379565b5b828201905092915050565b62000410816200036f565b82525050565b60006020820190506200042d600083018462000405565b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b600060028204905060018216806200047b57607f821691505b60208210810362000491576200049062000433565b5b50919050565b6113e480620004a76000396000f3fe608060405234801561001057600080fd5b50600436106100a95760003560e01c80633950935111610071578063395093511461016857806370a082311461019857806395d89b41146101c8578063a457c2d7146101e6578063a9059cbb14610216578063dd62ed3e14610246576100a9565b806306fdde03146100ae578063095ea7b3146100cc57806318160ddd146100fc57806323b872dd1461011a578063313ce5671461014a575b600080fd5b6100b6610276565b6040516100c39190610c45565b60405180910390f35b6100e660048036038101906100e19190610d00565b610308565b6040516100f39190610d5b565b60405180910390f35b610104610326565b6040516101119190610d85565b60405180910390f35b610134600480360381019061012f9190610da0565b610330565b6040516101419190610d5b565b60405180910390f35b610152610431565b60405161015f9190610e0f565b60405180910390f35b610182600480360381019061017d9190610d00565b61043a565b60405161018f9190610d5b565b60405180910390f35b6101b260048036038101906101ad9190610e2a565b6104e6565b6040516101bf9190610d85565b60405180910390f35b6101d061052e565b6040516101dd9190610c45565b60405180910390f35b61020060048036038101906101fb9190610d00565b6105c0565b60405161020d9190610d5b565b60405180910390f35b610230600480360381019061022b9190610d00565b6106b4565b60405161023d9190610d5b565b60405180910390f35b610260600480360381019061025b9190610e57565b6106d2565b60405161026d9190610d85565b60405180910390f35b60606003805461028590610ec6565b80601f01602080910402602001604051908101604052809291908181526020018280546102b190610ec6565b80156102fe5780601f106102d3576101008083540402835291602001916102fe565b820191906000526020600020905b8154815290600101906020018083116102e157829003601f168201915b5050505050905090565b600061031c610315610759565b8484610761565b6001905092915050565b6000600254905090565b600061033d84848461092a565b6000600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000610388610759565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905082811015610408576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103ff90610f69565b60405180910390fd5b61042585610414610759565b85846104209190610fb8565b610761565b60019150509392505050565b60006012905090565b60006104dc610447610759565b848460016000610455610759565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008873ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020546104d79190610fec565b610761565b6001905092915050565b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b60606004805461053d90610ec6565b80601f016020809104026020016040519081016040528092919081815260200182805461056990610ec6565b80156105b65780601f1061058b576101008083540402835291602001916105b6565b820191906000526020600020905b81548152906001019060200180831161059957829003601f168201915b5050505050905090565b600080600160006105cf610759565b73ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205490508281101561068c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610683906110b4565b60405180910390fd5b6106a9610697610759565b8585846106a49190610fb8565b610761565b600191505092915050565b60006106c86106c1610759565b848461092a565b6001905092915050565b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600033905090565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16036107d0576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016107c790611146565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff160361083f576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610836906111d8565b60405180910390fd5b80600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9258360405161091d9190610d85565b60405180910390a3505050565b600073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1603610999576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109909061126a565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1603610a08576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109ff906112fc565b60405180910390fd5b610a13838383610ba7565b60008060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905081811015610a99576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a909061138e565b60405180910390fd5b8181610aa59190610fb8565b6000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254610b359190610fec565b925050819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef84604051610b999190610d85565b60405180910390a350505050565b505050565b600081519050919050565b600082825260208201905092915050565b60005b83811015610be6578082015181840152602081019050610bcb565b83811115610bf5576000848401525b50505050565b6000601f19601f8301169050919050565b6000610c1782610bac565b610c218185610bb7565b9350610c31818560208601610bc8565b610c3a81610bfb565b840191505092915050565b60006020820190508181036000830152610c5f8184610c0c565b905092915050565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000610c9782610c6c565b9050919050565b610ca781610c8c565b8114610cb257600080fd5b50565b600081359050610cc481610c9e565b92915050565b6000819050919050565b610cdd81610cca565b8114610ce857600080fd5b50565b600081359050610cfa81610cd4565b92915050565b60008060408385031215610d1757610d16610c67565b5b6000610d2585828601610cb5565b9250506020610d3685828601610ceb565b9150509250929050565b60008115159050919050565b610d5581610d40565b82525050565b6000602082019050610d706000830184610d4c565b92915050565b610d7f81610cca565b82525050565b6000602082019050610d9a6000830184610d76565b92915050565b600080600060608486031215610db957610db8610c67565b5b6000610dc786828701610cb5565b9350506020610dd886828701610cb5565b9250506040610de986828701610ceb565b9150509250925092565b600060ff82169050919050565b610e0981610df3565b82525050565b6000602082019050610e246000830184610e00565b92915050565b600060208284031215610e4057610e3f610c67565b5b6000610e4e84828501610cb5565b91505092915050565b60008060408385031215610e6e57610e6d610c67565b5b6000610e7c85828601610cb5565b9250506020610e8d85828601610cb5565b9150509250929050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b60006002820490506001821680610ede57607f821691505b602082108103610ef157610ef0610e97565b5b50919050565b7f45524332303a207472616e7366657220616d6f756e742065786365656473206160008201527f6c6c6f77616e6365000000000000000000000000000000000000000000000000602082015250565b6000610f53602883610bb7565b9150610f5e82610ef7565b604082019050919050565b60006020820190508181036000830152610f8281610f46565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000610fc382610cca565b9150610fce83610cca565b925082821015610fe157610fe0610f89565b5b828203905092915050565b6000610ff782610cca565b915061100283610cca565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0382111561103757611036610f89565b5b828201905092915050565b7f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f7760008201527f207a65726f000000000000000000000000000000000000000000000000000000602082015250565b600061109e602583610bb7565b91506110a982611042565b604082019050919050565b600060208201905081810360008301526110cd81611091565b9050919050565b7f45524332303a20617070726f76652066726f6d20746865207a65726f2061646460008201527f7265737300000000000000000000000000000000000000000000000000000000602082015250565b6000611130602483610bb7565b915061113b826110d4565b604082019050919050565b6000602082019050818103600083015261115f81611123565b9050919050565b7f45524332303a20617070726f766520746f20746865207a65726f20616464726560008201527f7373000000000000000000000000000000000000000000000000000000000000602082015250565b60006111c2602283610bb7565b91506111cd82611166565b604082019050919050565b600060208201905081810360008301526111f1816111b5565b9050919050565b7f45524332303a207472616e736665722066726f6d20746865207a65726f20616460008201527f6472657373000000000000000000000000000000000000000000000000000000602082015250565b6000611254602583610bb7565b915061125f826111f8565b604082019050919050565b6000602082019050818103600083015261128381611247565b9050919050565b7f45524332303a207472616e7366657220746f20746865207a65726f206164647260008201527f6573730000000000000000000000000000000000000000000000000000000000602082015250565b60006112e6602383610bb7565b91506112f18261128a565b604082019050919050565b60006020820190508181036000830152611315816112d9565b9050919050565b7f45524332303a207472616e7366657220616d6f756e742065786365656473206260008201527f616c616e63650000000000000000000000000000000000000000000000000000602082015250565b6000611378602683610bb7565b91506113838261131c565b604082019050919050565b600060208201905081810360008301526113a78161136b565b905091905056fea264697066735822122083547f6a70a724e46d3ffcc3afc6c958c47b0d1a84323f0c8c7158a2c04e164264736f6c634300080d0033 \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/swap/AliceToken.json b/tests/xtvm_test/test_cases/QA_CASES/swap/AliceToken.json new file mode 100755 index 000000000..c7c9a6bd5 --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/swap/AliceToken.json @@ -0,0 +1,227 @@ +{ + "pre_data": {}, + "deploy_contract": [ + { + "src_address": "T60004befc5d4c0cf44e2295c01920bac668d2c4d61a4b", + "code_file_path": "AliceToken_sol_AliceToken.bin", + "gas_limit": 876585, + "value": "0", + "expected": { + "status": 0, + "extra_message": "contract_one", + "gas_used": 876585, + "logs": [] + } + } + ], + "test_cases": [ + { + "__comments":"获取代币name.返回Alice", + "src_address": "T60004befc5d4c0cf44e2295c01920bac668d2c4d61a4b", + "target_address": "contract_one", + "data": "0x06fdde03", + "gas_limit": 24514, + "value": "0", + "expected": { + "status": 0, + "extra_message": "0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000005416c696365000000000000000000000000000000000000000000000000000000", + "gas_used": 24514, + "logs": [] + } + }, + { + "__comments":"获取代币symbol.返回ATOKEN", + "src_address": "T60004befc5d4c0cf44e2295c01920bac668d2c4d61a4b", + "target_address": "contract_one", + "data": "0x95d89b41", + "gas_limit": 24557, + "value": "0", + "expected": { + "status": 0, + "extra_message": "0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000641544f4b454e0000000000000000000000000000000000000000000000000000", + "gas_used": 24557, + "logs": [] + } + }, + { + "__comments":"获取代币decimals.返回18", + "src_address": "T60004befc5d4c0cf44e2295c01920bac668d2c4d61a4b", + "target_address": "contract_one", + "data": "0x313ce567", + "gas_limit": 23624 , + "value": "0", + "expected": { + "status": 0, + "extra_message": "0x0000000000000000000000000000000000000000000000000000000000000012", + "gas_used": 23624 , + "logs": [] + } + }, + { + "__comments":"第1次发币mint(1000000000000000),消耗gas较多68425 ", + "src_address": "T60004befc5d4c0cf44e2295c01920bac668d2c4d61a4b", + "target_address": "contract_one", + "data": "0xa0712d6800000000000000000000000000000000000000000000000000038d7ea4c68000", + "gas_limit": 342250, + "value": "0", + "expected": { + "status": 0, + "extra_message": "", + "gas_used": 68425, + "logs": [ + { + "address": "contract_one", + "topics": [ + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "0x0000000000000000000000000000000000000000000000000000000000000000", + "0x000000000000000000000000befc5d4c0cf44e2295c01920bac668d2c4d61a4b" + ], + "data": "0x00000000000000000000000000000000000000000000000000038d7ea4c68000" + } + ] + } + }, + { + "__comments":"第2次发币mint(1000000000000000),消耗gas较少34225 ", + "src_address": "T60004befc5d4c0cf44e2295c01920bac668d2c4d61a4b", + "target_address": "contract_one", + "data": "0xa0712d6800000000000000000000000000000000000000000000000000038d7ea4c68000", + "gas_limit": 342250, + "value": "0", + "expected": { + "status": 0, + "extra_message": "", + "gas_used": 34225, + "logs": [ + { + "address": "contract_one", + "topics": [ + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "0x0000000000000000000000000000000000000000000000000000000000000000", + "0x000000000000000000000000befc5d4c0cf44e2295c01920bac668d2c4d61a4b" + ], + "data": "0x00000000000000000000000000000000000000000000000000038d7ea4c68000" + } + ] + } + }, + { + "__comments":"上面2个用例执行2次mint(1000000000000000),调用totalSupply查看发币总共有2000000000000000 ", + "src_address": "T60004befc5d4c0cf44e2295c01920bac668d2c4d61a4b", + "target_address": "contract_one", + "data": "0x18160ddd", + "gas_limit": 23538, + "value": "0", + "expected": { + "status": 0, + "extra_message": "0x00000000000000000000000000000000000000000000000000071afd498d0000", + "gas_used": 23538, + "logs": [] + } + }, + { + "__comments":"销毁burn(1000000000000000) ", + "src_address": "T60004befc5d4c0cf44e2295c01920bac668d2c4d61a4b", + "target_address": "contract_one", + "data": "0x42966c6800000000000000000000000000000000000000000000000000038d7ea4c68000", + "gas_limit": 34147, + "value": "0", + "expected": { + "status": 0, + "extra_message": "", + "gas_used": 34147, + "logs": [ + { + "address": "contract_one", + "topics": [ + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "0x000000000000000000000000befc5d4c0cf44e2295c01920bac668d2c4d61a4b", + "0x0000000000000000000000000000000000000000000000000000000000000000" + ], + "data": "0x00000000000000000000000000000000000000000000000000038d7ea4c68000" + } + ] + } + }, + { + "__comments":"上面2个用例执行2次发币1000000000000000),销毁1次,调用totalSupply查看发币总共有1000000000000000 ", + "src_address": "T60004befc5d4c0cf44e2295c01920bac668d2c4d61a4b", + "target_address": "contract_one", + "data": "0x18160ddd", + "gas_limit": 23538, + "value": "0", + "expected": { + "status": 0, + "extra_message": "0x00000000000000000000000000000000000000000000000000038d7ea4c68000", + "gas_used": 23538, + "logs": [] + } + }, + { + "__comments":"上面2个用例执行2次发币1000000000000000),销毁1次,调用balanceOf查看默认账户金额1000000000000000 ", + "src_address": "T60004befc5d4c0cf44e2295c01920bac668d2c4d61a4b", + "target_address": "contract_one", + "data": "0x70a08231000000000000000000000000befc5d4c0cf44e2295c01920bac668d2c4d61a4b", + "gas_limit": 24268, + "value": "0", + "expected": { + "status": 0, + "extra_message": "0x00000000000000000000000000000000000000000000000000038d7ea4c68000", + "gas_used": 24268, + "logs": [] + } + }, + { + "__comments":"transfer(0x15ad19ed3fa956877a8d45ec47657a64e9e01502,10000) ,返回true", + "src_address": "T60004befc5d4c0cf44e2295c01920bac668d2c4d61a4b", + "target_address": "contract_one", + "data": "0xa9059cbb00000000000000000000000015ad19ed3fa956877a8d45ec47657a64e9e015020000000000000000000000000000000000000000000000000000000000002710", + "gas_limit": 52169, + "value": "0", + "expected": { + "status": 0, + "extra_message": "0x0000000000000000000000000000000000000000000000000000000000000001", + "gas_used": 52169, + "logs": [ + { + "address": "contract_one", + "topics": [ + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "0x000000000000000000000000befc5d4c0cf44e2295c01920bac668d2c4d61a4b", + "0x00000000000000000000000015ad19ed3fa956877a8d45ec47657a64e9e01502" + ], + "data": "0x0000000000000000000000000000000000000000000000000000000000002710" + } + ] + } + }, + { + "__comments":"查看0x15ad19ed3fa956877a8d45ec47657a64e9e01502金额10000", + "src_address": "T60004befc5d4c0cf44e2295c01920bac668d2c4d61a4b", + "target_address": "contract_one", + "data": "0x70a0823100000000000000000000000015ad19ed3fa956877a8d45ec47657a64e9e01502", + "gas_limit": 24268, + "value": "0", + "expected": { + "status": 0, + "extra_message": "0x0000000000000000000000000000000000000000000000000000000000002710", + "gas_used": 24268, + "logs": [] + } + }, + { + "__comments":"非自己账号转账失败,transferFrom(0x15ad19ed3fa956877a8d45ec47657a64e9e01502,0x7767d8d47a370ec7c49b153f2731360fb08239e8,5000)", + "src_address": "T60004befc5d4c0cf44e2295c01920bac668d2c4d61a4b", + "target_address": "contract_one", + "data": "0x23b872dd00000000000000000000000015ad19ed3fa956877a8d45ec47657a64e9e015020000000000000000000000007767d8d47a370ec7c49b153f2731360fb08239e80000000000000000000000000000000000000000000000000000000000001388", + "gas_limit": 25338, + "value": "0", + "expected": { + "status": 1, + "extra_message": "0x4e487b710000000000000000000000000000000000000000000000000000000000000011", + "gas_used": 25338, + "logs": [] + } + } + ] +} \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/swap/AliceToken.sol b/tests/xtvm_test/test_cases/QA_CASES/swap/AliceToken.sol new file mode 100755 index 000000000..37953f6e1 --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/swap/AliceToken.sol @@ -0,0 +1,50 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.10; + +import "./IERC20.sol"; + +contract AliceToken is IERC20 { + uint public totalSupply; + mapping(address => uint) public balanceOf; + mapping(address => mapping(address => uint)) public allowance; + string public name = "Alice"; + string public symbol = "ATOKEN"; + uint8 public decimals = 18; + + function transfer(address recipient, uint amount) external returns (bool) { + balanceOf[msg.sender] -= amount; + balanceOf[recipient] += amount; + emit Transfer(msg.sender, recipient, amount); + return true; + } + + function approve(address spender, uint amount) external returns (bool) { + allowance[msg.sender][spender] = amount; + emit Approval(msg.sender, spender, amount); + return true; + } + + function transferFrom( + address sender, + address recipient, + uint amount + ) external returns (bool) { + allowance[sender][msg.sender] -= amount; + balanceOf[sender] -= amount; + balanceOf[recipient] += amount; + emit Transfer(sender, recipient, amount); + return true; + } + + function mint(uint amount) external { + balanceOf[msg.sender] += amount; + totalSupply += amount; + emit Transfer(address(0), msg.sender, amount); + } + + function burn(uint amount) external { + balanceOf[msg.sender] -= amount; + totalSupply -= amount; + emit Transfer(msg.sender, address(0), amount); + } +} diff --git a/tests/xtvm_test/test_cases/QA_CASES/swap/AliceToken_sol_AliceToken.abi b/tests/xtvm_test/test_cases/QA_CASES/swap/AliceToken_sol_AliceToken.abi new file mode 100755 index 000000000..450ef67c1 --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/swap/AliceToken_sol_AliceToken.abi @@ -0,0 +1 @@ +[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"burn","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"mint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}] \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/swap/AliceToken_sol_AliceToken.bin b/tests/xtvm_test/test_cases/QA_CASES/swap/AliceToken_sol_AliceToken.bin new file mode 100755 index 000000000..7d197665c --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/swap/AliceToken_sol_AliceToken.bin @@ -0,0 +1 @@ +60806040526040518060400160405280600581526020017f416c6963650000000000000000000000000000000000000000000000000000008152506003908051906020019062000051929190620000d0565b506040518060400160405280600681526020017f41544f4b454e0000000000000000000000000000000000000000000000000000815250600490805190602001906200009f929190620000d0565b506012600560006101000a81548160ff021916908360ff160217905550348015620000c957600080fd5b50620001e4565b828054620000de90620001af565b90600052602060002090601f0160209004810192826200010257600085556200014e565b82601f106200011d57805160ff19168380011785556200014e565b828001600101855582156200014e579182015b828111156200014d57825182559160200191906001019062000130565b5b5090506200015d919062000161565b5090565b5b808211156200017c57600081600090555060010162000162565b5090565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b60006002820490506001821680620001c857607f821691505b602082108103620001de57620001dd62000180565b5b50919050565b610d9580620001f46000396000f3fe608060405234801561001057600080fd5b50600436106100a95760003560e01c806342966c681161007157806342966c681461016857806370a082311461018457806395d89b41146101b4578063a0712d68146101d2578063a9059cbb146101ee578063dd62ed3e1461021e576100a9565b806306fdde03146100ae578063095ea7b3146100cc57806318160ddd146100fc57806323b872dd1461011a578063313ce5671461014a575b600080fd5b6100b661024e565b6040516100c391906109c7565b60405180910390f35b6100e660048036038101906100e19190610a82565b6102dc565b6040516100f39190610add565b60405180910390f35b6101046103ce565b6040516101119190610b07565b60405180910390f35b610134600480360381019061012f9190610b22565b6103d4565b6040516101419190610add565b60405180910390f35b610152610585565b60405161015f9190610b91565b60405180910390f35b610182600480360381019061017d9190610bac565b610598565b005b61019e60048036038101906101999190610bd9565b61066f565b6040516101ab9190610b07565b60405180910390f35b6101bc610687565b6040516101c991906109c7565b60405180910390f35b6101ec60048036038101906101e79190610bac565b610715565b005b61020860048036038101906102039190610a82565b6107ec565b6040516102159190610add565b60405180910390f35b61023860048036038101906102339190610c06565b610909565b6040516102459190610b07565b60405180910390f35b6003805461025b90610c75565b80601f016020809104026020016040519081016040528092919081815260200182805461028790610c75565b80156102d45780601f106102a9576101008083540402835291602001916102d4565b820191906000526020600020905b8154815290600101906020018083116102b757829003601f168201915b505050505081565b600081600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040516103bc9190610b07565b60405180910390a36001905092915050565b60005481565b600081600260008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546104629190610cd5565b9250508190555081600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546104b89190610cd5565b9250508190555081600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825461050e9190610d09565b925050819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516105729190610b07565b60405180910390a3600190509392505050565b600560009054906101000a900460ff1681565b80600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546105e79190610cd5565b92505081905550806000808282546105ff9190610cd5565b92505081905550600073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040516106649190610b07565b60405180910390a350565b60016020528060005260406000206000915090505481565b6004805461069490610c75565b80601f01602080910402602001604051908101604052809291908181526020018280546106c090610c75565b801561070d5780601f106106e25761010080835404028352916020019161070d565b820191906000526020600020905b8154815290600101906020018083116106f057829003601f168201915b505050505081565b80600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546107649190610d09565b925050819055508060008082825461077c9190610d09565b925050819055503373ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040516107e19190610b07565b60405180910390a350565b600081600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825461083d9190610cd5565b9250508190555081600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546108939190610d09565b925050819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516108f79190610b07565b60405180910390a36001905092915050565b6002602052816000526040600020602052806000526040600020600091509150505481565b600081519050919050565b600082825260208201905092915050565b60005b8381101561096857808201518184015260208101905061094d565b83811115610977576000848401525b50505050565b6000601f19601f8301169050919050565b60006109998261092e565b6109a38185610939565b93506109b381856020860161094a565b6109bc8161097d565b840191505092915050565b600060208201905081810360008301526109e1818461098e565b905092915050565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000610a19826109ee565b9050919050565b610a2981610a0e565b8114610a3457600080fd5b50565b600081359050610a4681610a20565b92915050565b6000819050919050565b610a5f81610a4c565b8114610a6a57600080fd5b50565b600081359050610a7c81610a56565b92915050565b60008060408385031215610a9957610a986109e9565b5b6000610aa785828601610a37565b9250506020610ab885828601610a6d565b9150509250929050565b60008115159050919050565b610ad781610ac2565b82525050565b6000602082019050610af26000830184610ace565b92915050565b610b0181610a4c565b82525050565b6000602082019050610b1c6000830184610af8565b92915050565b600080600060608486031215610b3b57610b3a6109e9565b5b6000610b4986828701610a37565b9350506020610b5a86828701610a37565b9250506040610b6b86828701610a6d565b9150509250925092565b600060ff82169050919050565b610b8b81610b75565b82525050565b6000602082019050610ba66000830184610b82565b92915050565b600060208284031215610bc257610bc16109e9565b5b6000610bd084828501610a6d565b91505092915050565b600060208284031215610bef57610bee6109e9565b5b6000610bfd84828501610a37565b91505092915050565b60008060408385031215610c1d57610c1c6109e9565b5b6000610c2b85828601610a37565b9250506020610c3c85828601610a37565b9150509250929050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b60006002820490506001821680610c8d57607f821691505b602082108103610ca057610c9f610c46565b5b50919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000610ce082610a4c565b9150610ceb83610a4c565b925082821015610cfe57610cfd610ca6565b5b828203905092915050565b6000610d1482610a4c565b9150610d1f83610a4c565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff03821115610d5457610d53610ca6565b5b82820190509291505056fea2646970667358221220a1c0357127418143440f3e774d56645ecdbebe3957106d3becfc347282ca534464736f6c634300080d0033 \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/swap/BobToken.json b/tests/xtvm_test/test_cases/QA_CASES/swap/BobToken.json new file mode 100755 index 000000000..0e489a691 --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/swap/BobToken.json @@ -0,0 +1,180 @@ +{ + "pre_data": {}, + "deploy_contract": [ + { + "src_address": "T600045B38Da6a701c568545dCfcB03FcB875f56beddC4", + "code_file_path": "AliceToken_sol_AliceToken.bin", + "gas_limit": 876585, + "value": "0", + "expected": { + "status": 0, + "extra_message": "contract_one", + "gas_used": 876585, + "logs": [] + } + } + ], + "test_cases": [ + { + "__comments":"第1次发币mint(1000000000000000),消耗gas较多68425 ", + "src_address": "T600045B38Da6a701c568545dCfcB03FcB875f56beddC4", + "target_address": "contract_one", + "data": "0xa0712d6800000000000000000000000000000000000000000000000000038d7ea4c68000", + "gas_limit": 342250, + "value": "0", + "expected": { + "status": 0, + "extra_message": "", + "gas_used": 68425, + "logs": [ + { + "address": "contract_one", + "topics": [ + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "0x0000000000000000000000000000000000000000000000000000000000000000", + "0x0000000000000000000000005b38da6a701c568545dcfcb03fcb875f56beddc4" + ], + "data": "0x00000000000000000000000000000000000000000000000000038d7ea4c68000" + } + ] + } + }, + { + "__comments":"第2次发币mint(1000000000000000),消耗gas较少34225 ", + "src_address": "T600045B38Da6a701c568545dCfcB03FcB875f56beddC4", + "target_address": "contract_one", + "data": "0xa0712d6800000000000000000000000000000000000000000000000000038d7ea4c68000", + "gas_limit": 342250, + "value": "0", + "expected": { + "status": 0, + "extra_message": "", + "gas_used": 34225, + "logs": [ + { + "address": "contract_one", + "topics": [ + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "0x0000000000000000000000000000000000000000000000000000000000000000", + "0x0000000000000000000000005b38da6a701c568545dcfcb03fcb875f56beddc4" + ], + "data": "0x00000000000000000000000000000000000000000000000000038d7ea4c68000" + } + ] + } + }, + { + "__comments":"上面2个用例执行2次mint(1000000000000000),调用totalSupply查看发币总共有2000000000000000 ", + "src_address": "T600045B38Da6a701c568545dCfcB03FcB875f56beddC4", + "target_address": "contract_one", + "data": "0x18160ddd", + "gas_limit": 23538, + "value": "0", + "expected": { + "status": 0, + "extra_message": "0x00000000000000000000000000000000000000000000000000071afd498d0000", + "gas_used": 23538, + "logs": [] + } + }, + { + "__comments":"上面2个用例执行2次mint(1000000000000000),调用balanceOf查看发币总共有2000000000000000 ", + "src_address": "T600045B38Da6a701c568545dCfcB03FcB875f56beddC4", + "target_address": "contract_one", + "data": "0x70a082310000000000000000000000005b38da6a701c568545dcfcb03fcb875f56beddc4", + "gas_limit": 24268, + "value": "0", + "expected": { + "status": 0, + "extra_message": "", + "gas_used": 24268, + "logs": [] + } + }, + { + "__comments":"approve 10000: 在给定接收者地址和数量的情况下,授权该地址从发布批准的帐户执行多次转账,直到到达指定的数量", + "src_address": "T600045B38Da6a701c568545dCfcB03FcB875f56beddC4", + "target_address": "contract_one", + "data": "0x095ea7b30000000000000000000000005b38da6a701c568545dcfcb03fcb875f56beddc40000000000000000000000000000000000000000000000000000000000002710", + "gas_limit": 46682, + "value": "0", + "expected": { + "status": 0, + "extra_message": "", + "gas_used": 46682, + "logs": [ + { + "address": "contract_one", + "topics": [ + "0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925", + "0x0000000000000000000000005b38da6a701c568545dcfcb03fcb875f56beddc4", + "0x0000000000000000000000005b38da6a701c568545dcfcb03fcb875f56beddc4" + ], + "data": "0x0000000000000000000000000000000000000000000000000000000000002710" + } + ] + } + }, + { + "__comments":"transfer 10", + "src_address": "T600045B38Da6a701c568545dCfcB03FcB875f56beddC4", + "target_address": "contract_one", + "data": "0x23b872dd0000000000000000000000005b38da6a701c568545dcfcb03fcb875f56beddc4000000000000000000000000ab8483f64d9c6d1ecf9b849ae677dd3315835cb2000000000000000000000000000000000000000000000000000000000000000a", + "gas_limit": 466820, + "value": "0", + "expected": { + "status": 0, + "extra_message": "", + "gas_used": 58119 , + "logs": [ + { + "address": "contract_one", + "topics": [ + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "0x0000000000000000000000005b38da6a701c568545dcfcb03fcb875f56beddc4", + "0x000000000000000000000000ab8483f64d9c6d1ecf9b849ae677dd3315835cb2"], + "data": "0x000000000000000000000000000000000000000000000000000000000000000a" + } + ] + } + }, + { + "__comments":"transfer 10", + "src_address": "T600045B38Da6a701c568545dCfcB03FcB875f56beddC4", + "target_address": "contract_one", + "data": "0x23b872dd0000000000000000000000005b38da6a701c568545dcfcb03fcb875f56beddc4000000000000000000000000ab8483f64d9c6d1ecf9b849ae677dd3315835cb2000000000000000000000000000000000000000000000000000000000000000a", + "gas_limit": 466820, + "value": "0", + "expected": { + "status": 0, + "extra_message": "", + "gas_used": 41019 , + "logs": [ + { + "address": "contract_one", + "topics": [ + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "0x0000000000000000000000005b38da6a701c568545dcfcb03fcb875f56beddc4", + "0x000000000000000000000000ab8483f64d9c6d1ecf9b849ae677dd3315835cb2"], + "data": "0x000000000000000000000000000000000000000000000000000000000000000a" + } + ] + } + } + , + { + "__comments":"transfer 10000,超过限制失败", + "src_address": "T600045B38Da6a701c568545dCfcB03FcB875f56beddC4", + "target_address": "contract_one", + "data": "0x23b872dd0000000000000000000000005b38da6a701c568545dcfcb03fcb875f56beddc4000000000000000000000000ab8483f64d9c6d1ecf9b849ae677dd3315835cb20000000000000000000000000000000000000000000000000000000000002710", + "gas_limit": 466820, + "value": "0", + "expected": { + "status": 1, + "extra_message": "", + "gas_used": 25338 , + "logs": [] + } + } + ] +} \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/swap/BobToken.sol b/tests/xtvm_test/test_cases/QA_CASES/swap/BobToken.sol new file mode 100755 index 000000000..b3cbfb546 --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/swap/BobToken.sol @@ -0,0 +1,50 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.10; + +import "./IERC20.sol"; + +contract BobToken is IERC20 { + uint public totalSupply; + mapping(address => uint) public balanceOf; + mapping(address => mapping(address => uint)) public allowance; + string public name = "Bob"; + string public symbol = "BTOKEN"; + uint8 public decimals = 18; + + function transfer(address recipient, uint amount) external returns (bool) { + balanceOf[msg.sender] -= amount; + balanceOf[recipient] += amount; + emit Transfer(msg.sender, recipient, amount); + return true; + } + + function approve(address spender, uint amount) external returns (bool) { + allowance[msg.sender][spender] = amount; + emit Approval(msg.sender, spender, amount); + return true; + } + + function transferFrom( + address sender, + address recipient, + uint amount + ) external returns (bool) { + allowance[sender][msg.sender] -= amount; + balanceOf[sender] -= amount; + balanceOf[recipient] += amount; + emit Transfer(sender, recipient, amount); + return true; + } + + function mint(uint amount) external { + balanceOf[msg.sender] += amount; + totalSupply += amount; + emit Transfer(address(0), msg.sender, amount); + } + + function burn(uint amount) external { + balanceOf[msg.sender] -= amount; + totalSupply -= amount; + emit Transfer(msg.sender, address(0), amount); + } +} diff --git a/tests/xtvm_test/test_cases/QA_CASES/swap/BobToken_sol_BobToken.abi b/tests/xtvm_test/test_cases/QA_CASES/swap/BobToken_sol_BobToken.abi new file mode 100755 index 000000000..450ef67c1 --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/swap/BobToken_sol_BobToken.abi @@ -0,0 +1 @@ +[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"burn","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"mint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}] \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/swap/BobToken_sol_BobToken.bin b/tests/xtvm_test/test_cases/QA_CASES/swap/BobToken_sol_BobToken.bin new file mode 100755 index 000000000..9c6e2f9f3 --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/swap/BobToken_sol_BobToken.bin @@ -0,0 +1 @@ +60806040526040518060400160405280600381526020017f426f6200000000000000000000000000000000000000000000000000000000008152506003908051906020019062000051929190620000d0565b506040518060400160405280600681526020017f42544f4b454e0000000000000000000000000000000000000000000000000000815250600490805190602001906200009f929190620000d0565b506012600560006101000a81548160ff021916908360ff160217905550348015620000c957600080fd5b50620001e4565b828054620000de90620001af565b90600052602060002090601f0160209004810192826200010257600085556200014e565b82601f106200011d57805160ff19168380011785556200014e565b828001600101855582156200014e579182015b828111156200014d57825182559160200191906001019062000130565b5b5090506200015d919062000161565b5090565b5b808211156200017c57600081600090555060010162000162565b5090565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b60006002820490506001821680620001c857607f821691505b602082108103620001de57620001dd62000180565b5b50919050565b610d9580620001f46000396000f3fe608060405234801561001057600080fd5b50600436106100a95760003560e01c806342966c681161007157806342966c681461016857806370a082311461018457806395d89b41146101b4578063a0712d68146101d2578063a9059cbb146101ee578063dd62ed3e1461021e576100a9565b806306fdde03146100ae578063095ea7b3146100cc57806318160ddd146100fc57806323b872dd1461011a578063313ce5671461014a575b600080fd5b6100b661024e565b6040516100c391906109c7565b60405180910390f35b6100e660048036038101906100e19190610a82565b6102dc565b6040516100f39190610add565b60405180910390f35b6101046103ce565b6040516101119190610b07565b60405180910390f35b610134600480360381019061012f9190610b22565b6103d4565b6040516101419190610add565b60405180910390f35b610152610585565b60405161015f9190610b91565b60405180910390f35b610182600480360381019061017d9190610bac565b610598565b005b61019e60048036038101906101999190610bd9565b61066f565b6040516101ab9190610b07565b60405180910390f35b6101bc610687565b6040516101c991906109c7565b60405180910390f35b6101ec60048036038101906101e79190610bac565b610715565b005b61020860048036038101906102039190610a82565b6107ec565b6040516102159190610add565b60405180910390f35b61023860048036038101906102339190610c06565b610909565b6040516102459190610b07565b60405180910390f35b6003805461025b90610c75565b80601f016020809104026020016040519081016040528092919081815260200182805461028790610c75565b80156102d45780601f106102a9576101008083540402835291602001916102d4565b820191906000526020600020905b8154815290600101906020018083116102b757829003601f168201915b505050505081565b600081600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040516103bc9190610b07565b60405180910390a36001905092915050565b60005481565b600081600260008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546104629190610cd5565b9250508190555081600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546104b89190610cd5565b9250508190555081600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825461050e9190610d09565b925050819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516105729190610b07565b60405180910390a3600190509392505050565b600560009054906101000a900460ff1681565b80600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546105e79190610cd5565b92505081905550806000808282546105ff9190610cd5565b92505081905550600073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040516106649190610b07565b60405180910390a350565b60016020528060005260406000206000915090505481565b6004805461069490610c75565b80601f01602080910402602001604051908101604052809291908181526020018280546106c090610c75565b801561070d5780601f106106e25761010080835404028352916020019161070d565b820191906000526020600020905b8154815290600101906020018083116106f057829003601f168201915b505050505081565b80600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546107649190610d09565b925050819055508060008082825461077c9190610d09565b925050819055503373ffffffffffffffffffffffffffffffffffffffff16600073ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040516107e19190610b07565b60405180910390a350565b600081600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825461083d9190610cd5565b9250508190555081600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546108939190610d09565b925050819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516108f79190610b07565b60405180910390a36001905092915050565b6002602052816000526040600020602052806000526040600020600091509150505481565b600081519050919050565b600082825260208201905092915050565b60005b8381101561096857808201518184015260208101905061094d565b83811115610977576000848401525b50505050565b6000601f19601f8301169050919050565b60006109998261092e565b6109a38185610939565b93506109b381856020860161094a565b6109bc8161097d565b840191505092915050565b600060208201905081810360008301526109e1818461098e565b905092915050565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000610a19826109ee565b9050919050565b610a2981610a0e565b8114610a3457600080fd5b50565b600081359050610a4681610a20565b92915050565b6000819050919050565b610a5f81610a4c565b8114610a6a57600080fd5b50565b600081359050610a7c81610a56565b92915050565b60008060408385031215610a9957610a986109e9565b5b6000610aa785828601610a37565b9250506020610ab885828601610a6d565b9150509250929050565b60008115159050919050565b610ad781610ac2565b82525050565b6000602082019050610af26000830184610ace565b92915050565b610b0181610a4c565b82525050565b6000602082019050610b1c6000830184610af8565b92915050565b600080600060608486031215610b3b57610b3a6109e9565b5b6000610b4986828701610a37565b9350506020610b5a86828701610a37565b9250506040610b6b86828701610a6d565b9150509250925092565b600060ff82169050919050565b610b8b81610b75565b82525050565b6000602082019050610ba66000830184610b82565b92915050565b600060208284031215610bc257610bc16109e9565b5b6000610bd084828501610a6d565b91505092915050565b600060208284031215610bef57610bee6109e9565b5b6000610bfd84828501610a37565b91505092915050565b60008060408385031215610c1d57610c1c6109e9565b5b6000610c2b85828601610a37565b9250506020610c3c85828601610a37565b9150509250929050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b60006002820490506001821680610c8d57607f821691505b602082108103610ca057610c9f610c46565b5b50919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000610ce082610a4c565b9150610ceb83610a4c565b925082821015610cfe57610cfd610ca6565b5b828203905092915050565b6000610d1482610a4c565b9150610d1f83610a4c565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff03821115610d5457610d53610ca6565b5b82820190509291505056fea2646970667358221220398ffe1d9f8500de12e8e741740f39c0dab8c1a3511b09d36749800a0d32f5a264736f6c634300080d0033 \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/swap/IERC20.sol b/tests/xtvm_test/test_cases/QA_CASES/swap/IERC20.sol new file mode 100755 index 000000000..5cc6e4c05 --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/swap/IERC20.sol @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.10; + +interface IERC20 { + function totalSupply() external view returns (uint); + + function balanceOf(address account) external view returns (uint); + + function transfer(address recipient, uint amount) external returns (bool); + + function allowance(address owner, address spender) external view returns (uint); + + function approve(address spender, uint amount) external returns (bool); + + function transferFrom( + address sender, + address recipient, + uint amount + ) external returns (bool); + + event Transfer(address indexed from, address indexed to, uint value); + event Approval(address indexed owner, address indexed spender, uint value); +} diff --git a/tests/xtvm_test/test_cases/QA_CASES/swap/IERC20_sol_IERC20.abi b/tests/xtvm_test/test_cases/QA_CASES/swap/IERC20_sol_IERC20.abi new file mode 100755 index 000000000..38876a993 --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/swap/IERC20_sol_IERC20.abi @@ -0,0 +1 @@ +[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}] \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/swap/IERC20_sol_IERC20.bin b/tests/xtvm_test/test_cases/QA_CASES/swap/IERC20_sol_IERC20.bin new file mode 100755 index 000000000..e69de29bb diff --git a/tests/xtvm_test/test_cases/QA_CASES/swap/TokenSwap.sol b/tests/xtvm_test/test_cases/QA_CASES/swap/TokenSwap.sol new file mode 100755 index 000000000..aaafea42d --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/swap/TokenSwap.sol @@ -0,0 +1,55 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.10; + +import "./IERC20.sol"; + +// 约定兑换比例: 10个AliceToken 兑换 20个BobToken +contract TokenSwap { + IERC20 public token1; + address public owner1; + uint256 public amount1; + IERC20 public token2; + address public owner2; + uint256 public amount2; + + constructor( + address _token1, + address _owner1, + uint256 _amount1, + address _token2, + address _owner2, + uint256 _amount2 + ) { + token1 = IERC20(_token1); + owner1 = _owner1; + amount1 = _amount1; + token2 = IERC20(_token2); + owner2 = _owner2; + amount2 = _amount2; + } + + function swap() public { + require(msg.sender == owner1 || msg.sender == owner2, "Not authorized"); + require( + token1.allowance(owner1, address(this)) >= amount1, + "Token 1 allowance too low" + ); + require( + token2.allowance(owner2, address(this)) >= amount2, + "Token 2 allowance too low" + ); + + _safeTransferFrom(token1, owner1, owner2, amount1); + _safeTransferFrom(token2, owner2, owner1, amount2); + } + + function _safeTransferFrom( + IERC20 token, + address sender, + address recipient, + uint256 amount + ) private { + bool sent = token.transferFrom(sender, recipient, amount); + require(sent, "Token transfer failed"); + } +} diff --git a/tests/xtvm_test/test_cases/QA_CASES/swap/TokenSwap_sol_TokenSwap.abi b/tests/xtvm_test/test_cases/QA_CASES/swap/TokenSwap_sol_TokenSwap.abi new file mode 100755 index 000000000..f24464b42 --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/swap/TokenSwap_sol_TokenSwap.abi @@ -0,0 +1 @@ +[{"inputs":[{"internalType":"address","name":"_token1","type":"address"},{"internalType":"address","name":"_owner1","type":"address"},{"internalType":"uint256","name":"_amount1","type":"uint256"},{"internalType":"address","name":"_token2","type":"address"},{"internalType":"address","name":"_owner2","type":"address"},{"internalType":"uint256","name":"_amount2","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"amount1","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"amount2","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner1","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner2","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"swap","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"token1","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"token2","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"}] \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/QA_CASES/swap/TokenSwap_sol_TokenSwap.bin b/tests/xtvm_test/test_cases/QA_CASES/swap/TokenSwap_sol_TokenSwap.bin new file mode 100755 index 000000000..f00ff1f80 --- /dev/null +++ b/tests/xtvm_test/test_cases/QA_CASES/swap/TokenSwap_sol_TokenSwap.bin @@ -0,0 +1 @@ +60806040523480156200001157600080fd5b5060405162000d4c38038062000d4c8339818101604052810190620000379190620001f9565b856000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555084600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508360028190555082600360006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555081600460006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508060058190555050505050505062000295565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000620001868262000159565b9050919050565b620001988162000179565b8114620001a457600080fd5b50565b600081519050620001b8816200018d565b92915050565b6000819050919050565b620001d381620001be565b8114620001df57600080fd5b50565b600081519050620001f381620001c8565b92915050565b60008060008060008060c0878903121562000219576200021862000154565b5b60006200022989828a01620001a7565b96505060206200023c89828a01620001a7565b95505060406200024f89828a01620001e2565b94505060606200026289828a01620001a7565b93505060806200027589828a01620001a7565b92505060a06200028889828a01620001e2565b9150509295509295509295565b610aa780620002a56000396000f3fe608060405234801561001057600080fd5b506004361061007d5760003560e01c8063736889141161005b57806373688914146100dc5780638119c065146100fa578063d21220a714610104578063f400fde4146101225761007d565b8063057bfcc71461008257806325be124e146100a057806352709725146100be575b600080fd5b61008a610140565b604051610097919061069c565b60405180910390f35b6100a8610146565b6040516100b59190610736565b60405180910390f35b6100c661016c565b6040516100d39190610772565b60405180910390f35b6100e4610192565b6040516100f19190610772565b60405180910390f35b6101026101b8565b005b61010c61058e565b6040516101199190610736565b60405180910390f35b61012a6105b2565b604051610137919061069c565b60405180910390f35b60055481565b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614806102615750600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16145b6102a0576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610297906107ea565b60405180910390fd5b60025460008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663dd62ed3e600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16306040518363ffffffff1660e01b815260040161032092919061080a565b602060405180830381865afa15801561033d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103619190610864565b10156103a2576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610399906108dd565b60405180910390fd5b600554600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663dd62ed3e600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16306040518363ffffffff1660e01b815260040161042492919061080a565b602060405180830381865afa158015610441573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104659190610864565b10156104a6576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161049d90610949565b60405180910390fd5b61051860008054906101000a900473ffffffffffffffffffffffffffffffffffffffff16600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166002546105b8565b61058c600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff166005546105b8565b565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60025481565b60008473ffffffffffffffffffffffffffffffffffffffff166323b872dd8585856040518463ffffffff1660e01b81526004016105f793929190610969565b6020604051808303816000875af1158015610616573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061063a91906109d8565b90508061067c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161067390610a51565b60405180910390fd5b5050505050565b6000819050919050565b61069681610683565b82525050565b60006020820190506106b1600083018461068d565b92915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b60006106fc6106f76106f2846106b7565b6106d7565b6106b7565b9050919050565b600061070e826106e1565b9050919050565b600061072082610703565b9050919050565b61073081610715565b82525050565b600060208201905061074b6000830184610727565b92915050565b600061075c826106b7565b9050919050565b61076c81610751565b82525050565b60006020820190506107876000830184610763565b92915050565b600082825260208201905092915050565b7f4e6f7420617574686f72697a6564000000000000000000000000000000000000600082015250565b60006107d4600e8361078d565b91506107df8261079e565b602082019050919050565b60006020820190508181036000830152610803816107c7565b9050919050565b600060408201905061081f6000830185610763565b61082c6020830184610763565b9392505050565b600080fd5b61084181610683565b811461084c57600080fd5b50565b60008151905061085e81610838565b92915050565b60006020828403121561087a57610879610833565b5b60006108888482850161084f565b91505092915050565b7f546f6b656e203120616c6c6f77616e636520746f6f206c6f7700000000000000600082015250565b60006108c760198361078d565b91506108d282610891565b602082019050919050565b600060208201905081810360008301526108f6816108ba565b9050919050565b7f546f6b656e203220616c6c6f77616e636520746f6f206c6f7700000000000000600082015250565b600061093360198361078d565b915061093e826108fd565b602082019050919050565b6000602082019050818103600083015261096281610926565b9050919050565b600060608201905061097e6000830186610763565b61098b6020830185610763565b610998604083018461068d565b949350505050565b60008115159050919050565b6109b5816109a0565b81146109c057600080fd5b50565b6000815190506109d2816109ac565b92915050565b6000602082840312156109ee576109ed610833565b5b60006109fc848285016109c3565b91505092915050565b7f546f6b656e207472616e73666572206661696c65640000000000000000000000600082015250565b6000610a3b60158361078d565b9150610a4682610a05565b602082019050919050565b60006020820190508181036000830152610a6a81610a2e565b905091905056fea2646970667358221220a2242de5c01d7f2e69abfcf5c081b08e69dd1c8679d5ab15cc17defe936e84cd64736f6c634300080d0033 \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/READMD.md b/tests/xtvm_test/test_cases/READMD.md new file mode 100644 index 000000000..ecb61f54f --- /dev/null +++ b/tests/xtvm_test/test_cases/READMD.md @@ -0,0 +1,6 @@ +copy from `tests/xevm_engine_test/test_cases/ ` + +* delete cases needed C++ precompile contracts.(TEP1 token) +* delete cases needed mock balance api +* fix `QA_CASES/call_contract` becase sharding contract_address issue by replacing `__address_in_evm` to `__address_in_top_shard` in call contract data. +* tried but still failed to fix `QA_CASES/new_swap` , so I just rename the json test-case file. \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/add/add.bin b/tests/xtvm_test/test_cases/add/add.bin new file mode 100644 index 000000000..75b2da77a --- /dev/null +++ b/tests/xtvm_test/test_cases/add/add.bin @@ -0,0 +1 @@ +0x608060405234801561001057600080fd5b50610304806100206000396000f3fe608060405234801561001057600080fd5b506004361061004c5760003560e01c80632fb3c740146100515780636e2c732d1461005b578063a05f9906146100a7578063fad772db146100d9575b600080fd5b610059610111565b005b6100a56004803603604081101561007157600080fd5b81019080803567ffffffffffffffff169060200190929190803567ffffffffffffffff1690602001909291905050506101b3565b005b6100af610242565b604051808267ffffffffffffffff1667ffffffffffffffff16815260200191505060405180910390f35b61010f600480360360208110156100ef57600080fd5b81019080803567ffffffffffffffff16906020019092919050505061025b565b005b60016000809054906101000a900467ffffffffffffffff16016000806101000a81548167ffffffffffffffff021916908367ffffffffffffffff1602179055507f4558e87569f3778927a0c0ab7e6c04d9cc3a08694412ac6b8b8bbd8276c8fb3d6000809054906101000a900467ffffffffffffffff16604051808267ffffffffffffffff1667ffffffffffffffff16815260200191505060405180910390a1565b600081830190507fba81e10edd752f92a850d20e6ca5897bc0ff54393985bc25b2c2bdc925218649838383604051808467ffffffffffffffff1667ffffffffffffffff1681526020018367ffffffffffffffff1667ffffffffffffffff1681526020018267ffffffffffffffff1667ffffffffffffffff168152602001935050505060405180910390a1505050565b6000809054906101000a900467ffffffffffffffff1681565b60006001820190507f76b87589c0efe817c6ec312c8fa2ab35ac24bbbd1e5fb8d3e3c3b4b789fdc7d48282604051808367ffffffffffffffff1667ffffffffffffffff1681526020018267ffffffffffffffff1667ffffffffffffffff1681526020019250505060405180910390a1505056fea2646970667358221220b81251e6353d97dcc679b08a746d7d8f00f5b7051bdf6c1793d3f6f3a9e361fa64736f6c63430006040033 \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/add/add.json b/tests/xtvm_test/test_cases/add/add.json new file mode 100644 index 000000000..3e81a9669 --- /dev/null +++ b/tests/xtvm_test/test_cases/add/add.json @@ -0,0 +1,107 @@ +{ + "pre_data": {}, + "deploy_contract": [ + { + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea2", + "code_file_path": "add.bin", + "gas_limit": 220022, + "value": "0", + "expected": { + "status": 0, + "extra_message": "contract_one", + "gas_used": 220022, + "logs": [] + } + }, + { + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea2", + "code_file_path": "add.bin", + "gas_limit": 200000, + "value": "0", + "expected": { + "status": 2, + "extra_message": "outofgas", + "gas_used": 200000, + "logs": [] + } + } + ], + "test_cases": [ + { + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea2", + "target_address": "contract_one", + "data": "0x6e2c732d0000000000000000000000000000000000000000000000000000000000003039000000000000000000000000000000000000000000000000000000000000d431", + "gas_limit": 23317, + "value": "0", + "expected": { + "status": 0, + "extra_message": "", + "gas_used": 23317, + "logs": [ + { + "address": "contract_one", + "topics": [ + "0xba81e10edd752f92a850d20e6ca5897bc0ff54393985bc25b2c2bdc925218649" + ], + "data": "0x0000000000000000000000000000000000000000000000000000000000003039000000000000000000000000000000000000000000000000000000000000d431000000000000000000000000000000000000000000000000000000000001046a" + } + ] + } + }, + { + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea2", + "target_address": "contract_one", + "data": "0x6e2c732d0000000000000000000000000000000000000000000000000000000000003039000000000000000000000000000000000000000000000000000000000000d431", + "gas_limit": 23000, + "value": "0", + "expected": { + "status": 2, + "extra_message": "", + "gas_used": 23000, + "logs": [] + } + }, + { + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea2", + "target_address": "contract_one", + "data": "0xfad772db000000000000000000000000000000000000000000000000000000000012d687", + "gas_limit": 22895, + "value": "0", + "expected": { + "status": 0, + "extra_message": "", + "gas_used": 22895, + "logs": [ + { + "address": "contract_one", + "topics": [ + "0x76b87589c0efe817c6ec312c8fa2ab35ac24bbbd1e5fb8d3e3c3b4b789fdc7d4" + ], + "data": "0x000000000000000000000000000000000000000000000000000000000012d687000000000000000000000000000000000000000000000000000000000012d688" + } + ] + } + }, + { + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea2", + "target_address": "contract_one", + "data": "0x2fb3c740", + "gas_limit": 44710, + "value": "0", + "expected": { + "status": 0, + "extra_message": "", + "gas_used": 44710, + "logs": [ + { + "address": "contract_one", + "topics": [ + "0x4558e87569f3778927a0c0ab7e6c04d9cc3a08694412ac6b8b8bbd8276c8fb3d" + ], + "data": "0x0000000000000000000000000000000000000000000000000000000000000001" + } + ] + } + } + ] +} \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/add/add.sol b/tests/xtvm_test/test_cases/add/add.sol new file mode 100644 index 000000000..742e9519e --- /dev/null +++ b/tests/xtvm_test/test_cases/add/add.sol @@ -0,0 +1,23 @@ +pragma solidity 0.6.4; + +contract xevm_test { + uint64 public global; + event catchAdd(uint64 a, uint64 b, uint64 c); + event catchAddOne(uint64 a, uint64 ret); + event catchGlobal(uint64 c); + + function add(uint64 a, uint64 b) public { + uint64 c = a + b; + emit catchAdd(a, b, c); + } + + function addOne(uint64 a) public { + uint64 b = a + 1; + emit catchAddOne(a, b); + } + + function addGlobal() public { + global = global + 1; + emit catchGlobal(global); + } +} diff --git a/tests/xtvm_test/test_cases/erc20/erc20.bin b/tests/xtvm_test/test_cases/erc20/erc20.bin new file mode 100644 index 000000000..9c50d9aa2 --- /dev/null +++ b/tests/xtvm_test/test_cases/erc20/erc20.bin @@ -0,0 +1 @@ +0x60806040526040518060400160405280600781526020017f4d794572633230000000000000000000000000000000000000000000000000008152506003908051906020019061004f92919061016a565b506040518060400160405280600381526020017f53594d00000000000000000000000000000000000000000000000000000000008152506004908051906020019061009b92919061016a565b506012600560006101000a81548160ff021916908360ff1602179055503480156100c457600080fd5b50620186a0600081905550600054600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055503373ffffffffffffffffffffffffffffffffffffffff167f60226e015dfa2f4684230d052fa02b7297d54471129f02a9585f4f4a81e9e0d26000546040518082815260200191505060405180910390a261020f565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106101ab57805160ff19168380011785556101d9565b828001600101855582156101d9579182015b828111156101d85782518255916020019190600101906101bd565b5b5090506101e691906101ea565b5090565b61020c91905b808211156102085760008160009055506001016101f0565b5090565b90565b610a5b8061021e6000396000f3fe608060405234801561001057600080fd5b506004361061009e5760003560e01c806342966c681161006657806342966c681461025457806370a082311461028257806395d89b41146102da578063a9059cbb1461035d578063dd62ed3e146103c35761009e565b806306fdde03146100a3578063095ea7b31461012657806318160ddd1461018c57806323b872dd146101aa578063313ce56714610230575b600080fd5b6100ab61043b565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100eb5780820151818401526020810190506100d0565b50505050905090810190601f1680156101185780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101726004803603604081101561013c57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506104d9565b604051808215151515815260200191505060405180910390f35b6101946105cb565b6040518082815260200191505060405180910390f35b610216600480360360608110156101c057600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506105d1565b604051808215151515815260200191505060405180910390f35b610238610767565b604051808260ff1660ff16815260200191505060405180910390f35b6102806004803603602081101561026a57600080fd5b810190808035906020019092919050505061077a565b005b6102c46004803603602081101561029857600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061083f565b6040518082815260200191505060405180910390f35b6102e2610857565b6040518080602001828103825283818151815260200191508051906020019080838360005b83811015610322578082015181840152602081019050610307565b50505050905090810190601f16801561034f5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6103a96004803603604081101561037357600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506108f5565b604051808215151515815260200191505060405180910390f35b610425600480360360408110156103d957600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610a00565b6040518082815260200191505060405180910390f35b60038054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156104d15780601f106104a6576101008083540402835291602001916104d1565b820191906000526020600020905b8154815290600101906020018083116104b457829003601f168201915b505050505081565b600081600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040518082815260200191505060405180910390a36001905092915050565b60005481565b600081600260008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254039250508190555081600160008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254039250508190555081600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825401925050819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a3600190509392505050565b600560009054906101000a900460ff1681565b80600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282540392505081905550806000808282540392505081905550600073ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a350565b60016020528060005260406000206000915090505481565b60048054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156108ed5780601f106108c2576101008083540402835291602001916108ed565b820191906000526020600020905b8154815290600101906020018083116108d057829003601f168201915b505050505081565b600081600160003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254039250508190555081600160008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825401925050819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040518082815260200191505060405180910390a36001905092915050565b600260205281600052604060002060205280600052604060002060009150915050548156fea2646970667358221220ef6dc905a974572d7d24ef729ced84f37fea828dfe571b8d82bd0a96b82ddabc64736f6c63430006040033 \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/erc20/erc20.json b/tests/xtvm_test/test_cases/erc20/erc20.json new file mode 100644 index 000000000..88bcfb082 --- /dev/null +++ b/tests/xtvm_test/test_cases/erc20/erc20.json @@ -0,0 +1,90 @@ +{ + "pre_data": {}, + "deploy_contract": [ + { + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea2", + "code_file_path": "erc20.bin", + "gas_limit": 746214, + "value": "0", + "expected": { + "status": 0, + "extra_message": "contract_one", + "gas_used": 746214, + "logs": [ + { + "address": "contract_one", + "topics": [ + "0x60226e015dfa2f4684230d052fa02b7297d54471129f02a9585f4f4a81e9e0d2", + "0x0000000000000000000000004dce5c8961e283786cb31ad7fc072347227d7ea2" + ], + "data": "0x00000000000000000000000000000000000000000000000000000000000186a0" + } + ] + } + } + ], + "test_cases": [ + { + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea2", + "target_address": "contract_one", + "data": "0x18160ddd", + "gas_limit": 23414, + "value": "0", + "expected": { + "status": 0, + "extra_message": "", + "gas_used": 23414, + "logs": [] + } + }, + { + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea2", + "target_address": "contract_one", + "data": "0x70a08231000000000000000000000000000000000000000000000000000000000000007b", + "gas_limit": 23695, + "value": "0", + "expected": { + "status": 0, + "extra_message": "", + "gas_used": 23695, + "logs": [] + } + }, + { + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea2", + "target_address": "contract_one", + "data": "0xa9059cbb000000000000000000000000000000000000000000000000000000000000007b0000000000000000000000000000000000000000000000000000000000003039", + "gas_limit": 50942, + "value": "0", + "expected": { + "status": 0, + "extra_message": "", + "gas_used": 50942, + "logs": [ + { + "address": "contract_one", + "topics": [ + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "0x0000000000000000000000004dce5c8961e283786cb31ad7fc072347227d7ea2", + "0x000000000000000000000000000000000000000000000000000000000000007b" + ], + "data": "0x0000000000000000000000000000000000000000000000000000000000003039" + } + ] + } + }, + { + "src_address": "T600044dce5c8961e283786cb31ad7fc072347227d7ea2", + "target_address": "contract_one", + "data": "0x70a08231000000000000000000000000000000000000000000000000000000000000007b", + "gas_limit": 23695, + "value": "0", + "expected": { + "status": 0, + "extra_message": "", + "gas_used": 23695, + "logs": [] + } + } + ] +} \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/erc20/erc20.sol b/tests/xtvm_test/test_cases/erc20/erc20.sol new file mode 100644 index 000000000..853a5db32 --- /dev/null +++ b/tests/xtvm_test/test_cases/erc20/erc20.sol @@ -0,0 +1,94 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.6.4; + +// https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.0.0/contracts/token/ERC20/IERC20.sol +interface InterfaceERC20 { + function totalSupply() external view returns (uint256); + + function balanceOf(address account) external view returns (uint256); + + function transfer(address recipient, uint256 amount) + external + returns (bool); + + function allowance(address owner, address spender) + external + view + returns (uint256); + + function approve(address spender, uint256 amount) external returns (bool); + + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + event Transfer(address indexed from, address indexed to, uint256 value); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); + event ERC20(address indexed owner, uint256 value); +} + +contract ERC20 is InterfaceERC20 { + uint256 public override totalSupply; + mapping(address => uint256) public override balanceOf; + mapping(address => mapping(address => uint256)) public override allowance; + string public name = "MyErc20"; + string public symbol = "SYM"; + uint8 public decimals = 18; + + constructor() public { + totalSupply = 100000; + balanceOf[msg.sender] = totalSupply; + emit ERC20(msg.sender, totalSupply); + } + + function transfer(address recipient, uint256 amount) + external + override + returns (bool) + { + balanceOf[msg.sender] -= amount; + balanceOf[recipient] += amount; + emit Transfer(msg.sender, recipient, amount); + return true; + } + + function approve(address spender, uint256 amount) + external + override + returns (bool) + { + allowance[msg.sender][spender] = amount; + emit Approval(msg.sender, spender, amount); + return true; + } + + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external override returns (bool) { + allowance[sender][msg.sender] -= amount; + balanceOf[sender] -= amount; + balanceOf[recipient] += amount; + emit Transfer(sender, recipient, amount); + return true; + } + + // function mint(uint256 amount) external { + // balanceOf[msg.sender] += amount; + // totalSupply += amount; + // emit Transfer(address(0), msg.sender, amount); + // } + + function burn(uint256 amount) external { + balanceOf[msg.sender] -= amount; + totalSupply -= amount; + emit Transfer(msg.sender, address(0), amount); + } +} diff --git a/tests/xtvm_test/test_cases/storage_set_zero/storage_set_zero.bin b/tests/xtvm_test/test_cases/storage_set_zero/storage_set_zero.bin new file mode 100644 index 000000000..ef4aada22 --- /dev/null +++ b/tests/xtvm_test/test_cases/storage_set_zero/storage_set_zero.bin @@ -0,0 +1 @@ +0x608060405260016000806101000a81548160ff021916908315150217905550600a60015534801561002f57600080fd5b506101bd8061003f6000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c806309cdcf9b146100465780630dbe671f146100625780634df7e3d014610080575b600080fd5b610060600480360381019061005b91906100fa565b61009e565b005b61006a6100a8565b6040516100779190610142565b60405180910390f35b6100886100b9565b604051610095919061016c565b60405180910390f35b8060018190555050565b60008054906101000a900460ff1681565b60015481565b600080fd5b6000819050919050565b6100d7816100c4565b81146100e257600080fd5b50565b6000813590506100f4816100ce565b92915050565b6000602082840312156101105761010f6100bf565b5b600061011e848285016100e5565b91505092915050565b60008115159050919050565b61013c81610127565b82525050565b60006020820190506101576000830184610133565b92915050565b610166816100c4565b82525050565b6000602082019050610181600083018461015d565b9291505056fea2646970667358221220717bd7ea17fe9f1ead170d773c838bc78fa87c1551dcef0e66202f7132706ff564736f6c634300080a0033 \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/storage_set_zero/storage_set_zero.json b/tests/xtvm_test/test_cases/storage_set_zero/storage_set_zero.json new file mode 100644 index 000000000..697e21694 --- /dev/null +++ b/tests/xtvm_test/test_cases/storage_set_zero/storage_set_zero.json @@ -0,0 +1,117 @@ +{ + "pre_data": {}, + "deploy_contract": [ + { + "src_address": "T60004001bdc8251890aafc5841b05620c0eab336e3ebc", + "code_file_path": "storage_set_zero.bin", + "gas_limit": 223041, + "value": "0", + "expected": { + "status": 0, + "extra_message": "contract_one", + "gas_used": 193948, + "logs": [] + } + } + ], + "test_cases": [ + { + "src_address": "T60004001bdc8251890aafc5841b05620c0eab336e3ebc", + "target_address": "contract_one", + "__comment": "get a", + "data": "0x0dbe671f", + "gas_limit": 30579, + "value": "0", + "expected": { + "status": 0, + "extra_message": "", + "gas_used": 23532, + "logs": [] + } + }, + { + "src_address": "T60004001bdc8251890aafc5841b05620c0eab336e3ebc", + "target_address": "contract_one", + "__comment": "set B = 0", + "data": "0x09cdcf9b0000000000000000000000000000000000000000000000000000000000000000", + "gas_limit": 30579, + "value": "0", + "expected": { + "status": 0, + "extra_message": "", + "gas_used": 21790, + "logs": [] + } + }, + { + "src_address": "T60004001bdc8251890aafc5841b05620c0eab336e3ebc", + "target_address": "contract_one", + "__comment": "get a", + "data": "0x0dbe671f", + "gas_limit": 30579, + "value": "0", + "expected": { + "status": 0, + "extra_message": "0x0000000000000000000000000000000000000000000000000000000000000001", + "gas_used": 23532, + "logs": [] + } + }, + { + "src_address": "T60004001bdc8251890aafc5841b05620c0eab336e3ebc", + "target_address": "contract_one", + "__comment": "get b", + "data": "0x4df7e3d0", + "gas_limit": 30579, + "value": "0", + "expected": { + "status": 0, + "extra_message": "0x0000000000000000000000000000000000000000000000000000000000000000", + "gas_used": 23515, + "logs": [] + } + }, + { + "src_address": "T60004001bdc8251890aafc5841b05620c0eab336e3ebc", + "target_address": "contract_one", + "__comment": "set B = 100", + "data": "0x09cdcf9b0000000000000000000000000000000000000000000000000000000000000064", + "gas_limit": 50258, + "value": "0", + "expected": { + "status": 0, + "extra_message": "", + "gas_used": 43702, + "logs": [] + } + }, + { + "src_address": "T60004001bdc8251890aafc5841b05620c0eab336e3ebc", + "target_address": "contract_one", + "__comment": "get b", + "data": "0x4df7e3d0", + "gas_limit": 30579, + "value": "0", + "expected": { + "status": 0, + "extra_message": "0x0000000000000000000000000000000000000000000000000000000000000064", + "gas_used": 23515, + "logs": [] + } + }, + { + "src_address": "T60004001bdc8251890aafc5841b05620c0eab336e3ebc", + "target_address": "contract_one", + "__comment": "get a", + "data": "0x0dbe671f", + "gas_limit": 30579, + "value": "0", + "expected": { + "status": 0, + "extra_message": "0x0000000000000000000000000000000000000000000000000000000000000001", + "gas_used": 23532, + "logs": [] + } + } + ] +} \ No newline at end of file diff --git a/tests/xtvm_test/test_cases/storage_set_zero/storage_set_zero.sol b/tests/xtvm_test/test_cases/storage_set_zero/storage_set_zero.sol new file mode 100644 index 000000000..42aad288e --- /dev/null +++ b/tests/xtvm_test/test_cases/storage_set_zero/storage_set_zero.sol @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-3.0 + +pragma solidity >=0.7.0 <0.9.0; + +contract Test1 { + bool public a = true; +} + +contract Test2 is Test1 { + uint256 public b = 10; + + function setB(uint256 c) public { + b = c; + } +} diff --git a/tests/xtvm_test/test_main.cpp b/tests/xtvm_test/test_main.cpp new file mode 100644 index 000000000..bdc675929 --- /dev/null +++ b/tests/xtvm_test/test_main.cpp @@ -0,0 +1,57 @@ +#include "xbase/xhash.h" +#include "xbase/xlog.h" +#include "xdata/xrootblock.h" +#include "xutility/xhash.h" + +#include + +#include + +#include "tests/xtvm_test/fixture/xtvm_test_fixture.h" + + +int tvm_tests_argc; +char ** tvm_tests_argv; + +using namespace std; +using namespace top; + +class xhashtest_t : public top::base::xhashplugin_t { +public: + xhashtest_t() + : top::base::xhashplugin_t(-1) //-1 = support every hash types + { + } + +private: + xhashtest_t(const xhashtest_t &); + xhashtest_t & operator=(const xhashtest_t &); + virtual ~xhashtest_t(){}; + +public: + virtual const std::string hash(const std::string & input, enum_xhash_type type) override { + auto hash = top::utl::xsha2_256_t::digest(input); + return std::string(reinterpret_cast(hash.data()), hash.size()); + } +}; + +int main(int argc, char ** argv) { + cout << "xtvm test main run" << endl; + + XMETRICS_INIT(); + + testing::InitGoogleTest(&argc, argv); + tvm_tests_argc = argc; + tvm_tests_argv = argv; + + xinit_log("./xtvm_test.log", true, true); + xset_log_level(enum_xlog_level_debug); + xdbg("------------------------------------------------------------------"); + xinfo("new log start here"); + + new xhashtest_t(); + top::data::xrootblock_para_t para; + top::data::xrootblock_t::init(para); + + return RUN_ALL_TESTS(); +} \ No newline at end of file diff --git a/tests/xtvm_test/test_tvm_cases_json.cpp b/tests/xtvm_test/test_tvm_cases_json.cpp new file mode 100644 index 000000000..93849e288 --- /dev/null +++ b/tests/xtvm_test/test_tvm_cases_json.cpp @@ -0,0 +1,9 @@ +#include "tests/xtvm_test/fixture/xtvm_test_fixture.h" + +NS_BEG3(top, tvm, tests) + +TEST_F(xtest_tvm_fixture, ALL_IN_ONE) { + execute(); +} + +NS_END3 From 46856e0cefeaa895fd90fc90049ac57bc6aeac9e Mon Sep 17 00:00:00 2001 From: "payton.wu" Date: Wed, 15 Mar 2023 15:30:01 +0800 Subject: [PATCH 4/4] fix compiling error in release mode. --- src/xtopcom/xtvm_runtime/src/xtvm_action_runner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xtopcom/xtvm_runtime/src/xtvm_action_runner.cpp b/src/xtopcom/xtvm_runtime/src/xtvm_action_runner.cpp index ece6b3480..25c642eb5 100644 --- a/src/xtopcom/xtvm_runtime/src/xtvm_action_runner.cpp +++ b/src/xtopcom/xtvm_runtime/src/xtvm_action_runner.cpp @@ -32,7 +32,7 @@ evm_common::xevm_transaction_result_t xtop_vm_action_runner::execute_action(std: // fetch result auto return_result_bytes = logic_ptr->get_return_value(); - xdbg("xtop_vm_action_runner::execute_action result %s return_bytes_size: %zu", bool_result ? "success" : "fail", return_result_bytes.size()); + xinfo("xtop_vm_action_runner::execute_action result %s return_bytes_size: %zu", bool_result ? "success" : "fail", return_result_bytes.size()); tvm_import_instance::instance()->remove_logic();