0

So, basically I was learning from updraft and i came across this issue.

This is my DecStblCoin.sol file

// weth: erc20 version of ethereum // SPDX-License-Identifier: MIT pragma solidity ^0.8.20; import {ERC20Burnable, ERC20} from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol"; import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; /** * @title DecStblCoin * @author Harsh Anand * Collateral: Exogenous (ETH & BTC) * Minting: Algorithmic (Decentralized) * Relative Stablility: Pegged to USD * * This contract is meant to be governed by DSCEngine. This contract is just the ERC20 implementation of our stablecoin system. */ contract DecStblCoin is ERC20Burnable, Ownable { error DecStblCoin__MustBeMoreThanZero(); error DecStblCoin__BurnAmountExceedsBalance(); error DecStblCoin__NotZeroAddess(); constructor() ERC20("DecStblCoin", "DCS") Ownable(msg.sender) {} function burn(uint256 _amount) public override onlyOwner { uint256 balance = balanceOf(msg.sender); if (balance <= 0) { revert DecStblCoin__MustBeMoreThanZero(); } if (_amount > balance) { revert DecStblCoin__BurnAmountExceedsBalance(); } super.burn(_amount); } function mint(address _to, uint256 _amount) external onlyOwner returns (bool) { if (_to == address(0)) { revert DecStblCoin__NotZeroAddess(); } if (_amount <= 0) { revert DecStblCoin__MustBeMoreThanZero(); } _mint(_to, _amount); return true; } } 

and this is my foundry test code:

// SPDX-License-Identifier: MIT pragma solidity ^0.8.20; import {DecStblCoin} from "../../src/DecStblCoin.sol"; import {Test, console} from "forge-std/Test.sol"; import {StdCheats} from "forge-std/StdCheats.sol"; contract DecStblCoinTest is StdCheats, Test { DecStblCoin dsc; function setUp() external { dsc = new DecStblCoin(); } function test_MustMintMoreThanZero() public { // Arrange, Act, Assert vm.prank(dsc.owner()); vm.expectRevert(); dsc.mint(address(this), 0); } function test_MustMintMoreThanZero() public { // Arrange, Act, Assert vm.prank(dsc.owner()); vm.expectRevert(); dsc.mint(dsc.owner(), 0); } } 

so i mentioned two functions for same name because it is not working properly. for first snippet if i test, it passes but for second it shows error that:

forge test --mt test_MustMintMoreThanZero [⠊] Compiling... [⠰] Compiling 1 files with Solc 0.8.30 [⠔] Solc 0.8.30 finished in 395.55ms Compiler run successful! Ran 1 test for test/unit/DecStblCoinTest.t.sol:DecStblCoinTest [FAIL: next call did not revert as expected] test_MustMintMoreThanZero() (gas: 12606) Suite result: FAILED. 0 passed; 1 failed; 0 skipped; finished in 4.02ms (1.40ms CPU time) Ran 1 test suite in 106.12ms (4.02ms CPU time): 0 tests passed, 1 failed, 0 skipped (1 total tests) Failing tests: Encountered 1 failing test in test/unit/DecStblCoinTest.t.sol:DecStblCoinTest [FAIL: next call did not revert as expected] test_MustMintMoreThanZero() (gas: 12606) Encountered a total of 1 failing tests, 0 tests succeeded 

but anyways the testing is for zero minting so why should it matter whether owner is testing or the testing contract. it should revert right. please someone look into.

1
  • This is weird. Can you use different test names and run both tests together, with verbose -vvvvv . It'll be more clear looking at the traces. Commented Oct 26 at 15:12

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.