Skip to content

Commit

Permalink
chore: configure medusa with two basic fuzz tests
Browse files Browse the repository at this point in the history
- used --foundry-compile-all to ensure the test contract under
  `test/properties` is compiled (otherwise it is not compiled and medusa
  crashes when it can't find it's compiled representation)
- set src,test,script to test/properties/medusa to not waste time
  compiling contracts that are not required for the medusa campaign
  • Loading branch information
0xteddybear committed Aug 8, 2024
1 parent d469a49 commit cfb3f68
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/contracts-bedrock/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,8 @@ src = 'test/kontrol/proofs'
out = 'kout-proofs'
test = 'test/kontrol/proofs'
script = 'test/kontrol/proofs'

[profile.medusa]
src = 'test/properties/medusa/'
test = 'test/properties/medusa/'
script = 'test/properties/medusa/'
82 changes: 82 additions & 0 deletions packages/contracts-bedrock/medusa.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"fuzzing": {
"workers": 10,
"workerResetLimit": 50,
"timeout": 0,
"testLimit": 500,
"callSequenceLength": 100,
"corpusDirectory": "",
"coverageEnabled": true,
"targetContracts": ["SuperchainERC20FactoryFuzz"],
"targetContractsBalances": [],
"constructorArgs": {},
"deployerAddress": "0x30000",
"senderAddresses": [
"0x10000",
"0x20000",
"0x30000"
],
"blockNumberDelayMax": 60480,
"blockTimestampDelayMax": 604800,
"blockGasLimit": 125000000,
"transactionGasLimit": 12500000,
"testing": {
"stopOnFailedTest": true,
"stopOnFailedContractMatching": false,
"stopOnNoTests": true,
"testAllContracts": false,
"traceAll": false,
"assertionTesting": {
"enabled": true,
"testViewMethods": false,
"panicCodeConfig": {
"failOnCompilerInsertedPanic": false,
"failOnAssertion": true,
"failOnArithmeticUnderflow": false,
"failOnDivideByZero": false,
"failOnEnumTypeConversionOutOfBounds": false,
"failOnIncorrectStorageAccess": false,
"failOnPopEmptyArray": false,
"failOnOutOfBoundsArrayAccess": false,
"failOnAllocateTooMuchMemory": false,
"failOnCallUninitializedVariable": false
}
},
"propertyTesting": {
"enabled": false,
"testPrefixes": [
"property_"
]
},
"optimizationTesting": {
"enabled": false,
"testPrefixes": [
"optimize_"
]
},
"targetFunctionSignatures": [],
"excludeFunctionSignatures": []
},
"chainConfig": {
"codeSizeCheckDisabled": true,
"cheatCodes": {
"cheatCodesEnabled": true,
"enableFFI": false
}
}
},
"compilation": {
"platform": "crytic-compile",
"platformConfig": {
"target": ".",
"solcVersion": "",
"exportDirectory": "",
"args": ["--foundry-out-directory", "artifacts","--foundry-compile-all"]
}
},
"logging": {
"level": "info",
"logDirectory": "",
"noColor": false
}
}
1 change: 1 addition & 0 deletions packages/contracts-bedrock/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"gas-snapshot": "pnpm build:go-ffi && pnpm gas-snapshot:no-build",
"kontrol-summary": "./test/kontrol/scripts/make-summary-deployment.sh",
"kontrol-summary-fp": "KONTROL_FP_DEPLOYMENT=true pnpm kontrol-summary",
"medusa":"FOUNDRY_PROFILE=medusa medusa fuzz",
"snapshots": "forge build && npx tsx scripts/autogen/generate-snapshots.ts && pnpm kontrol-summary-fp && pnpm kontrol-summary",
"snapshots:check": "./scripts/checks/check-snapshots.sh",
"semver-lock": "forge script scripts/SemverLock.s.sol",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;
import {Test} from "forge-std/Test.sol";

import { SuperchainERC20Factory } from "src/L2/SuperchainERC20Factory.sol";

contract SuperchainERC20FactoryFuzz is Test{
struct DeployParams {
address remoteToken;
string name;
string symbol;
uint8 decimals;
}

SuperchainERC20Factory internal factory;

constructor() {
factory = new SuperchainERC20Factory();
}

// this is a stateless check, so halmos will probably supersede it
function testContractAddressDependsOnParams(DeployParams memory left, DeployParams memory right) external {
require(
left.remoteToken != right.remoteToken
|| keccak256(bytes(left.name)) != keccak256(bytes(right.name))
|| keccak256(bytes(left.symbol)) != keccak256(bytes(right.symbol))
|| left.decimals != right.decimals
);
address superc20Left = factory.deploy(left.remoteToken, left.name, left.symbol, left.decimals);
address superc20Right = factory.deploy(right.remoteToken, right.name, right.symbol, right.decimals);
assert(superc20Left != superc20Right);
}

function testContractAddressDoesNotDependOnChainId(DeployParams memory params, uint256 chainIdLeft, uint256 chainIdRight) external {
vm.chainId(chainIdLeft);
address superc20Left = factory.deploy(params.remoteToken, params.name, params.symbol, params.decimals);
vm.chainId(chainIdRight);
address superc20Right = factory.deploy(params.remoteToken, params.name, params.symbol, params.decimals);
assert(superc20Left == superc20Right);
}
}

0 comments on commit cfb3f68

Please sign in to comment.