Пример #1
0
 def test_json(self):
     self.blockchain.add_block(
         self.blockchain.generate_new_block('new-block'))
     self.assertEqual(
         convert_dumps(
             {'blocks': [b.dict() for b in self.blockchain.blocks]}),
         self.blockchain.json())
Пример #2
0
    async def test_query_all(self):
        ws = await self.client.ws_connect('/ws')
        ws.send_str(convert_dumps({'type': MessageTypes.QUERY_ALL}))

        async for msg in ws:
            data = convert_loads(msg.data)['data']
            self.assertEqual(data, self.server.blockchain.dict())
            return ws.close()
Пример #3
0
 def test_json(self):
     self.assertEqual(
         convert_dumps({
             'index': 1,
             'previous_hash': '12',
             'timestamp': 1465154705,
             'data': 'test-block',
             'hash': '12345'
         }), self.block.json())
Пример #4
0
    async def test_blockchain_received__append(self):
        other_blockchain = Blockchain()
        other_blockchain.add_block(
            other_blockchain.generate_new_block('new-block'))

        ws = await self.client.ws_connect('/ws')
        ws.send_str(
            convert_dumps({
                'type': MessageTypes.RESPONSE_BLOCKCHAIN,
                'data': other_blockchain.dict()
            }))

        async for msg in ws:
            self.assertEqual(other_blockchain.latest_block,
                             self.server.blockchain.latest_block)
            return ws.close()
Пример #5
0
 async def handle_query_latest(self, ws):
     ws.send_str(
         convert_dumps({
             'type': MessageTypes.RESPONSE_BLOCKCHAIN,
             'data': self.blockchain.latest_block.dict()
         }))
Пример #6
0
 def get_query_all_msg(self) -> str:
     return convert_dumps({'type': MessageTypes.QUERY_ALL})
Пример #7
0
 def get_response_latest_msg(self) -> str:
     return convert_dumps({
         'type': MessageTypes.RESPONSE_BLOCKCHAIN,
         'data': [self.blockchain.latest_block.dict()]
     })