-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Medusa swap tests #1167
Open
elshan-eth
wants to merge
39
commits into
main
Choose a base branch
from
medusa-swap-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Medusa swap tests #1167
Changes from 37 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
24902af
init stateful fuzz harness
bohendo 374ff25
Merge branch 'main' into medusa-fuzz-tests
joaobrunoah 91003e0
Medusa Base Test
joaobrunoah c892b54
Implement Stateful tests with Medusa
joaobrunoah 4cfd5bb
Merge branch 'main' into medusa-add-remove-test
joaobrunoah 44e71fd
Lint
joaobrunoah b21e28b
Fix Medusa tests
joaobrunoah 680bd02
Merge branch 'main' into medusa-add-remove-test
joaobrunoah cba2ae1
Merge branch 'main' into medusa-add-remove-test
joaobrunoah 86d3f6f
Remove unused test contract
joaobrunoah de2c8d7
Remove stale comment
joaobrunoah 7a8b83c
Improve documentation
joaobrunoah 6502799
Remove Echidna configuration
joaobrunoah 37af832
Replace Tabs by spaces
joaobrunoah dc7b881
Fix weights boundaries
joaobrunoah d20d6a9
Fix comments
joaobrunoah 453b82a
Fix WETH token in Medusa
joaobrunoah 4a90c76
Remove getBalancesLength function.
joaobrunoah 97cf79d
Comments
joaobrunoah 78c819f
Remove getBptRate implementation
joaobrunoah c46ac2e
Fix initial pool balances
joaobrunoah 965170e
Comment
joaobrunoah bc7f83e
Set swap fee percentage to 0
joaobrunoah 138080f
Merge branch 'main' into medusa-add-remove-test
joaobrunoah fb03881
Fix comment
joaobrunoah 64eeb64
Merge branch 'main' into medusa-add-remove-test
joaobrunoah 7bc5bd5
Fix constant
joaobrunoah d527849
Merge branch 'main' into medusa-add-remove-test
joaobrunoah d3c03d0
add main swap medusa tests
elshan-eth 7a83ab8
fix swap medusa tests
elshan-eth 9bb49e5
fix bound
elshan-eth bd5eb70
fix swap medusa tests
elshan-eth 58ba4c8
fix medusa config
elshan-eth a291997
Merge branch 'main' into medusa-add-remove-test
joaobrunoah 9a53d80
Fix medusa
joaobrunoah 50603e2
add tests for stable and weighted pools
elshan-eth ae9b5c5
Merge branch 'medusa-add-remove-test' into medusa-swap-tests
elshan-eth 0fb160d
Merge branch 'main' into medusa-swap-tests
joaobrunoah 52e42f1
small fixes
elshan-eth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,3 +50,7 @@ slither/ | |
# Misc | ||
.vscode/ | ||
.idea/ | ||
|
||
# Fuzz tests | ||
crytic-export/ | ||
medusa-corpus/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
pragma solidity ^0.8.24; | ||
|
||
interface IStdMedusaCheats { | ||
// Set block.timestamp | ||
function warp(uint256) external; | ||
|
||
// Set block.number | ||
function roll(uint256) external; | ||
|
||
// Set block.basefee | ||
function fee(uint256) external; | ||
|
||
// Set block.difficulty and block.prevrandao | ||
function difficulty(uint256) external; | ||
|
||
// Set block.chainid | ||
function chainId(uint256) external; | ||
|
||
// Sets the block.coinbase | ||
function coinbase(address) external; | ||
|
||
// Loads a storage slot from an address | ||
function load(address account, bytes32 slot) external returns (bytes32); | ||
|
||
// Stores a value to an address' storage slot | ||
function store(address account, bytes32 slot, bytes32 value) external; | ||
|
||
// Sets the *next* call's msg.sender to be the input address | ||
function prank(address) external; | ||
|
||
// Set msg.sender to the input address until the current call exits | ||
function prankHere(address) external; | ||
|
||
// Sets an address' balance | ||
function deal(address who, uint256 newBalance) external; | ||
|
||
// Sets an address' code | ||
function etch(address who, bytes calldata code) external; | ||
|
||
// Signs data | ||
function sign(uint256 privateKey, bytes32 digest) external returns (uint8 v, bytes32 r, bytes32 s); | ||
|
||
// Computes address for a given private key | ||
function addr(uint256 privateKey) external returns (address); | ||
|
||
// Gets the nonce of an account | ||
function getNonce(address account) external returns (uint64); | ||
|
||
// Sets the nonce of an account | ||
// The new nonce must be higher than the current nonce of the account | ||
function setNonce(address account, uint64 nonce) external; | ||
|
||
// Performs a foreign function call via terminal | ||
function ffi(string[] calldata) external returns (bytes memory); | ||
|
||
// Take a snapshot of the current state of the EVM | ||
function snapshot() external returns (uint256); | ||
|
||
// Revert state back to a snapshot | ||
function revertTo(uint256) external returns (bool); | ||
|
||
// Convert Solidity types to strings | ||
function toString(address) external returns (string memory); | ||
|
||
function toString(bytes calldata) external returns (string memory); | ||
|
||
function toString(bytes32) external returns (string memory); | ||
|
||
function toString(bool) external returns (string memory); | ||
|
||
function toString(uint256) external returns (string memory); | ||
|
||
function toString(int256) external returns (string memory); | ||
|
||
// Convert strings into Solidity types | ||
function parseBytes(string memory) external returns (bytes memory); | ||
|
||
function parseBytes32(string memory) external returns (bytes32); | ||
|
||
function parseAddress(string memory) external returns (address); | ||
|
||
function parseUint(string memory) external returns (uint256); | ||
|
||
function parseInt(string memory) external returns (int256); | ||
|
||
function parseBool(string memory) external returns (bool); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
{ | ||
"fuzzing": { | ||
"workers": 10, | ||
"workerResetLimit": 50, | ||
"timeout": 0, | ||
"testLimit": 100000, | ||
"shrinkLimit": 5000, | ||
"callSequenceLength": 10, | ||
"corpusDirectory": "medusa-corpus", | ||
"coverageEnabled": true, | ||
"targetContracts": ["AddAndRemoveLiquidityStableMedusaTest", "SwapMedusaTest"], | ||
"predeployedContracts": {}, | ||
"targetContractsBalances": [], | ||
"constructorArgs": {}, | ||
"deployerAddress": "0x30000", | ||
"senderAddresses": [ | ||
"0x10000", | ||
"0x20000", | ||
"0x30000" | ||
], | ||
"blockNumberDelayMax": 60480, | ||
"blockTimestampDelayMax": 604800, | ||
"blockGasLimit": 1250000000, | ||
"transactionGasLimit": 125000000, | ||
"testing": { | ||
"stopOnFailedTest": false, | ||
"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": true, | ||
"testPrefixes": [ | ||
"property_" | ||
] | ||
}, | ||
"optimizationTesting": { | ||
"enabled": true, | ||
"testPrefixes": [ | ||
"optimize_" | ||
] | ||
}, | ||
"targetFunctionSignatures": [], | ||
"excludeFunctionSignatures": [] | ||
}, | ||
"chainConfig": { | ||
"codeSizeCheckDisabled": true, | ||
"cheatCodes": { | ||
"cheatCodesEnabled": true, | ||
"enableFFI": true | ||
} | ||
} | ||
}, | ||
"compilation": { | ||
"platform": "crytic-compile", | ||
"platformConfig": { | ||
"target": ".", | ||
"solcVersion": "", | ||
"exportDirectory": "", | ||
"args": ["--foundry-out-directory=forge-artifacts", "--foundry-compile-all"] | ||
} | ||
}, | ||
"logging": { | ||
"level": "info", | ||
"logDirectory": "", | ||
"noColor": false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
pkg/pool-stable/test/foundry/fuzz/AddAndRemoveLiquidityStable.medusa.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
pragma solidity ^0.8.24; | ||
|
||
import "forge-std/Test.sol"; | ||
|
||
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
|
||
import { IVault } from "@balancer-labs/v3-interfaces/contracts/vault/IVault.sol"; | ||
import "@balancer-labs/v3-interfaces/contracts/vault/VaultTypes.sol"; | ||
|
||
import { InputHelpers } from "@balancer-labs/v3-solidity-utils/contracts/helpers/InputHelpers.sol"; | ||
|
||
import { | ||
AddAndRemoveLiquidityMedusaTest | ||
} from "@balancer-labs/v3-vault/test/foundry/fuzz/AddAndRemoveLiquidity.medusa.sol"; | ||
|
||
import { StablePoolFactory } from "../../../contracts/StablePoolFactory.sol"; | ||
import { StablePool } from "../../../contracts/StablePool.sol"; | ||
|
||
contract AddAndRemoveLiquidityStableMedusaTest is AddAndRemoveLiquidityMedusaTest { | ||
uint256 private constant DEFAULT_SWAP_FEE = 1e16; | ||
uint256 internal constant _AMPLIFICATION_PARAMETER = 1000; | ||
|
||
constructor() AddAndRemoveLiquidityMedusaTest() { | ||
maxRateTolerance = 0; | ||
} | ||
|
||
function createPool( | ||
IERC20[] memory tokens, | ||
uint256[] memory initialBalances | ||
) internal override returns (address newPool) { | ||
StablePoolFactory factory = new StablePoolFactory(IVault(address(vault)), 365 days, "Factory v1", "Pool v1"); | ||
PoolRoleAccounts memory roleAccounts; | ||
|
||
StablePool newPool = StablePool( | ||
factory.create( | ||
"Stable Pool", | ||
"STABLE", | ||
vault.buildTokenConfig(tokens), | ||
_AMPLIFICATION_PARAMETER, | ||
roleAccounts, | ||
DEFAULT_SWAP_FEE, // Swap fee is set to 0 in the test constructor | ||
address(0), // No hooks | ||
false, // Do not enable donations | ||
false, // Do not disable unbalanced add/remove liquidity | ||
// NOTE: sends a unique salt. | ||
bytes32(poolCreationNonce++) | ||
) | ||
); | ||
|
||
// Initialize liquidity of stable pool. | ||
medusa.prank(lp); | ||
router.initialize(address(newPool), tokens, initialBalances, 0, false, bytes("")); | ||
|
||
return address(newPool); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
pragma solidity ^0.8.24; | ||
|
||
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
|
||
import { IVault } from "@balancer-labs/v3-interfaces/contracts/vault/IVault.sol"; | ||
import "@balancer-labs/v3-interfaces/contracts/vault/VaultTypes.sol"; | ||
|
||
import { SwapMedusaTest } from "@balancer-labs/v3-vault/test/foundry/fuzz/Swap.medusa.sol"; | ||
|
||
import { StablePoolFactory } from "../../../contracts/StablePoolFactory.sol"; | ||
import { StablePool } from "../../../contracts/StablePool.sol"; | ||
|
||
contract SwapStableMedusaTest is SwapMedusaTest { | ||
uint256 private constant DEFAULT_SWAP_FEE = 1e16; | ||
uint256 internal constant _AMPLIFICATION_PARAMETER = 1000; | ||
|
||
constructor() SwapMedusaTest() {} | ||
|
||
function createPool( | ||
IERC20[] memory tokens, | ||
uint256[] memory initialBalances | ||
) internal override returns (address newPool) { | ||
StablePoolFactory factory = new StablePoolFactory(IVault(address(vault)), 365 days, "Factory v1", "Pool v1"); | ||
PoolRoleAccounts memory roleAccounts; | ||
|
||
StablePool newPool = StablePool( | ||
factory.create( | ||
"Stable Pool", | ||
"STABLE", | ||
vault.buildTokenConfig(tokens), | ||
_AMPLIFICATION_PARAMETER, | ||
roleAccounts, | ||
DEFAULT_SWAP_FEE, // Swap fee is set to 0 in the test constructor | ||
address(0), // No hooks | ||
false, // Do not enable donations | ||
false, // Do not disable unbalanced add/remove liquidity | ||
// NOTE: sends a unique salt. | ||
bytes32(poolCreationNonce++) | ||
) | ||
); | ||
|
||
// Initialize liquidity of stable pool. | ||
medusa.prank(lp); | ||
router.initialize(address(newPool), tokens, initialBalances, 0, false, bytes("")); | ||
|
||
return address(newPool); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
{ | ||
"fuzzing": { | ||
"workers": 10, | ||
"workerResetLimit": 50, | ||
"timeout": 0, | ||
"testLimit": 100000, | ||
"shrinkLimit": 5000, | ||
"callSequenceLength": 10, | ||
"corpusDirectory": "medusa-corpus", | ||
"coverageEnabled": true, | ||
"targetContracts": ["AddAndRemoveLiquidityWeightedMedusaTest", "SwapMedusaTest"], | ||
"predeployedContracts": {}, | ||
"targetContractsBalances": [], | ||
"constructorArgs": {}, | ||
"deployerAddress": "0x30000", | ||
"senderAddresses": ["0x10000", "0x20000", "0x30000"], | ||
"blockNumberDelayMax": 60480, | ||
"blockTimestampDelayMax": 604800, | ||
"blockGasLimit": 1250000000, | ||
"transactionGasLimit": 125000000, | ||
"testing": { | ||
"stopOnFailedTest": false, | ||
"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": true, | ||
"testPrefixes": ["property_"] | ||
}, | ||
"optimizationTesting": { | ||
"enabled": true, | ||
"testPrefixes": ["optimize_"] | ||
}, | ||
"targetFunctionSignatures": [], | ||
"excludeFunctionSignatures": [] | ||
}, | ||
"chainConfig": { | ||
"codeSizeCheckDisabled": true, | ||
"cheatCodes": { | ||
"cheatCodesEnabled": true, | ||
"enableFFI": true | ||
} | ||
} | ||
}, | ||
"compilation": { | ||
"platform": "crytic-compile", | ||
"platformConfig": { | ||
"target": ".", | ||
"solcVersion": "", | ||
"exportDirectory": "", | ||
"args": ["--foundry-out-directory=forge-artifacts", "--foundry-compile-all"] | ||
} | ||
}, | ||
"logging": { | ||
"level": "info", | ||
"logDirectory": "", | ||
"noColor": false | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Older versions of Medusa conflicted here (I was using 0.1.16 and it did not work), but upgrading to 0.1.18 made it work. Much better to have actions in different files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean we need to have two
medusa.json
settings for each medusa test file?