'Testing whether the API returns the correct statistics'

@deferred(timeout=10)
def test_get_statistics(self):

    block = TrustChainBlock()
    block.public_key = self.member.public_key
    block.link_public_key = 'deadbeef'.decode('HEX')
    block.link_sequence_number = 21
    block.transaction = {'up': 42, 'down': 8, 'total_up': 1024, 'total_down': 2048}
    block.sequence_number = 3
    block.previous_hash = 'babecafe'.decode('HEX')
    block.signature = 'babebeef'.decode('HEX')
    self.tc_community.persistence.add_block(block)
    def verify_response(response):
        response_json = json.loads(response)
        self.assertTrue(('statistics' in response_json))
        stats = response_json['statistics']
        self.assertEqual(stats['id'], self.member.public_key.encode('HEX'))
        self.assertEqual(stats['total_blocks'], 3)
        self.assertEqual(stats['total_up'], 1024)
        self.assertEqual(stats['total_down'], 2048)
        self.assertEqual(stats['peers_that_pk_helped'], 1)
        self.assertEqual(stats['peers_that_helped_pk'], 1)
        self.assertIn('latest_block', stats)
        self.assertNotEqual(stats['latest_block']['insert_time'], '')
        self.assertEqual(stats['latest_block']['hash'], block.hash.encode('HEX'))
        self.assertEqual(stats['latest_block']['link_public_key'], 'deadbeef')
        self.assertEqual(stats['latest_block']['link_sequence_number'], 21)
        self.assertEqual(stats['latest_block']['up'], 42)
        self.assertEqual(stats['latest_block']['down'], 8)
    self.should_check_equality = False
    return self.do_request('trustchain/statistics', expected_code=200).addCallback(verify_response)
