src/test/test_martkist_services.cpp
// generate n Blocks, with up to 10 seconds relay time buffer for other nodes to get the blocks.
// may fail if your network is slow or you try to generate too many blocks such that can't relay within 10 seconds
generate n Blocks, with up to 10 seconds relay time buffer for other nodes to get the blocks.
may fail if your network is slow or you try to generate too many blocks such that can't relay within 10 seconds
generate n Blocks with up to 10 seconds relay time buffer for other nodes to get the blocks . may fail if your network is slow or you try to generate too many blocks such that can ' t relay within 10 seconds
void GenerateBlocks(int nBlocks, const string& node)
{
	int height, newHeight, timeoutCounter;
	UniValue r;
	string otherNode1, otherNode2;
	GetOtherNodes(node, otherNode1, otherNode2);
	try
	{
		r = CallRPC(node, "getinfo");
	}
	catch (const runtime_error &e)
	{
		return;
	}
	newHeight = find_value(r.get_obj(), "blocks").get_int() + nBlocks;
	const string &sBlocks = strprintf("%d", nBlocks);
	BOOST_CHECK_NO_THROW(r = CallRPC(node, "generate " + sBlocks));
	BOOST_CHECK_NO_THROW(r = CallRPC(node, "getinfo"));
	height = find_value(r.get_obj(), "blocks").get_int();
	BOOST_CHECK(height >= newHeight);
	height = 0;
	timeoutCounter = 0;
	MilliSleep(10);
	while (!otherNode1.empty() && height < newHeight)
	{
		try
		{
			r = CallRPC(otherNode1, "getinfo");
		}
		catch (const runtime_error &e)
		{
			r = NullUniValue;
		}
		if (!r.isObject())
		{
			height = newHeight;
			break;
		}
		height = find_value(r.get_obj(), "blocks").get_int();
		timeoutCounter++;
		if (timeoutCounter > 100) {
			printf("Error: Timeout on getinfo for %s, height %d vs newHeight %d!\n", otherNode1.c_str(), height, newHeight);
			break;
		}
		MilliSleep(10);
	}
	if (!otherNode1.empty())
		BOOST_CHECK(height >= newHeight);
	height = 0;
	timeoutCounter = 0;
	while (!otherNode2.empty() && height < newHeight)
	{
		try
		{
			r = CallRPC(otherNode2, "getinfo");
		}
		catch (const runtime_error &e)
		{
			r = NullUniValue;
		}
		if (!r.isObject())
		{
			height = newHeight;
			break;
		}
		height = find_value(r.get_obj(), "blocks").get_int();
		timeoutCounter++;
		if (timeoutCounter > 100) {
			printf("Error: Timeout on getinfo for %s, height %d vs newHeight %d!\n", otherNode2.c_str(), height, newHeight);
			break;
		}
		MilliSleep(10);
	}
	if (!otherNode2.empty())
		BOOST_CHECK(height >= newHeight);
	height = 0;
	timeoutCounter = 0;
}
void GenerateBlocks ( int nBlocks , const string & node ) { int height , newHeight , timeoutCounter ; UniValue r ; string otherNode1 , otherNode2 ; GetOtherNodes ( node , otherNode1 , otherNode2 ) ; try { r = CallRPC ( node , " " ) ; } catch ( const runtime_error & e ) { return ; } newHeight = find_value ( r . get_obj ( ) , " " ) . get_int ( ) + nBlocks ; const string & sBlocks = strprintf ( " " , nBlocks ) ; BOOST_CHECK_NO_THROW ( r = CallRPC ( node , " " + sBlocks ) ) ; BOOST_CHECK_NO_THROW ( r = CallRPC ( node , " " ) ) ; height = find_value ( r . get_obj ( ) , " " ) . get_int ( ) ; BOOST_CHECK ( height >= newHeight ) ; height = 0 ; timeoutCounter = 0 ; MilliSleep ( 10 ) ; while ( ! otherNode1 . empty ( ) && height < newHeight ) { try { r = CallRPC ( otherNode1 , " " ) ; } catch ( const runtime_error & e ) { r = NullUniValue ; } if ( ! r . isObject ( ) ) { height = newHeight ; break ; } height = find_value ( r . get_obj ( ) , " " ) . get_int ( ) ; timeoutCounter ++ ; if ( timeoutCounter > 100 ) { printf ( " \n " , otherNode1 . c_str ( ) , height , newHeight ) ; break ; } MilliSleep ( 10 ) ; } if ( ! otherNode1 . empty ( ) ) BOOST_CHECK ( height >= newHeight ) ; height = 0 ; timeoutCounter = 0 ; while ( ! otherNode2 . empty ( ) && height < newHeight ) { try { r = CallRPC ( otherNode2 , " " ) ; } catch ( const runtime_error & e ) { r = NullUniValue ; } if ( ! r . isObject ( ) ) { height = newHeight ; break ; } height = find_value ( r . get_obj ( ) , " " ) . get_int ( ) ; timeoutCounter ++ ; if ( timeoutCounter > 100 ) { printf ( " \n " , otherNode2 . c_str ( ) , height , newHeight ) ; break ; } MilliSleep ( 10 ) ; } if ( ! otherNode2 . empty ( ) ) BOOST_CHECK ( height >= newHeight ) ; height = 0 ; timeoutCounter = 0 ; }
generate n Blocks, with up to 10 seconds relay time buffer for other nodes to get the blocks.
generate n Blocks with up to 10 seconds relay time buffer for other nodes to get the blocks .