Hi, not sure why I am getting this error...
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.13 <0.9.0;
import "hardhat/console.sol";
import "abdk-libraries-solidity/ABDKMath64x64.sol";
library BreedingHelpers {
uint256 constant floor = 10 * 10**18;
uint256 constant percentage_factor = 5;
function min_breeding_price(
uint256 supply_of_apples,
uint256 supply_of_trees
) public pure returns (uint256) {
return
floor +
ABDKMath64x64.toUInt(
ABDKMath64x64.mul(
ABDKMath64x64.mul(
ABDKMath64x64.mul(
ABDKMath64x64.pow(ABDKMath64x64.fromUInt(10), 18),
ABDKMath64x64.sqrt(
ABDKMath64x64.fromUInt(supply_of_apples)
)
),
ABDKMath64x64.sqrt(
ABDKMath64x64.fromUInt(supply_of_trees)
)
),
ABDKMath64x64.divu(percentage_factor, 100)
)
);
}
}
const { ethers } = require('hardhat')
const { use, expect } = require('chai')
const { solidity } = require('ethereum-waffle')
var utils = require('ethers').utils;
use(solidity)
describe('BreedingHelpers', async function () {
let breedingHelpers;
const [owner] = await ethers.getSigners();
// quick fix to let gas reporter fetch data from gas station & coinmarketcap
before((done) => {
setTimeout(done, 2000)
})
beforeEach(async () => {
const BreedingHelpersContract = await ethers.getContractFactory(
'BreedingHelpers',
)
breedingHelpers = await BreedingHelpersContract.deploy();
})
describe('min_breeding_price', () => {
const testCases = [
[0, 1, '9.99', '10.1'],
[1, 1, '10', '10.1'],
[2, 2, '9.99', '10.1'],
[5, 5, '10.2', '10.3'],
[10, 10, '9.99', '100.1'],
]
testCases.forEach(testCase => {
const supplyOfApples = testCase[0];
const supplyOfTress = testCase[1];
const minBreedingPriceLowerBound = testCase[2];
const minBreedingPriceUpperBound = testCase[3];
it(`supplyOfApples: ${supplyOfApples}, supplyOfTrees: ${supplyOfTress} -> min-breeding price lowerBound: ${minBreedingPriceLowerBound}, min-breeding price upperBound: ${minBreedingPriceUpperBound}`, async () => {
const result = await breedingHelpers.min_breeding_price(
supplyOfApples, supplyOfTress
);
console.log('resultBreedingString: ')
console.log(result.toString())
expect(result.gt(utils.parseEther(minBreedingPriceLowerBound))).to.be.true;
expect(result.lt(utils.parseEther(minBreedingPriceUpperBound))).to.be.true;
})
})
})
})
It works without the last test case, but it seems like bigger big numbers throw this strange error...