Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
sysio::testing Namespace Reference

Namespaces

namespace  mock
 

Classes

class  base_tester
 
struct  chainbase_fixture
 
struct  fc_assert_exception_message_is
 
struct  fc_assert_exception_message_starts_with
 
struct  fc_exception_message_is
 
struct  fc_exception_message_starts_with
 
struct  sysio_assert_code_is
 
struct  sysio_assert_message_is
 
struct  sysio_assert_message_starts_with
 
class  tester
 provides utility function to simplify the creation of unit tests More...
 
class  tester_network
 The tester_network class provides a simplistic virtual P2P network connecting testing_blockchains together. More...
 
class  validating_tester
 

Typedefs

using subjective_restriction_map = std::map<builtin_protocol_feature_t, protocol_feature_subjective_restrictions>
 

Enumerations

enum class  setup_policy {
  none , old_bios_only , preactivate_feature_only , preactivate_feature_and_new_bios ,
  old_wasm_parser , full
}
 

Functions

std::vector< uint8_tread_wasm (const char *fn)
 
std::vector< char > read_abi (const char *fn)
 
std::string read_wast (const char *fn)
 
std::string read_binary_snapshot (const char *fn)
 
fc::variant read_json_snapshot (const char *fn)
 
fc::variant_object filter_fields (const fc::variant_object &filter, const fc::variant_object &value)
 
void copy_row (const chain::key_value_object &obj, vector< char > &data)
 
bool expect_assert_message (const fc::exception &ex, string expected)
 
protocol_feature_set make_protocol_feature_set (const subjective_restriction_map &custom_subjective_restrictions={})
 
 FC_CAPTURE_AND_RETHROW ((account)) void base_tester
 

Typedef Documentation

◆ subjective_restriction_map

Enumeration Type Documentation

◆ setup_policy

Enumerator
none 
old_bios_only 
preactivate_feature_only 
preactivate_feature_and_new_bios 
old_wasm_parser 
full 

Definition at line 61 of file tester.hpp.

Function Documentation

◆ copy_row()

void sysio::testing::copy_row ( const chain::key_value_object & obj,
vector< char > & data )

Definition at line 105 of file tester.cpp.

105 {
106 data.resize( obj.value.size() );
107 memcpy( data.data(), obj.value.data(), obj.value.size() );
108 }
memcpy((char *) pInfo->slotDescription, s, l)
Here is the call graph for this function:

◆ expect_assert_message()

bool sysio::testing::expect_assert_message ( const fc::exception & ex,
string expected )

Definition at line 91 of file tester.cpp.

91 {
92 BOOST_TEST_MESSAGE("LOG : " << "expected: " << expected << ", actual: " << ex.get_log().at(0).get_message());
93 return (ex.get_log().at(0).get_message().find(expected) != std::string::npos);
94 }
const log_messages & get_log() const
Here is the call graph for this function:

◆ FC_CAPTURE_AND_RETHROW()

sysio::testing::FC_CAPTURE_AND_RETHROW ( (account) )

Definition at line 911 of file tester.cpp.

914 {
916 trx.actions.emplace_back( vector<permission_level>{{account,config::active_name}},
917 setcode{
918 .account = account,
919 .vmtype = 0,
920 .vmversion = 0,
921 .code = bytes(wasm.begin(), wasm.end())
922 });
923
924 set_transaction_headers(trx);
925 if( signer ) {
926 trx.sign( *signer, control->get_chain_id() );
927 } else {
928 trx.sign( get_private_key( account, "active" ), control->get_chain_id() );
929 }
930 push_transaction( trx );
931 } FC_CAPTURE_AND_RETHROW( (account) )
932
933
934 void base_tester::set_abi( account_name account, const char* abi_json, const private_key_type* signer ) {
935 auto abi = fc::json::from_string(abi_json).template as<abi_def>();
936 signed_transaction trx;
937 trx.actions.emplace_back( vector<permission_level>{{account,config::active_name}},
938 setabi{
939 .account = account,
940 .abi = fc::raw::pack(abi)
941 });
942
943 set_transaction_headers(trx);
944 if( signer ) {
945 trx.sign( *signer, control->get_chain_id() );
946 } else {
947 trx.sign( get_private_key( account, "active" ), control->get_chain_id() );
948 }
949 push_transaction( trx );
950 }
static variant from_string(const string &utf8_str, const parse_type ptype=parse_type::legacy_parser, uint32_t max_depth=DEFAULT_MAX_RECURSION_DEPTH)
Definition json.cpp:442
#define FC_CAPTURE_AND_RETHROW(...)
void pack(Stream &s, const std::deque< T > &value)
Definition raw.hpp:531
auto get_private_key(chain::name keyname, std::string role="owner")
fc::variant push_transaction(signed_transaction &trx, packed_transaction::compression_type compression=packed_transaction::compression_type::none)
Definition main.cpp:325
const signature_type & sign(const private_key_type &key, const chain_id_type &chain_id)
vector< action > actions

