Comments (9)
Hi @ZeroEkkusu
Sorry, I just found the real problem.
that because forge is not case sensitive, and I import the console file withs "Console.sol" in ContactA.sol, then the error reproduce.
Maybe itβs not a big problem, thanks for your time
from forge-std.
Gm, @tonypig.
There should be no issues with importing/using console
and console2
. Can you show me an example setup?
The only case I can think of when you would get a DeclarationError
is when you try to import console
from console2.sol
and vice-versa.
from forge-std.
Hi @ZeroEkkusu
My scenario is simple:
two contract:
ContractA.sol and ContractA.t.sol (test)
While import console in ContractA.sol, then forge build/test will throw an DeclarationError
that because forge-std/Test.sol also import the console (through Script.sol)
from forge-std.
@tonypig, like so? I can't reproduce the error.
ContractA.sol
import "forge-std/console.sol";
import "forge-std/console2.sol";
contract ContractA {
function f() external {
console.log("gm with console");
console2.log("gm with console2");
}
}
ContractA.t.sol
import "forge-std/Test.sol";
import "src/ContractA.sol";
contract ContractATest is Test {
ContractA cA;
function setUp() public {
cA = new ContractA();
}
function testExample() public {
cA.f();
console.log("test");
console2.log("test 2");
}
}
from forge-std.
I think this still could be an issue for users who use Hardhat console in their production contracts, and use Forge Test in their test contracts.
import "hardhat/console.sol";
contract MyContract {}
import "forge-std/Test.sol";
import "contracts/MyContract.sol";
contract MyContractTest is Test {}
Compile it will throw error[2333]: DeclarationError: Identifier already declared.
Is there a way to import the library so that it only affects current file and it's child-contracts, but not sibling contracts in the inheritance chain?
from forge-std.
@ranmocy, import console
from forge-std
instead of hardhat
in your production contracts:
import "forge-std/console.sol";
Another option is to use selective imports to import only MyContract
in your test contracts:
import {MyContract} from "contracts/MyContract.sol";
from forge-std.
I also cannot get console2
to work on a particular project that I built from scratch. I've ran multiple repos locally that have had it implemented already, and have configured my repo in the same way as the ones that work.
foundry.toml remappings
remappings = [
"forge-std/=lib/forge-std/src/",
"@openzeppelin/=lib/openzeppelin-contracts/",
"@uniswap/v2-core/=lib/v2-core/",
"@uniswap/v3-core/=lib/v3-core/",
"@uniswap/v3-periphery/=lib/v3-periphery/"
]
having trouble importing in both ContractTest.t.sol
and ContractScript.s.sol
files:
// have tried
import "forge-std/console2.sol";
// as well as
import {console2} from "forge-std/console2.sol";
// as well as
import {Script} from "forge-std/Script.sol";
import {console2} from "forge-std/console2.sol";
import {MyContract} from "../src/MyContract.sol";
getting this error on forge build
:
Error (7576): Undeclared identifier. Did you mean "console"?
script/PriceOracle.s.sol:19:9: DeclarationError: Undeclared identifier. Did you mean "console"?
console2.log("initializing price oracle...");
^------^
from forge-std.
I think the issue I was running into had to do with Solidity and my PriceOracle.sol
contract being version ^0.7.6
was able to resolve the error using pragma abicoder v2
on the script/test contracts for PriceOracle
from forge-std.
Btw, no need to use console2
; it's only there for legacy support. You can just use console
.
from forge-std.
Related Issues (20)
- assertEq "Invalid data" HOT 2
- Add prompt cheatcode
- Change `vm` visibility to internal in `StdAssertions` and `StdUtils` HOT 2
- Package.json version is not updated. HOT 4
- Feature request: block gas limits for most popular chains HOT 2
- 1.7.1 -> 1.8.1 breaking change: why is DSTest no longer inherited by Test? HOT 1
- Add Vm.prevrandao as uint256 overloaded function
- Add envExists cheatcode function
- Add isContext cheatcode function HOT 1
- add new blobhash cheatcodes HOT 2
- Can't seem to read `CallerMode` from `vm.readCallers()` HOT 4
- Add new random cheatcodes HOT 3
- [FAIL. Reason: revert: stdStorage find(StdStorage): Failed to write value.] HOT 2
- Problem installing forge-std library HOT 2
- Enhancement:- Git repository should not be needed for installing `forge-std`
- BUG StdStorage: Unexpected 'find' function behavior when dynamic array length matches searched element value HOT 3
- Restore `fail` with a message HOT 2
- new release 1.92
- add broadcastRawTransaction cheatcode
- Add vm.getFoundryVersion() cheatcode
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from forge-std.