✅Authentication
Testing authentication in Foundry
Last updated
Testing authentication in Foundry
Last updated
The target is a wallet contract Wallet.sol
:
Create a test file Auth.t.sol
:
This AuthTest
contract can call wallet.setOwner()
because it was set as the owner
in the constructor.
Write a fail test case:
vm.prank(address(1))
means "for the next call, pretend we are address(1)
". This test case would fail because address(1)
is not the owner so that it cannot call wallet.setOwner()
.
An extension of vm.prank()
is the vm.startPrank()
and vm.endPrank()
pair. The impersonation will start on vm.startPrank()
until vm.endPrank()
is executed.