def test_convert_amount():
    """double convert gives same amount"""
    random.seed('Reproducible test')
    for i in range(10):
        amount = random.random() * 100
        f8_amount = str('{:.8f}'.format(Decimal(amount)))
        int_amount = Transaction.f8_to_int(f8_amount)
        assert f8_amount == Transaction.int_to_f8(int_amount)
示例#2
0
def balance_new2(db, address: str):
    q1 = db.execute(
        "SELECT (SELECT sum(iamount + ireward) FROM transactions WHERE recipient = ? ) "
        "- (SELECT sum(iamount + ifee) FROM transactions WHERE address = ?)",
        (address, address),
    )
    r1 = q1.fetchone()
    balance = r1[0] if r1[0] else 0

    return Transaction.int_to_f8(balance)
示例#3
0
def balance_new(db, address: str):
    q1 = db.execute(
        "SELECT sum(iamount + ireward) FROM transactions WHERE recipient = ? ",
        (address,),
    )
    r1 = q1.fetchone()
    credit = r1[0] if r1[0] else 0
    q2 = db.execute(
        "SELECT sum(iamount + ifee) FROM transactions WHERE address = ? ",
        (address,),
    )
    r2 = q2.fetchone()
    debit = r2[0] if r2[0] else 0
    return Transaction.int_to_f8(credit-debit)