Skip to content
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

Mistake in the last block of Invariant tests #1032

Open
cryptonomicon46 opened this issue Oct 29, 2023 · 0 comments
Open

Mistake in the last block of Invariant tests #1032

cryptonomicon46 opened this issue Oct 29, 2023 · 0 comments

Comments

@cryptonomicon46
Copy link

The chapter on invariant tests, Link
ends with the following block of code explaining how the actors are fuzzed.

function deposit(
    uint256 assets,
    uint256 actorIndexSeed
) public virtual useActor(actorIndexSeed) {
    asset.mint(currentActor, assets);

    asset.approve(address(token), assets);

    uint256 beforeBalance = asset.balanceOf(address(this)); //@Issue

    uint256 shares = token.deposit(assets, address(this));

    assertEq(asset.balanceOf(address(this)), beforeBalance - assets);

    sumBalanceOf += shares;

    sumDeposits[currentActor] += assets
}

However, in this case, since the useActor(actorIndexSeed) results in the asset being minted to the currentActor.
The beforeBalance should be accounted for the currentActor and not for address(this).

uint256 beforeBalance = asset.balanceOf(currentActor)); 

Further, to make this test accurate, the minted shares should go to the the currentActor by setting them as the receiver.
And then the balance check should be performed on the currentActor as detailed below.

 uint256 shares = token.deposit(assets,currentActor);
assertEq(asset.balanceOf(currentActor), beforeBalance - assets);

Here's the corrected block of code.

// Unbounded
function deposit(
    uint256 assets,
    uint256 actorIndexSeed
) public virtual useActor(actorIndexSeed) {
    asset.mint(currentActor, assets);

    asset.approve(address(token), assets);

    uint256 beforeBalance = asset.balanceOf(currentActor); //@Issue

    uint256 shares = token.deposit(assets, address(this));

    assertEq(asset.balanceOf(currentActor), beforeBalance - assets);

    sumBalanceOf += shares;

    sumDeposits[currentActor] += assets
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

No branches or pull requests

1 participant