|
COOPENOMICS
v1
Кооперативная Экономика
|
#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) |
| #define TEST_INCLUDE |
| add_to_expected_table | ( | cur_block_height | , |
| cur_block_timestamp | |||
| ) |
| add_to_expected_table | ( | start_block_height | , |
| start_block_timestamp | |||
| ) |
| BOOST_CHECK | ( | check_tables_match(expected_table, actual_table) | ) |
| BOOST_CHECK | ( | info. | batch_start_height = =info.batch_current_end_height | ) |
| BOOST_CHECK | ( | result. | has_error() | ) |
| BOOST_CHECK | ( | rolling_window_size | = =actual_table.size() | ) |
| BOOST_REQUIRE | ( | ) |
| BOOST_REQUIRE | ( | check_tables_match(expected_table, actual_table) | ) |
| create_account_with_resources | ( | blockinfo_tester_account_name | , |
| config::system_account_name | , | ||
| core_sym::from_string("10.0000") | , | ||
| false | |||
| ) |
| expected_table erase | ( | expected_table. | begin() | ) |
| 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.
| 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 | ) |
| produce_blocks | ( | 2 | ) |
| produce_blocks | ( | rolling_window_size - | 1 | ) |
| set_code | ( | blockinfo_tester_account_name | , |
| test_contracts::blockinfo_tester_wasm() | |||
| ) |
| actual_table = get_blockinfo_table() |
| auto add_to_expected_table |
| advance_cur_block |
| 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 expected_batch_current_end_timestamp = start_block_timestamp + block_time_delta(2) |
| auto expected_batch_start_timestamp = start_block_timestamp + block_time_delta(1) |
| std::vector<block_info_record> expected_table |
| auto latest_block_batch_info |
| auto require_latest_block_batch_info |
| auto start_block_height = control->head_block_num() |
| auto start_block_timestamp = control->head_block_time() |
| try |