I am trying to implement a simple token transfer to a Vault but I'm having trouble approving the transaction and when I run tests using foundry, I receive this error:
[FAIL. Reason: ERC20: transfer amount exceeds allowance] testDeposit() (gas: 86770)
My code is for the deposit function is here:
function deposit(uint256 amount) external {
console.log("RANDOM inside deposit = ");
console.log(IERC20(underlyingToken).balanceOf(msg.sender));
console.log("msg sender =");
console.log(msg.sender);
console.log("approve = ");
console.log(IERC20(underlyingToken).approve(address(this), amount));
// IERC20(underlyingToken).approve(msg.sender, amount);
console.log("RANDOM inside deposit after approve = ");
console.log(IERC20(underlyingToken).allowance(msg.sender, address(this)));
IERC20(underlyingToken).transferFrom(msg.sender, address(this), amount);
// // totalDeposited += amount;
IPool(aavePool).supply(underlyingToken, amount, address(this), 0);
totalUnderlyingDeposited += amount;
}
Thank you for the help in advance