Skip to content

Commit 275f123

Browse files
committed
IS-1426 extend test helpers; add consensus restart from db test for bite and non-bite builds
1 parent ddf9c59 commit 275f123

4 files changed

Lines changed: 430 additions & 9 deletions

File tree

CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,15 +339,16 @@ file(GLOB_RECURSE COMMON_TEST_SOURCES
339339
"tests/unit/db/*.cpp"
340340
"tests/consensus_tests.cpp"
341341
"tests/sgx_tests.cpp"
342+
"tests/e2e/RestartBootstrapTests.cpp"
342343
)
343344

344345
set(TEST_SOURCES ${COMMON_TEST_SOURCES})
345346

346347
# Conditionally add rlp test sources if BITE is enabled
347348
if (DEFINED BITE)
348-
file(GLOB_RECURSE BITE_TEST_SOURCES
349-
"tests/unit/bite/*.cpp"
350-
"tests/e2e/ReencryptionRandomConsensusTests.cpp"
349+
file(GLOB_RECURSE BITE_TEST_SOURCES "tests/unit/bite/*.cpp")
350+
list(APPEND BITE_TEST_SOURCES
351+
"tests/e2e/bite/ReencryptionRandomConsensusTests.cpp"
351352
)
352353
list(APPEND TEST_SOURCES ${BITE_TEST_SOURCES} libBLS/test/utils.cpp)
353354

tests/e2e/ConsensusEngineTestAccess.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66

77
class ConsensusEngineTestAccess {
88
public:
9+
static node_id getFirstNodeId( const ConsensusEngine& e ) {
10+
CHECK_STATE( e.nodes.size() > 0 );
11+
auto it = e.nodes.begin();
12+
CHECK_STATE( it != e.nodes.end() );
13+
CHECK_STATE( it->second );
14+
return it->first;
15+
}
16+
917
static ptr<CommittedBlock> getCommittedBlockForBlockId(
1018
const ConsensusEngine& e, uint64_t id) {
1119

@@ -42,4 +50,44 @@ class ConsensusEngineTestAccess {
4250
return block;
4351

4452
}
53+
54+
static uint64_t getBootstrapBlockIDForNode( const ConsensusEngine& e, node_id node ) {
55+
auto it = e.nodes.find( node );
56+
CHECK_STATE2( it != e.nodes.end(), "Node with id " + to_string( node ) + " not found" );
57+
CHECK_STATE( it->second );
58+
auto schain = it->second->getSchain();
59+
CHECK_STATE( schain );
60+
return (uint64_t) schain->getBootstrapBlockID();
61+
}
62+
63+
static uint64_t getBootstrapBlockID( const ConsensusEngine& e ) {
64+
return getBootstrapBlockIDForNode( e, getFirstNodeId( e ) );
65+
}
66+
67+
static block_id getCurrentLastCommittedBlockIDForNode( const ConsensusEngine& e, node_id node ) {
68+
auto it = e.nodes.find( node );
69+
CHECK_STATE2( it != e.nodes.end(), "Node with id " + to_string( node ) + " not found" );
70+
CHECK_STATE( it->second );
71+
auto schain = it->second->getSchain();
72+
CHECK_STATE( schain );
73+
return schain->getLastCommittedBlockID();
74+
}
75+
76+
static block_id getCurrentLastCommittedBlockID( const ConsensusEngine& e ) {
77+
return getCurrentLastCommittedBlockIDForNode( e, getFirstNodeId( e ) );
78+
}
79+
80+
static TimeStamp getCurrentLastCommittedBlockTimeStampForNode(
81+
const ConsensusEngine& e, node_id node ) {
82+
auto it = e.nodes.find( node );
83+
CHECK_STATE2( it != e.nodes.end(), "Node with id " + to_string( node ) + " not found" );
84+
CHECK_STATE( it->second );
85+
auto schain = it->second->getSchain();
86+
CHECK_STATE( schain );
87+
return schain->getLastCommittedBlockTimeStamp();
88+
}
89+
90+
static TimeStamp getCurrentLastCommittedBlockTimeStamp( const ConsensusEngine& e ) {
91+
return getCurrentLastCommittedBlockTimeStampForNode( e, getFirstNodeId( e ) );
92+
}
4593
};

tests/e2e/E2ETestHelper.h

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class E2ETestHelper {
3838
inline static const string TWO_NODE_TEST_DATA_DIR = TEST_DATA_ROOT_DIR + "/twonodes_sameip";
3939
static constexpr uint64_t DEFAULT_RUN_TIME_S = 4;
4040
static constexpr uint64_t CROSS_NODE_RUN_TIME_S = 20;
41+
static constexpr uint64_t DEFAULT_STORAGE_LIMIT_BYTES = 1000000000;
4142

4243
static void configureTestEnvironment(
4344
bool _cleanDataDir,
@@ -64,6 +65,38 @@ class E2ETestHelper {
6465
setTestEnvVar( "TEST_TIME_S", "4", 0 );
6566
}
6667

68+
static void startEngine(
69+
ConsensusEngine*& _engine,
70+
int64_t _lastId,
71+
const std::map< string, uint64_t >& _patchTimestamps = {
72+
#ifdef BITE
73+
{ "bite2PatchTimestamp", 0 }
74+
#endif
75+
},
76+
ConsensusExtFace* _extFace = nullptr,
77+
uint64_t _lastCommittedBlockTimeStamp = 0,
78+
uint64_t _lastCommittedBlockTimeStampMs = 0,
79+
bool _useBlockIDFromConsensus = false ) {
80+
CATCH_REQUIRE( _engine == nullptr );
81+
82+
if ( _extFace != nullptr ) {
83+
CATCH_REQUIRE( _lastId >= 0 );
84+
_engine = new ConsensusEngine( *_extFace, (uint64_t) _lastId,
85+
_lastCommittedBlockTimeStamp, _lastCommittedBlockTimeStampMs, _patchTimestamps,
86+
DEFAULT_STORAGE_LIMIT_BYTES );
87+
} else {
88+
_engine = new ConsensusEngine( _lastId, DEFAULT_STORAGE_LIMIT_BYTES );
89+
if ( !_patchTimestamps.empty() ) {
90+
_engine->setTestPatchTimestamps( _patchTimestamps );
91+
}
92+
}
93+
94+
auto useBlockIdFromConsensus = _useBlockIDFromConsensus || ( _extFace == nullptr && _lastId == -1 );
95+
_engine->parseTestConfigsAndCreateAllNodes(
96+
Consensust::getConfigDirPath(), useBlockIdFromConsensus );
97+
_engine->slowStartBootStrapTest();
98+
}
99+
67100
static block_id startEngineAndWait(
68101
ConsensusEngine*& _engine,
69102
int64_t _lastId,
@@ -73,12 +106,7 @@ class E2ETestHelper {
73106
{ "bite2PatchTimestamp", 0 }
74107
#endif
75108
} ) {
76-
_engine = new ConsensusEngine( _lastId, 1000000000 );
77-
if ( !_patchTimestamps.empty() ) {
78-
_engine->setTestPatchTimestamps( _patchTimestamps );
79-
}
80-
_engine->parseTestConfigsAndCreateAllNodes( Consensust::getConfigDirPath(), _lastId == -1 );
81-
_engine->slowStartBootStrapTest();
109+
startEngine( _engine, _lastId, _patchTimestamps );
82110

83111
usleep( 1000 * 1000 * _runTimeS );
84112

0 commit comments

Comments
 (0)