Example #1
0
def test_read_genesis_block(monkeypatch):
    """
    test reading the genesis block from the blockchain
    """
    hblockchain.blockchain.clear()
    monkeypatch.setattr(hblockchain, "merkle_root",
                        lambda x, y: rcrypt.make_SHA256_hash('msg0'))

    hblockchain.add_block(block_0)
    assert hblockchain.read_block(0) == block_0
    hblockchain.blockchain.clear()
Example #2
0
def test_read_genesis_block(monkeypatch):
    """
    test reading the genesis block from the blockchain
    """
    hblockchain.blockchain.clear()
    monkeypatch.setattr(tx, "validate_transaction", lambda x, y: True)
    monkeypatch.setattr(blk_index, "put_index", lambda x, y: None)
    monkeypatch.setattr(hblockchain, "merkle_root", lambda x, y: "")

    hblockchain.add_block(block_0)
    assert hblockchain.read_block(0) == block_0
    hblockchain.blockchain.clear()
Example #3
0
def test_genesis_block_height(monkeypatch):
    """
    test genesis block height
    """
    hblockchain.blockchain.clear()
    monkeypatch.setattr(hblockchain, "merkle_root",
                        lambda x, y: rcrypt.make_SHA256_hash('msg0'))
    block_0["height"] = 0

    assert hblockchain.add_block(block_0) == True
    blk = hblockchain.read_block(0)
    assert blk != False
    assert blk["height"] == 0
    hblockchain.blockchain.clear()
Example #4
0
def test_genesis_block_height(monkeypatch):
    """
    test genesis block height
    """
    hblockchain.blockchain.clear()
    monkeypatch.setattr(hblockchain, "merkle_root",
                        lambda x, y: rcrypt.make_SHA256_hash('msg0'))
    monkeypatch.setattr(blk_index, "put_index", lambda x, y: None)
    monkeypatch.setattr(tx, "validate_transaction", lambda x, y: True)
    block_0["height"] = 0

    assert hblockchain.add_block(block_0) == True
    blk = hblockchain.read_block(0)
    assert blk != False
    assert blk["height"] == 0
    hblockchain.blockchain.clear()
Example #5
0
def test_read_second_block(monkeypatch):
    """
    test reading the second block from the blockchain
    """
    hblockchain.blockchain.clear()
    assert len(hblockchain.blockchain) == 0

    monkeypatch.setattr(hblockchain, "merkle_root",
                        lambda x, y: rcrypt.make_SHA256_hash('msg0'))
    monkeypatch.setitem(block_1, "prevblockhash",
                        hblockchain.blockheader_hash(block_0))

    ret = hblockchain.add_block(block_0)
    assert ret == True
    monkeypatch.setattr(hblockchain, "merkle_root", lambda x, y: \
        rcrypt.make_SHA256_hash('msg1'))
    ret = hblockchain.add_block(block_1)
    assert ret == True
    block = hblockchain.read_block(1)
    assert block != False
    hblockchain.blockchain.clear()
Example #6
0
def test_block_height(monkeypatch):
    """
    test height of the the second block
    """
    hblockchain.blockchain.clear()
    monkeypatch.setattr(hblockchain, "merkle_root",
                        lambda x, y: rcrypt.make_SHA256_hash('msg0'))
    monkeypatch.setitem(block_0, "height", 0)
    monkeypatch.setitem(block_0, "prevblockhash", "")
    monkeypatch.setitem(block_1, "height", 1)
    monkeypatch.setitem(block_1, "prevblockhash",
                        hblockchain.blockheader_hash(block_0))

    assert hblockchain.add_block(block_0) == True

    monkeypatch.setattr(hblockchain, "merkle_root",
                        lambda x, y: rcrypt.make_SHA256_hash('msg1'))
    assert hblockchain.add_block(block_1) == True
    blk = hblockchain.read_block(1)
    assert blk != False
    assert blk["height"] == 1
    hblockchain.blockchain.clear()