Questions tagged [foundry]
Questions about Foundry, the blazing fast smart contract toolchain
176
questions
0
votes
1
answer
13
views
How to use anvil accounts in the Foundry Test
How can i use anvil accounts into the foundry tests? Like in hardhat node i can getNamedAccounts() but how can I use the anvil accounts into my forge Tests?
1
vote
0
answers
10
views
Is it Possible to Run Multithreaded Tasks in Foundry?
I'm looking to run custom tasks/functions in parallel while using Foundry. Specifically, I'm interested in understanding if there's a way to use Foundry's fuzz testing capabilities to achieve ...
0
votes
0
answers
12
views
Is it possible to import foundry anvil in rust?
I successfully installed and used anvil from the wsl shell.
I have some rust code, where i want to import foundry anvil instead of running from shell, cause i want to be able to control it from the ...
0
votes
1
answer
23
views
Fork specific blocknumber on BSC Mainnet call deployed contract failed
I want to call Quoter Contract on BSC Mainnet which is deployed already.
I'm using HardHat or Foundry to fork Mainnet specific blocknumber, here is HardHat Config JS:
module.exports = {
solidity: &...
0
votes
1
answer
36
views
How to get consensus layer data for many blocks in a single RPC call?
You can get consensus related values such prevrandao and validator details with eth_getBlockByNumber or eth_getBlockByHash, but how can you get this data for many blocks without making thousands of ...
0
votes
1
answer
70
views
vm.startPrank doesn't change the msg.sender in foundry
While I'm performing the testing in foundry. I'm facing an issue of vm.startPrank doesn't change the msg.sender.
CheatCodes cheats = CheatCodes(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);
address ...
1
vote
2
answers
93
views
For a given block, how to extract only transactions that involve newly minted NFTs, with either Foundry or ethers.js?
Firstly, I’ll say that I prefer to do this with Foundry, but if it turns out to be too much of a pain, I’m open to doing this with ethers.js as well.
Take this block, for instance:
https://etherscan....
2
votes
0
answers
16
views
Getting error ERC20: insufficient allowance even after the user approving the tokens. Need help with debugging
The following code is from a Stablecoin project.
To gain more context, please refer to this Github repo.
I've added a new function to the DSCEngine.sol name collapseDsc() which is responsible for ...
0
votes
1
answer
28
views
How do I input parameter for foundry test cases?
When you run forge test --match-case testFunction it works even without parameters. Why? Do I have to input them?
function testFunction(
uint64 poolId,
string memory tokenName,
...
1
vote
1
answer
43
views
What are the differences of Foundry vm.prank vs vm.broadcast
What are the differences of Foundry vm.prank vs vm.broadcast
1
vote
1
answer
79
views
How to deploy a contract in Foundry?
I want to deploy a smart contract using Foundry, but I don't want to pass my variables every time I run forge create inside of the terminal and I don't want to have to follow up every deployment with ...
1
vote
1
answer
54
views
foundry forge vm.rollFork not working as expected
I'm using vm.rollFork feature in foundry to get _token.totalSupply() at two different blocks but test failing because its returning same totalSupply number for two different blocks. I have checked and ...
1
vote
0
answers
18
views
Foundry : cast storage command storage slot argument posing length issue
When I try to get the private variable stored at storage slot 0 of the contract storage using the cast storage command,
cast storage <my-contract-address> 0 --rpc-url <my-rpc-url>
I get ...
0
votes
0
answers
30
views
Must be authenticated error using Alchemy RPC URL
I am getting this error
Error:
(code: -32000, message: Must be authenticated!, data: None)
When running this command
forge script script/DeploySimpleStorage.s.sol --rpc-url $SEPOLIA_RPC_URL --...
1
vote
0
answers
37
views
console.log results in Anvil output
I am using the library forge-std/console.sol in a contract for debugging purposes and execute the corresponding functions on a local Anvil network. I use Cast to send the transaction to the network.
...
1
vote
1
answer
60
views
How to Resolve Compiler Version Conflicts in Foundry Test Contracts?
I'm working on a Foundry project, and I'm encountering issues with compiler versions when trying to deploy Uniswap V3 core and periphery contracts in a test contract(i.e. UniswapTest shown below). The ...
1
vote
0
answers
25
views
How Foundry interactive with other Contract Function and Log its Revert Message
I'm using Foundry to develop my contract. I want to calculate Uniswap V3 amount out. I find a Quoter Contract and call it in my Test Unit
The Quoter Contract Address: https://etherscan.io/address/...
0
votes
1
answer
28
views
Why installing foundry did'nt install lib folder
I ran the command curl -L https://foundry.paradigm.xyz | bash....but it did'nt install the lib folder...I am trying again and again but it does'nt install..please help me
1
vote
1
answer
170
views
How Can I Simulate a Live Network Transaction Using Foundry or Hardhat?
I have written code in Rust to do Uniswap V2 swap via the ethers-rs library. This code is not part of a contract but rather a standalone application.
I understand it's possible to test this locally. ...
5
votes
1
answer
307
views
How to configure multiple solidity compiler versions in foundry?
I have a foundry project with files that have multiple solidity versions(0.7.x and 0.8.x). hardhat can relatively easily be configured to compile all files in the project as follows:
https://hardhat....
0
votes
1
answer
43
views
How can I install multiple versions of a dependency in foundry?
In hardhat multiple versions of a dependency can be installed as follows in the package.json(assuming yarn is being used):
"@openzeppelin/contracts": "^4.3.2",
"openzeppelin-...
0
votes
1
answer
72
views
Foundry forge unit tests fail when use customERC20Token.balanceOf(msg.sender)
I have a raffle contract that required a custom ERC20 token as an entrance fee.
In Raffle contract I have the enterRaffle function:
function enterRaffle() public payable {
uint256 ...
1
vote
1
answer
71
views
Does Foundry Support Dynamical Library Linking in Solidity?
I would like to deploy a contract that has external library dependencies that need to be dynamically linked. This is typically done in hardhat ethers as follows:
const MyLibrary = await ethers....
0
votes
2
answers
155
views
Foundry tests fails with EvmError: Revert Counterexample, when calling transfer
I'm getting an error when trying to test my treasury:
[FAIL. Reason: EvmError: Revert Counterexample: calldata=...
1
vote
0
answers
68
views
How to test Chainlink Operator.sol in Foundry and find cause of revert?
I am trying to rewrite this test from Truffle/Javascript to Foundry/Solidity.
This is the specific part I am stuck on:
it("should not fulfill from unauthorized job", async function () {
...
0
votes
0
answers
15
views
Type contract is not implicitly convertible to expected type tuple in my foundry setup
I am trying to test my project, but keeps throwing an error in the test setup.
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
import {Test} from "forge-std/Test.sol";
import {...
4
votes
0
answers
79
views
Hardhat and foundry, contract bytecode different
I'm developing a contract in hardhat project. But now I want to write test by foundry. My problem is I'm using create2, but when running contract by hardhat and foundry they gave different addresses. ...
0
votes
0
answers
34
views
Is it possible to use Foundry to monitor the mempool?
I have been able to use other frameworks / libraries (e.g., web3.py and ethers.py) to monitor mempool events.
I see that anvil has one mention in the docs related to mempool monitoring (a switch for ...
0
votes
1
answer
98
views
Why in foundry I got lib/forge-std/lib folder empty?
Hey Everyone I initialize foundry framework and got folder structures however initially lib folder was missing which i later installed via this command git submodule add --force --name lib/forge-std ...
0
votes
1
answer
33
views
When can we use FORK_URL as Alchemy API key during foundry test?
When can we use FORK_URL as Alchemy API key during foundry test? I am trying to learn how to use foundry, but seems like a youtuber is using FORK_URL as Alchemy API key. Is FORK_URL depends on a ...
0
votes
1
answer
85
views
Encountering error when trying to run `forge create`
I am in the process of switching to foundry for contract development and testing. I have written some basic contracts, and am trying to use the alchemy RPC URL to deploy the contracts onto the testnet ...
0
votes
0
answers
72
views
Guidance on writing a Foundry Test for a deploy script! (Lesson 9: Raffle contract)
I am following the new foundry course by Patrick and was wondering if I could get tips on how to test the deploy script - https://github.com/Cyfrin/foundry-smart-contract-lottery-f23/blob/main/script/...
0
votes
1
answer
59
views
Foundry Fuzzing How to increase the runs to be more than default 256
I am testing the Foundry Fuzzing feature. Therefore I created this simple contract:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Vault {
bool public s_locked;
uint private ...
0
votes
0
answers
42
views
Transaction not found using `cast publish` of Foundry
I wrote this function in go-ethereum to return a raw transaction:
func createTx(c *ethclient.Client) (rawTxnHex string) {
from := common.HexToAddress("...
0
votes
1
answer
117
views
Why do I get "Nothing to compile" everytime I run forge test -m *testname* on my foundry project?
I always get "Nothing to compile" everytime I run forge test -m testname on my foundry project and I don't know why
1
vote
0
answers
75
views
Publishing a signed transaction using flashbots rpc takes many tries?
I'm sending a signed transaction using flashbots rpc, in the following way. But often it takes many tries 2 ~ 4 times to be picked up?
cast publish --rpc-url https://rpc-goerli.flashbots.net/ ...
0
votes
1
answer
49
views
Foundry Breaks if You change your function's names, (WHY ?)?
Hope you are all doing great
I have this weird problem with naming my test functions in foundry, I am watching Patrick Collins New Videos collections.
in lesson 7(), patrick wrote a test name ...
0
votes
0
answers
55
views
foundry debug: unknown address at
I use debug in foundry, but it doesn't show the contract. I have read these two issues, but doesn't work.issues#2348, issues#2947
forge debug --debug src/Counter.sol --sig "setMember()"
0
votes
0
answers
75
views
Foundry: compile and test too slow
The problem is as the title. As we know, foundry is created by rust, it is very fast. But why my foundry is so slow?
my version: forge 0.2.0 (8307d6d 2023-04-19T16:44:52.696636400Z).cast 0.2.0 (...
0
votes
2
answers
10
views
Insufficient allowance on liquidate unit test
I don't understand why I'm getting this error:
When running this test I get an insufficient allowance error on the transferFrom function.
Here is my test:
function testIfInsolventCanBeLiquidated(...
0
votes
1
answer
18
views
Having more than one prank at the same time
I'm trying to deploy a simple Lottery contract with the Foundry framework. While testing I had some little problem, in fact I defined the following modifier:
modifier selectedWinner() {
vm....
1
vote
1
answer
44
views
UUPS Upgrades using Foundry
I am wondering if any of you have tried to do UUPS smart contract upgrade using Foundry ? Similarly the same way you write a script in hardhat. If so, how to do it properly.
2
votes
2
answers
120
views
How to check state value by using cast in Foundry?
I'm a beginner in develop solidity and using Foundry.
I've created a contract which is include some state value as below
address[] public owners;
mapping(address => bool) public isOwner;
...
0
votes
1
answer
79
views
assertEq is showing error when written in the test file foundry
I am writing the test by following the lesson 7 tutorial and got this error, even I imported Test from forge-std
Undeclared identifier. Did you mean "assert"?
this is the actual error
// ...
0
votes
1
answer
76
views
add liquidity to a curve pool
I am working on adding liquidity to a curve pool in Foundry in order to test the curve pool oracle in my project, however, I'm getting some difficulty in adding liquidity to a curve pool. I believe ...
0
votes
1
answer
66
views
How to handle structs with mappings in foundry tests?
This is the mapping containing the struct.
mapping(address => UserFessInfo) public userFeesInfo;
This is the struct UserFeeInfo
struct UserFessInfo {
uint256 stakedAmount;
uint256 ...
0
votes
1
answer
33
views
How Foundry knows if the build is already done or not?
As we all know foundry skips the compilation for an already-built project. How does Foundry check whether the project has any changes, whether to build or skip the build?
2
votes
1
answer
70
views
How to use foundry cast call with a struct that has a uint and string
Two uint works, two strings works, but as soon as the struct is a uint and a string I get
"could not decode output. did you specify the wrong function return data type perhaps?"
The command:
...
-1
votes
1
answer
46
views
Solidity Error (6160): foundry
while running this code
import {Test, console} from "forge-std/Test.sol";
import {FundMe} from "../src/FundMe.sol";
contract FundMeTest is Test{
FundMe public fundMe;
...
0
votes
0
answers
19
views
per file compile optimisation settings
I use both hardhat and foundry to build and both seem to offer just one value for runs for the whole project. But I have one large initialisation contract which will only be run once so I'd like runs =...