Lesson 7: Incorrect Decimals? 06:29:31 #498
-
For the first test via brownie, I believe the decimals being used are incorrect. When I run the test, I get the following:
Taking a look at the length of both sides. I get the following: Can someone please help me understand why we are seeing these different values? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
Hello @abdulrabbani00 the assertion is failing because the way you are setting up the |
Beta Was this translation helpful? Give feedback.
-
@cromewar - Good catch on the constructor(address _priceFeedAddress) public {
usdEntryFee = 50 * (10**18);
ethUsdPriceFeed = AggregatorV3Interface(_priceFeedAddress);
lottery_state = LOTTERY_STATE.CLOSED;
} function getEntranceFee() public view returns(uint256) {
(,int price,,,) = ethUsdPriceFeed.latestRoundData();
uint256 adjustedprice = uint256(price) * 10**10;//18 decimal
// $50, $4000 / ETH
// 50/2000
// 50 * 10000 / 2000
uint256 costToEnter = (usdEntryFee * 10 ** 18) / adjustedprice ;
return costToEnter;
} |
Beta Was this translation helpful? Give feedback.
-
Actually my bad I was expecting another zero, but as your code does not have it, the 0.014 might be correct so the error is not by that side, the eth price for 50$ is 0.012, so your test would pass setting them bellow and above that number, however the entrance fee is returning a bigger number as it's not converting the floating numbers. Anyways you will change that test later on the course as is just intended to be used on local networks, I have a workaround for you, don't use to Wei for this test, use just numbers (your know 11 * 10.... and 14*10...). let us know it this works for you. This is how the function will like later: def test_get_entrance_fee():
if network.show_active() not in LOCAL_BLOCKCHAIN_ENVIRONMENTS:
pytest.skip()
lottery = deploy_lottery()
# Act
expected_entrace_fee = Web3.toWei(0.025, "ether")
entrance_fee = lottery.getEntranceFee()
# Assert
print(expected_entrace_fee)
print(entrance_fee)
assert expected_entrace_fee == entrance_fee |
Beta Was this translation helpful? Give feedback.
Actually my bad I was expecting another zero, but as your code does not have it, the 0.014 might be correct so the error is not by that side, the eth price for 50$ is 0.012, so your test would pass setting them bellow and above that number, however the entrance fee is returning a bigger number as it's not converting the floating numbers. Anyways you will change that test later on the course as is just intended to be used on local networks,
I have a workaround for you, don't use to Wei for this test, use just numbers (your know 11 * 10.... and 14*10...). let us know it this works for you.
This is how the function will like later: