dappuniversity / token_sale

Code Your Own Cryptocurrency & ICO on Ethereum | Tutorial
406 stars 387 forks source link

Test gives wrong indication I guess #46

Open tschnoelzer opened 3 years ago

tschnoelzer commented 3 years ago

Hi Gregory,

you are testing bytoken and checking for error:

return tokenSaleInstance.buyTokens(800000, { from: buyer, value: numberOfTokens * tokenPrice }) }).then(assert.fail).catch(function(error) { assert(error.message.indexOf('revert') >= 0, 'cannot purchase more tokens than available');

As the function checks msg.value as numberOfTokens times price first and you are passing 800.000 as product, I think the raised error comes from incorrect product instead of checked "tokens available" ... am I wrong?

require(msg.value == multiply(_numberOfTokens, tokenPrice)); require(tokenContract.balanceOf(this) >= _numberOfTokens);

best

Timo

vinaykharayat commented 2 years ago

Same question @gwmccubbin. You wrote this code return tokenSaleInstance.buyTokens(800000, { from: buyer, value: numberOfTokens * tokenPrice }) But I think it should be return tokenSaleInstance.buyTokens(800000)