9#include <boost/test/unit_test.hpp>
10#include <boost/tuple/tuple_io.hpp>
15#define REQUIRE_EQUAL_OBJECTS(left, right) { auto a = fc::variant( left ); auto b = fc::variant( right ); BOOST_REQUIRE_EQUAL( true, a.is_object() ); \
16 BOOST_REQUIRE_EQUAL( true, b.is_object() ); \
17 BOOST_REQUIRE_EQUAL_COLLECTIONS( a.get_object().begin(), a.get_object().end(), b.get_object().begin(), b.get_object().end() ); }
19#define REQUIRE_MATCHING_OBJECT(left, right) { auto a = fc::variant( left ); auto b = fc::variant( right ); BOOST_REQUIRE_EQUAL( true, a.is_object() ); \
20 BOOST_REQUIRE_EQUAL( true, b.is_object() ); \
21 auto filtered = ::sysio::testing::filter_fields( a.get_object(), b.get_object() ); \
22 BOOST_REQUIRE_EQUAL_COLLECTIONS( a.get_object().begin(), a.get_object().end(), filtered.begin(), filtered.end() ); }
32namespace boost {
namespace test_tools {
namespace tt_detail {
35 struct print_log_value<
fc::variant> {
38 ::operator<<( osm, v );
43 struct print_log_value<
fc::variant_object> {
46 ::operator<<( osm, v );
51 struct print_log_value<
fc::variant_object::entry> {
54 ::operator<<( osm, e );
70 std::vector<uint8_t>
read_wasm(
const char* fn );
71 std::vector<char>
read_abi(
const char* fn );
109 auto json = std::string(
"{\"origin\":\"https://") +
111 "\",\"type\":\"webauthn.get\",\"challenge\":\"" +
114 std::vector<uint8_t> auth_data(37);
119 e.
write((
char*)auth_data.data(), auth_data.size());
120 e.
write(client_data_hash.data(), client_data_hash.data_size());
123 char serialized_sig[4096];
157 void init(
const setup_policy policy =
setup_policy::full,
db_read_mode read_mode = db_read_mode::SPECULATIVE, std::optional<uint32_t> genesis_max_inline_action_size = std::optional<uint32_t>{}, std::optional<uint32_t> config_max_nonprivileged_inline_action_size = std::optional<uint32_t>{});
167 template <
typename Lambda>
174 void open( std::optional<chain_id_type> expected_chain_id = {} );
236 bool include_code =
true
240 traces.reserve(names.size());
241 for(
auto n : names ) traces.emplace_back(
create_account( n, config::system_account_name,
multisig, include_code ) );
257 permission_name parent,
const vector<permission_level>& auths,
const vector<private_key_type>& keys );
266 bool include_code =
true
277 template<
typename ObjectType>
282 template<
typename ObjectType,
typename IndexBy,
typename... Args>
283 const auto&
get( Args&&... args ) {
284 return control->db().get<ObjectType,IndexBy>( forward<Args>(args)... );
287 template<
typename ObjectType,
typename IndexBy,
typename... Args>
288 const auto*
find( Args&&... args ) {
289 return control->db().find<ObjectType,IndexBy>( forward<Args>(args)... );
292 template<
typename KeyType = fc::ecc::private_key_shim >
295 if constexpr (std::is_same_v<KeyType, mock::webauthn_private_key>) {
302 template<
typename KeyType = fc::ecc::private_key_shim >
315 const symbol& asset_symbol,
340 return [
this](
const account_name&
name ) -> std::optional<abi_serializer> {
347 return std::optional<abi_serializer>();
357 template<
typename Object>
359 auto* maybe_tid =
find_table(code, scope, table);
360 if( maybe_tid ==
nullptr ) {
361 BOOST_FAIL(
"table for code=\"" + code.to_string()
363 +
"\" table=\"" + table.to_string()
364 +
"\" does not exist" );
370 BOOST_FAIL(
"object does not exist for primary_key=\"" +
name(key).
to_string() +
"\"");
391 genesis.initial_key =
get_public_key( config::system_account_name,
"active" );
396 static std::pair<controller::config, genesis_state>
default_config(
const fc::temp_directory&
tempdir, std::optional<uint32_t> genesis_max_inline_action_size = std::optional<uint32_t>{}, std::optional<uint32_t> config_max_nonprivileged_inline_action_size = std::optional<uint32_t>{}) {
405 for(
int i = 0; i < boost::unit_test::framework::master_test_suite().argc; ++i) {
406 if(boost::unit_test::framework::master_test_suite().
argv[i] == std::string(
"--sys-vm"))
408 else if(boost::unit_test::framework::master_test_suite().
argv[i] == std::string(
"--sys-vm-jit"))
410 else if(boost::unit_test::framework::master_test_suite().
argv[i] == std::string(
"--sys-vm-oc"))
414 if (genesis_max_inline_action_size) {
415 gen.initial_configuration.max_inline_action_size = *genesis_max_inline_action_size;
417 if (config_max_nonprivileged_inline_action_size) {
426 bool no_throw, std::vector<transaction_trace_ptr>& traces );
450 tester(
setup_policy policy =
setup_policy::full,
db_read_mode read_mode = db_read_mode::SPECULATIVE, std::optional<uint32_t> genesis_max_inline_action_size = std::optional<uint32_t>{}, std::optional<uint32_t> config_max_nonprivileged_inline_action_size = std::optional<uint32_t>{}) {
451 init(policy, read_mode, genesis_max_inline_action_size, config_max_nonprivileged_inline_action_size);
468 cfg = def_conf.first;
478 template <
typename Lambda>
481 cfg = def_conf.first;
514 elog(
"~validating_tester() called with empty validating_node; likely in the middle of failure" );
521 BOOST_REQUIRE_EQUAL(
validate(),
true );
531 vcfg = def_conf.first;
537 init(def_conf.first, def_conf.second);
569 vcfg = def_conf.first;
574 init(def_conf.first, def_conf.second);
577 init(def_conf.first);
581 template <
typename Lambda>
584 conf_edit(def_conf.first);
585 vcfg = def_conf.first;
590 init(def_conf.first, def_conf.second);
593 init(def_conf.first);
630 auto hbh =
control->head_block_state()->header;
633 hbh.previous == vn_hbh.previous &&
634 hbh.timestamp == vn_hbh.timestamp &&
635 hbh.transaction_mroot == vn_hbh.transaction_mroot &&
636 hbh.action_mroot == vn_hbh.action_mroot &&
637 hbh.producer == vn_hbh.producer;
683 bool operator()(
const fc::assert_exception& ex );
695 bool operator()(
const fc::assert_exception& ex );
705 :
expected(
"assertion failure with message: " ) {
709 bool operator()(
const sysio_assert_message_exception& ex );
719 :
expected(
"assertion failure with message: " ) {
723 bool operator()(
const sysio_assert_message_exception& ex );
733 :
expected(
"assertion failure with error code: " ) {
734 expected.append( std::to_string(error_code) );
737 bool operator()(
const sysio_assert_code_exception& ex );
static private_key regenerate(const typename KeyType::data_type &data)
an elliptic curve private key.
public_key get_public_key() const
compact_signature sign_compact(const fc::sha256 &digest) const
static private_key regenerate(const fc::sha256 &secret)
public_key_data serialize() const
Used to generate a useful error report when an exception is thrown.
std::string to_detail_string(log_level ll=log_level::all) const
fc::path parent_path() const
fc::path filename() const
std::string generic_string() const
void write(const char *d, uint32_t dlen)
static sha256 hash(const char *d, uint32_t dlen)
const char * data() const
const fc::path & path() const
static time_point from_iso_string(const fc::string &s)
static constexpr time_point maximum()
An order-preserving dictionary of variants.
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
The table_id_object class tracks the mapping of (scope, code, table) to an opaque identifier.
void add_aborted(std::vector< transaction_metadata_ptr > aborted_trxs)
virtual signed_block_ptr finish_block()=0
static std::pair< controller::config, genesis_state > default_config(const fc::temp_directory &tempdir, std::optional< uint32_t > genesis_max_inline_action_size=std::optional< uint32_t >{}, std::optional< uint32_t > config_max_nonprivileged_inline_action_size=std::optional< uint32_t >{})
void produce_min_num_of_blocks_to_spend_time_wo_inactive_prod(const fc::microseconds target_elapsed_time=fc::microseconds())
vector< char > get_row_by_account(name code, name scope, name table, const account_name &act) const
transaction_trace_ptr transfer(account_name from, account_name to, asset amount, string memo, account_name currency)
std::map< chain::public_key_type, chain::private_key_type > block_signing_private_keys
static uint64_t to_uint64(fc::variant x)
transaction_trace_ptr push_reqauth(account_name from, const vector< permission_level > &auths, const vector< private_key_type > &keys)
void produce_blocks_for_n_rounds(const uint32_t num_of_rounds=1)
action get_action(account_name code, action_name acttype, vector< permission_level > auths, const variant_object &data) const
void delete_authority(account_name account, permission_name perm, const vector< permission_level > &auths, const vector< private_key_type > &keys)
static const fc::microseconds abi_serializer_max_time
map< account_name, block_id_type > get_last_produced_block_map() const
virtual signed_block_ptr produce_block(fc::microseconds skip_time=fc::milliseconds(config::block_interval_ms))=0
transaction_trace_ptr set_producers_legacy(const vector< account_name > &producer_names)
static genesis_state default_genesis()
transaction_trace_ptr set_producer_schedule(const vector< producer_authority > &schedule)
static const uint32_t DEFAULT_BILLED_CPU_TIME_US
static vector< uint8_t > to_uint8_vector(const string &s)
action_result push_action(action &&cert_act, uint64_t authorizer)
virtual signed_block_ptr produce_empty_block(fc::microseconds skip_time=fc::milliseconds(config::block_interval_ms))=0
transaction_trace_ptr push_transaction(packed_transaction &trx, fc::time_point deadline=fc::time_point::maximum(), uint32_t billed_cpu_time_us=DEFAULT_BILLED_CPU_TIME_US)
static auto get_private_key(name keyname, string role="owner")
void execute_setup_policy(const setup_policy policy)
vector< transaction_id_type > get_scheduled_transactions() const
void _start_block(fc::time_point block_time)
transaction_trace_ptr create_account(account_name name, account_name creator=config::system_account_name, bool multisig=false, bool include_code=true)
void push_block(signed_block_ptr b)
unapplied_transaction_queue & get_unapplied_transaction_queue()
bool get_table_entry(Object &obj, account_name code, account_name scope, account_name table, uint64_t key, bool require=true)
unapplied_transaction_queue unapplied_transactions
transaction_trace_ptr issue(account_name to, string amount, account_name currency, string memo)
void set_before_preactivate_bios_contract()
void sync_with(base_tester &other)
bool is_same_chain(base_tester &other)
map< transaction_id_type, transaction_receipt > chain_transactions
vector< producer_authority > get_producer_authorities(const vector< account_name > &producer_names) const
static const uint32_t DEFAULT_EXPIRATION_DELTA
signed_block_ptr _produce_block(fc::microseconds skip_time, bool skip_pending_trxs)
void set_code(account_name name, const char *wast, const private_key_type *signer=nullptr)
void unlink_authority(account_name account, account_name code, action_name type={})
const auto * find(Args &&... args)
static string to_string(fc::variant x)
void set_code(account_name name, const vector< uint8_t > wasm, const private_key_type *signer=nullptr)
void link_authority(account_name account, account_name code, permission_name req, action_name type={})
const auto & get(Args &&... args)
vector< transaction_trace_ptr > create_accounts(vector< account_name > names, bool multisig=false, bool include_code=true)
transaction_trace_ptr push_dummy(account_name from, const string &v="blah", uint32_t billed_cpu_time_us=DEFAULT_BILLED_CPU_TIME_US)
void produce_blocks(uint32_t n=1, bool empty=false)
unique_ptr< controller > control
map< account_name, block_id_type > last_produced_block
transaction_trace_ptr set_producers(const vector< account_name > &producer_names)
void preactivate_all_builtin_protocol_features()
void preactivate_builtin_protocol_features(const std::vector< builtin_protocol_feature_t > &features)
static action_result wasm_assert_code(uint64_t error_code)
void set_last_produced_block_map(const map< account_name, block_id_type > &lpb)
bool chain_has_transaction(const transaction_id_type &txid) const
const auto & get(const chainbase::oid< ObjectType > &key)
fc::temp_directory tempdir
vector< digest_type > protocol_features_to_be_activated_wo_preactivation
void set_before_producer_authority_bios_contract()
asset get_currency_balance(const account_name &contract, const symbol &asset_symbol, const account_name &account) const
void schedule_protocol_features_wo_preactivation(const vector< digest_type > feature_digests)
void produce_blocks_until_end_of_round()
signed_block_ptr _finish_block()
void set_abi(account_name name, const char *abi_json, const private_key_type *signer=nullptr)
static action_result error(const string &msg)
void preactivate_protocol_features(const vector< digest_type > feature_digests)
void set_transaction_headers(transaction &trx, uint32_t expiration=DEFAULT_EXPIRATION_DELTA, uint32_t delay_sec=0) const
const table_id_object * find_table(name code, name scope, name table)
static auto get_public_key(name keyname, string role="owner")
const controller::config & get_config() const
static action_result wasm_assert_msg(const string &msg)
void open(protocol_feature_set &&pfs, std::optional< chain_id_type > expected_chain_id, Lambda lambda)
static action_result success()
const transaction_receipt & get_transaction_receipt(const transaction_id_type &txid) const
void set_authority(account_name account, permission_name perm, authority auth, permission_name parent, const vector< permission_level > &auths, const vector< private_key_type > &keys)
provides utility function to simplify the creation of unit tests
signed_block_ptr produce_empty_block(fc::microseconds skip_time=fc::milliseconds(config::block_interval_ms)) override
tester(const fc::temp_directory &tempdir, bool use_genesis)
tester(controller::config config)
signed_block_ptr produce_block(fc::microseconds skip_time=fc::milliseconds(config::block_interval_ms)) override
tester(controller::config config, protocol_feature_set &&pfs, const genesis_state &genesis)
tester(controller::config config, const genesis_state &genesis)
tester(setup_policy policy=setup_policy::full, db_read_mode read_mode=db_read_mode::SPECULATIVE, std::optional< uint32_t > genesis_max_inline_action_size=std::optional< uint32_t >{}, std::optional< uint32_t > config_max_nonprivileged_inline_action_size=std::optional< uint32_t >{})
signed_block_ptr finish_block() override
tester(const fc::temp_directory &tempdir, Lambda conf_edit, bool use_genesis)
validating_tester(const fc::temp_directory &tempdir, Lambda conf_edit, bool use_genesis)
unique_ptr< controller > validating_node
validating_tester(const fc::temp_directory &tempdir, bool use_genesis)
signed_block_ptr produce_empty_block(fc::microseconds skip_time=fc::milliseconds(config::block_interval_ms)) override
signed_block_ptr produce_block_no_validation(fc::microseconds skip_time=fc::milliseconds(config::block_interval_ms))
uint32_t num_blocks_to_producer_before_shutdown
void validate_push_block(const signed_block_ptr &sb)
signed_block_ptr finish_block() override
signed_block_ptr produce_block(fc::microseconds skip_time=fc::milliseconds(config::block_interval_ms)) override
validating_tester(const flat_set< account_name > &trusted_producers=flat_set< account_name >(), deep_mind_handler *dmlog=nullptr)
static unique_ptr< controller > create_validating_node(controller::config vcfg, const genesis_state &genesis, bool use_genesis, deep_mind_handler *dmlog=nullptr)
virtual ~validating_tester()
static void config_validator(controller::config &vcfg)
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
#define FC_RETHROW_EXCEPTIONS(LOG_LEVEL, FORMAT,...)
Catchs all exception's, std::exceptions, and ... and rethrows them after appending the provided log m...
void unpack(Stream &s, std::deque< T > &value)
void pack(Stream &s, const std::deque< T > &value)
fc::sha256 digest(const T &value)
std::string base64url_encode(unsigned char const *bytes_to_encode, unsigned int in_len)
constexpr microseconds milliseconds(int64_t s)
constexpr std::size_t get_index()
fc::crypto::public_key public_key_type
std::shared_ptr< transaction_trace > transaction_trace_ptr
sysio::chain::action_name action_name
std::shared_ptr< signed_block > signed_block_ptr
std::shared_ptr< snapshot_reader > snapshot_reader_ptr
std::function< transaction_metadata_ptr(const transaction_id_type &)> trx_meta_cache_lookup
std::function< void(const branch_type &)> forked_branch_callback
void copy_row(const chain::key_value_object &obj, vector< char > &data)
std::string read_wast(const char *fn)
fc::variant read_json_snapshot(const char *fn)
std::string read_binary_snapshot(const char *fn)
protocol_feature_set make_protocol_feature_set(const subjective_restriction_map &custom_subjective_restrictions={})
bool expect_assert_message(const fc::exception &ex, string expected)
@ preactivate_feature_only
@ preactivate_feature_and_new_bios
std::map< builtin_protocol_feature_t, protocol_feature_subjective_restrictions > subjective_restriction_map
fc::variant_object filter_fields(const fc::variant_object &filter, const fc::variant_object &value)
std::vector< uint8_t > read_wasm(const char *fn)
std::vector< char > read_abi(const char *fn)
unsigned __int64 uint64_t
void operator()(std::ostream &osm, const fc::variant_object::entry &e)
static yield_function_t create_yield_function(const fc::microseconds &max_serialization_time)
static bool to_abi(const Vec &abi_vec, abi_def &abi)
uint32_t max_nonprivileged_inline_action_size
eosvmoc::config eosvmoc_config
uint64_t state_guard_size
flat_set< account_name > trusted_producers
wasm_interface::vm_type wasm_runtime
time_point initial_timestamp
Immutable except for fc::from_variant.
std::string to_string() const
bool operator()(const fc::assert_exception &ex)
fc_assert_exception_message_is(const string &msg)
fc_assert_exception_message_starts_with(const string &msg)
bool operator()(const fc::assert_exception &ex)
bool operator()(const fc::exception &ex)
fc_exception_message_is(const string &msg)
bool operator()(const fc::exception &ex)
fc_exception_message_starts_with(const string &msg)
static auto regenerate(const fc::sha256 &secret)
webauthn_private_key(webauthn_private_key &&)=default
static const fc::sha256 _origin_hash
webauthn_private_key(const webauthn_private_key &)=default
webauthn_private_key(r1::private_key &&priv_key)
static const std::string _origin
public_key get_public_key(webauthn::public_key::user_presence_t presence=webauthn::public_key::user_presence_t::USER_PRESENCE_NONE) const
signature sign(const sha256 &digest, bool=true) const
bool operator()(const sysio_assert_code_exception &ex)
sysio_assert_code_is(uint64_t error_code)
sysio_assert_message_is(const string &msg)
bool operator()(const sysio_assert_message_exception &ex)
sysio_assert_message_starts_with(const string &msg)
bool operator()(const sysio_assert_message_exception &ex)
sysio::chain::asset core_from_string(const std::string &s)
std::ostream & operator<<(std::ostream &osm, const fc::variant &v)
sysio::testing
void bsf(const Reg ®, const Operand &op)
memcpy((char *) pInfo->slotDescription, s, l)