Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
tester.hpp
Go to the documentation of this file.
1#pragma once
8#include <fc/io/json.hpp>
9#include <boost/test/unit_test.hpp>
10#include <boost/tuple/tuple_io.hpp>
11
12#include <iosfwd>
13#include <optional>
14
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() ); }
18
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() ); }
23
24std::ostream& operator<<( std::ostream& osm, const fc::variant& v );
25
26std::ostream& operator<<( std::ostream& osm, const fc::variant_object& v );
27
28std::ostream& operator<<( std::ostream& osm, const fc::variant_object::entry& e );
29
30sysio::chain::asset core_from_string(const std::string& s);
31
32namespace boost { namespace test_tools { namespace tt_detail {
33
34 template<>
35 struct print_log_value<fc::variant> {
36 void operator()( std::ostream& osm, const fc::variant& v )
37 {
38 ::operator<<( osm, v );
39 }
40 };
41
42 template<>
43 struct print_log_value<fc::variant_object> {
44 void operator()( std::ostream& osm, const fc::variant_object& v )
45 {
46 ::operator<<( osm, v );
47 }
48 };
49
50 template<>
51 struct print_log_value<fc::variant_object::entry> {
52 void operator()( std::ostream& osm, const fc::variant_object::entry& e )
53 {
54 ::operator<<( osm, e );
55 }
56 };
57
58} } }
59
60namespace sysio { namespace testing {
69
70 std::vector<uint8_t> read_wasm( const char* fn );
71 std::vector<char> read_abi( const char* fn );
72 std::string read_wast( const char* fn );
73
74 std::string read_binary_snapshot( const char* fn );
75 fc::variant read_json_snapshot( const char* fn );
76
77 using namespace sysio::chain;
78
80
81 void copy_row(const chain::key_value_object& obj, vector<char>& data);
82
83 bool expect_assert_message(const fc::exception& ex, string expected);
84
85 using subjective_restriction_map = std::map<builtin_protocol_feature_t, protocol_feature_subjective_restrictions>;
86
87 protocol_feature_set make_protocol_feature_set(const subjective_restriction_map& custom_subjective_restrictions = {});
88
89 namespace mock {
90 using namespace fc::crypto;
96
99
100 static auto regenerate(const fc::sha256& secret) {
102 }
103
104 public_key get_public_key(webauthn::public_key::user_presence_t presence = webauthn::public_key::user_presence_t::USER_PRESENCE_NONE) const {
106 }
107
108 signature sign( const sha256& digest, bool = true) const {
109 auto json = std::string("{\"origin\":\"https://") +
110 _origin +
111 "\",\"type\":\"webauthn.get\",\"challenge\":\"" +
113 "\"}";
114 std::vector<uint8_t> auth_data(37);
115 memcpy(auth_data.data(), _origin_hash.data(), sizeof(_origin_hash));
116
117 auto client_data_hash = fc::sha256::hash(json);
119 e.write((char*)auth_data.data(), auth_data.size());
120 e.write(client_data_hash.data(), client_data_hash.data_size());
121 auto sig = priv_key.sign_compact(e.result());
122
123 char serialized_sig[4096];
124 datastream<char*> sig_ds(serialized_sig, sizeof(serialized_sig));
126 fc::raw::pack(sig_ds, sig);
127 fc::raw::pack(sig_ds, auth_data);
128 fc::raw::pack(sig_ds, json);
129 sig_ds.seekp(0);
130
132 fc::raw::unpack(sig_ds, ret);
133 return ret;
134 }
135
137 static const std::string _origin;
139 };
140 }
141
147 public:
148 typedef string action_result;
149
151
154
155 virtual ~base_tester() {};
156
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>{});
158 void init(controller::config config, const snapshot_reader_ptr& snapshot);
159 void init(controller::config config, const genesis_state& genesis);
164 void execute_setup_policy(const setup_policy policy);
165
166 void close();
167 template <typename Lambda>
168 void open( protocol_feature_set&& pfs, std::optional<chain_id_type> expected_chain_id, Lambda lambda );
169 void open( protocol_feature_set&& pfs, const snapshot_reader_ptr& snapshot );
170 void open( protocol_feature_set&& pfs, const genesis_state& genesis );
171 void open( protocol_feature_set&& pfs, std::optional<chain_id_type> expected_chain_id = {} );
172 void open( const snapshot_reader_ptr& snapshot );
173 void open( const genesis_state& genesis );
174 void open( std::optional<chain_id_type> expected_chain_id = {} );
175 bool is_same_chain( base_tester& other );
176
177 virtual signed_block_ptr produce_block( fc::microseconds skip_time = fc::milliseconds(config::block_interval_ms) ) = 0;
178 virtual signed_block_ptr produce_empty_block( fc::microseconds skip_time = fc::milliseconds(config::block_interval_ms) ) = 0;
180 // produce one block and return traces for all applied transactions, both failed and executed
181 signed_block_ptr produce_block( std::vector<transaction_trace_ptr>& traces );
182 void produce_blocks( uint32_t n = 1, bool empty = false );
184 void produce_blocks_for_n_rounds(const uint32_t num_of_rounds = 1);
185 // Produce minimal number of blocks as possible to spend the given time without having any producer become inactive
188
200
203
204 [[nodiscard]]
205 action_result push_action(action&& cert_act, uint64_t authorizer); // TODO/QUESTION: Is this needed?
206
208 const action_name& acttype,
209 const account_name& actor,
210 const variant_object& data,
212 uint32_t delay_sec = 0 );
214 const action_name& acttype,
215 const vector<account_name>& actors,
216 const variant_object& data,
218 uint32_t delay_sec = 0 );
220 const action_name& acttype,
221 const vector<permission_level>& auths,
222 const variant_object& data,
224 uint32_t delay_sec = 0 );
225
226
228 const variant_object& data )const;
229
232 uint32_t delay_sec = 0 )const;
233
235 bool multisig = false,
236 bool include_code = true
237 )
238 {
240 traces.reserve(names.size());
241 for( auto n : names ) traces.emplace_back( create_account( n, config::system_account_name, multisig, include_code ) );
242 return traces;
243 }
244
247 void set_bios_contract();
248
253
254 void link_authority( account_name account, account_name code, permission_name req, action_name type = {} );
255 void unlink_authority( account_name account, account_name code, action_name type = {} );
256 void set_authority( account_name account, permission_name perm, authority auth,
257 permission_name parent, const vector<permission_level>& auths, const vector<private_key_type>& keys );
258 void set_authority( account_name account, permission_name perm, authority auth,
259 permission_name parent = config::owner_name );
260 void delete_authority( account_name account, permission_name perm, const vector<permission_level>& auths, const vector<private_key_type>& keys );
261 void delete_authority( account_name account, permission_name perm );
262
264 account_name creator = config::system_account_name,
265 bool multisig = false,
266 bool include_code = true
267 );
268
269 transaction_trace_ptr push_reqauth( account_name from, const vector<permission_level>& auths, const vector<private_key_type>& keys );
270 transaction_trace_ptr push_reqauth(account_name from, string role, bool multi_sig = false);
271 // use when just want any old non-context free action
272 transaction_trace_ptr push_dummy(account_name from, const string& v = "blah", uint32_t billed_cpu_time_us = DEFAULT_BILLED_CPU_TIME_US );
273 transaction_trace_ptr transfer( account_name from, account_name to, asset amount, string memo, account_name currency );
274 transaction_trace_ptr transfer( account_name from, account_name to, string amount, string memo, account_name currency );
275 transaction_trace_ptr issue( account_name to, string amount, account_name currency , string memo);
276
277 template<typename ObjectType>
278 const auto& get(const chainbase::oid< ObjectType >& key) {
279 return control->db().get<ObjectType>(key);
280 }
281
282 template<typename ObjectType, typename IndexBy, typename... Args>
283 const auto& get( Args&&... args ) {
284 return control->db().get<ObjectType,IndexBy>( forward<Args>(args)... );
285 }
286
287 template<typename ObjectType, typename IndexBy, typename... Args>
288 const auto* find( Args&&... args ) {
289 return control->db().find<ObjectType,IndexBy>( forward<Args>(args)... );
290 }
291
292 template< typename KeyType = fc::ecc::private_key_shim >
293 static auto get_private_key( name keyname, string role = "owner" ) {
294 auto secret = fc::sha256::hash(keyname.to_string() + role);
295 if constexpr (std::is_same_v<KeyType, mock::webauthn_private_key>) {
297 } else {
299 }
300 }
301
302 template< typename KeyType = fc::ecc::private_key_shim >
303 static auto get_public_key( name keyname, string role = "owner" ) {
304 return get_private_key<KeyType>( keyname, role ).get_public_key();
305 }
306
307 void set_code( account_name name, const char* wast, const private_key_type* signer = nullptr );
308 void set_code( account_name name, const vector<uint8_t> wasm, const private_key_type* signer = nullptr );
309 void set_abi( account_name name, const char* abi_json, const private_key_type* signer = nullptr );
310
311 bool chain_has_transaction( const transaction_id_type& txid ) const;
313
314 asset get_currency_balance( const account_name& contract,
315 const symbol& asset_symbol,
316 const account_name& account ) const;
317
318 vector<char> get_row_by_account( name code, name scope, name table, const account_name& act ) const;
319
320 map<account_name, block_id_type> get_last_produced_block_map()const { return last_produced_block; };
321 void set_last_produced_block_map( const map<account_name, block_id_type>& lpb ) { last_produced_block = lpb; }
322
323 static vector<uint8_t> to_uint8_vector(const string& s);
324
326
328
329 static string to_string(fc::variant x);
330
331 static action_result success() { return string(); }
332
333 static action_result error( const string& msg ) { return msg; }
334
335 static action_result wasm_assert_msg( const string& msg ) { return "assertion failure with message: " + msg; }
336
337 static action_result wasm_assert_code( uint64_t error_code ) { return "assertion failure with error code: " + std::to_string(error_code); }
338
340 return [this]( const account_name& name ) -> std::optional<abi_serializer> {
341 try {
342 const auto& accnt = control->db().get<account_object, by_name>( name );
343 abi_def abi;
344 if( abi_serializer::to_abi( accnt.abi, abi )) {
346 }
347 return std::optional<abi_serializer>();
348 } FC_RETHROW_EXCEPTIONS( error, "Failed to find or parse ABI for ${name}", ("name", name))
349 };
350 }
351
352 void sync_with(base_tester& other);
353
354 const table_id_object* find_table( name code, name scope, name table );
355
356 // method treats key as a name type, if this is not appropriate in your case, pass require == false and report the correct behavior
357 template<typename Object>
358 bool get_table_entry(Object& obj, account_name code, account_name scope, account_name table, uint64_t key, bool require = true) {
359 auto* maybe_tid = find_table(code, scope, table);
360 if( maybe_tid == nullptr ) {
361 BOOST_FAIL( "table for code=\"" + code.to_string()
362 + "\" scope=\"" + scope.to_string()
363 + "\" table=\"" + table.to_string()
364 + "\" does not exist" );
365 }
366
367 auto* o = control->db().find<key_value_object, by_scope_primary>(boost::make_tuple(maybe_tid->id, key));
368 if( o == nullptr ) {
369 if( require )
370 BOOST_FAIL("object does not exist for primary_key=\"" + name(key).to_string() + "\"");
371
372 return false;
373 }
374
375 fc::raw::unpack(o->value.data(), o->value.size(), obj);
376 return true;
377 }
378
380 return cfg;
381 }
382
384 void preactivate_protocol_features(const vector<digest_type> feature_digests);
385 void preactivate_builtin_protocol_features(const std::vector<builtin_protocol_feature_t>& features);
387
389 genesis_state genesis;
390 genesis.initial_timestamp = fc::time_point::from_iso_string("2020-01-01T00:00:00.000");
391 genesis.initial_key = get_public_key( config::system_account_name, "active" );
392
393 return genesis;
394 }
395
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>{}) {
398 cfg.blocks_dir = tempdir.path() / config::default_blocks_dir_name;
399 cfg.state_dir = tempdir.path() / config::default_state_dir_name;
400 cfg.state_size = 1024*1024*16;
402 cfg.contracts_console = true;
403 cfg.eosvmoc_config.cache_size = 1024*1024*8;
404
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"))
407 cfg.wasm_runtime = chain::wasm_interface::vm_type::eos_vm;
408 else if(boost::unit_test::framework::master_test_suite().argv[i] == std::string("--sys-vm-jit"))
409 cfg.wasm_runtime = chain::wasm_interface::vm_type::eos_vm_jit;
410 else if(boost::unit_test::framework::master_test_suite().argv[i] == std::string("--sys-vm-oc"))
411 cfg.wasm_runtime = chain::wasm_interface::vm_type::eos_vm_oc;
412 }
413 auto gen = default_genesis();
414 if (genesis_max_inline_action_size) {
415 gen.initial_configuration.max_inline_action_size = *genesis_max_inline_action_size;
416 }
417 if (config_max_nonprivileged_inline_action_size) {
418 cfg.max_nonprivileged_inline_action_size = *config_max_nonprivileged_inline_action_size;
419 }
420 return {cfg, gen};
421 }
422
423 protected:
424 signed_block_ptr _produce_block( fc::microseconds skip_time, bool skip_pending_trxs );
425 signed_block_ptr _produce_block( fc::microseconds skip_time, bool skip_pending_trxs,
426 bool no_throw, std::vector<transaction_trace_ptr>& traces );
427
428 void _start_block(fc::time_point block_time);
430
431 // Fields:
432 protected:
433 // tempdir field must come before control so that during destruction the tempdir is deleted only after controller finishes
435 public:
437 std::map<chain::public_key_type, chain::private_key_type> block_signing_private_keys;
438 protected:
440 map<transaction_id_type, transaction_receipt> chain_transactions;
441 map<account_name, block_id_type> last_produced_block;
443
444 public:
446 };
447
448 class tester : public base_tester {
449 public:
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);
452 }
453
455 init(config, genesis);
456 }
457
461
463 init(config, std::move(pfs), genesis);
464 }
465
466 tester(const fc::temp_directory& tempdir, bool use_genesis) {
467 auto def_conf = default_config(tempdir);
468 cfg = def_conf.first;
469
470 if (use_genesis) {
471 init(cfg, def_conf.second);
472 }
473 else {
474 init(cfg);
475 }
476 }
477
478 template <typename Lambda>
479 tester(const fc::temp_directory& tempdir, Lambda conf_edit, bool use_genesis) {
480 auto def_conf = default_config(tempdir);
481 cfg = def_conf.first;
482 conf_edit(cfg);
483
484 if (use_genesis) {
485 init(cfg, def_conf.second);
486 }
487 else {
488 init(cfg);
489 }
490 }
491
493
494 signed_block_ptr produce_block( fc::microseconds skip_time = fc::milliseconds(config::block_interval_ms) )override {
495 return _produce_block(skip_time, false);
496 }
497
498 signed_block_ptr produce_empty_block( fc::microseconds skip_time = fc::milliseconds(config::block_interval_ms) )override {
500 return _produce_block(skip_time, true);
501 }
502
504 return _finish_block();
505 }
506
507 bool validate() { return true; }
508 };
509
511 public:
513 if( !validating_node ) {
514 elog( "~validating_tester() called with empty validating_node; likely in the middle of failure" );
515 return;
516 }
517 try {
520 if (!skip_validate)
521 BOOST_REQUIRE_EQUAL( validate(), true );
522 } catch( const fc::exception& e ) {
523 wdump((e.to_detail_string()));
524 }
525 }
527
528 validating_tester(const flat_set<account_name>& trusted_producers = flat_set<account_name>(), deep_mind_handler* dmlog = nullptr) {
529 auto def_conf = default_config(tempdir);
530
531 vcfg = def_conf.first;
533 vcfg.trusted_producers = trusted_producers;
534
535 validating_node = create_validating_node(vcfg, def_conf.second, true, dmlog);
536
537 init(def_conf.first, def_conf.second);
539 }
540
543 && vcfg.state_dir.filename().generic_string() != ".", "invalid path names in controller::config" );
544
545 vcfg.blocks_dir = vcfg.blocks_dir.parent_path() / std::string("v_").append( vcfg.blocks_dir.filename().generic_string() );
546 vcfg.state_dir = vcfg.state_dir.parent_path() / std::string("v_").append( vcfg.state_dir.filename().generic_string() );
547
548 vcfg.contracts_console = false;
549 }
550
551 static unique_ptr<controller> create_validating_node(controller::config vcfg, const genesis_state& genesis, bool use_genesis, deep_mind_handler* dmlog = nullptr) {
552 unique_ptr<controller> validating_node = std::make_unique<controller>(vcfg, make_protocol_feature_set(), genesis.compute_chain_id());
553 validating_node->add_indices();
554 if(dmlog)
555 {
556 validating_node->enable_deep_mind(dmlog);
557 }
558 if (use_genesis) {
559 validating_node->startup( [](){}, []() { return false; }, genesis );
560 }
561 else {
562 validating_node->startup( [](){}, []() { return false; } );
563 }
564 return validating_node;
565 }
566
567 validating_tester(const fc::temp_directory& tempdir, bool use_genesis) {
568 auto def_conf = default_config(tempdir);
569 vcfg = def_conf.first;
571 validating_node = create_validating_node(vcfg, def_conf.second, use_genesis);
572
573 if (use_genesis) {
574 init(def_conf.first, def_conf.second);
575 }
576 else {
577 init(def_conf.first);
578 }
579 }
580
581 template <typename Lambda>
582 validating_tester(const fc::temp_directory& tempdir, Lambda conf_edit, bool use_genesis) {
583 auto def_conf = default_config(tempdir);
584 conf_edit(def_conf.first);
585 vcfg = def_conf.first;
587 validating_node = create_validating_node(vcfg, def_conf.second, use_genesis);
588
589 if (use_genesis) {
590 init(def_conf.first, def_conf.second);
591 }
592 else {
593 init(def_conf.first);
594 }
595 }
596
597 signed_block_ptr produce_block( fc::microseconds skip_time = fc::milliseconds(config::block_interval_ms) )override {
598 auto sb = _produce_block(skip_time, false);
599 auto bsf = validating_node->create_block_state_future( sb->calculate_id(), sb );
601
602 return sb;
603 }
604
606 return _produce_block(skip_time, false);
607 }
608
610 auto bsf = validating_node->create_block_state_future( sb->calculate_id(), sb );
612 }
613
614 signed_block_ptr produce_empty_block( fc::microseconds skip_time = fc::milliseconds(config::block_interval_ms) )override {
616 auto sb = _produce_block(skip_time, true);
617 auto bsf = validating_node->create_block_state_future( sb->calculate_id(), sb );
619
620 return sb;
621 }
622
624 return _finish_block();
625 }
626
627 bool validate() {
628
629
630 auto hbh = control->head_block_state()->header;
631 auto vn_hbh = validating_node->head_block_state()->header;
632 bool ok = control->head_block_id() == validating_node->head_block_id() &&
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;
638
639 validating_node.reset();
640 validating_node = std::make_unique<controller>(vcfg, make_protocol_feature_set(), control->get_chain_id());
641 validating_node->add_indices();
642 validating_node->startup( [](){}, []() { return false; } );
643
644 return ok;
645 }
646
649 bool skip_validate = false;
650 };
651
656 fc_exception_message_is( const string& msg )
657 : expected( msg ) {}
658
659 bool operator()( const fc::exception& ex );
660
661 string expected;
662 };
663
669 : expected( msg ) {}
670
671 bool operator()( const fc::exception& ex );
672
673 string expected;
674 };
675
681 : expected( msg ) {}
682
683 bool operator()( const fc::assert_exception& ex );
684
685 string expected;
686 };
687
693 : expected( msg ) {}
694
695 bool operator()( const fc::assert_exception& ex );
696
697 string expected;
698 };
699
704 sysio_assert_message_is( const string& msg )
705 : expected( "assertion failure with message: " ) {
706 expected.append( msg );
707 }
708
709 bool operator()( const sysio_assert_message_exception& ex );
710
711 string expected;
712 };
713
719 : expected( "assertion failure with message: " ) {
720 expected.append( msg );
721 }
722
723 bool operator()( const sysio_assert_message_exception& ex );
724
725 string expected;
726 };
727
733 : expected( "assertion failure with error code: " ) {
734 expected.append( std::to_string(error_code) );
735 }
736
737 bool operator()( const sysio_assert_code_exception& ex );
738
739 string expected;
740 };
741
742} }
std::string name
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.
Definition exception.hpp:58
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)
Definition sha256.cpp:59
static sha256 hash(const char *d, uint32_t dlen)
Definition sha256.cpp:44
const char * data() const
Definition sha256.cpp:31
size_t data_size() const
Definition sha256.hpp:23
const fc::path & path() const
static time_point from_iso_string(const fc::string &s)
Definition time.cpp:67
static constexpr time_point maximum()
Definition time.hpp:46
An order-preserving dictionary of variants.
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
Definition variant.hpp:191
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 >{})
Definition tester.hpp:396
void produce_min_num_of_blocks_to_spend_time_wo_inactive_prod(const fc::microseconds target_elapsed_time=fc::microseconds())
Definition tester.cpp:489
vector< char > get_row_by_account(name code, name scope, name table, const account_name &act) const
Definition tester.cpp:986
transaction_trace_ptr transfer(account_name from, account_name to, asset amount, string memo, account_name currency)
Definition tester.cpp:771
std::map< chain::public_key_type, chain::private_key_type > block_signing_private_keys
Definition tester.hpp:437
static uint64_t to_uint64(fc::variant x)
Definition tester.cpp:1022
transaction_trace_ptr push_reqauth(account_name from, const vector< permission_level > &auths, const vector< private_key_type > &keys)
Definition tester.cpp:698
void produce_blocks_for_n_rounds(const uint32_t num_of_rounds=1)
Definition tester.cpp:483
action get_action(account_name code, action_name acttype, vector< permission_level > auths, const variant_object &data) const
Definition tester.cpp:680
void delete_authority(account_name account, permission_name perm, const vector< permission_level > &auths, const vector< private_key_type > &keys)
Definition tester.cpp:886
static const fc::microseconds abi_serializer_max_time
Definition tester.hpp:153
map< account_name, block_id_type > get_last_produced_block_map() const
Definition tester.hpp:320
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)
Definition tester.cpp:1107
static genesis_state default_genesis()
Definition tester.hpp:388
transaction_trace_ptr set_producer_schedule(const vector< producer_authority > &schedule)
Definition tester.cpp:1094
static const uint32_t DEFAULT_BILLED_CPU_TIME_US
Definition tester.hpp:152
static vector< uint8_t > to_uint8_vector(const string &s)
Definition tester.cpp:1008
action_result push_action(action &&cert_act, uint64_t authorizer)
Definition tester.cpp:609
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)
Definition tester.cpp:562
static auto get_private_key(name keyname, string role="owner")
Definition tester.hpp:293
void execute_setup_policy(const setup_policy policy)
Definition tester.cpp:192
vector< transaction_id_type > get_scheduled_transactions() const
Definition tester.cpp:461
void _start_block(fc::time_point block_time)
Definition tester.cpp:383
transaction_trace_ptr create_account(account_name name, account_name creator=config::system_account_name, bool multisig=false, bool include_code=true)
Definition tester.cpp:516
void push_block(signed_block_ptr b)
Definition tester.cpp:323
unapplied_transaction_queue & get_unapplied_transaction_queue()
Definition tester.hpp:199
bool get_table_entry(Object &obj, account_name code, account_name scope, account_name table, uint64_t key, bool require=true)
Definition tester.hpp:358
unapplied_transaction_queue unapplied_transactions
Definition tester.hpp:442
transaction_trace_ptr issue(account_name to, string amount, account_name currency, string memo)
Definition tester.cpp:800
void set_before_preactivate_bios_contract()
Definition tester.cpp:1063
void sync_with(base_tester &other)
Definition tester.cpp:1039
bool is_same_chain(base_tester &other)
Definition tester.cpp:149
map< transaction_id_type, transaction_receipt > chain_transactions
Definition tester.hpp:440
vector< producer_authority > get_producer_authorities(const vector< account_name > &producer_names) const
Definition tester.cpp:1079
static const uint32_t DEFAULT_EXPIRATION_DELTA
Definition tester.hpp:150
controller::config cfg
Definition tester.hpp:439
signed_block_ptr _produce_block(fc::microseconds skip_time, bool skip_pending_trxs)
Definition tester.cpp:338
void set_code(account_name name, const char *wast, const private_key_type *signer=nullptr)
Definition tester.cpp:909
void unlink_authority(account_name account, account_name code, action_name type={})
Definition tester.cpp:840
const auto * find(Args &&... args)
Definition tester.hpp:288
static string to_string(fc::variant x)
Definition tester.cpp:1030
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={})
Definition tester.cpp:828
const auto & get(Args &&... args)
Definition tester.hpp:283
vector< transaction_trace_ptr > create_accounts(vector< account_name > names, bool multisig=false, bool include_code=true)
Definition tester.hpp:234
transaction_trace_ptr push_dummy(account_name from, const string &v="blah", uint32_t billed_cpu_time_us=DEFAULT_BILLED_CPU_TIME_US)
Definition tester.cpp:731
void produce_blocks(uint32_t n=1, bool empty=false)
Definition tester.cpp:451
unique_ptr< controller > control
Definition tester.hpp:436
map< account_name, block_id_type > last_produced_block
Definition tester.hpp:441
transaction_trace_ptr set_producers(const vector< account_name > &producer_names)
Definition tester.cpp:1088
void preactivate_all_builtin_protocol_features()
Definition tester.cpp:1158
void preactivate_builtin_protocol_features(const std::vector< builtin_protocol_feature_t > &features)
Definition tester.cpp:1145
static action_result wasm_assert_code(uint64_t error_code)
Definition tester.hpp:337
void set_last_produced_block_map(const map< account_name, block_id_type > &lpb)
Definition tester.hpp:321
bool chain_has_transaction(const transaction_id_type &txid) const
Definition tester.cpp:953
const auto & get(const chainbase::oid< ObjectType > &key)
Definition tester.hpp:278
fc::temp_directory tempdir
Definition tester.hpp:434
vector< digest_type > protocol_features_to_be_activated_wo_preactivation
Definition tester.hpp:445
void set_before_producer_authority_bios_contract()
Definition tester.cpp:1068
asset get_currency_balance(const account_name &contract, const symbol &asset_symbol, const account_name &account) const
Definition tester.cpp:966
void schedule_protocol_features_wo_preactivation(const vector< digest_type > feature_digests)
Definition tester.cpp:1130
void produce_blocks_until_end_of_round()
Definition tester.cpp:474
signed_block_ptr _finish_block()
Definition tester.cpp:416
void set_abi(account_name name, const char *abi_json, const private_key_type *signer=nullptr)
static action_result error(const string &msg)
Definition tester.hpp:333
void preactivate_protocol_features(const vector< digest_type > feature_digests)
Definition tester.cpp:1138
void set_transaction_headers(transaction &trx, uint32_t expiration=DEFAULT_EXPIRATION_DELTA, uint32_t delay_sec=0) const
Definition tester.cpp:506
const table_id_object * find_table(name code, name scope, name table)
Definition tester.cpp:1125
static auto get_public_key(name keyname, string role="owner")
Definition tester.hpp:303
const controller::config & get_config() const
Definition tester.hpp:379
static action_result wasm_assert_msg(const string &msg)
Definition tester.hpp:335
void open(protocol_feature_set &&pfs, std::optional< chain_id_type > expected_chain_id, Lambda lambda)
Definition tester.cpp:273
static action_result success()
Definition tester.hpp:331
const transaction_receipt & get_transaction_receipt(const transaction_id_type &txid) const
Definition tester.cpp:958
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)
Definition tester.cpp:852
provides utility function to simplify the creation of unit tests
Definition tester.hpp:448
signed_block_ptr produce_empty_block(fc::microseconds skip_time=fc::milliseconds(config::block_interval_ms)) override
Definition tester.hpp:498
tester(const fc::temp_directory &tempdir, bool use_genesis)
Definition tester.hpp:466
tester(controller::config config)
Definition tester.hpp:458
signed_block_ptr produce_block(fc::microseconds skip_time=fc::milliseconds(config::block_interval_ms)) override
Definition tester.hpp:494
tester(controller::config config, protocol_feature_set &&pfs, const genesis_state &genesis)
Definition tester.hpp:462
tester(controller::config config, const genesis_state &genesis)
Definition tester.hpp:454
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 >{})
Definition tester.hpp:450
signed_block_ptr finish_block() override
Definition tester.hpp:503
tester(const fc::temp_directory &tempdir, Lambda conf_edit, bool use_genesis)
Definition tester.hpp:479
validating_tester(const fc::temp_directory &tempdir, Lambda conf_edit, bool use_genesis)
Definition tester.hpp:582
unique_ptr< controller > validating_node
Definition tester.hpp:647
validating_tester(const fc::temp_directory &tempdir, bool use_genesis)
Definition tester.hpp:567
signed_block_ptr produce_empty_block(fc::microseconds skip_time=fc::milliseconds(config::block_interval_ms)) override
Definition tester.hpp:614
signed_block_ptr produce_block_no_validation(fc::microseconds skip_time=fc::milliseconds(config::block_interval_ms))
Definition tester.hpp:605
uint32_t num_blocks_to_producer_before_shutdown
Definition tester.hpp:648
void validate_push_block(const signed_block_ptr &sb)
Definition tester.hpp:609
signed_block_ptr finish_block() override
Definition tester.hpp:623
signed_block_ptr produce_block(fc::microseconds skip_time=fc::milliseconds(config::block_interval_ms)) override
Definition tester.hpp:597
validating_tester(const flat_set< account_name > &trusted_producers=flat_set< account_name >(), deep_mind_handler *dmlog=nullptr)
Definition tester.hpp:528
static unique_ptr< controller > create_validating_node(controller::config vcfg, const genesis_state &genesis, bool use_genesis, deep_mind_handler *dmlog=nullptr)
Definition tester.hpp:551
static void config_validator(controller::config &vcfg)
Definition tester.hpp:541
#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...
char ** argv
void init()
Definition lib_test.cpp:3
#define wdump(SEQ)
Definition logger.hpp:160
#define elog(FORMAT,...)
Definition logger.hpp:130
void unpack(Stream &s, std::deque< T > &value)
Definition raw.hpp:540
void pack(Stream &s, const std::deque< T > &value)
Definition raw.hpp:531
namespace sysio::chain
Definition authority.cpp:3
std::string string
Definition string.hpp:10
fc::sha256 digest(const T &value)
Definition digest.hpp:9
std::string base64url_encode(unsigned char const *bytes_to_encode, unsigned int in_len)
Definition base64.cpp:101
constexpr microseconds milliseconds(int64_t s)
Definition time.hpp:33
constexpr std::size_t get_index()
Definition name.hpp:106
fc::crypto::public_key public_key_type
Definition types.hpp:76
std::shared_ptr< transaction_trace > transaction_trace_ptr
Definition trace.hpp:20
sysio::chain::action_name action_name
std::shared_ptr< signed_block > signed_block_ptr
Definition block.hpp:105
std::shared_ptr< snapshot_reader > snapshot_reader_ptr
Definition snapshot.hpp:294
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)
Definition tester.cpp:105
std::string read_wast(const char *fn)
Definition tester.cpp:23
fc::variant read_json_snapshot(const char *fn)
Definition tester.cpp:85
std::string read_binary_snapshot(const char *fn)
Definition tester.cpp:81
protocol_feature_set make_protocol_feature_set(const subjective_restriction_map &custom_subjective_restrictions={})
Definition tester.cpp:110
bool expect_assert_message(const fc::exception &ex, string expected)
Definition tester.cpp:91
std::map< builtin_protocol_feature_t, protocol_feature_subjective_restrictions > subjective_restriction_map
Definition tester.hpp:85
fc::variant_object filter_fields(const fc::variant_object &filter, const fc::variant_object &value)
Definition tester.cpp:96
std::vector< uint8_t > read_wasm(const char *fn)
Definition tester.cpp:38
std::vector< char > read_abi(const char *fn)
Definition tester.cpp:52
#define value
Definition pkcs11.h:157
unsigned int uint32_t
Definition stdint.h:126
unsigned char uint8_t
Definition stdint.h:124
unsigned __int64 uint64_t
Definition stdint.h:136
void operator()(std::ostream &osm, const fc::variant &v)
Definition tester.hpp:36
void operator()(std::ostream &osm, const fc::variant_object &v)
Definition tester.hpp:44
void operator()(std::ostream &osm, const fc::variant_object::entry &e)
Definition tester.hpp:52
static yield_function_t create_yield_function(const fc::microseconds &max_serialization_time)
static bool to_abi(const Vec &abi_vec, abi_def &abi)
flat_set< account_name > trusted_producers
wasm_interface::vm_type wasm_runtime
Immutable except for fc::from_variant.
Definition name.hpp:43
std::string to_string() const
Definition name.cpp:19
bool operator()(const fc::assert_exception &ex)
Definition tester.cpp:1218
bool operator()(const fc::assert_exception &ex)
Definition tester.cpp:1232
bool operator()(const fc::exception &ex)
Definition tester.cpp:1200
fc_exception_message_is(const string &msg)
Definition tester.hpp:656
bool operator()(const fc::exception &ex)
Definition tester.cpp:1209
static auto regenerate(const fc::sha256 &secret)
Definition tester.hpp:100
webauthn_private_key(webauthn_private_key &&)=default
static const fc::sha256 _origin_hash
Definition tester.hpp:138
webauthn_private_key(const webauthn_private_key &)=default
webauthn_private_key(r1::private_key &&priv_key)
Definition tester.hpp:92
public_key get_public_key(webauthn::public_key::user_presence_t presence=webauthn::public_key::user_presence_t::USER_PRESENCE_NONE) const
Definition tester.hpp:104
signature sign(const sha256 &digest, bool=true) const
Definition tester.hpp:108
bool operator()(const sysio_assert_code_exception &ex)
Definition tester.cpp:1264
sysio_assert_code_is(uint64_t error_code)
Definition tester.hpp:732
sysio_assert_message_is(const string &msg)
Definition tester.hpp:704
bool operator()(const sysio_assert_message_exception &ex)
Definition tester.cpp:1246
bool operator()(const sysio_assert_message_exception &ex)
Definition tester.cpp:1255
sysio::chain::asset core_from_string(const std::string &s)
Definition tester.cpp:18
std::ostream & operator<<(std::ostream &osm, const fc::variant &v)
sysio::testing
Definition tester.cpp:1277
void bsf(const Reg &reg, const Operand &op)
uint8_t key[16]
Definition yubico_otp.c:41
CK_RV ret
char * s
memcpy((char *) pInfo->slotDescription, s, l)