예제 #1
0
def Main():
    rangeSupply = InputGenerator.UniformDistribution(MINIMUM_VALUE_SUPPLY, MAXIMUM_VALUE_SUPPLY, SAMPLES_COUNT_SUPPLY)
    rangeBalance = InputGenerator.UniformDistribution(MINIMUM_VALUE_BALANCE, MAXIMUM_VALUE_BALANCE, SAMPLES_COUNT_BALANCE)
    rangeRatios = InputGenerator.UniformDistribution(MINIMUM_VALUE_RATIOS, MAXIMUM_VALUE_RATIOS, SAMPLES_COUNT_RATIOS)
    rangeAmount = InputGenerator.UniformDistribution(MINIMUM_VALUE_AMOUNT, MAXIMUM_VALUE_AMOUNT, SAMPLES_COUNT_AMOUNT)

    testNum = 0
    numOfTests = len(rangeSupply) * len(rangeBalance) * len(rangeRatios) * len(rangeAmount)

    tester = Web3Wrapper.Contract('BancorFormula').tester()
    minGas = float('+inf')
    maxGas = float('-inf')
    totalGas = 0
    countGas = 0

    for supply in rangeSupply:
        for balance in rangeBalance:
            for ratios in rangeRatios:
                for amount in rangeAmount:
                    testNum += 1
                    if amount <= supply:
                        try:
                            gas = tester.calculateLiquidateReturn(supply, balance, ratios, amount)
                            minGas = min(minGas, gas)
                            maxGas = max(maxGas, gas)
                            totalGas += gas
                            countGas += 1
                            print('Test {} out of {}: gas = {}, minimum = {}, maximum = {}, average = {}'.format(testNum, numOfTests, gas, minGas, maxGas, totalGas // countGas))
                        except:
                            pass
예제 #2
0
def Main():
    rangeBalance1 = InputGenerator.UniformDistribution(MINIMUM_VALUE_BALANCE, MAXIMUM_VALUE_BALANCE, SAMPLES_COUNT_BALANCE)
    rangeWeight1 = InputGenerator.UniformDistribution(MINIMUM_VALUE_WEIGHT, MAXIMUM_VALUE_WEIGHT, SAMPLES_COUNT_WEIGHT)
    rangeBalance2 = InputGenerator.UniformDistribution(MINIMUM_VALUE_BALANCE, MAXIMUM_VALUE_BALANCE, SAMPLES_COUNT_BALANCE)
    rangeWeight2 = InputGenerator.UniformDistribution(MINIMUM_VALUE_WEIGHT, MAXIMUM_VALUE_WEIGHT, SAMPLES_COUNT_WEIGHT)
    rangeAmount = InputGenerator.UniformDistribution(MINIMUM_VALUE_AMOUNT, MAXIMUM_VALUE_AMOUNT, SAMPLES_COUNT_AMOUNT)

    testNum = 0
    numOfTests = len(rangeBalance1) * len(rangeWeight1) * len(rangeBalance2) * len(rangeWeight2) * len(rangeAmount)

    FormulaContract = Web3Wrapper.Contract('BancorFormula')
    FormulaContractAddr = FormulaContract.tester()

    minGas = float('+inf')
    maxGas = float('-inf')

    totalGas = 0
    countGas = 0

    for balance1 in rangeBalance1:
        for weight1 in rangeWeight1:
            for balance2 in rangeBalance2:
                for weight2 in rangeWeight2:
                    for amount in rangeAmount:
                        testNum += 1
                        if True:
                            try:
                                gas = FormulaContractAddr.crossReserveTargetAmount(balance1, weight1, balance2, weight2, amount)
                                minGas = min(minGas, gas)
                                maxGas = max(maxGas, gas)
                                totalGas += gas
                                countGas += 1
                                print('Test {} out of {}: gas = {}, minimum = {}, maximum = {}, average = {}'.format(testNum, numOfTests, gas, minGas, maxGas, totalGas // countGas))
                            except:
                                pass
예제 #3
0
def Main():
    rangeBalance1 = InputGenerator.UniformDistribution(MINIMUM_VALUE_BALANCE, MAXIMUM_VALUE_BALANCE, SAMPLES_COUNT_BALANCE)
    rangeRatio1 = InputGenerator.UniformDistribution(MINIMUM_VALUE_RATIO, MAXIMUM_VALUE_RATIO, SAMPLES_COUNT_RATIO)
    rangeBalance2 = InputGenerator.UniformDistribution(MINIMUM_VALUE_BALANCE, MAXIMUM_VALUE_BALANCE, SAMPLES_COUNT_BALANCE)
    rangeRatio2 = InputGenerator.UniformDistribution(MINIMUM_VALUE_RATIO, MAXIMUM_VALUE_RATIO, SAMPLES_COUNT_RATIO)
    rangeAmount = InputGenerator.UniformDistribution(MINIMUM_VALUE_AMOUNT, MAXIMUM_VALUE_AMOUNT, SAMPLES_COUNT_AMOUNT)

    testNum = 0
    numOfTests = len(rangeBalance1) * len(rangeRatio1) * len(rangeBalance2) * len(rangeRatio2) * len(rangeAmount)

    tester = Web3Wrapper.Contract('BancorFormula').tester()
    minGas = float('+inf')
    maxGas = float('-inf')
    totalGas = 0
    countGas = 0

    for balance1 in rangeBalance1:
        for ratio1 in rangeRatio1:
            for balance2 in rangeBalance2:
                for ratio2 in rangeRatio2:
                    for amount in rangeAmount:
                        testNum += 1
                        if True:
                            try:
                                gas = tester.calculateCrossReserveReturn(balance1, ratio1, balance2, ratio2, amount)
                                minGas = min(minGas, gas)
                                maxGas = max(maxGas, gas)
                                totalGas += gas
                                countGas += 1
                                print('Test {} out of {}: gas = {}, minimum = {}, maximum = {}, average = {}'.format(testNum, numOfTests, gas, minGas, maxGas, totalGas // countGas))
                            except:
                                pass
def Main():
    rangeSupply = InputGenerator.UniformDistribution(MINIMUM_VALUE_SUPPLY, MAXIMUM_VALUE_SUPPLY, SAMPLES_COUNT_SUPPLY)
    rangeBalance = InputGenerator.UniformDistribution(MINIMUM_VALUE_BALANCE, MAXIMUM_VALUE_BALANCE, SAMPLES_COUNT_BALANCE)
    rangeWeights = InputGenerator.UniformDistribution(MINIMUM_VALUE_WEIGHT, MAXIMUM_VALUE_WEIGHT, SAMPLES_COUNT_WEIGHT)
    rangeAmount = InputGenerator.UniformDistribution(MINIMUM_VALUE_AMOUNT, MAXIMUM_VALUE_AMOUNT, SAMPLES_COUNT_AMOUNT)

    testNum = 0
    numOfTests = len(rangeSupply) * len(rangeBalance) * len(rangeWeights) * len(rangeAmount)

    FormulaContract = Web3Wrapper.Contract('SovrynSwapFormula')
    FormulaContract.setter().init()
    FormulaContractAddr = FormulaContract.getter()

    for supply in rangeSupply:
        for balance in rangeBalance:
            for weights in rangeWeights:
                for amount in rangeAmount:
                    testNum += 1
                    if True:
                        resultSolidityPort = Run(FormulaSolidityPort, supply, balance, weights, amount)
                        resultContractAddr = Run(FormulaContractAddr, supply, balance, weights, amount)
                        print('Test {} out of {}: resultSolidityPort = {}, resultContractAddr = {}'.format(testNum, numOfTests, resultSolidityPort, resultContractAddr))
                        if resultSolidityPort != resultContractAddr:
                            print('Emulation Error:')
                            print('supply  = {}'.format(supply))
                            print('balance = {}'.format(balance))
                            print('weights = {}'.format(weights))
                            print('amount  = {}'.format(amount))
                            return
예제 #5
0
def Main():
    rangeSupply = InputGenerator.UniformDistribution(MINIMUM_VALUE_SUPPLY, MAXIMUM_VALUE_SUPPLY, SAMPLES_COUNT_SUPPLY)
    rangeBalance = InputGenerator.UniformDistribution(MINIMUM_VALUE_BALANCE, MAXIMUM_VALUE_BALANCE, SAMPLES_COUNT_BALANCE)
    rangeWeight = InputGenerator.UniformDistribution(MINIMUM_VALUE_WEIGHT, MAXIMUM_VALUE_WEIGHT, SAMPLES_COUNT_WEIGHT)
    rangeAmount = InputGenerator.UniformDistribution(MINIMUM_VALUE_AMOUNT, MAXIMUM_VALUE_AMOUNT, SAMPLES_COUNT_AMOUNT)

    testNum = 0
    numOfTests = len(rangeSupply) * len(rangeBalance) * len(rangeWeight) * len(rangeAmount)

    FormulaContract = Web3Wrapper.Contract('SovrynSwapFormula')
    FormulaContract.setter().init()
    FormulaContractAddr = FormulaContract.tester()

    minGas = float('+inf')
    maxGas = float('-inf')

    totalGas = 0
    countGas = 0

    for supply in rangeSupply:
        for balance in rangeBalance:
            for weight in rangeWeight:
                for amount in rangeAmount:
                    testNum += 1
                    if True:
                        try:
                            gas = FormulaContractAddr.purchaseTargetAmount(supply, balance, weight, amount)
                            minGas = min(minGas, gas)
                            maxGas = max(maxGas, gas)
                            totalGas += gas
                            countGas += 1
                            print('Test {} out of {}: gas = {}, minimum = {}, maximum = {}, average = {}'.format(testNum, numOfTests, gas, minGas, maxGas, totalGas // countGas))
                        except:
                            pass
def Main():
    rangeBalance1 = InputGenerator.ExponentialDistribution(MINIMUM_VALUE_BALANCE, MAXIMUM_VALUE_BALANCE, GROWTH_FACTOR_BALANCE)
    rangeWeight1 = InputGenerator.ExponentialDistribution(MINIMUM_VALUE_WEIGHT, MAXIMUM_VALUE_WEIGHT, GROWTH_FACTOR_WEIGHT)
    rangeBalance2 = InputGenerator.ExponentialDistribution(MINIMUM_VALUE_BALANCE, MAXIMUM_VALUE_BALANCE, GROWTH_FACTOR_BALANCE)
    rangeWeight2 = InputGenerator.ExponentialDistribution(MINIMUM_VALUE_WEIGHT, MAXIMUM_VALUE_WEIGHT, GROWTH_FACTOR_WEIGHT)
    rangeAmount = InputGenerator.ExponentialDistribution(MINIMUM_VALUE_AMOUNT, MAXIMUM_VALUE_AMOUNT, GROWTH_FACTOR_AMOUNT)

    testNum = 0
    numOfTests = len(rangeBalance1) * len(rangeWeight1) * len(rangeBalance2) * len(rangeWeight2) * len(rangeAmount)

    FormulaContractAddr = Web3Wrapper.Contract('BancorFormula').getter()

    for balance1 in rangeBalance1:
        for weight1 in rangeWeight1:
            for balance2 in rangeBalance2:
                for weight2 in rangeWeight2:
                    for amount in rangeAmount:
                        testNum += 1
                        if True:
                            resultSolidityPort = Run(FormulaSolidityPort, balance1, weight1, balance2, weight2, amount)
                            resultContractAddr = Run(FormulaContractAddr, balance1, weight1, balance2, weight2, amount)
                            print('Test {} out of {}: resultSolidityPort = {}, resultContractAddr = {}'.format(testNum, numOfTests, resultSolidityPort, resultContractAddr))
                            if resultSolidityPort != resultContractAddr:
                                print('Emulation Error:')
                                print('balance1 = {}'.format(balance1))
                                print('weight1  = {}'.format(weight1))
                                print('balance2 = {}'.format(balance2))
                                print('weight2  = {}'.format(weight2))
                                print('amount   = {}'.format(amount))
                                return
def Main():
    rangeSupply = InputGenerator.ExponentialDistribution(MINIMUM_VALUE_SUPPLY, MAXIMUM_VALUE_SUPPLY, GROWTH_FACTOR_SUPPLY)
    rangeBalance = InputGenerator.ExponentialDistribution(MINIMUM_VALUE_BALANCE, MAXIMUM_VALUE_BALANCE, GROWTH_FACTOR_BALANCE)
    rangeWeights = InputGenerator.ExponentialDistribution(MINIMUM_VALUE_WEIGHTS, MAXIMUM_VALUE_WEIGHTS, GROWTH_FACTOR_WEIGHTS)
    rangeAmount = InputGenerator.ExponentialDistribution(MINIMUM_VALUE_AMOUNT, MAXIMUM_VALUE_AMOUNT, GROWTH_FACTOR_AMOUNT)

    testNum = 0
    numOfTests = len(rangeSupply) * len(rangeBalance) * len(rangeWeights) * len(rangeAmount)

    FormulaContractAddr = Web3Wrapper.Contract('BancorFormula').getter()

    for supply in rangeSupply:
        for balance in rangeBalance:
            for weights in rangeWeights:
                for amount in rangeAmount:
                    testNum += 1
                    if amount <= supply:
                        resultSolidityPort = Run(FormulaSolidityPort, supply, balance, weights, amount)
                        resultContractAddr = Run(FormulaContractAddr, supply, balance, weights, amount)
                        print('Test {} out of {}: resultSolidityPort = {}, resultContractAddr = {}'.format(testNum, numOfTests, resultSolidityPort, resultContractAddr))
                        if resultSolidityPort != resultContractAddr:
                            print('Emulation Error:')
                            print('supply  = {}'.format(supply))
                            print('balance = {}'.format(balance))
                            print('weights = {}'.format(weights))
                            print('amount  = {}'.format(amount))
                            return
def Main():
    rangeSupply = InputGenerator.ExponentialDistribution(MINIMUM_VALUE_SUPPLY, MAXIMUM_VALUE_SUPPLY, GROWTH_FACTOR_SUPPLY)
    rangeBalance = InputGenerator.ExponentialDistribution(MINIMUM_VALUE_BALANCE, MAXIMUM_VALUE_BALANCE, GROWTH_FACTOR_BALANCE)
    rangeWeights = InputGenerator.ExponentialDistribution(MINIMUM_VALUE_WEIGHTS, MAXIMUM_VALUE_WEIGHTS, GROWTH_FACTOR_WEIGHTS)
    rangeAmount = InputGenerator.ExponentialDistribution(MINIMUM_VALUE_AMOUNT, MAXIMUM_VALUE_AMOUNT, GROWTH_FACTOR_AMOUNT)

    testNum = 0
    numOfTests = len(rangeSupply) * len(rangeBalance) * len(rangeWeights) * len(rangeAmount)

    FormulaContract = Web3Wrapper.Contract('BancorFormula')
    FormulaContract.setter().init()
    FormulaContractAddr = FormulaContract.tester()

    minGas = float('+inf')
    maxGas = float('-inf')

    totalGas = 0
    countGas = 0

    for supply in rangeSupply:
        for balance in rangeBalance:
            for weights in rangeWeights:
                for amount in rangeAmount:
                    testNum += 1
                    if True:
                        try:
                            gas = FormulaContractAddr.fundCost(supply, balance, weights, amount)
                            minGas = min(minGas, gas)
                            maxGas = max(maxGas, gas)
                            totalGas += gas
                            countGas += 1
                            print('Test {} out of {}: gas = {}, minimum = {}, maximum = {}, average = {}'.format(testNum, numOfTests, gas, minGas, maxGas, totalGas // countGas))
                        except:
                            pass
예제 #9
0
def Main():
    rangeStaked1 = InputGenerator.ExponentialDistribution(MINIMUM_VALUE_STAKED, MAXIMUM_VALUE_STAKED, GROWTH_FACTOR_STAKED)
    rangeBalance1 = InputGenerator.ExponentialDistribution(MINIMUM_VALUE_BALANCE, MAXIMUM_VALUE_BALANCE, GROWTH_FACTOR_BALANCE)
    rangeBalance2 = InputGenerator.ExponentialDistribution(MINIMUM_VALUE_BALANCE, MAXIMUM_VALUE_BALANCE, GROWTH_FACTOR_BALANCE)
    rangeRate1 = InputGenerator.ExponentialDistribution(MINIMUM_VALUE_RATE, MAXIMUM_VALUE_RATE, GROWTH_FACTOR_RATE)
    rangeRate2 = InputGenerator.ExponentialDistribution(MINIMUM_VALUE_RATE, MAXIMUM_VALUE_RATE, GROWTH_FACTOR_RATE)

    testNum = 0
    numOfTests = len(rangeStaked1) * len(rangeBalance1) * len(rangeBalance2) * len(rangeRate1) * len(rangeRate2)

    FormulaContract = Web3Wrapper.Contract('BancorFormula')
    FormulaContract.setter().init()
    FormulaContractAddr = FormulaContract.getter()

    for staked1 in rangeStaked1:
        for balance1 in rangeBalance1:
            for balance2 in rangeBalance2:
                for rate1 in rangeRate1:
                    for rate2 in rangeRate2:
                        testNum += 1
                        if True:
                            resultSolidityPort = Run(FormulaSolidityPort, staked1, balance1, balance2, rate1, rate2)
                            resultContractAddr = Run(FormulaContractAddr, staked1, balance1, balance2, rate1, rate2)
                            print('Test {} out of {}: resultSolidityPort = {}, resultContractAddr = {}'.format(testNum, numOfTests, resultSolidityPort, resultContractAddr))
                            if resultSolidityPort != resultContractAddr:
                                print('Emulation Error:')
                                print('staked1  = {}'.format(staked1))
                                print('balance1 = {}'.format(balance1))
                                print('balance2 = {}'.format(balance2))
                                print('rate1    = {}'.format(rate1))
                                print('rate2    = {}'.format(rate2))
                                return
예제 #10
0
def Main():
    rangeStaked1 = InputGenerator.UniformDistribution(MINIMUM_VALUE_STAKED,
                                                      MAXIMUM_VALUE_STAKED,
                                                      SAMPLES_COUNT_STAKED)
    rangeBalance1 = InputGenerator.UniformDistribution(MINIMUM_VALUE_BALANCE,
                                                       MAXIMUM_VALUE_BALANCE,
                                                       SAMPLES_COUNT_BALANCE)
    rangeBalance2 = InputGenerator.UniformDistribution(MINIMUM_VALUE_BALANCE,
                                                       MAXIMUM_VALUE_BALANCE,
                                                       SAMPLES_COUNT_BALANCE)
    rangeRate1 = InputGenerator.UniformDistribution(MINIMUM_VALUE_RATE,
                                                    MAXIMUM_VALUE_RATE,
                                                    SAMPLES_COUNT_RATE)
    rangeRate2 = InputGenerator.UniformDistribution(MINIMUM_VALUE_RATE,
                                                    MAXIMUM_VALUE_RATE,
                                                    SAMPLES_COUNT_RATE)

    testNum = 0
    numOfTests = len(rangeStaked1) * len(rangeBalance1) * len(
        rangeBalance2) * len(rangeRate1) * len(rangeRate2)

    FormulaContract = Web3Wrapper.Contract('SovrynSwapFormula')
    FormulaContract.setter().init()
    FormulaContractAddr = FormulaContract.tester()

    minGas = float('+inf')
    maxGas = float('-inf')

    totalGas = 0
    countGas = 0

    for staked1 in rangeStaked1:
        for balance1 in rangeBalance1:
            for balance2 in rangeBalance2:
                for rate1 in rangeRate1:
                    for rate2 in rangeRate2:
                        testNum += 1
                        if True:
                            try:
                                gas = FormulaContractAddr.balancedWeights(
                                    staked1, balance1, balance2, rate1, rate2)
                                minGas = min(minGas, gas)
                                maxGas = max(maxGas, gas)
                                totalGas += gas
                                countGas += 1
                                print(
                                    'Test {} out of {}: gas = {}, minimum = {}, maximum = {}, average = {}'
                                    .format(testNum, numOfTests, gas, minGas,
                                            maxGas, totalGas // countGas))
                            except:
                                pass
예제 #11
0
def Main():
    rangeBalance1 = InputGenerator.UniformDistribution(MINIMUM_VALUE_BALANCE,
                                                       MAXIMUM_VALUE_BALANCE,
                                                       SAMPLES_COUNT_BALANCE)
    rangeRatio1 = InputGenerator.UniformDistribution(MINIMUM_VALUE_RATIO,
                                                     MAXIMUM_VALUE_RATIO,
                                                     SAMPLES_COUNT_RATIO)
    rangeBalance2 = InputGenerator.UniformDistribution(MINIMUM_VALUE_BALANCE,
                                                       MAXIMUM_VALUE_BALANCE,
                                                       SAMPLES_COUNT_BALANCE)
    rangeRatio2 = InputGenerator.UniformDistribution(MINIMUM_VALUE_RATIO,
                                                     MAXIMUM_VALUE_RATIO,
                                                     SAMPLES_COUNT_RATIO)
    rangeAmount = InputGenerator.UniformDistribution(MINIMUM_VALUE_AMOUNT,
                                                     MAXIMUM_VALUE_AMOUNT,
                                                     SAMPLES_COUNT_AMOUNT)

    testNum = 0
    numOfTests = len(rangeBalance1) * len(rangeRatio1) * len(
        rangeBalance2) * len(rangeRatio2) * len(rangeAmount)

    FormulaContractAddr = Web3Wrapper.Contract('BancorFormula').getter()

    for balance1 in rangeBalance1:
        for ratio1 in rangeRatio1:
            for balance2 in rangeBalance2:
                for ratio2 in rangeRatio2:
                    for amount in rangeAmount:
                        testNum += 1
                        if True:
                            resultSolidityPort = Run(FormulaSolidityPort,
                                                     balance1, ratio1,
                                                     balance2, ratio2, amount)
                            resultContractAddr = Run(FormulaContractAddr,
                                                     balance1, ratio1,
                                                     balance2, ratio2, amount)
                            print(
                                'Test {} out of {}: resultSolidityPort = {}, resultContractAddr = {}'
                                .format(testNum, numOfTests,
                                        resultSolidityPort,
                                        resultContractAddr))
                            if resultSolidityPort != resultContractAddr:
                                print('Emulation Error:')
                                print('balance1 = {}'.format(balance1))
                                print('ratio1   = {}'.format(ratio1))
                                print('balance2 = {}'.format(balance2))
                                print('ratio2   = {}'.format(ratio2))
                                print('amount   = {}'.format(amount))
                                return
예제 #12
0
def Main():
    rangeBalance1 = InputGenerator.ExponentialDistribution(
        MINIMUM_VALUE_BALANCE, MAXIMUM_VALUE_BALANCE, GROWTH_FACTOR_BALANCE)
    rangeWeight1 = InputGenerator.ExponentialDistribution(
        MINIMUM_VALUE_WEIGHT, MAXIMUM_VALUE_WEIGHT, GROWTH_FACTOR_WEIGHT)
    rangeBalance2 = InputGenerator.ExponentialDistribution(
        MINIMUM_VALUE_BALANCE, MAXIMUM_VALUE_BALANCE, GROWTH_FACTOR_BALANCE)
    rangeWeight2 = InputGenerator.ExponentialDistribution(
        MINIMUM_VALUE_WEIGHT, MAXIMUM_VALUE_WEIGHT, GROWTH_FACTOR_WEIGHT)
    rangeAmount = InputGenerator.ExponentialDistribution(
        MINIMUM_VALUE_AMOUNT, MAXIMUM_VALUE_AMOUNT, GROWTH_FACTOR_AMOUNT)

    testNum = 0
    numOfTests = len(rangeBalance1) * len(rangeWeight1) * len(
        rangeBalance2) * len(rangeWeight2) * len(rangeAmount)

    tester = Web3Wrapper.Contract('BancorFormula').tester()
    minGas = float('+inf')
    maxGas = float('-inf')
    totalGas = 0
    countGas = 0

    for balance1 in rangeBalance1:
        for weight1 in rangeWeight1:
            for balance2 in rangeBalance2:
                for weight2 in rangeWeight2:
                    for amount in rangeAmount:
                        testNum += 1
                        if True:
                            try:
                                gas = tester.calculateCrossConnectorReturn(
                                    balance1, weight1, balance2, weight2,
                                    amount)
                                minGas = min(minGas, gas)
                                maxGas = max(maxGas, gas)
                                totalGas += gas
                                countGas += 1
                                print(
                                    'Test {} out of {}: gas = {}, minimum = {}, maximum = {}, average = {}'
                                    .format(testNum, numOfTests, gas, minGas,
                                            maxGas, totalGas // countGas))
                            except:
                                pass
예제 #13
0
def Main():
    rangeSupply = InputGenerator.UniformDistribution(MINIMUM_VALUE_SUPPLY,
                                                     MAXIMUM_VALUE_SUPPLY,
                                                     SAMPLES_COUNT_SUPPLY)
    rangeBalance = InputGenerator.UniformDistribution(MINIMUM_VALUE_BALANCE,
                                                      MAXIMUM_VALUE_BALANCE,
                                                      SAMPLES_COUNT_BALANCE)
    rangeRatios = InputGenerator.UniformDistribution(MINIMUM_VALUE_RATIOS,
                                                     MAXIMUM_VALUE_RATIOS,
                                                     SAMPLES_COUNT_RATIOS)
    rangeAmount = InputGenerator.UniformDistribution(MINIMUM_VALUE_AMOUNT,
                                                     MAXIMUM_VALUE_AMOUNT,
                                                     SAMPLES_COUNT_AMOUNT)

    testNum = 0
    numOfTests = len(rangeSupply) * len(rangeBalance) * len(rangeRatios) * len(
        rangeAmount)

    FormulaContractAddr = Web3Wrapper.Contract('BancorFormula').getter()

    for supply in rangeSupply:
        for balance in rangeBalance:
            for ratios in rangeRatios:
                for amount in rangeAmount:
                    testNum += 1
                    if amount <= supply:
                        resultSolidityPort = Run(FormulaSolidityPort, supply,
                                                 balance, ratios, amount)
                        resultContractAddr = Run(FormulaContractAddr, supply,
                                                 balance, ratios, amount)
                        print(
                            'Test {} out of {}: resultSolidityPort = {}, resultContractAddr = {}'
                            .format(testNum, numOfTests, resultSolidityPort,
                                    resultContractAddr))
                        if resultSolidityPort != resultContractAddr:
                            print('Emulation Error:')
                            print('supply  = {}'.format(supply))
                            print('balance = {}'.format(balance))
                            print('ratios  = {}'.format(ratios))
                            print('amount  = {}'.format(amount))
                            return
예제 #14
0
def Main():
    rangeSupply = InputGenerator.ExponentialDistribution(
        MINIMUM_VALUE_SUPPLY, MAXIMUM_VALUE_SUPPLY, GROWTH_FACTOR_SUPPLY)
    rangeBalance = InputGenerator.ExponentialDistribution(
        MINIMUM_VALUE_BALANCE, MAXIMUM_VALUE_BALANCE, GROWTH_FACTOR_BALANCE)
    rangeRatio = InputGenerator.ExponentialDistribution(
        MINIMUM_VALUE_RATIO, MAXIMUM_VALUE_RATIO, GROWTH_FACTOR_RATIO)
    rangeAmount = InputGenerator.ExponentialDistribution(
        MINIMUM_VALUE_AMOUNT, MAXIMUM_VALUE_AMOUNT, GROWTH_FACTOR_AMOUNT)

    testNum = 0
    numOfTests = len(rangeSupply) * len(rangeBalance) * len(rangeRatio) * len(
        rangeAmount)

    tester = Web3Wrapper.Contract('BancorFormula').tester()
    minGas = float('+inf')
    maxGas = float('-inf')
    totalGas = 0
    countGas = 0

    for supply in rangeSupply:
        for balance in rangeBalance:
            for ratio in rangeRatio:
                for amount in rangeAmount:
                    testNum += 1
                    if True:
                        try:
                            gas = tester.calculatePurchaseReturn(
                                supply, balance, ratio, amount)
                            minGas = min(minGas, gas)
                            maxGas = max(maxGas, gas)
                            totalGas += gas
                            countGas += 1
                            print(
                                'Test {} out of {}: gas = {}, minimum = {}, maximum = {}, average = {}'
                                .format(testNum, numOfTests, gas, minGas,
                                        maxGas, totalGas // countGas))
                        except:
                            pass