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

Align prank behavior to Foundry #190

Open
palinatolmach opened this issue Nov 20, 2023 · 0 comments
Open

Align prank behavior to Foundry #190

palinatolmach opened this issue Nov 20, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@palinatolmach
Copy link
Collaborator

Follow up to #120 and #110.
Related: #124.

Based on a Slack discussion with @hjorthjort and @anvacaru: in Foundry, prank is not effective when the test contract calls a function that is defined in a contract that the test is inherited from. With Foundry, all tests in the following contract pass:

// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.6.2 <0.9.0;

import "forge-std/Test.sol";
import "forge-std/Vm.sol";
import "../src/timetravel/CallBreaker.sol";


contract PrankParent is Test {
  function parentFunction(address p) public {
    assertEq(p,msg.sender);
  }
}

contract External is Test {
  constructor(address p) {
    assertEq(p,msg.sender);
  }

  function externalFunction(address p) public {
    assertEq(p,msg.sender);
  }
}

contract PrankTest is PrankParent {

  function test_startP(address p) public {
    address sender = msg.sender;
    vm.startPrank(p);
    assertEq(msg.sender, sender);
    localFunc(sender);
    parentFunction(sender);
    External e = new External(p);
    e.externalFunction(p);
    vm.stopPrank();
  }

  function test_p(address p) public {
    vm.prank(p); External e = new External(p);
    address sender = msg.sender;
    vm.prank(p); assertEq(msg.sender, sender); e.externalFunction(p);
    vm.prank(p); localFunc(sender); e.externalFunction(p);
    vm.prank(p); parentFunction(sender); e.externalFunction(p);
    vm.prank(p); e.externalFunction(p);
  }


  function localFunc(address p) public {
    assertEq(p,msg.sender);
  }
}

In addition, vm.prank(x); vm.prank(x); causes a runtime failure in Foundry, while, in Kontrol, we insert a prank only if no other is active (source); this specific scenario is not handled, so the configuration would get stuck. We have a test for this here.

We should align prank-related behavior of Kontrol with Foundry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants