Files
openzeppelin-contracts/contracts/mocks/ReentrancyMock.sol
Elena Gesheva 04fc35707d Migrate contracts to Solidity 0.7 (#2319)
* Update contract pragmas to solidity 0.7

* Remove internal declaration on constructors

* Reference SafeMath explicitely

* Remove public constructor declaration from abstract contracts

* Remove public constructor declaration from non-abstract contracts
2020-07-29 18:11:32 -03:00

45 lines
1.1 KiB
Solidity

// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
import "../utils/ReentrancyGuard.sol";
import "./ReentrancyAttack.sol";
contract ReentrancyMock is ReentrancyGuard {
uint256 public counter;
constructor () {
counter = 0;
}
function callback() external nonReentrant {
_count();
}
function countLocalRecursive(uint256 n) public nonReentrant {
if (n > 0) {
_count();
countLocalRecursive(n - 1);
}
}
function countThisRecursive(uint256 n) public nonReentrant {
if (n > 0) {
_count();
// solhint-disable-next-line avoid-low-level-calls
(bool success,) = address(this).call(abi.encodeWithSignature("countThisRecursive(uint256)", n - 1));
require(success, "ReentrancyMock: failed call");
}
}
function countAndCall(ReentrancyAttack attacker) public nonReentrant {
_count();
bytes4 func = bytes4(keccak256("callback()"));
attacker.callSender(func);
}
function _count() private {
counter += 1;
}
}