I'm testing a simple fallback function with Truffle, the fallback function is:
function () public payable {
internalTransfer(this, msg.sender, 100000000);
FundSuccess(msg.sender, msg.value);
}
function internalTransfer(address _from, address _to, uint256 _value)
internal returns (bool) {
// SafeMath.sub will throw if there is not enough balance.
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
return true;
}
where .sub and .add are imported from SafeMath library, in the truffle test I have
trx = await token.send(power18(1), {from: accounts[1]});
console.log(trx);
var balance1 = await token.balanceOf.call(accounts[1]);
console.log(balance1);
what I found was, no matter what I specify in the from, balance is always assigned to account[0]. Checking the transaction in Ganache shows that the transaction was recorded as sent from account[0].
I know {from:...} works, I have used it in other places and never had a problem. This is the first time I used it on ".send". I am at a stage where I do not know how to proceed, tried googling but couldn't find good information, please help!