Skip to content

Commit

Permalink
Merge pull request #57 from allo-protocol/test/medusa-longrun-fix
Browse files Browse the repository at this point in the history
fix(medusa): test error
  • Loading branch information
0xRaccoon authored Jan 10, 2025
2 parents ecb9b74 + c0ffee8 commit 447d8bd
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 13 deletions.
24 changes: 23 additions & 1 deletion test/invariant/fuzz/FoundryReproducer.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,27 @@ import {FuzzTest} from "./FuzzTest.t.sol";
import {Actors} from "./Setup.t.sol";

contract FoundryReproducer is FuzzTest {
function test_reproduce() public {}
function test_reproduce() public {
vm.prank(0x0000000000000000000000000000000000030000);
this.prop_userShouldBeAbleToAllocateForRecipient(
65470522219147760542297629177260492758330451046586353365186138383415357260838,
1509582196578503177461010778390437972531468713191143884749957185113494224093,
89229295462212643039624780950210918505109522327
);
vm.prank(0x0000000000000000000000000000000000060000);
this.prop_anyoneCanIncreaseFundInAPool(
90478538821160176029553084342971992267408980458414155569537349510758777025,
34975190900157507771765603026738285331613690897913920486807842265001996323842
);
vm.prank(0x0000000000000000000000000000000000010000);
this.prop_userShouldBeAbleToAllocateForRecipient(
15399640836418672336170156801852452249328667064094080731578185228974333700948, 0, 0
);
vm.prank(0x0000000000000000000000000000000000080000);
this.prop_poolManagerShouldBeAbleToDistributeToRecipient(
12597593260854621660063764814177296654485874981570297329262025885303773529766,
130562404660594923429462152262227885253804884096052314249779392188261064,
364185190279861233828574312957711184182191084776794442650732427845193
);
}
}
2 changes: 1 addition & 1 deletion test/invariant/fuzz/helpers/FuzzBaseStrategy.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ contract FuzzBaseStrategy is BaseStrategy {
override
{
for (uint256 i = 0; i < _recipients.length; i++) {
allocated[_recipients[i]] = _amounts[i];
allocated[_recipients[i]] += _amounts[i];
}
}

Expand Down
24 changes: 13 additions & 11 deletions test/invariant/fuzz/properties/PropertiesStrategies.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,19 @@ contract PropertiesStrategies is HandlersParent {
? abi.encode(token, new bytes(0))
: abi.encode(_tokens);

// Needed for direct allocation
token.transfer(_allocator, _amount);
_actor.callThroughAnchor(address(token), 0, abi.encodeCall(ERC20.approve, (address(_strategy), _amount)));
// DirectAllocation distribute when allocate is called
if (_poolStrategy(_strategy) == PoolStrategies.DirectAllocation) {
token.transfer(_allocator, _amount);
_actor.callThroughAnchor(address(token), 0, abi.encodeCall(ERC20.approve, (address(_strategy), _amount)));
}

(bool _success, bytes memory _ret) = _actor.callThroughAnchor(
address(allo), 0, abi.encodeCall(allo.allocate, (_poolId, _recipients, _amounts, _data))
);

if (_success) {
// Check strategy specific post-conditions
_assertValidAllocate(payable(_strategy), _allocator, _recipient, _amount);
_assertValidAllocate(_poolId, _allocator, _recipient, _amount);

if (_poolStrategy(_strategy) == PoolStrategies.DirectAllocation) {
// allocation is directly distributed
Expand All @@ -100,8 +102,7 @@ contract PropertiesStrategies is HandlersParent {
function prop_poolManagerShouldBeAbleToDistributeToRecipient(
uint256 _idSeed,
uint256 _managerSeed,
uint256 _actorSeed,
uint256 _amount
uint256 _actorSeed
) public {
address _recipient = address(_currentActor());
address[] memory _recipients = new address[](1);
Expand Down Expand Up @@ -131,7 +132,7 @@ contract PropertiesStrategies is HandlersParent {
// Allocation if there is one
assertTrue(_hasAllocation, "property-id 3: Distribution succeeded without allocation");

ghost_totalWithdrawn += _amount;
ghost_totalWithdrawn += _recipientNewBalance - _recipientPreviousBalance;
} else {
// Revert if:
// - There is no allocation
Expand Down Expand Up @@ -176,9 +177,9 @@ contract PropertiesStrategies is HandlersParent {
//

// Check strategy dependent post-conditions if a call to allocate is successful
function _assertValidAllocate(address payable _strategy, address _allocator, address _recipient, uint256 _amount)
internal
{
function _assertValidAllocate(uint256 _poolId, address _allocator, address _recipient, uint256 _amount) internal {
address _strategy = address(allo.getPool(_poolId).strategy);

if (
_poolStrategy(_strategy) == PoolStrategies.QuadraticVoting
|| _poolStrategy(_strategy) == PoolStrategies.ImpactStream
Expand All @@ -195,7 +196,8 @@ contract PropertiesStrategies is HandlersParent {
);
} else if (_poolStrategy(_strategy) == PoolStrategies.FuzzBaseStrategy) {
assertTrue(
FuzzBaseStrategy(_strategy).allocated(_recipient) == _amount,
FuzzBaseStrategy(payable(_strategy)).allocated(_recipient)
== ghost_allocations[_poolId][address(_recipient)] + _amount,
"property-id 1 Fuzz: wrong amount allocated"
);
} else if (_poolStrategy(_strategy) == PoolStrategies.DirectAllocation) {
Expand Down

0 comments on commit 447d8bd

Please sign in to comment.