2020 @date 2026
2121*/
2222
23+ #include < cstdint>
2324#ifdef BITE2
2425
2526#include " thirdparty/catch.hpp"
@@ -72,6 +73,77 @@ std::map< uint64_t, u256 > readReencryptionRandoms(
7273
7374using namespace RandomTests ;
7475
76+
77+ CATCH_TEST_CASE (
78+ " normal consensus prior to bite2 patch timestamp with default blocks" ,
79+ " [pre-patch][end-to-end][db][bite2]" ) {
80+
81+ ConsensusEngine* testEngine = nullptr ;
82+
83+ try {
84+ E2EHelper::configureTestEnvironment ( true , " test/twonodes_sameip" );
85+ auto runTimeS = E2EHelper::CROSS_NODE_RUN_TIME_S ;
86+ auto lastId =
87+ ( uint64_t ) E2EHelper::startEngineAndWait ( testEngine, 0 , runTimeS );
88+
89+ // Two-node setup can need extra time before first DB commit; poll briefly before failing.
90+ for ( int i = 0 ; i < 70 && lastId == 0 ; i++ ) {
91+ usleep ( 500 * 1000 );
92+ lastId = ( uint64_t ) testEngine->getLargestCommittedBlockIDInDb ();
93+ }
94+
95+ CATCH_REQUIRE ( lastId > 0 );
96+ CATCH_REQUIRE ( ( uint64_t ) testEngine->nodesCount () == 2 );
97+
98+ auto nodeIds = testEngine->getNodeIDs ();
99+ CATCH_REQUIRE ( nodeIds.size () == 2 );
100+
101+ auto nodeIt = nodeIds.begin ();
102+ auto firstNodeId = *nodeIt;
103+ ++nodeIt;
104+ auto secondNodeId = *nodeIt;
105+
106+ uint32_t exceptionsNode1 = 0 ;
107+ uint32_t exceptionsNode2 = 0 ;
108+
109+ // no reencryption random should be present for any block
110+ // Calls SHOULD throw until patch timestamp (meaning they are not usable)
111+ for ( uint64_t blockId = 1 ; blockId <= lastId; blockId++ ) {
112+ try {
113+ testEngine->getReencryptionRandomForBlockIdForNode ( blockId, firstNodeId );
114+ } catch ( ... ) {
115+ exceptionsNode1++;
116+ }
117+
118+ try {
119+ testEngine->getReencryptionRandomForBlockIdForNode ( blockId, secondNodeId );
120+ } catch ( ... ) {
121+ exceptionsNode2++;
122+ }
123+ }
124+
125+ CATCH_REQUIRE ( exceptionsNode1 > 0 );
126+ CATCH_REQUIRE ( exceptionsNode2 > 0 );
127+ CATCH_REQUIRE ( exceptionsNode1 == exceptionsNode2 );
128+
129+ E2EHelper::stopEngineGracefully ( testEngine );
130+ } catch ( SkaleException& e ) {
131+ if ( testEngine ) {
132+ E2EHelper::stopEngineGracefully ( testEngine );
133+ }
134+ SkaleException::logNested ( e );
135+ throw ;
136+ } catch ( ... ) {
137+ if ( testEngine ) {
138+ E2EHelper::stopEngineGracefully ( testEngine );
139+ }
140+ throw ;
141+ }
142+
143+ CATCH_SUCCEED ();
144+ }
145+
146+
75147CATCH_TEST_CASE (
76148 " reencryption random is equal across nodes for same block ids" ,
77149 " [reencryption-random-cross-node][end-to-end][db][bite2]" ) {
@@ -82,18 +154,15 @@ CATCH_TEST_CASE(
82154 E2EHelper::configureTestEnvironment ( true , " test/twonodes_sameip" );
83155 auto runTimeS = E2EHelper::CROSS_NODE_RUN_TIME_S ;
84156 auto lastId =
85- ( uint64_t ) E2EHelper::startEngineAndWait ( testEngine, 0 , runTimeS );
86- auto lastIdInMemory = ( uint64_t ) testEngine-> getLargestCommittedBlockID ( );
157+ ( uint64_t ) E2EHelper::startEngineAndWait ( testEngine, 0 , runTimeS,
158+ { { " bite2PatchTimestamp " , 1 } } );
87159
88160 // Two-node setup can need extra time before first DB commit; poll briefly before failing.
89161 for ( int i = 0 ; i < 70 && lastId == 0 ; i++ ) {
90162 usleep ( 500 * 1000 );
91163 lastId = ( uint64_t ) testEngine->getLargestCommittedBlockIDInDb ();
92- lastIdInMemory = ( uint64_t ) testEngine->getLargestCommittedBlockID ();
93164 }
94165
95- CATCH_INFO (
96- " lastIdInDb=" << lastId << " , lastIdInMemory=" << lastIdInMemory << " , runTimeS=" << runTimeS );
97166 CATCH_REQUIRE ( lastId > 0 );
98167 CATCH_REQUIRE ( ( uint64_t ) testEngine->nodesCount () == 2 );
99168
@@ -154,11 +223,12 @@ CATCH_TEST_CASE(
154223 " [reencryption-random-committed][end-to-end][db][bite2]" ) {
155224
156225 ConsensusEngine* testEngine = nullptr ;
157-
226+
158227 try {
159228 E2EHelper::configureTestEnvironment ( true );
160229 // Start consensus and wait for blocks to be committed
161- auto lastId = E2EHelper::startEngineAndWait ( testEngine, 0 , E2EHelper::DEFAULT_RUN_TIME_S );
230+ auto lastId = E2EHelper::startEngineAndWait ( testEngine, 0 , E2EHelper::DEFAULT_RUN_TIME_S ,
231+ { { " bite2PatchTimestamp" , 1 } } );
162232
163233 CATCH_REQUIRE ( lastId > 0 );
164234
@@ -199,11 +269,12 @@ CATCH_TEST_CASE(
199269 " [reencryption-random-deterministic][end-to-end][db][bite2]" ) {
200270
201271 ConsensusEngine* testEngine = nullptr ;
202-
272+
203273 try {
204274 E2EHelper::configureTestEnvironment ( true );
205275 // Start consensus and wait for blocks to be committed
206- auto lastId = E2EHelper::startEngineAndWait ( testEngine, 0 , E2EHelper::DEFAULT_RUN_TIME_S );
276+ auto lastId = E2EHelper::startEngineAndWait ( testEngine, 0 , E2EHelper::DEFAULT_RUN_TIME_S ,
277+ { { " bite2PatchTimestamp" , 1 } } );
207278
208279 CATCH_REQUIRE ( lastId > 0 );
209280
@@ -245,17 +316,14 @@ CATCH_TEST_CASE(
245316 try {
246317 E2EHelper::configureTestEnvironment ( true );
247318 // Start consensus and wait for blocks to be committed
248- auto lastId = (uint64_t ) E2EHelper::startEngineAndWait ( testEngine, 0 , E2EHelper::DEFAULT_RUN_TIME_S );
319+ auto lastId = (uint64_t ) E2EHelper::startEngineAndWait ( testEngine, 0 , E2EHelper::DEFAULT_RUN_TIME_S ,
320+ { { " bite2PatchTimestamp" , 1 } } );
249321
250322 CATCH_REQUIRE ( lastId > 0 );
251323
252324 uint64_t checkedBlocks = 0 ;
253- uint64_t startBlock = 1 ;
254- #ifdef BITE2
255- startBlock = 2 ;
256- #endif
257325
258- for ( uint64_t blockId = startBlock ; blockId <= lastId; blockId++ ) {
326+ for ( uint64_t blockId = 1 ; blockId <= lastId; blockId++ ) {
259327 try {
260328 // For same committed block id, compare:
261329 // getReencryptionRandomForBlockId(id) vs getRandomForBlockId(id)
@@ -295,11 +363,12 @@ CATCH_TEST_CASE(
295363 " [reencryption-random-restart-1][end-to-end][db][bite2]" ) {
296364
297365 ConsensusEngine* testEngine = nullptr ;
298-
366+
299367 try {
300368 E2EHelper::configureTestEnvironment ( true );
301369 // First run: start from scratch and collect reencryption randoms
302- auto lastId = (uint64_t ) E2EHelper::startEngineAndWait ( testEngine, 0 , E2EHelper::DEFAULT_RUN_TIME_S );
370+ auto lastId = (uint64_t ) E2EHelper::startEngineAndWait ( testEngine, 0 , E2EHelper::DEFAULT_RUN_TIME_S ,
371+ { { " bite2PatchTimestamp" , 1 } } );
303372
304373 CATCH_REQUIRE ( lastId > 0 );
305374
@@ -333,10 +402,10 @@ CATCH_TEST_CASE(
333402
334403CATCH_TEST_CASE (
335404 " reencryption random survives restart - continue after restart" ,
336- " [reencryption-random-restart-2][end-to-end][bite2]" ) {
405+ " [reencryption-random-restart-2][end-to-end][db][ bite2]" ) {
337406
338407 ConsensusEngine* testEngine = nullptr ;
339-
408+
340409 try {
341410 E2EHelper::configureTestEnvironment ( false );
342411 // Load the randoms from before restart
@@ -359,6 +428,7 @@ CATCH_TEST_CASE(
359428
360429 // Restart with continue mode (_lastId == -1 path)
361430 testEngine = new ConsensusEngine ( -1 , 1000000000 );
431+ testEngine->setTestPatchTimestamps ({ { " bite2PatchTimestamp" , 1 } } );
362432 testEngine->parseTestConfigsAndCreateAllNodes ( Consensust::getConfigDirPath (), true );
363433 testEngine->slowStartBootStrapTest ();
364434
0 commit comments