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

Functions

fc::sha256 operator""_h (const char *input, std::size_t)
 
chain::name operator""_n (const char *input, std::size_t)
 
chain::asset operator""_t (const char *input, std::size_t)
 
auto get_private_key (chain::name keyname, std::string role="owner")
 
auto get_public_key (chain::name keyname, std::string role="owner")
 
chain::bytes make_transfer_data (chain::name from, chain::name to, chain::asset quantity, std::string &&memo)
 
auto make_block_state (chain::block_id_type previous, uint32_t height, uint32_t slot, chain::name producer, std::vector< chain::packed_transaction > trxs)
 
void to_kv_helper (const fc::variant &v, std::function< void(const std::string &, const std::string &)> &&append)
 
auto to_kv (const fc::variant &v)
 

Detailed Description

Utilities that make writing tests easier

Function Documentation

◆ get_private_key()

auto sysio::trace_api::test_common::get_private_key ( chain::name keyname,
std::string role = "owner" )

Definition at line 34 of file test_common.hpp.

34 {
35 auto secret = fc::sha256::hash( keyname.to_string() + role );
36 return chain::private_key_type::regenerate<fc::ecc::private_key_shim>( secret );
37 }
static sha256 hash(const char *d, uint32_t dlen)
Definition sha256.cpp:44
std::string to_string() const
Definition name.cpp:19
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_public_key()

auto sysio::trace_api::test_common::get_public_key ( chain::name keyname,
std::string role = "owner" )

Definition at line 39 of file test_common.hpp.

39 {
40 return get_private_key( keyname, role ).get_public_key();
41 }
auto get_private_key(chain::name keyname, std::string role="owner")
Here is the call graph for this function:
Here is the caller graph for this function:

◆ make_block_state()

auto sysio::trace_api::test_common::make_block_state ( chain::block_id_type previous,
uint32_t height,
uint32_t slot,
chain::name producer,
std::vector< chain::packed_transaction > trxs )

Definition at line 55 of file test_common.hpp.

56 {
57 chain::signed_block_ptr block = std::make_shared<chain::signed_block>();
58 for( auto& trx : trxs ) {
59 block->transactions.emplace_back( trx );
60 }
61 block->producer = producer;
62 block->timestamp = chain::block_timestamp_type(slot);
63 // make sure previous contains correct block # so block_header::block_num() returns correct value
64 if( previous == chain::block_id_type() ) {
65 previous._hash[0] &= 0xffffffff00000000;
66 previous._hash[0] += fc::endian_reverse_u32(height - 1);
67 }
68 block->previous = previous;
69
70 auto priv_key = get_private_key( block->producer, "active" );
71 auto pub_key = get_public_key( block->producer, "active" );
72
73 auto prev = std::make_shared<chain::block_state>();
74 auto header_bmroot = chain::digest_type::hash( std::make_pair( block->digest(), prev->blockroot_merkle.get_root()));
75 auto sig_digest = chain::digest_type::hash( std::make_pair( header_bmroot, prev->pending_schedule.schedule_hash ));
76 block->producer_signature = priv_key.sign( sig_digest );
77
78 std::vector<chain::private_key_type> signing_keys;
79 signing_keys.emplace_back( std::move( priv_key ));
80 auto signer = [&]( chain::digest_type d ) {
81 std::vector<chain::signature_type> result;
82 result.reserve( signing_keys.size());
83 for( const auto& k: signing_keys )
84 result.emplace_back( k.sign( d ));
85 return result;
86 };
87 chain::pending_block_header_state pbhs;
88 pbhs.producer = block->producer;
89 pbhs.timestamp = block->timestamp;
90 chain::producer_authority_schedule schedule = {0, {chain::producer_authority{block->producer,
91 chain::block_signing_authority_v0{1, {{pub_key, 1}}}}}};
92 pbhs.active_schedule = schedule;
93 pbhs.valid_block_signing_authority = chain::block_signing_authority_v0{1, {{pub_key, 1}}};
94 auto bsp = std::make_shared<chain::block_state>(
95 std::move( pbhs ),
96 std::move( block ),
97 std::vector<chain::transaction_metadata_ptr>(),
98 chain::protocol_feature_set(),
99 []( chain::block_timestamp_type timestamp,
100 const fc::flat_set<chain::digest_type>& cur_features,
101 const std::vector<chain::digest_type>& new_features ) {},
102 signer
103 );
104 bsp->block_num = height;
105
106 return bsp;
107 }
uint32_t endian_reverse_u32(uint32_t x)
Definition bitutil.hpp:19
std::shared_ptr< signed_block > signed_block_ptr
Definition block.hpp:105
yubihsm_pkcs11_slot * slot
CK_ULONG d
Here is the call graph for this function:
Here is the caller graph for this function:

