How to test If ERC20 approve function has executed correctly?

Hi everybody!

In OpenZeppelin documentation for ERC20 API (v3) appears that the approve function return a bool.

However when writing unit tests with ethers I got a result of type Promise<ContractTransaction>. :open_mouth:

How Do I test If the approve operation occurred correctly? Is there a way to get the bool result from ContractTransaction object return type? Or Do I have to check if the approval event was emitted? :thinking:

Any help will be great!


If the transaction failed the promise would reject and you would receive an exception.

You can wait until the transaction is mined and then check the allowance to see if approve went through.

1 Like

Thanks a lot, @frangio !