Esempio n. 1
0
def test_nonce_in_tx_correct():
    # test if the nonce is correct in the tx
    w = wallet.generate_new_wallet()

    t = Transaction(sender=w.get_address(),
                    receivers=["01"],
                    amounts=[1],
                    nonce=w.get_nonce(),
                    fee=100)
    assert t.nonce == w.get_nonce()

    tx_hash_old = ""
    tx_sig_old = ""
    for i in range(10):
        # sign tx
        w.sign_transaction(t)
        # get sig
        signature = t.get_signature()
        # nonce gets bigger every signed tx
        assert t.nonce == w.get_nonce() - 1
        assert t.nonce == i
        # make sure tx_signature changes
        assert signature != tx_sig_old
        # make sure tx_hash changes
        assert t.hash() != tx_hash_old
        # finally test if verify works
        assert t.verify()
        # save values for next iteration
        tx_hash_old = t.hash()
        tx_sig_old = signature
    # assert that we counted correctly
    assert w.get_nonce() == 10
def test_verify_tx():
    """
    tests if a signed transaction can be validated
    we just need the address for this, because address=public_key
    """
    w = wallet.generate_new_wallet()
    sender = w.get_address()
    receivers = ["fe"]
    amounts = [1]
    fee = 100
    t = Transaction(sender, receivers, amounts, fee)
    w.sign_transaction(t)
    assert cryptoutil.verify_transaction_sig(t, t.get_signature())
    assert t.verify()