Skip to content

Commit

Permalink
fix unittest compile error, explicit set inlina action size to 4kB
Browse files Browse the repository at this point in the history
  • Loading branch information
taokayan committed Oct 12, 2023
1 parent 922ec30 commit 8a92bd9
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,5 @@ target_compile_options(evm_runtime PUBLIC --no-missing-ricardian-clause)
if (WITH_LARGE_STACK)
target_link_options(evm_runtime PUBLIC --stack-size=50000000)
else()
target_link_options(evm_runtime PUBLIC --stack-size=37600)
target_link_options(evm_runtime PUBLIC --stack-size=36000)
endif()
4 changes: 3 additions & 1 deletion tests/admin_actions_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ BOOST_FIXTURE_TEST_CASE(setkvstore_tests, admin_action_tester) try {
const int64_t to_bridge = 1000000;
transfer_token("alice"_n, evm_account_name, make_asset(to_bridge), evm1.address_0x());

auto [contract_addr, contract_account_id] = deploy_simple_contract(evm1);
evmc::address contract_addr;
uint64_t contract_account_id;
std::tie(contract_addr, contract_account_id) = deploy_simple_contract(evm1);

// Call method "setval" on simple contract (sha3('setval(uint256)') = 0x559c9c4a)
auto txn = generate_tx(contract_addr, 0, 500'000);
Expand Down
2 changes: 1 addition & 1 deletion tests/basic_evm_tester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ balance_and_dust::operator intx::uint256() const
struct vault_balance_row
{
name owner;
asset balance;
asset balance{};
uint64_t dust = 0;
};

Expand Down
130 changes: 125 additions & 5 deletions tests/basic_evm_tester.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ struct account_object
std::optional<uint32_t> flags;

inline bool has_flag(flag f)const {
return (flags.has_value() && flags.value() & static_cast<uint32_t>(f) != 0);
return (flags.has_value() && (flags.value() & static_cast<uint32_t>(f)) != 0);
}
};

Expand Down Expand Up @@ -201,10 +201,125 @@ class evm_eoa
};

