COOPENOMICS  v1
Кооперативная Экономика
Файл eosio.system_blockinfo_tests.cpp
#include <functional>
#include <limits>
#include <boost/test/unit_test.hpp>
#include <eosio/chain/config.hpp>
#include <eosio/chain/contract_table_objects.hpp>
#include <eosio/testing/tester.hpp>
#include <fc/io/datastream.hpp>
#include <fc/io/raw.hpp>
#include <fc/log/logger.hpp>
#include <fc/time.hpp>
#include "eosio.system_tester.hpp"
#include "../system/contracts/test_contracts/blockinfo_tester/include/blockinfo_tester/blockinfo_tester.hpp"

Классы

struct  anonymous_namespace{eosio.system_blockinfo_tests.cpp}::block_info_record
 

Пространства имен

namespace  anonymous_namespace{eosio.system_blockinfo_tests.cpp}
 

Макросы

#define TEST_INCLUDE
 

Функции

 FC_REFLECT (block_info_record,(version)(block_height)(block_timestamp)) namespace
 
 produce_blocks (1)
 
 add_to_expected_table (start_block_height, start_block_timestamp)
 
 BOOST_REQUIRE (check_tables_match(expected_table, actual_table))
 
 produce_blocks (rolling_window_size - 1)
 
 for (uint32_t end_block_height=start_block_height+rolling_window_size - 1;cur_block_height<=end_block_height;advance_cur_block())
 
 BOOST_CHECK (rolling_window_size==actual_table.size())
 
 BOOST_CHECK (check_tables_match(expected_table, actual_table))
 
expected_table erase (expected_table.begin())
 
 add_to_expected_table (cur_block_height, cur_block_timestamp)
 
 create_account_with_resources (blockinfo_tester_account_name, config::system_account_name, core_sym::from_string("10.0000"), false)
 
 set_code (blockinfo_tester_account_name, test_contracts::blockinfo_tester_wasm())
 
 BOOST_CHECK (result.has_error())
 
 BOOST_REQUIRE (8< start_block_height)
 
 BOOST_CHECK (info.batch_start_height==info.batch_current_end_height)
 
 produce_blocks (2)
 

Переменные

static constexpr uint32_t anonymous_namespace{eosio.system_blockinfo_tests.cpp}::rolling_window_size = 10
 
 try
 
auto start_block_height = control->head_block_num()
 
auto start_block_timestamp = control->head_block_time()
 
std::vector< block_info_record > expected_table
 
auto add_to_expected_table
 
auto actual_table = get_blockinfo_table()
 
auto block_time_delta = fc::milliseconds(eosio::chain::config::block_interval_ms)
 
uint32_t cur_block_height = start_block_height + 1
 
auto cur_block_timestamp = start_block_timestamp + block_time_delta
 
auto advance_cur_block
 
auto latest_block_batch_info
 
auto require_latest_block_batch_info
 
auto expected_batch_start_timestamp = start_block_timestamp + block_time_delta(1)
 
auto expected_batch_current_end_timestamp = start_block_timestamp + block_time_delta(2)
 

Макросы

◆ TEST_INCLUDE

#define TEST_INCLUDE

Функции

◆ add_to_expected_table() [1/2]

add_to_expected_table ( cur_block_height  ,
cur_block_timestamp   
)

◆ add_to_expected_table() [2/2]

add_to_expected_table ( start_block_height  ,
start_block_timestamp   
)

◆ BOOST_CHECK() [1/4]

