Ejemplo n.º 1
0
 def setUp(self):
     self.host = '127.0.0.1'
     self.port = 3000
     self.blockchain = Blockchain()
     self.transactions_pool = TransactionsPool()
     self.p2p_server = P2PServer(self.blockchain, self.transactions_pool)
     self.p2p_server.bind(self.host, self.port)
Ejemplo n.º 2
0
 def setUp(self):
     super(BlockchainTest, self).setUp()
     self.chain_length = random.randint(5, 10)
     self.valid_chain = self._generate_valid_chain(self.chain_length)
     self.invalid_chain = self._generate_invalid_chain()
     self.blockchain = Blockchain(self.valid_chain)
     self.serialized = self.blockchain.serialize()
Ejemplo n.º 3
0
 def test_transactions_pool_clear_pool(self):
     data = self.transactions_pool.data
     blockchain = Blockchain()
     blockchain.add_block(data)
     self.assertEqual(self.transactions_pool.size, len(data))
     self.transactions_pool.clear_pool(blockchain)
     self.assertEqual(self.transactions_pool.size, 0)
Ejemplo n.º 4
0
 def _generate_blockchain(self, blocks: int = 5):
     blockchain = Blockchain()
     data = []
     for _ in range(0, blocks):
         transaction = self._generate_transaction()
         data.append(transaction.info)
     blockchain.add_block(data)
     return blockchain
Ejemplo n.º 5
0
 def setUp(self):
     super(ApiTest, self).setUp()
     chain_length = random.randint(5, 10)
     chain = self._generate_valid_chain(chain_length)
     pool = self._generate_transactions_pool()
     app.blockchain = Blockchain(chain)
     app.transactions_pool = TransactionsPool(pool)
     self.client = TestClient(app)
Ejemplo n.º 6
0
 def blockchain(self) -> Blockchain:
     if not hasattr(self, '_blockchain'):
         self._blockchain = Blockchain()
     return self._blockchain