示例#1
0
def test_TestTransactionsFees():
    txns = utils.makeTransactions(0)
    # Nil txns
    err, fee = skycoin.SKY_coin_Transactions_Fees(
        txns, calc)
    assert err == skycoin.SKY_OK
    assert fee == 0

    # 2 transactions, calc() always returns 1
    txn = utils.makeEmptyTransaction()
    assert skycoin.SKY_coin_Transactions_Add(txns, txn) == skycoin.SKY_OK
    txn1 = utils.makeEmptyTransaction()
    assert skycoin.SKY_coin_Transactions_Add(txns, txn1) == skycoin.SKY_OK
    err, fee = skycoin.SKY_coin_Transactions_Fees(
        txns, calc)
    assert err == skycoin.SKY_OK
    assert fee == 2

    # calc error
    err, _ = skycoin.SKY_coin_Transactions_Fees(
        txns, utils.badFeeCalculator)
    assert err == skycoin.SKY_ERROR

    # # summing of calculated fees overflows
    err, _ = skycoin.SKY_coin_Transactions_Fees(txns, overflowCalc)
    assert err == skycoin.SKY_ERROR
示例#2
0
def test_TestTransactionsHashes():
    handle = utils.makeTransactions(4)
    err, hashes = skycoin.SKY_coin_Transactions_Hashes(handle)
    assert err == skycoin.SKY_OK
    len_hashes = len(hashes)
    assert len_hashes == 4
    for i in range(len_hashes):
        err, tx = skycoin.SKY_coin_Transactions_GetAt(handle, i)
        assert err == skycoin.SKY_OK
        h = skycoin.cipher_SHA256()
        assert skycoin.SKY_coin_Transaction_Hash(tx, h) == skycoin.SKY_OK
        assert h == hashes[i]
        i += 1
示例#3
0
def test_TestTransactionsSize():
    handle = utils.makeTransactions(10)
    size = 0
    for i in range(10):
        err, tx = skycoin.SKY_coin_Transactions_GetAt(handle, i)
        assert err == skycoin.SKY_OK
        err, b = skycoin.SKY_coin_Transaction_Serialize(tx)
        size += len(b)
        i += 1

    assert size != 0
    err, sizetx = skycoin.SKY_coin_Transactions_Size(handle)
    assert err == skycoin.SKY_OK
    assert sizetx == size
示例#4
0
def test_TestTransactionsTruncateBytesTo():
    handles = utils.makeTransactions(10)
    trunc = 0
    for i in range(5):
        err, handle = skycoin.SKY_coin_Transactions_GetAt(handles, i)
        assert err == skycoin.SKY_OK
        err, count = skycoin.SKY_coin_Transaction_Size(handle)
        assert err == skycoin.SKY_OK
        trunc += count
        i += 1
    # Trucating halfway
    err, tnxs2 = skycoin.SKY_coin_Transactions_TruncateBytesTo(handles, trunc)
    assert err == skycoin.SKY_OK
    err, len_tnxs2 = skycoin.SKY_coin_Transactions_Length(tnxs2)
    assert err == skycoin.SKY_OK
    assert len_tnxs2 == 5
    err, count = skycoin.SKY_coin_Transactions_Size(tnxs2)
    assert err == skycoin.SKY_OK
    assert count == trunc

    # Stepping into next boundary has same cutoff, must exceed
    trunc += 1
    err, txns2 = skycoin.SKY_coin_Transactions_TruncateBytesTo(handles, trunc)
    assert err == skycoin.SKY_OK
    err, count = skycoin.SKY_coin_Transactions_Length(tnxs2)
    assert err == skycoin.SKY_OK
    assert count == 5
    err, count = skycoin.SKY_coin_Transactions_Size(tnxs2)
    assert err == skycoin.SKY_OK
    assert count == int(trunc - 1)

    # Moving to 1 before next level
    err, tnxs_5 = skycoin.SKY_coin_Transactions_GetAt(handles, 5)
    assert err == skycoin.SKY_OK
    err, count = skycoin.SKY_coin_Transaction_Size(tnxs_5)
    assert err == skycoin.SKY_OK
    trunc += int(count - 2)
    err, txns2 = skycoin.SKY_coin_Transactions_TruncateBytesTo(handles, trunc)
    assert err == skycoin.SKY_OK
    err, count = skycoin.SKY_coin_Transactions_Length(txns2)
    assert err == skycoin.SKY_OK
    assert count == 5
    err, count = skycoin.SKY_coin_Transactions_Size(txns2)
    assert err == skycoin.SKY_OK
    err, count_tnxs5 = skycoin.SKY_coin_Transaction_Size(tnxs_5)
    assert err == skycoin.SKY_OK
    assert int(trunc - count_tnxs5 + 1) == count

    # Moving to next level
    trunc += 1
    err, txns2 = skycoin.SKY_coin_Transactions_TruncateBytesTo(handles, trunc)
    assert err == skycoin.SKY_OK
    err, count = skycoin.SKY_coin_Transactions_Length(txns2)
    assert err == skycoin.SKY_OK
    assert count == 6
    err, count = skycoin.SKY_coin_Transactions_Size(txns2)
    assert err == skycoin.SKY_OK
    assert count == trunc

    # Truncating to full available amt
    err, trunc = skycoin.SKY_coin_Transactions_Size(handles)
    assert err == skycoin.SKY_OK
    err, txns2 = skycoin.SKY_coin_Transactions_TruncateBytesTo(handles, trunc)
    assert err == skycoin.SKY_OK
    assert err == skycoin.SKY_OK
    err, count = skycoin.SKY_coin_Transactions_Size(txns2)
    assert err == skycoin.SKY_OK
    assert count == trunc
    assert utils.equalTransactions(handles, txns2) == skycoin.SKY_OK

    # Truncating over amount
    trunc += 1
    err, txns2 = skycoin.SKY_coin_Transactions_TruncateBytesTo(handles, trunc)
    assert utils.equalTransactions(handles, txns2) == skycoin.SKY_OK
    err, count = skycoin.SKY_coin_Transactions_Size(handles)
    assert err == skycoin.SKY_OK
    assert count == int(trunc - 1)

    # Truncating to 0
    trunc = 0
    err, txns2 = skycoin.SKY_coin_Transactions_TruncateBytesTo(handles, 0)
    assert err == skycoin.SKY_OK
    err, count = skycoin.SKY_coin_Transactions_Length(txns2)
    assert err == skycoin.SKY_OK
    assert count == 0
    err, count = skycoin.SKY_coin_Transactions_Size(txns2)
    assert err == skycoin.SKY_OK
    assert count == trunc