-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfork_test_utilities.cpp
More file actions
55 lines (47 loc) · 1.98 KB
/
fork_test_utilities.cpp
File metadata and controls
55 lines (47 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "fork_test_utilities.hpp"
private_key_type get_private_key( name keyname, string role ) {
return private_key_type::regenerate<fc::ecc::private_key_shim>(fc::sha256::hash(keyname.to_string()+role));
}
public_key_type get_public_key( name keyname, string role ){
return get_private_key( keyname, role ).get_public_key();
}
void push_blocks( tester& from, tester& to, uint32_t block_num_limit ) {
while( to.control->fork_db_pending_head_block_num()
< std::min( from.control->fork_db_pending_head_block_num(), block_num_limit ) )
{
auto fb = from.control->fetch_block_by_number( to.control->fork_db_pending_head_block_num()+1 );
to.push_block( fb );
}
}
namespace {
template<typename Pred>
bool produce_empty_blocks_until( base_tester& t, uint32_t max_num_blocks_to_produce, Pred&& pred) {
for( uint32_t blocks_produced = 0;
blocks_produced < max_num_blocks_to_produce;
t.produce_block(), ++blocks_produced )
{
if( pred() )
return true;
}
return pred();
}
}
bool produce_until_transition( base_tester& t,
account_name last_producer,
account_name next_producer,
uint32_t max_num_blocks_to_produce )
{
return produce_empty_blocks_until(t, max_num_blocks_to_produce, [&t, last_producer, next_producer]() {
return t.control->pending_block_producer() == next_producer && t.control->head_block_producer() == last_producer;
});
}
bool produce_until_blocks_from( base_tester& t,
const std::set<account_name>& expected_producers,
uint32_t max_num_blocks_to_produce )
{
auto remaining_producers = expected_producers;
return produce_empty_blocks_until(t, max_num_blocks_to_produce, [&t, &remaining_producers]() {
remaining_producers.erase(t.control->head_block_producer());
return remaining_producers.size() == 0;
});
}