Beispiel #1
0
def testTooLargeSaleReturns():
    """
    Contains some testcases, found during random testing, where the sale return was larger than expected
    """


    testdata = [
        [2571869000000000000000000000000000,360061000000000000000000000000000,14,284283000000000000000000000000000,204102574328104782565993111517581,2.04102574323e+32],
        [300000000000000000000000000000000,63000000000000000000000000000000,21,2401000000000000000000000000000,2365120993837509886570622084182,0],        
        [300000000000000000000000000000000,63000000000000000000000000000000,21,1000000000000000000000000000,1000012229933918459614528650,9.99993730188e+26],
        [300000000000000000000000000000000,63000000000000000000000000000000,21,49000000000000000000000000000,48984954188962049634901119411,4.89849483746e+28],
        [300000000000000000000000000000000,63000000000000000000000000000000,21,81000000000000000000000000000,80958876280831287208758481856,8.09588737955e+28],
    ]
    for td in testdata:
        [s,r,f,t,x,y] = td
        e = formula.calculateSaleReturnSolidity(s,r,f,t)
        e_cor = formula.calculateSaleReturn(s,r,f,t)
        print("E   : %s"% e)
        print("E_C : %s"% e_cor)
        diff = e - e_cor
        smin = formula.calcSaleMin(r)
        print("diff: %s"%  diff)
        print("smin: %s "%  smin )
        print("d/s : %s " % (diff/smin))
        print("")
Beispiel #2
0
def saleReturn(S,R,F,T):
    """ Returns a tuple
    ( python high-precision purchase return, python-solidity purchase return )
    """

    E = formula.calculateSaleReturn(S,R,F,T)
    try:
        Esol = formula.calculateSaleReturnSolidity(S,R,F,T)
        if Esol > E:
            addTooLargeReturnOnSale(S,R,F,T,E,Esol)
        return (E,Esol)
    except Exception as e:
        addExpectedThrowOnSale(S,R,F,E, str(e))
    
    return (E,0)
Beispiel #3
0
def testCornercase2():
    S = 300000e18
    R = 63000e18
    F = 21

    tokens = 1e18 # 99 995 476 193 726 0661

    while True:
        wei = formula.calculateSaleReturnSolidity(S,R,F,tokens)
        correct_wei = formula.calculateSaleReturn(S,R,F,tokens)
        print "%f => %f error" % (tokens , (correct_wei - wei))
        if(correct_wei < wei):
            print("Diff %d wei" % (correct_wei - wei) )
        tokens = tokens+1e10

    print "Market"
    print m
Beispiel #4
0
            if math.floor(T) < math.floor(T_S):
                purchaseResults.append("\t[%d,%d,%d,%d,%d, %f], # %d" % ( int(S), int(R), int(F), int(E),math.floor(T), T, T_S ))
                
        except Exception, e:
            pass       


    saleResults = []

    for i in range(1, 10000):
        S = float(random.randint(1, 3e18))
        F = random.randint(1, 100 )
        R = math.floor(F*S / 100)
        T = float(random.randint(700, 300000))
        try:
            E = formula.calculateSaleReturn(int(S),int(R),float(F),int(T))
            E_S = formula.calculateSaleReturnSolidity(int(S),int(R),float(F),int(T))
            if math.floor(E) < math.floor(E_S):
                saleResults.append("\t[%d,%d,%d,%d,%d, %f], # %d" % ( int(S), int(R), int(F), int(T),math.floor(E), E ,E_S))
        except Exception, e:
            pass

    print("module.exports.randomPurchaseReturns2 = [")
    print("\n".join(purchaseResults))
    print("];")

    print("module.exports.randomSaleReturns2 = [")
    print("\n".join(saleResults))
    print("];")

def testCornercase():
Beispiel #5
0
                purchaseResults.append(
                    "\t[%d,%d,%d,%d,%d, %f], # %d" %
                    (int(S), int(R), int(F), int(E), math.floor(T), T, T_S))

        except Exception, e:
            pass

    saleResults = []

    for i in range(1, 10000):
        S = float(random.randint(1, 3e18))
        F = random.randint(1, 100)
        R = math.floor(F * S / 100)
        T = float(random.randint(700, 300000))
        try:
            E = formula.calculateSaleReturn(int(S), int(R), float(F), int(T))
            E_S = formula.calculateSaleReturnSolidity(int(S), int(R), float(F),
                                                      int(T))
            if math.floor(E) < math.floor(E_S):
                saleResults.append(
                    "\t[%d,%d,%d,%d,%d, %f], # %d" %
                    (int(S), int(R), int(F), int(T), math.floor(E), E, E_S))
        except Exception, e:
            pass

    print("module.exports.randomPurchaseReturns2 = [")
    print("\n".join(purchaseResults))
    print("];")

    print("module.exports.randomSaleReturns2 = [")
    print("\n".join(saleResults))