BOOST_CHECK ( check_tables_match(expected_table, actual_table )

◆ BOOST_CHECK() [2/4]

BOOST_CHECK ( info.  batch_start_height = =info.batch_current_end_height)
Инициализатор
{
auto require_latest_block_batch_info
Definition: eosio.system_blockinfo_tests.cpp:342
auto start_block_height
Definition: eosio.system_blockinfo_tests.cpp:261
asset max(10, symbol(SY(0, NKT)))

◆ BOOST_CHECK() [3/4]

BOOST_CHECK ( result.  has_error())
Инициализатор
{
auto result = latest_block_batch_info(0, 1)
auto latest_block_batch_info
Definition: eosio.system_blockinfo_tests.cpp:325

◆ BOOST_CHECK() [4/4]

BOOST_CHECK ( rolling_window_size  = =actual_table.size())

◆ BOOST_REQUIRE() [1/2]

BOOST_REQUIRE ( )

◆ BOOST_REQUIRE() [2/2]

BOOST_REQUIRE ( check_tables_match(expected_table, actual_table )

◆ create_account_with_resources()

create_account_with_resources ( blockinfo_tester_account_name  ,
config::system_account_name  ,
core_sym::from_string("10.0000")  ,
false   
)

◆ erase()

expected_table erase ( expected_table.  begin())

◆ FC_REFLECT()

FC_REFLECT ( block_info_record  ,
(version)(block_height)(block_timestamp)   
)

Scans filtered rows in blockinfo table in order of ascending block height where filtering only picks rows corresponding to block heights in the closed interval [start_block_height, end_block_height].

For each row visited, its deserialized block_info_record structure is passed into the visitor function. If a call to the visitor function returns false, scanning will stop and this function will return.

Предусловие
start_block_height <= end_block_height
Возвращает
number of rows visited

◆ for()

for ( uint32_t  end_block_height = start_block_height + rolling_window_size - 1;  cur_block_height <= end_block_height;  advance_cur_block())

◆ produce_blocks() [1/3]

produce_blocks ( )

◆ produce_blocks() [2/3]

produce_blocks ( )

◆ produce_blocks() [3/3]

produce_blocks ( rolling_window_size -  1)

◆ set_code()

set_code ( blockinfo_tester_account_name  ,
test_contracts::blockinfo_tester_wasm()   
)

Переменные

◆ actual_table

actual_table = get_blockinfo_table()

◆ add_to_expected_table

auto add_to_expected_table
Инициализатор
= [&expected_table](uint32_t block_height, fc::time_point block_timestamp) {
expected_table.push_back(block_info_record{
.block_height = block_height,
.block_timestamp = block_timestamp,
});
}
std::vector< block_info_record > expected_table
Definition: eosio.system_blockinfo_tests.cpp:264
eosio::time_point time_point
Definition: blockinfo_tester.hpp:30

◆ advance_cur_block

advance_cur_block
Инициализатор
}
auto block_time_delta
Definition: eosio.system_blockinfo_tests.cpp:281
auto cur_block_timestamp
Definition: eosio.system_blockinfo_tests.cpp:284
uint32_t cur_block_height
Definition: eosio.system_blockinfo_tests.cpp:283

◆ block_time_delta

auto block_time_delta = fc::milliseconds(eosio::chain::config::block_interval_ms)

◆ cur_block_height

uint32_t cur_block_height = start_block_height + 1

◆ cur_block_timestamp

auto cur_block_timestamp = start_block_timestamp + block_time_delta

◆ expected_batch_current_end_timestamp

auto expected_batch_current_end_timestamp = start_block_timestamp + block_time_delta(2)

◆ expected_batch_start_timestamp

auto expected_batch_start_timestamp = start_block_timestamp + block_time_delta(1)

◆ expected_table

std::vector<block_info_record> expected_table

◆ latest_block_batch_info

auto latest_block_batch_info
Инициализатор
= [this](uint32_t batch_start_height_offset,
uint32_t batch_size) -> blockinfo_tester::latest_block_batch_info_result
{
.batch_start_height_offset = batch_start_height_offset,
.batch_size = batch_size,
});
if (!result.first.has_value()) {
const eosio::chain::transaction_trace& trace = *result.second;
if (trace.except.has_value()) {
elog(trace.except->to_detail_string());
}
}
BOOST_REQUIRE(result.first.has_value());
return *result.first;
}
transaction_trace_ptr trace
Definition: eosio.msig_tests.cpp:305
BOOST_REQUIRE(check_tables_match(expected_table, actual_table))
latest_block_batch_info_result get_latest_block_batch_info(uint32_t batch_start_height_offset, uint32_t batch_size, eosio::name system_account_name="eosio"_n)
Definition: block_info.hpp:84

◆ require_latest_block_batch_info

auto require_latest_block_batch_info
Инициализатор
=
[latest_block_batch_info](uint32_t batch_start_height_offset,
uint32_t batch_size) -> blockinfo_tester::block_batch_info
{
auto result = latest_block_batch_info(batch_start_height_offset, batch_size);
if (result.has_error()) {
elog("require_latest_block_batch_info returned error: ${err}", ("err", result.get_error()));
}
BOOST_REQUIRE(!result.has_error());
return *result.result;
}

◆ start_block_height

auto start_block_height = control->head_block_num()

◆ start_block_timestamp

auto start_block_timestamp = control->head_block_time()

◆ try

try
Инициализатор
{
static_assert(rolling_window_size >= 2)
static constexpr uint32_t rolling_window_size
Definition: eosio.system_blockinfo_tests.cpp:35