Ejemplo n.º 1
0
def test_validation_2():

    tx_in = TxIn(OutPoint("00" * 32, 0), Script())
    tx_out = TxOut(10**10, Script())
    tx_1 = Tx([tx_in], [tx_out])
    header = BlockHeader()
    block = Block(header, [tx_1])
    assert not block.is_valid()

    header.merkle_root = generate_merkle_root(block.transactions)
    header.previous_pow = "00" * 32
    assert header.is_valid()
    assert block.is_valid()  # has a coinbase tx
Ejemplo n.º 2
0
def test_invalid_merkleroot():

    tx_in = TxIn(OutPoint("ff" * 32, 0), Script())
    tx_out = TxOut(10, Script())
    tx_1 = Tx([tx_in], [tx_out])
    header = BlockHeader()
    block = Block(header, [tx_1])
    header.merkle_root = "00" * 32
    header.previous_pow = "00" * 32
    assert not block.is_valid()
Ejemplo n.º 3
0
def test_double_coinbase():
    coinbase_1 = Tx(
        [TxIn(OutPoint("00" * 32, 0), Script.from_hex("00030000aa"))],
        [TxOut(10**10, Script())],
    )
    coinbase_2 = Tx(
        [TxIn(OutPoint("00" * 32, 0), Script.from_hex("00030000bb"))],
        [TxOut(10**10, Script())],
    )
    header = BlockHeader()
    block = Block(header, [coinbase_1, coinbase_2])
    header.merkle_root = generate_merkle_root(block.transactions)
    header.previous_pow = "00" * 32
    assert not block.is_valid()
Ejemplo n.º 4
0
def test_validation_3():

    tx_in = TxIn(OutPoint("ff" * 32, 256**2 - 1), Script())
    tx_out = TxOut(10, Script())
    tx_1 = Tx([tx_in], [tx_out])
    tx_in_2 = TxIn(OutPoint("ff" * 32, 256**2 - 1), Script())
    tx_out_2 = TxOut(10, Script())
    tx_2 = Tx([tx_in_2], [tx_out_2])
    header = BlockHeader()
    block = Block(header, [tx_1, tx_2])

    header.merkle_root = generate_merkle_root(block.transactions)
    header.previous_pow = "00" * 32
    assert header.is_valid()
    assert not block.is_valid()  # two coinbases
Ejemplo n.º 5
0
def test_empty_block():
    header = BlockHeader()
    block = Block(header, [])
    header.merkle_root = "00" * 32
    header.previous_pow = "00" * 32
    assert not block.is_valid()