Skip to content

Commit

Permalink
chore: foundry migration (#40)
Browse files Browse the repository at this point in the history
* chore: track assertion failures

this is so foundry's invariant contract can check that an assertion
returned false in the handler, while still allowing `fail_on_revert =
false` so we can still take full advantage of medusa's fuzzer & coverage
reports

* fix: explicitly skip duplicate supertoken deployments

* chore: remove duplicated PROPERTIES.md file

* chore: expose data to foundry's external invariant checker

* test: run medusa fuzzing campaign from within foundry

* fix: eagerly check for duplicate deployments

* fix: feedback from doc

* chore: shoehorn medusa campaign into foundry dir structure

* chore: remove PROPERTIES.md file

* chore: delete medusa config

* docs: limited support for subdirectories in test/invariant

* chore: rename contracts to be more sneaky about medusa

* docs: rewrite invariant docs in a way compliant with autogen scripts
  • Loading branch information
0xteddybear authored Sep 5, 2024
1 parent 9d3123b commit 50df837
Show file tree
Hide file tree
Showing 20 changed files with 189 additions and 650 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,3 @@
[submodule "packages/contracts-bedrock/lib/openzeppelin-contracts-v5"]
path = packages/contracts-bedrock/lib/openzeppelin-contracts-v5
url = https://github.com/OpenZeppelin/openzeppelin-contracts
[submodule "packages/contracts-bedrock/lib/properties"]
path = packages/contracts-bedrock/lib/properties
url = https://github.com/crytic/properties
5 changes: 0 additions & 5 deletions packages/contracts-bedrock/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,3 @@ 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/'
via-ir=true
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
# `OptimismSuperchainERC20` Invariants

## Calls to sendERC20 should always succeed as long as the actor has enough balance. Actor's balance should also not increase out of nowhere but instead should decrease by the amount sent.
**Test:** [`OptimismSuperchainERC20.t.sol#L194`](../test/invariants/OptimismSuperchainERC20.t.sol#L194)
## sum of supertoken total supply across all chains is always <= to convert(legacy, super)- convert(super, legacy)
**Test:** [`OptimismSuperchainERC20#L36`](../test/invariants/OptimismSuperchainERC20#L36)



## Calls to relayERC20 should always succeeds when a message is received from another chain. Actor's balance should only increase by the amount relayed.
**Test:** [`OptimismSuperchainERC20.t.sol#L212`](../test/invariants/OptimismSuperchainERC20.t.sol#L212)
## sum of supertoken total supply across all chains is equal to convert(legacy, super)- convert(super, legacy) when all when all cross-chain messages are processed
**Test:** [`OptimismSuperchainERC20#L57`](../test/invariants/OptimismSuperchainERC20#L57)



## many other assertion mode invariants are also defined under `test/invariants/OptimismSuperchainERC20/fuzz/` .
**Test:** [`OptimismSuperchainERC20#L79`](../test/invariants/OptimismSuperchainERC20#L79)

since setting`fail_on_revert=false` also ignores StdAssertion failures, this invariant explicitly asks the handler for assertion test failures
3 changes: 0 additions & 3 deletions packages/contracts-bedrock/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ test: build-go-ffi
test-kontrol:
./test/kontrol/scripts/run-kontrol.sh script

test-medusa timeout='100':
FOUNDRY_PROFILE=medusa medusa fuzz --timeout {{timeout}}

test-rerun: build-go-ffi
forge test --rerun -vvv

Expand Down
1 change: 0 additions & 1 deletion packages/contracts-bedrock/lib/properties
Submodule properties deleted from bb1b78
86 changes: 0 additions & 86 deletions packages/contracts-bedrock/medusa.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ func docGen(invariantsDir, docsDir string) error {
// Read the contents of the invariant test file.
fileName := file.Name()
filePath := filepath.Join(invariantsDir, fileName)
// where invariants for a module have their own directory, interpret
// the test file with the same name as the directory as a 'main' of
// sorts, from where documentation is pulled
if file.IsDir() {
filePath = filepath.Join(filePath, strings.Join([]string{fileName, ".t.sol"}, ""))
}
fileContents, err := os.ReadFile(filePath)
if err != nil {
return fmt.Errorf("error reading file %q: %w", filePath, err)
Expand Down

This file was deleted.

Loading

0 comments on commit 50df837

Please sign in to comment.