def test_block():
    utxo_mgr = UTXOManager()
    utxo_mgr.utxo_set.clear()

    chain_mgr = ChainManager()
    chain_mgr.add_block_to_chain(block_with_nonce)

    assert len(chain_mgr.active_chain) == 1
    assert block_with_nonce.nonce != genesis_block.nonce
    assert block_with_nonce._base_hash == b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x18\xff\x02\xdd\xbe\x1c5\xef\xc7M\xc4J\xa8G\xcf\r&\t\xf1\xde/\x05\xfd\xed\xeb\xc4\xcf\xb7k\x1e\xbd\xb6\x80\r\xdcY@B\x10\x1e'
    assert block_with_nonce.nonce == 161201

    assert len(utxo_mgr.utxo_set) == 1
    assert UTXOManager().get_current_balance_for_addr(address_1) == 5000000

    # let's add some additional spending here
    # let's send some money from wallet 1 (address_1) to 2 (1Q3DzrqjyK54rGxqan9aiEWgRN5RrQ4Whb)
    txn1 = build_transaction(address_2, 50000, address_1, signing_key_1)
    txn2 = build_transaction(address_2, 50000, address_1, signing_key_1)
    txns = [txn1, txn2]

    second_block = Block.assemble_and_solve_block(block_with_nonce.id,
                                                  address_2, txns)
    chain_mgr.add_block_to_chain(second_block)

    # there should be 5 utxo
    assert len(utxo_mgr.utxo_set) == 5

    assert second_block.transaction_fees[txn1.id] == TRANSACTION_FEE
    assert second_block.transaction_fees[txn2.id] == TRANSACTION_FEE

    assert second_block.fees == len(txns) * TRANSACTION_FEE

    # should be 5000000 - 51000 - 51000
    assert UTXOManager().get_current_balance_for_addr(address_1) == 10400000
Beispiel #2
0
def test_block():
	utxo_set.clear()
	block_with_nonce = genesis_block.mine()
	block_with_nonce.add_to_chain()

	assert len(chain) == 1
	assert block_with_nonce.nonce != genesis_block.nonce
	assert block_with_nonce._base_hash == b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x18\xff\x02\xdd\xbe\x1c5\xef\xc7M\xc4J\xa8G\xcf\r&\t\xf1\xde/\x05\xfd\xed\xeb\xc4\xcf\xb7k\x1e\xbd\xb6\x80\r\xdcY@B\x10\x1e'
	assert block_with_nonce.nonce == 161201

	assert get_current_balance_for_addr(address_1) == 5000000

	# let's add some additional spending here
	# let's send some money from wallet 1 (address_1) to 2 (1Q3DzrqjyK54rGxqan9aiEWgRN5RrQ4Whb)
	signing_key = signing_key_from_bytes(address_pk_1)
	txn1 = build_transaction(address_2, 50000, address_1, signing_key)
	txn2 = build_transaction(address_2, 50000, address_1, signing_key)
	txns = [txn1, txn2]

	second_block = Block.assemble_and_solve_block(block_with_nonce.id, address_1, txns)
	assert second_block.transaction_fees[txn1.id] == TRANSACTION_FEE
	assert second_block.transaction_fees[txn2.id] == TRANSACTION_FEE

	assert second_block.fees == len(txns) * TRANSACTION_FEE