Пример #1
0
def test_any_other_node_found_correct_hash_then_mining_should_be_stopped():
    from dokuztas.blockchain import Blockchain, PendingBlock, Block
    node = NodeComponent(miner=True)
    node.chain = Blockchain(difficulty=10)

    def adds_genesis():
        genesis = Block(id=0,
                        blockhash=0,
                        previous_hash=0,
                        nonce=0,
                        merkleroot=0,
                        data=['genesis'])
        node.chain.blocks.append(genesis)

    genesis_patcher = patch('dokuztas.node.NodeComponent.create_genesis_chain',
                            side_effect=adds_genesis)
    genesis_patcher.start()
    node.create_genesis_chain()
    genesis_patcher.stop()

    pending_block = PendingBlock()
    pending_block.add_txs(['a', 'b', 'c'])
    node.pending_blocks.append(pending_block)
    node.mine()
    block_to_add = Block(id=123,
                         previous_hash=0,
                         nonce=123,
                         merkleroot=123,
                         blockhash=111,
                         data=['a', 'b', 'c'])
    node.block_added(block_to_add)
    assert node.chain.blocks[1].blockhash == 111
    assert len(node.chain.blocks) == 2
Пример #2
0
 def func_wrapper():
     from dokuztas.blockchain import Blockchain
     node = NodeComponent()
     node.chain = Blockchain(difficulty=difficulty)
     node.miner = True
     node.create_genesis_chain()
     for x in range(0, txs_count):
         node.add_transaction(str(x))
     func(node)
Пример #3
0
def test_if_first_pendingblock_is_just_created_then_mining_should_be_started_once():
    node = NodeComponent(miner=True)
    node.create_genesis_chain()
    patcher = patch('dokuztas.node.NodeComponent.mine')
    mock = patcher.start()
    for x in range(0, 200):
        node.add_transaction(x)
    patcher.stop()
    mock.assert_called_once()
Пример #4
0
 def func_wrapper():
     patcher = patch('dokuztas.node.NodeComponent.mine')
     patcher.start()
     node = NodeComponent()
     node.miner = True
     node.create_genesis_chain()
     for x in range(0, txs_count):
         node.add_transaction(str(x))
     patcher.stop()
     func(node)
Пример #5
0
def test_if_node_is_not_a_miner_then_mine_function_should_throw_minerexception(
):
    node = NodeComponent(miner=False)
    node.create_genesis_chain()
    with pytest.raises(MinerException):
        node.mine()