◆ filter_fields()

fc::variant_object sysio::testing::filter_fields ( const fc::variant_object & filter,
const fc::variant_object & value )

Definition at line 96 of file tester.cpp.

96 {
98 for( auto& entry : filter ) {
99 auto it = value.find(entry.key());
100 res( it->key(), it->value() );
101 }
102 return res;
103 }
An order-preserving dictionary of variants.
#define value
Definition pkcs11.h:157

◆ make_protocol_feature_set()

protocol_feature_set sysio::testing::make_protocol_feature_set ( const subjective_restriction_map & custom_subjective_restrictions = {})

Definition at line 110 of file tester.cpp.

110 {
112
113 map< builtin_protocol_feature_t, std::optional<digest_type> > visited_builtins;
114
115 std::function<digest_type(builtin_protocol_feature_t)> add_builtins =
116 [&pfs, &visited_builtins, &add_builtins, &custom_subjective_restrictions]
118 auto res = visited_builtins.emplace( codename, std::optional<digest_type>() );
119 if( !res.second ) {
120 SYS_ASSERT( res.first->second, protocol_feature_exception,
121 "invariant failure: cycle found in builtin protocol feature dependencies"
122 );
123 return *res.first->second;
124 }
125
126 auto f = protocol_feature_set::make_default_builtin_protocol_feature( codename,
127 [&add_builtins]( builtin_protocol_feature_t d ) {
128 return add_builtins( d );
129 } );
130
131 const auto itr = custom_subjective_restrictions.find(codename);
132 if( itr != custom_subjective_restrictions.end() ) {
133 f.subjective_restrictions = itr->second;
134 }
135
136 const auto& pf = pfs.add_feature( f );
137 res.first->second = pf.feature_digest;
138
139 return pf.feature_digest;
140 };
141
142 for( const auto& p : builtin_protocol_feature_codenames ) {
143 add_builtins( p.first );
144 }
145
146 return pfs;
147 }
const mie::Vuint & p
Definition bn.cpp:27
#define SYS_ASSERT(expr, exc_type, FORMAT,...)
Definition exceptions.hpp:7
const protocol_feature & add_feature(const builtin_protocol_feature &f)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_abi()

std::vector< char > sysio::testing::read_abi ( const char * fn)

Definition at line 52 of file tester.cpp.

52 {
53 std::ifstream abi_file(fn);
54 FC_ASSERT( abi_file.is_open(), "abi file cannot be found" );
55 abi_file.seekg(0, std::ios::end);
56 std::vector<char> abi;
57 int len = abi_file.tellg();
58 FC_ASSERT( len >= 0, "abi file length is -1" );
59 abi.resize(len+1);
60 abi_file.seekg(0, std::ios::beg);
61 abi_file.read(abi.data(), abi.size());
62 abi[abi.size()-1] = '\0';
63 abi_file.close();
64 return abi;
65 }
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
size_t len

◆ read_binary_snapshot()

std::string sysio::testing::read_binary_snapshot ( const char * fn)

Definition at line 81 of file tester.cpp.

81 {
82 return read_gzipped_snapshot(fn);
83 }

◆ read_json_snapshot()

fc::variant sysio::testing::read_json_snapshot ( const char * fn)

Definition at line 85 of file tester.cpp.

85 {
86 return fc::json::from_string( read_gzipped_snapshot(fn) );
87 }
Here is the call graph for this function:

◆ read_wasm()

std::vector< uint8_t > sysio::testing::read_wasm ( const char * fn)

Definition at line 38 of file tester.cpp.

38 {
39 std::ifstream wasm_file(fn, std::ios::binary);
40 FC_ASSERT( wasm_file.is_open(), "wasm file cannot be found" );
41 wasm_file.seekg(0, std::ios::end);
42 std::vector<uint8_t> wasm;
43 int len = wasm_file.tellg();
44 FC_ASSERT( len >= 0, "wasm file length is -1" );
45 wasm.resize(len);
46 wasm_file.seekg(0, std::ios::beg);
47 wasm_file.read((char*)wasm.data(), wasm.size());
48 wasm_file.close();
49 return wasm;
50 }

◆ read_wast()

std::string sysio::testing::read_wast ( const char * fn)

Definition at line 23 of file tester.cpp.

23 {
24 std::ifstream wast_file(fn);
25 FC_ASSERT( wast_file.is_open(), "wast file cannot be found" );
26 wast_file.seekg(0, std::ios::end);
27 std::vector<char> wast;
28 int len = wast_file.tellg();
29 FC_ASSERT( len >= 0, "wast file length is -1" );
30 wast.resize(len+1);
31 wast_file.seekg(0, std::ios::beg);
32 wast_file.read(wast.data(), wast.size());
33 wast[wast.size()-1] = '\0';
34 wast_file.close();
35 return {wast.data()};
36 }