Ejemplo n.º 1
0
 def __generate_genasis(self):
     """ Generate the genesis block """
     b = Block(prev_hash="########")
     b.id = 0
     b.hash = "----------------"
     b.proof_no = 0
     return b
Ejemplo n.º 2
0
 def test_create_block(self):
     gen_block = block = Block.generate_genasis()
     block = Block.generate_block(last_block=gen_block,
                                  nonce=100,
                                  transaction={})
     assert block.prev_hash == "----------------"
     assert block.nonce == 100
Ejemplo n.º 3
0
    def test_update_next_hash(self):
        gen_block = block = Block.generate_genasis()
        block = Block.generate_block(last_block=gen_block,
                                     nonce=100,
                                     transaction={})
        block2 = Block.generate_block(last_block=gen_block,
                                      nonce=100,
                                      transaction={})
        block.update_next_hash(block2.hash)

        assert block.next_hash == block2.hash
Ejemplo n.º 4
0
    def generate_block(self, last_block_hash, proof_of_work, transaction):
        """ generate a block and add it to the chain"""
        b = Block(id=self.last_block.id + 1,
                  prev_hash=last_block_hash,
                  proof_no=proof_of_work,
                  data=transaction);
        self.transactions = []
        self.blocks.append(b)

        return b
Ejemplo n.º 5
0
 def test_create_genasis_block(self):
     block = Block.generate_genasis()
     assert block.prev_hash == "########"
     assert block.hash == "----------------"
Ejemplo n.º 6
0
 def test_to_json(self):
     gen_block = Block.generate_genasis().to_json()
     print(gen_block)
Ejemplo n.º 7
0
    def test_to_string(self):
        gen_block = Block.generate_genasis().to_string()

        assert gen_block == "id = 0 , hash = ---------------- , prev_hash = ######## , next_hash = None , nonce = None , permission = None , data = None"
        print(gen_block)