-
Notifications
You must be signed in to change notification settings - Fork 982
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for
Contract.fallback_function
and `Contract.receive_function`
- Loading branch information
1 parent
8731a92
commit 5703b9d
Showing
2 changed files
with
49 additions
and
0 deletions.
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
pragma solidity ^0.6.12; | ||
|
||
contract FakeFallback { | ||
mapping(address => uint) public contributions; | ||
address payable public owner; | ||
|
||
constructor() public { | ||
owner = payable(msg.sender); | ||
contributions[msg.sender] = 1000 * (1 ether); | ||
} | ||
|
||
function fallback() public payable { | ||
contributions[msg.sender] += msg.value; | ||
} | ||
|
||
function receive() public payable { | ||
contributions[msg.sender] += msg.value; | ||
} | ||
} | ||
|
||
contract Fallback is FakeFallback { | ||
receive() external payable { | ||
contributions[msg.sender] += msg.value; | ||
} | ||
|
||
fallback() external payable { | ||
contributions[msg.sender] += msg.value; | ||
} | ||
} |
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,20 @@ | ||
from pathlib import Path | ||
from solc_select import solc_select | ||
|
||
from slither import Slither | ||
from slither.core.declarations.function import FunctionType | ||
|
||
TEST_DATA_DIR = Path(__file__).resolve().parent / "test_data" | ||
|
||
|
||
def test_fallback_receive(): | ||
solc_select.switch_global_version("0.6.12", always_install=True) | ||
file = Path(TEST_DATA_DIR, "fallback.sol").as_posix() | ||
slither = Slither(file) | ||
fake_fallback = slither.get_contract_from_name("FakeFallback")[0] | ||
real_fallback = slither.get_contract_from_name("Fallback")[0] | ||
|
||
assert fake_fallback.fallback_function is None | ||
assert fake_fallback.receive_function is None | ||
assert real_fallback.fallback_function.function_type == FunctionType.FALLBACK | ||
assert real_fallback.receive_function.function_type == FunctionType.RECEIVE |