def test_getStats_timeseries(self): with MockedBlockchain.create(10) as mock_blockchain: service = PublicAPIService(mock_blockchain.qrlnode) request = qrl_pb2.GetStatsReq(include_timeseries=1) stats = service.GetStats(request=request, context=None) print(stats.block_timeseries) self.assertEqual(11, len(stats.block_timeseries)) self.assertEqual(61, stats.block_time_mean) self.assertEqual(1, stats.block_time_sd)
def getStats_forking(self, timeseries_size): number_blocks = 10 with MockedBlockchain.create(number_blocks) as mock_blockchain: with set_timeseries_size(timeseries_size): service = PublicAPIService(mock_blockchain.qrlnode) request = qrl_pb2.GetStatsReq(include_timeseries=True) stats = service.GetStats(request=request, context=None) self.assertEqual(timeseries_size, len(stats.block_timeseries)) # Fork at node 9 with 2 blocks (b) block_9 = mock_blockchain.qrlnode.get_block_from_index(9) block_10 = mock_blockchain.qrlnode.get_block_last() block_10b = mock_blockchain.create_block(block_9.headerhash) mock_blockchain.add_block(block_10b) block_11b = mock_blockchain.create_block(block_10b.headerhash) mock_blockchain.add_block(block_11b) # Get time series request = qrl_pb2.GetStatsReq(include_timeseries=True) stats = service.GetStats(request=request, context=None) self.assertEqual(timeseries_size, len(stats.block_timeseries)) # check stats have moved to the correct branch self.assertEqual(block_11b.headerhash, stats.block_timeseries[-1].header_hash) # Add back to the original chain (a) block_11 = mock_blockchain.create_block(block_10.headerhash) mock_blockchain.add_block(block_11) block_12 = mock_blockchain.create_block(block_11.headerhash) mock_blockchain.add_block(block_12) # Get time series request = qrl_pb2.GetStatsReq(include_timeseries=True) stats = service.GetStats(request=request, context=None) self.assertEqual(timeseries_size, len(stats.block_timeseries)) # check stats have moved back to the correct branch self.assertEqual(block_12.headerhash, stats.block_timeseries[-1].header_hash)
def test_getStats(self): number_blocks = 1 with MockedBlockchain.create(number_blocks) as mock_blockchain: with set_timeseries_size(10): service = PublicAPIService(mock_blockchain.qrlnode) for i in range(number_blocks + 1, 50): mock_blockchain.add_new_block() request = qrl_pb2.GetStatsReq() request.include_timeseries = True stats = service.GetStats(request=request, context=None) self.assertEqual(min(10, i + 1), len(stats.block_timeseries))
def test_getStats(self): db_state = Mock(spec=State) db_state.total_coin_supply = MagicMock(return_value=1000) db_state.get_measurement = MagicMock(return_value=60) p2p_factory = Mock(spec=P2PFactory) p2p_factory.sync_state = SyncState() p2p_factory.connections = 23 p2p_factory.pow = Mock() chain_manager = Mock(spec=ChainManager) chain_manager.height = 0 chain_manager.get_last_block = MagicMock(return_value=GenesisBlock()) chain_manager.get_block_by_number = MagicMock(return_value=None) chain_manager.state = db_state qrlnode = QRLNode(db_state, mining_address=b'') qrlnode.set_chain_manager(chain_manager) qrlnode._p2pfactory = p2p_factory qrlnode._pow = p2p_factory.pow service = PublicAPIService(qrlnode) request = qrl_pb2.GetStatsReq() stats = service.GetStats(request=request, context=None) # self.assertEqual(__version__, stats.node_info.version) # FIXME self.assertEqual(qrl_pb2.NodeInfo.UNSYNCED, stats.node_info.state) self.assertEqual(23, stats.node_info.num_connections) # self.assertEqual("testnet", stats.node_info.network_id) # FIXME self.assertEqual(0, stats.epoch) self.assertEqual(0, stats.uptime_network) self.assertEqual(65000000000000000, stats.block_last_reward) self.assertEqual(60, stats.block_time_mean) self.assertEqual(0, stats.block_time_sd) self.assertEqual(105000000, stats.coins_total_supply) self.assertEqual(1000, stats.coins_emitted) self.assertEqual(0, len(stats.block_timeseries))
def get_stats(qrl_client): request = qrl_pb2.GetStatsReq() response = qrl_client.GetStats(request) log_msg('', response)