Skip to content

Commit

Permalink
Add test for Contract.fallback_function
Browse files Browse the repository at this point in the history
and `Contract.receive_function`
  • Loading branch information
webthethird committed Mar 28, 2023
1 parent 8731a92 commit 5703b9d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/unit/core/test_data/fallback.sol
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;
}
}
20 changes: 20 additions & 0 deletions tests/unit/core/test_fallback_receive.py
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

0 comments on commit 5703b9d

Please sign in to comment.