struct vault_balance_row;
class basic_evm_tester : public testing::validating_tester
class evm_validating_tester : public testing::base_tester {
public:
virtual ~evm_validating_tester() {
if( !validating_node ) {
elog( "~evm_validating_tester() called with empty validating_node; likely in the middle of failure" );
return;
}
try {
if( num_blocks_to_producer_before_shutdown > 0 )
produce_blocks( num_blocks_to_producer_before_shutdown );
if (!skip_validate && std::uncaught_exceptions() == 0)
BOOST_CHECK_EQUAL( validate(), true );
} catch( const fc::exception& e ) {
wdump((e.to_detail_string()));
}
}
controller::config vcfg;

evm_validating_tester(const flat_set<account_name>& trusted_producers = flat_set<account_name>(), deep_mind_handler* dmlog = nullptr, testing::setup_policy p = testing::setup_policy::full) {
auto def_conf = default_config(tempdir, 4096 /* genesis_max_inline_action_size max inline action size*/);

vcfg = def_conf.first;
config_validator(vcfg);
vcfg.trusted_producers = trusted_producers;

validating_node = create_validating_node(vcfg, def_conf.second, true, dmlog);

init(def_conf.first, def_conf.second);
execute_setup_policy(p);
}

static void config_validator(controller::config& vcfg) {
FC_ASSERT( vcfg.blocks_dir.filename().generic_string() != "."
&& vcfg.state_dir.filename().generic_string() != ".", "invalid path names in controller::config" );

vcfg.blocks_dir = vcfg.blocks_dir.parent_path() / std::string("v_").append( vcfg.blocks_dir.filename().generic_string() );
vcfg.state_dir = vcfg.state_dir.parent_path() / std::string("v_").append( vcfg.state_dir.filename().generic_string() );

vcfg.contracts_console = false;
}

static unique_ptr<controller> create_validating_node(controller::config vcfg, const genesis_state& genesis, bool use_genesis, deep_mind_handler* dmlog = nullptr) {
unique_ptr<controller> validating_node = std::make_unique<controller>(vcfg, testing::make_protocol_feature_set(), genesis.compute_chain_id());
validating_node->add_indices();
if(dmlog)
{
validating_node->enable_deep_mind(dmlog);
}
if (use_genesis) {
validating_node->startup( [](){}, []() { return false; }, genesis );
}
else {
validating_node->startup( [](){}, []() { return false; } );
}
return validating_node;
}

signed_block_ptr produce_block( fc::microseconds skip_time = fc::milliseconds(config::block_interval_ms) )override {
auto sb = _produce_block(skip_time, false);
auto bsf = validating_node->create_block_state_future( sb->calculate_id(), sb );
controller::block_report br;
validating_node->push_block( br, bsf.get(), forked_branch_callback{}, trx_meta_cache_lookup{} );

return sb;
}

signed_block_ptr produce_block_no_validation( fc::microseconds skip_time = fc::milliseconds(config::block_interval_ms) ) {
return _produce_block(skip_time, false);
}

void validate_push_block(const signed_block_ptr& sb) {
auto bsf = validating_node->create_block_state_future( sb->calculate_id(), sb );
controller::block_report br;
validating_node->push_block( br, bsf.get(), forked_branch_callback{}, trx_meta_cache_lookup{} );
}

signed_block_ptr produce_empty_block( fc::microseconds skip_time = fc::milliseconds(config::block_interval_ms) )override {
unapplied_transactions.add_aborted( control->abort_block() );
auto sb = _produce_block(skip_time, true);
auto bsf = validating_node->create_block_state_future( sb->calculate_id(), sb );
controller::block_report br;
validating_node->push_block( br, bsf.get(), forked_branch_callback{}, trx_meta_cache_lookup{} );

return sb;
}

signed_block_ptr finish_block()override {
return _finish_block();
}

bool validate() {


auto hbh = control->head_block_state()->header;
auto vn_hbh = validating_node->head_block_state()->header;
bool ok = control->head_block_id() == validating_node->head_block_id() &&
hbh.previous == vn_hbh.previous &&
hbh.timestamp == vn_hbh.timestamp &&
hbh.transaction_mroot == vn_hbh.transaction_mroot &&
hbh.action_mroot == vn_hbh.action_mroot &&
hbh.producer == vn_hbh.producer;

validating_node.reset();
validating_node = std::make_unique<controller>(vcfg, testing::make_protocol_feature_set(), control->get_chain_id());
validating_node->add_indices();
validating_node->startup( [](){}, []() { return false; } );

return ok;
}

unique_ptr<controller> validating_node;
uint32_t num_blocks_to_producer_before_shutdown = 0;
bool skip_validate = false;
};

class basic_evm_tester : public evm_validating_tester
{
public:
using testing::validating_tester::push_action;
using evm_validating_tester::push_action;

static constexpr name token_account_name = "eosio.token"_n;
static constexpr name faucet_account_name = "faucet"_n;
Expand Down Expand Up @@ -244,6 +359,11 @@ class basic_evm_tester : public testing::validating_tester
const std::optional<asset> ingress_bridge_fee = std::nullopt,
const bool also_prepare_self_balance = true);

template <typename... T>
void start_block(T... t) {
evm_validating_tester::_start_block(t...);
}

void prepare_self_balance(uint64_t fund_amount = 100'0000);

config_table_row get_config() const;
Expand Down Expand Up @@ -355,14 +475,14 @@ inline constexpr intx::uint256 operator"" _ether(const char* s)
}

template <typename Tester>
class speculative_block_starter
class speculative_block_starter
{
public:
// Assumes user will not abort or finish blocks using the tester passed into the constructor for the lifetime of this
// object.
explicit speculative_block_starter(Tester& tester, uint32_t time_gap_sec = 0) : t(tester)
{
t.control->start_block(t.control->head_block_time() + fc::milliseconds(500 + 1000 * time_gap_sec), 0);
t.start_block(t.control->head_block_time() + fc::milliseconds(500 + 1000 * time_gap_sec));
}

speculative_block_starter(speculative_block_starter&& other) : t(other.t) { other.canceled = true; }
Expand Down
2 changes: 1 addition & 1 deletion tests/mapping_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ try {

// Now actually commit the init action into a block to do further testing on top of that state in later blocks.
{
control->start_block(control->head_block_time() + fc::milliseconds(500), 0);
this->_start_block(control->head_block_time() + fc::milliseconds(500));
BOOST_REQUIRE_EQUAL(control->pending_block_time().sec_since_epoch(), bm.genesis_timestamp);

init();
Expand Down

0 comments on commit 8a92bd9

Please sign in to comment.