Greetings!
I am testing a smart contract suite with hardhat.
I want to test reentrance, so here is my scenario.
I have a contract A. It's an ERC20.sol from OZ.
I have a contract B that is made to call my Token contract A
The contract B have the interface to call A.
The owner of Contract B makes the sellShares call to B, the victim is A:
As per the logs The address is right and the allowance as well.
function sellShares() public payable {
approveVictim();
uint256 allowance = victim.allowance(address(this), address(victim));
console.log(allowance);
console.log(address(this));
victim.sellShares(1000000000000000000);
}
function approveVictim() public{
victim.approve(address(victim), 400000000000000000000000);
}
This call gets sent to the victim Contract A
function sellShares(uint256 amount) public nonReentrant {
console.log(allowance(msg.sender, address(this)));
console.log(msg.sender);
transferFrom(_msgSender(), address(this), amount);
}
Here again the values for the address and allowance are as expected.
I initiate this call from my test file
let allowance = await www3Shares.allowance(B.target, A.target)
console.log("=>",allowance)
console.log("=>",B.target)
Here as well, the values are as expected.
It keeps reverting with
reverted with reason string 'ERC20: insufficient allowance
Code to reproduce
Environment
"hardhat": "^2.18.2",
node v16.17.1
"@openzeppelin/contracts": "^4.8.3",