◆ make_transfer_data()

chain::bytes sysio::trace_api::test_common::make_transfer_data ( chain::name from,
chain::name to,
chain::asset quantity,
std::string && memo )

Definition at line 43 of file test_common.hpp.

43 {
45 fc::raw::pack(ps, from, to, quantity, memo);
46 chain::bytes result( ps.tellp());
47
48 if( result.size()) {
49 fc::datastream<char *> ds( result.data(), size_t( result.size()));
50 fc::raw::pack(ds, from, to, quantity, memo);
51 }
52 return result;
53 }
void pack(Stream &s, const std::deque< T > &value)
Definition raw.hpp:531
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator""_h()

fc::sha256 sysio::trace_api::test_common::operator""_h ( const char * input,
std::size_t  )

Definition at line 22 of file test_common.hpp.

22 {
23 return fc::sha256(input);
24 }

◆ operator""_n()

chain::name sysio::trace_api::test_common::operator""_n ( const char * input,
std::size_t  )

Definition at line 26 of file test_common.hpp.

26 {
27 return chain::name(input);
28 }
Immutable except for fc::from_variant.
Definition name.hpp:43

◆ operator""_t()

chain::asset sysio::trace_api::test_common::operator""_t ( const char * input,
std::size_t  )

Definition at line 30 of file test_common.hpp.

30 {
31 return chain::asset::from_string(input);
32 }
Here is the call graph for this function:

◆ to_kv()

auto sysio::trace_api::test_common::to_kv ( const fc::variant & v)

Definition at line 132 of file test_common.hpp.

132 {
133 std::map<std::string, std::string> result;
134 to_kv_helper(v, [&result](const std::string& k, const std::string& v){
135 result.emplace(k, v);
136 });
137 return result;
138 }
void to_kv_helper(const fc::variant &v, std::function< void(const std::string &, const std::string &)> &&append)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ to_kv_helper()

void sysio::trace_api::test_common::to_kv_helper ( const fc::variant & v,
std::function< void(const std::string &, const std::string &)> && append )

Definition at line 109 of file test_common.hpp.

109 {
110 if (v.is_object() ) {
111 const auto& obj = v.get_object();
112 static const std::string sep = ".";
113
114 for (const auto& entry: obj) {
115 to_kv_helper( entry.value(), [&append, &entry](const std::string& path, const std::string& value){
116 append(sep + entry.key() + path, value);
117 });
118 }
119 } else if (v.is_array()) {
120 const auto& arr = v.get_array();
121 for (size_t idx = 0; idx < arr.size(); idx++) {
122 const auto& entry = arr.at(idx);
123 to_kv_helper( entry, [&append, idx](const std::string& path, const std::string& value){
124 append(std::string("[") + std::to_string(idx) + std::string("]") + path, value);
125 });
126 }
127 } else if (!v.is_null()) {
128 append("", v.as_string());
129 }
130 }
wraps boost::filesystem::path to provide platform independent path manipulation.
bool is_array() const
Definition variant.cpp:368
variant_object & get_object()
Definition variant.cpp:554
bool is_null() const
Definition variant.cpp:309
bool is_object() const
Definition variant.cpp:363
string as_string() const
Definition variant.cpp:469
variants & get_array()
Definition variant.cpp:496
#define value
Definition pkcs11.h:157
Here is the call graph for this function:
Here is the caller graph for this function: