Check docs
project.
Install
bun
curl -fsSL https://bun.sh/install | bash
Install
foundry
curl -L https://foundry.paradigm.xyz | bash
# Follow on-screen command
Install all the packages
bun i
Build contracts
forge build
# Or
npm run build
Success message
> @lazychain/[email protected] build
> forge build --extra-output-files bin --extra-output-files abi
[⠊] Compiling...
[⠢] Compiling 12 files with Solc 0.8.24
[⠆] Solc 0.8.24 finished in 118.77ms
Compiler run successful!
Test should have to be design to receive (inject) the variable we want to test (Inversion of control). On foundry, we can do this be configuring the foundry.toml
add [fuzz]
section.
On foundry:
- import StdInvariant.sol
.
- Inherit on the test contract is StdInvariant, Test
.
- On Setup()
set the entrypoint targetContract(address(<contract under test>))
.
on Echidna or Medusa.
// src/contracts/MyContract.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
contract MyContract {
struct UserNameSpace {
address userAddress;
string nickName;
uint256 draws_count;
uint256 win_count;
}
function updateUserNameSpace(UserNameSpace calldata newNamespace) public {
// ... implementation logic
}
}
// test/MyContractTest.t.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
import "forge-std/Test.sol";
import "../src/contracts/MyContract.sol";
contract MyContractTest is Test {
MyContract myContract;
// Needed so the test contract itself can receive ether
// when withdrawing
receive() external payable {}
function setUp() public {
myContract = new MyContract();
}
function testUpdateUserNameSpaceFuzz(address userAddress, string memory nickName, uint256 drawsCount, uint256 winCount) public {
UserNameSpace memory namespace = UserNameSpace(userAddress, nickName, drawsCount, winCount);
myContract.updateUserNameSpace(namespace);
// Add assertions here to check the state of the contract after the update
// ...
}
}
forge test
TODO
TODO
forge install transmissions11/solmate
forge remappings