-
Notifications
You must be signed in to change notification settings - Fork 378
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
104 additions
and
1 deletion.
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
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,94 @@ | ||
interface IHevm { | ||
function prank(address newSender) external; | ||
function startPrank(address sender) external; | ||
function stopPrank() external; | ||
} | ||
|
||
contract ExpectedCreator { | ||
event Sender(address); | ||
event AssertionFailed(string); | ||
IHevm constant vm = IHevm(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D); | ||
|
||
constructor(address s) public { | ||
if (s != msg.sender) { | ||
emit Sender(msg.sender); | ||
emit AssertionFailed("fail on construct"); | ||
} | ||
} | ||
} | ||
|
||
contract SenderVerifierChild { | ||
event Sender(address); | ||
event AssertionFailed(string); | ||
IHevm constant vm = IHevm(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D); | ||
|
||
function verifyMsgSender(address s) public { | ||
if (s != msg.sender) { | ||
emit Sender(msg.sender); | ||
emit AssertionFailed("fail on inner call"); | ||
} | ||
} | ||
} | ||
|
||
contract SenderVerifierParent { | ||
event Sender(address); | ||
event AssertionFailed(string); | ||
IHevm constant vm = IHevm(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D); | ||
|
||
SenderVerifierChild c; | ||
constructor() public { | ||
c = new SenderVerifierChild(); | ||
} | ||
|
||
function verifyMsgSender(address s) public { | ||
if (s != msg.sender) { | ||
emit Sender(msg.sender); | ||
emit AssertionFailed("fail on first call"); | ||
} | ||
c.verifyMsgSender(address(this)); | ||
new ExpectedCreator(address(this)); | ||
} | ||
} | ||
|
||
contract TestPrank { | ||
IHevm constant vm = IHevm(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D); | ||
|
||
SenderVerifierParent p; | ||
constructor() public { | ||
p = new SenderVerifierParent(); | ||
} | ||
|
||
function withPrank() public { | ||
vm.prank(address(0x123)); | ||
p.verifyMsgSender(address(0x123)); | ||
p.verifyMsgSender(address(this)); | ||
|
||
vm.prank(address(0x123)); | ||
new ExpectedCreator(address(0x123)); | ||
new ExpectedCreator(address(this)); | ||
} | ||
|
||
function withStartPrank() public { | ||
vm.startPrank(address(0x123)); | ||
p.verifyMsgSender(address(0x123)); | ||
p.verifyMsgSender(address(0x123)); | ||
new ExpectedCreator(address(0x123)); | ||
new ExpectedCreator(address(0x123)); | ||
} | ||
|
||
function withStartPrankStopPrank() public { | ||
vm.startPrank(address(0x123)); | ||
p.verifyMsgSender(address(0x123)); | ||
p.verifyMsgSender(address(0x123)); | ||
new ExpectedCreator(address(0x123)); | ||
new ExpectedCreator(address(0x123)); | ||
vm.stopPrank(); | ||
p.verifyMsgSender(address(this)); | ||
new ExpectedCreator(address(this)); | ||
} | ||
|
||
function withNothing() public { | ||
p.verifyMsgSender(address(this)); | ||
new ExpectedCreator(address(this)); | ||
} | ||
} |
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,3 @@ | ||
testLimit: 1000 | ||
seqLen: 10 | ||
testMode: assertion |