Esempio n. 1
0
def test_pool():
    """test that adding the same tx twice is not possible"""
    p = TransactionPool()
    assert p.get_size() == 0
    assert p.get_tx_list() == []

    sender = "iWVjc8hWuRuePAv1X8nDZdcjKcqivDUH62YKhBXBHqp2yGfgeXyHJDj5XwCHwjWB6GevCjMYT59XSBiQvMYHQ4P"
    receivers = ["01", "02", "0a"]
    amounts = [1, 2, 3]
    fee = 100
    tx1 = Transaction(sender, receivers, amounts, fee)

    p.add(tx1)
    assert p.get_size() == 1
    assert p.get_tx_list()[0].string() == tx1.string()

    tx2 = Transaction(sender, receivers, amounts, fee)

    p.add(tx2)

    assert p.get_size() == 1
    assert p.get_tx_list()[0].string() == tx1.string()
    assert p.get_tx_list()[0].string() == tx2.string()

    p.remove(tx1)

    assert p.get_size() == 0
    assert p.get_tx_list() == []
Esempio n. 2
0
def test_pool_multi_add_same_tx():
    p = TransactionPool()
    assert p.get_size() == 0
    assert p.get_tx_list() == []

    sender = "iWVjc8hWuRuePAv1X8nDZdcjKcqivDUH62YKhBXBHqp2yGfgeXyHJDj5XwCHwjWB6GevCjMYT59XSBiQvMYHQ4P"
    receivers = ["01", "02", "0a"]
    amounts = [1, 2, 3]
    fee = 100
    tx = Transaction(sender, receivers, amounts, fee)

    p.add(tx)

    assert p.get_size() == 1
    assert p.get_tx_list()[0].string() == tx.string()

    p.add(tx)

    assert p.get_size() == 1
    assert p.get_tx_list()[0].string() == tx.string()

    p.add(tx)

    assert p.get_size() == 1
    assert p.get_tx_list()[0].string() == tx.string()

    p.remove(tx)

    assert p.get_size() == 0
    assert p.get_tx_list() == []
def test_tx_from_json():
    """test serialization and deserialization"""
    sender = "abcd"
    receivers = ["fe"]
    amounts = [1]
    fee = 100
    t1 = Transaction(sender, receivers, amounts, fee)
    t2 = transaction.from_json(t1.string())
    assert t1.string() == t2.string()
    assert t1.hash() == t2.hash()
    assert t1.unsigned_hash() == t2.unsigned_hash()
Esempio n. 4
0
 def json_string_tx():
     """creates a main block for testing purposes"""
     sender = "iWVjc8hWuRuePAv1X8nDZdcjKcqivDUH62YKhBXBHqp2yGfgeXyHJDj5XwCHwjWB6GevCjMYT59XSBiQvMYHQ4P"
     receivers = ["01", "02", "0a"]
     amounts = [1, 2, 3]
     fee = 100
     tx = Transaction(sender, receivers, amounts, fee)
     return tx.string()
Esempio n. 5
0
    def json_string_transaction():
        """base test for transaction"""
        sender = "iWVjc8hWuRuePAv1X8nDZdcjKcqivDUH62YKhBXBHqp2yGfgeXyHJDj5XwCHwjWB6GevCjMYT59XSBiQvMYHQ4P"
        receivers = ["01", "02", "0a"]
        amounts = [1, 2, 3]
        nonce = 1
        fee = 100
        tx = Transaction(sender, receivers, amounts, nonce, fee)

        tx_string = tx.string()
        return tx_string
def test_transaction():
    """base test for transaction"""
    sender = "iWVjc8hWuRuePAv1X8nDZdcjKcqivDUH62YKhBXBHqp2yGfgeXyHJDj5XwCHwjWB6GevCjMYT59XSBiQvMYHQ4P"
    receivers = ["01", "02", "0a"]
    amounts = [1, 2, 3]
    fee = 100
    tx = Transaction(sender, receivers, amounts, fee)

    assert tx.string() == \
        '{"sender": "iWVjc8hWuRuePAv1X8nDZdcjKcqivDUH62YKhBXBHqp2yGfgeXyHJDj5XwCHwjWB6GevCjMYT59XSBiQvMYHQ4P", "receivers": ["01", "02", "0a"], "amounts": [1, 2, 3], "nonce": 0, "fee": 100, "signature": ""}'
    assert tx.hash(
    ) == "a564b3a98ed7d3f66b69ee4d9f7fab588a875ae06c6f7919c7f83121bb72f859"
def test_transaction():
    """base test for transaction"""
    sender = "iWVjc8hWuRuePAv1X8nDZdcjKcqivDUH62YKhBXBHqp2yGfgeXyHJDj5XwCHwjWB6GevCjMYT59XSBiQvMYHQ4P"
    receivers = ["01", "02", "0a"]
    amounts = [1, 2, 3]
    nonce = 1
    fee = 100
    tx = Transaction(sender, receivers, amounts, nonce, fee)

    tx_string = tx.string()
    assert tx_string == '{"sender_address": "iWVjc8hWuRuePAv1X8nDZdcjKcqivDUH62YKhBXBHqp2yGfgeXyHJDj5XwCHwjWB6GevCjMYT59XSBiQvMYHQ4P", "receivers": ["01", "02", "0a"], "amounts": [1, 2, 3], "nonce": 1, "fee": 100, "signature": ""}'
    tx_hash = tx.hash()
    assert tx_hash == "e9f65b7385ffb2e9c8809da75ff86bc10b8490dd02e3bfa26daf0c189a535b5b"