Lesson 12 Fuzz test depositCollateral #604
-
I get this error when trying to do the first test using the Handler (03:57:08 in the 3rd video. https://youtu.be/wUjYK5gwNZs?t=14228 ) Thats my repository: https://github.com/Mepsss/foundry-simplified-DAI-f23 Thats the point where the test should fail ~50% of the time but mine always fails because of the insufficient allowance error. meps@DESKTOP-3L4CA2N:~/foundry-f23/foundry-defi-stablecoin-f23$ forge test --match-test invariant_protocolMustHaveMoreValueThanTotalSupply
[⠔] Compiling...
No files changed, compilation skipped
Running 1 test for test/fuzz/Invariants.t.sol:Invariants
[FAIL. Reason: ERC20: insufficient allowance]
[Sequence]
sender=0x000000000000000000000000000000000000042a addr=[test/fuzz/Handler.t.sol:Handler]0x2e234dae75c793f67a35089c9d99245e1c58470b calldata=failed():(bool), args=[]
sender=0x0000000000000000000000000000000000000527 addr=[test/fuzz/Handler.t.sol:Handler]0x2e234dae75c793f67a35089c9d99245e1c58470b calldata=failed():(bool), args=[]
sender=0xf5a96da3858d4a76e31020817484c82d7eebda67 addr=[test/fuzz/Handler.t.sol:Handler]0x2e234dae75c793f67a35089c9d99245e1c58470b calldata=depositCollateral(uint256,uint256), args=[471428386612561126165474702797 [4.714e29], 2]
invariant_protocolMustHaveMoreValueThanTotalSupply() (runs: 1, calls: 3, reverts: 1)
Test result: FAILED. 0 passed; 1 failed; 0 skipped; finished in 8.47ms
Ran 1 test suites: 0 tests passed, 1 failed, 0 skipped (1 total tests)
Failing tests:
Encountered 1 failing test in test/fuzz/Invariants.t.sol:Invariants
[FAIL. Reason: ERC20: insufficient allowance]
[Sequence]
sender=0x000000000000000000000000000000000000042a addr=[test/fuzz/Handler.t.sol:Handler]0x2e234dae75c793f67a35089c9d99245e1c58470b calldata=failed():(bool), args=[]
sender=0x0000000000000000000000000000000000000527 addr=[test/fuzz/Handler.t.sol:Handler]0x2e234dae75c793f67a35089c9d99245e1c58470b calldata=failed():(bool), args=[]
sender=0xf5a96da3858d4a76e31020817484c82d7eebda67 addr=[test/fuzz/Handler.t.sol:Handler]0x2e234dae75c793f67a35089c9d99245e1c58470b calldata=depositCollateral(uint256,uint256), args=[471428386612561126165474702797 [4.714e29], 2]
invariant_protocolMustHaveMoreValueThanTotalSupply() (runs: 1, calls: 3, reverts: 1)
Encountered a total of 1 failing tests, 0 tests succeeded |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
You are missing couple of things in First, in order to deposit collateral, Second, Third you need to prank
After all the changes your
|
Beta Was this translation helpful? Give feedback.
You are missing couple of things in
Handler::depositCollateral
function.First, in order to deposit collateral,
msg.sender
have to have the deposit amount in the first place. to get it docollateral.mint(msg.sender, amountCollateral);
.Second,
msg.sender
needs to approve theamountCollateral
to DSCEngine so that it can be transferred to DSCEngine, do it like thiscollateral.approve(address(dsce), amountCollateral);
Third you need to prank
approve
anddepositCollateral
functions withmsg.sender
, do it like thisAfter all the changes…